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



##########
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:
       @Pearl1594 
   I just read the cloudstack document 
http://docs.cloudstack.apache.org/en/latest/adminguide/networking/persistent_networks.html
   which was updated by 
https://github.com/apache/cloudstack-documentation/pull/183
   
   The only thing different from what I understand is
   ```
   -  Creation of an L2 Persistent network setups up the network devices namely,
      bridges, VLANs or port-groups across all hosts in a zone.
   ```
   
   I do not see the benifit to have permanent linux bridges but without any vm 
on kvm hosts.
   I have no idea it is useful for vmware or xenserver.
   
   in my understanding, `persistent network` means the network will not be 
shutdown even if no vm running. therefore vlan will be released/re-allocated, 
virtual router will not be stopped, which are useful for network administrators 
and users.




-- 
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