Pearl1594 commented on a change in pull request #5977:
URL: https://github.com/apache/cloudstack/pull/5977#discussion_r812979696



##########
File path: 
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
##########
@@ -142,11 +192,63 @@ public boolean hostDisconnected(long hostId, long poolId) 
{
 
     @Override
     public boolean hostAboutToBeRemoved(long hostId) {
+        // send host the cleanup persistent network resources
+        HostVO host = hostDao.findById(hostId);
+        if (host == null) {
+            s_logger.warn("Host with id " + hostId + " can't be found");
+            return false;
+        }
+
+        List<NetworkVO> allPersistentNetworks = 
networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId()); // find 
zoneId of host
+        for (NetworkVO persistentNetworkVO : allPersistentNetworks) {
+            NetworkOfferingVO networkOfferingVO = 
networkOfferingDao.findById(persistentNetworkVO.getNetworkOfferingId());
+            CleanupPersistentNetworkResourceCommand cleanupCmd =
+                    new 
CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO,
 networkOfferingVO, host));
+            Answer answer = agentMgr.easySend(hostId, cleanupCmd);
+            if (answer == null) {
+                s_logger.error("Unable to get answer to the cleanup persistent 
network command " + persistentNetworkVO.getId());
+                continue;
+            }
+            if (!answer.getResult()) {
+                String msg = String.format("Unable to cleanup persistent 
network resources from network %d on the host %d", persistentNetworkVO.getId(), 
hostId);
+               s_logger.error(msg);
+            }
+        }
         return true;
     }
 
     @Override
     public boolean hostRemoved(long hostId, long clusterId) {
         return true;
     }
+
+    @Override
+    public boolean hostEnabled(long hostId) {
+        HostVO host = hostDao.findById(hostId);
+        if (host == null) {
+            s_logger.warn(String.format("Host with id %d can't be found", 
hostId));
+            return false;
+        }
+        setupPersistentNetwork(host);
+        return true;
+    }
+
+    private void setupPersistentNetwork(HostVO host) {

Review comment:
       So, we had persistent networks in ACS - and by definition, these 
networks are meant to be setup at the time of network created across all hosts. 
However, while the definition in the docs said that, it didn't actually behave 
that way. So when a new host is added no bridge/vlan/port-group of the existing 
persistent network is present. So the idea of this enhancement, is to setup 
network on the new hosts or when disable hosts are enabled to stay true to the 
definition of Persistent networks as per docs.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to