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



##########
File path: 
engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -1827,6 +1848,63 @@ private void orchestrateStop(final String vmUuid, final 
boolean cleanUpEvenIfUna
         advanceStop(vm, cleanUpEvenIfUnableToStop);
     }
 
+    private void getPersistenceMap(Map<String, Boolean> vlanToPersistenceMap, 
NetworkVO networkVO) {
+        NetworkOfferingVO offeringVO = 
networkOfferingDao.findById(networkVO.getNetworkOfferingId());
+        if (offeringVO != null) {
+            Pair<String, Boolean> data = getVMNetworkDetails(networkVO, 
offeringVO.isPersistent());
+            Boolean shouldDeleteNwResource = 
(MapUtils.isNotEmpty(vlanToPersistenceMap) && data != null) ? 
vlanToPersistenceMap.get(data.first()) : null;
+            if (data != null && (shouldDeleteNwResource == null || 
shouldDeleteNwResource)) {
+                vlanToPersistenceMap.put(data.first(), data.second());
+            }
+        }
+    }
+
+    private Map<String, Boolean> getVlanToPersistenceMapForVM(long vmId) {
+        List<UserVmJoinVO> userVmJoinVOS = userVmJoinDao.searchByIds(vmId);
+        Map<String, Boolean> vlanToPersistenceMap = new HashMap<>();
+        for (UserVmJoinVO userVmJoinVO : userVmJoinVOS) {
+            NetworkVO networkVO = 
_networkDao.findById(userVmJoinVO.getNetworkId());
+            getPersistenceMap(vlanToPersistenceMap, networkVO);
+        }
+        if (userVmJoinVOS.isEmpty()) {
+            VMInstanceVO vmInstanceVO = _vmDao.findById(vmId);
+            if (vmInstanceVO != null && vmInstanceVO.getType() == 
VirtualMachine.Type.DomainRouter) {
+                DomainRouterJoinVO routerVO = 
domainRouterJoinDao.findById(vmId);
+                NetworkVO networkVO = 
_networkDao.findById(routerVO.getNetworkId());
+                getPersistenceMap(vlanToPersistenceMap, networkVO);
+            }
+        }
+        return vlanToPersistenceMap;
+    }
+
+    /**
+     *
+     * @param networkVO - the network object used to determine the vlanId from 
the broadcast URI
+     * @param isPersistent - indicates if the corresponding network's network 
offering is Persistent
+     *
+     * @return <VlanId, ShouldKVMBridgeBeDeleted> - basically returns the vlan 
ID which is used to determine the
+     * bridge name for KVM hypervisor and based on the network and isolation 
type and persistent setting of the offering
+     * we decide whether the bridge is to be deleted (KVM) if the last VM in 
that host is destroyed / migrated
+     */
+    private Pair<String, Boolean> getVMNetworkDetails(NetworkVO networkVO, 
boolean isPersistent) {
+        URI broadcastUri = networkVO.getBroadcastUri();
+        if (broadcastUri != null) {
+            String scheme = broadcastUri.getScheme();
+            String vlanId = 
Networks.BroadcastDomainType.getValue(broadcastUri);
+            boolean shouldDelete = !((networkVO.getGuestType() == 
Network.GuestType.L2 || networkVO.getGuestType() == Network.GuestType.Isolated) 
&&

Review comment:
       L2 persistence mode isn't supported for VxLAN isolation type




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

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


Reply via email to