You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/03/09 19:39:46 UTC

[GitHub] [cloudstack] GabrielBrascher commented on a change in pull request #4701: Added support for removing unused port groups on VMWare

GabrielBrascher commented on a change in pull request #4701:
URL: https://github.com/apache/cloudstack/pull/4701#discussion_r590653001



##########
File path: plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -5732,16 +5733,24 @@ protected Answer execute(UnregisterNicCommand cmd) {
     }
 
     public void cleanupNetwork(HostMO hostMo, NetworkDetails netDetails) {
-        // we will no longer cleanup VLAN networks in order to support native VMware HA
-        /*
-         * assert(netDetails.getName() != null); try { synchronized(this) { NetworkMO networkMo = new
-         * NetworkMO(hostMo.getContext(), netDetails.getNetworkMor()); ManagedObjectReference[] vms =
-         * networkMo.getVMsOnNetwork(); if(vms == null || vms.length == 0) { if(s_logger.isInfoEnabled()) {
-         * s_logger.info("Cleanup network as it is currently not in use: " + netDetails.getName()); }
-         *
-         * hostMo.deletePortGroup(netDetails.getName()); } } } catch(Throwable e) {
-         * s_logger.warn("Unable to cleanup network due to exception, skip for next time"); }
-         */
+        if (!VmwareManager.s_vmwareCleanupPortGroups.value()){
+            return;
+        }
+        assert(netDetails.getName() != null);
+        try {
+            synchronized(this) {
+                NetworkMO networkMo = new NetworkMO(hostMo.getContext(), netDetails.getNetworkMor());
+                List<ManagedObjectReference> vms = networkMo.getVMsOnNetwork();
+                if(vms == null || vms.size() == 0) {

Review comment:
       @GutoVeronezi `vms.isEmpty()` is a nice option indeed. I would suggest [CollectionsUtils.isEmpty(vms)](https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/CollectionUtils.html#isEmpty-java.util.Collection-) as it is a null safe validation.
   
   `if(vms == null || vms.size() == 0) {` :arrow_right: `if (CollectionUtils.isEmpty(vms)) {`
   
   
   

##########
File path: plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -5732,16 +5733,24 @@ protected Answer execute(UnregisterNicCommand cmd) {
     }
 
     public void cleanupNetwork(HostMO hostMo, NetworkDetails netDetails) {
-        // we will no longer cleanup VLAN networks in order to support native VMware HA
-        /*
-         * assert(netDetails.getName() != null); try { synchronized(this) { NetworkMO networkMo = new
-         * NetworkMO(hostMo.getContext(), netDetails.getNetworkMor()); ManagedObjectReference[] vms =
-         * networkMo.getVMsOnNetwork(); if(vms == null || vms.length == 0) { if(s_logger.isInfoEnabled()) {
-         * s_logger.info("Cleanup network as it is currently not in use: " + netDetails.getName()); }
-         *
-         * hostMo.deletePortGroup(netDetails.getName()); } } } catch(Throwable e) {
-         * s_logger.warn("Unable to cleanup network due to exception, skip for next time"); }
-         */
+        if (!VmwareManager.s_vmwareCleanupPortGroups.value()){
+            return;
+        }
+        assert(netDetails.getName() != null);

Review comment:
       I would recommend using an `if` statement in the place of the `assert`. It would allow launching an exception with a  verbose log message regarding the network cleanup failure.
   
   But no problem at all, assert is fine here if you prefer.




----------------------------------------------------------------
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:
users@infra.apache.org