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



##########
File path: 
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -1622,6 +1589,83 @@ private ExecutionResult 
prepareNetworkElementCommand(IpAssocCommand cmd) {
         return new ExecutionResult(true, null);
     }
 
+    private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            IpAddressTO[] ips = cmd.getIpAddresses();
+            String routerName = 
cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
+            // command may sometimes be redirected to a wrong host, we relax
+            // the check and will try to find it within datacenter
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    final DatacenterMO dcMo = new DatacenterMO(context, 
hyperHost.getHyperHostDatacenter());
+                    vmMo = dcMo.findVm(routerName);
+                }
+            }
+
+            if (vmMo == null) {
+                String msg = String.format("Router %s no longer exists to 
execute IPAssoc command ", routerName);
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+            final String lastIp = 
cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
+            if (ips.length == 1 && !ips[0].isAdd()) {
+                Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo, 
ips[0]);
+
+                if (nicInfo.first() == null && 
lastIp.equalsIgnoreCase("true")) {
+                    if (nicInfo.second() == 2) {
+                        return new ExecutionResult(false, "Unable to remove 
eth2 in network VR because it is the public NIC of source NAT");
+                    }
+                    return new ExecutionResult(false, "Couldn't find NIC");
+                }
+                configureNicDevice(vmMo, nicInfo.first(), 
VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand");

Review comment:
       @Pearl1594 
   nic can be unplugged only if `lastIp.equalsIgnoreCase("true")`
   
   
https://github.com/apache/cloudstack/blob/593f1b698836749856f38f706b30b23a660d26a3/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java#L2129-L2136
   

##########
File path: 
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -1622,6 +1589,83 @@ private ExecutionResult 
prepareNetworkElementCommand(IpAssocCommand cmd) {
         return new ExecutionResult(true, null);
     }
 
+    private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            IpAddressTO[] ips = cmd.getIpAddresses();
+            String routerName = 
cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
+            // command may sometimes be redirected to a wrong host, we relax
+            // the check and will try to find it within datacenter
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    final DatacenterMO dcMo = new DatacenterMO(context, 
hyperHost.getHyperHostDatacenter());
+                    vmMo = dcMo.findVm(routerName);
+                }
+            }
+
+            if (vmMo == null) {
+                String msg = String.format("Router %s no longer exists to 
execute IPAssoc command ", routerName);
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+            final String lastIp = 
cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
+            if (ips.length == 1 && !ips[0].isAdd()) {
+                Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo, 
ips[0]);
+
+                if (nicInfo.first() == null && 
lastIp.equalsIgnoreCase("true")) {
+                    if (nicInfo.second() == 2) {
+                        return new ExecutionResult(false, "Unable to remove 
eth2 in network VR because it is the public NIC of source NAT");
+                    }
+                    return new ExecutionResult(false, "Couldn't find NIC");

Review comment:
       return a success if no need to unplug the nic ?




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