GutoVeronezi commented on code in PR #5938:
URL: https://github.com/apache/cloudstack/pull/5938#discussion_r856531949


##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -1804,9 +1804,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) {
             networkUsage(privateIp, "create", null);
         }
 
+        if (VirtualMachineName.isValidRouterName(vmName)) {
+            reconfigureDomainRouterAfterStart(vmName);
+        }
+
         return new CheckSshAnswer(cmd);
     }
 
+    private void reconfigureDomainRouterAfterStart(String vmName) {
+        s_logger.debug("Reconfigure to remove machine.id from domain router 
after start. vmName: " + vmName);
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    ClusterMO clusterMo = new 
ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
+                    vmMo = clusterMo.findVmOnHyperHost(vmName);
+                }
+            }

Review Comment:
   ```suggestion
               if (vmMo == null && hyperHost instanceof HostMO) {
                   ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), 
((HostMO) hyperHost).getParentMor());
                   vmMo = clusterMo.findVmOnHyperHost(vmName);
               }
   ```



##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -1804,9 +1804,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) {
             networkUsage(privateIp, "create", null);
         }
 
+        if (VirtualMachineName.isValidRouterName(vmName)) {
+            reconfigureDomainRouterAfterStart(vmName);
+        }
+
         return new CheckSshAnswer(cmd);
     }
 
+    private void reconfigureDomainRouterAfterStart(String vmName) {
+        s_logger.debug("Reconfigure to remove machine.id from domain router 
after start. vmName: " + vmName);
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    ClusterMO clusterMo = new 
ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
+                    vmMo = clusterMo.findVmOnHyperHost(vmName);
+                }
+            }
+            if (vmMo == null) {
+                String msg = "VM " + vmName + " no longer exists to execute 
UnPlugNic command";
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+            VirtualMachineConfigSpec vmConfigSpec = new 
VirtualMachineConfigSpec();
+            OptionValue option = new OptionValue();
+            option.setKey("machine.id");
+            option.setValue("");
+            vmConfigSpec.getExtraConfig().add(option);
+            if (!vmMo.configureVm(vmConfigSpec)) {
+                throw new Exception("Failed to reconfigure domain router after 
start. vmName: " + vmName);
+            }
+        } catch (Exception e) {
+            s_logger.error("Unexpected exception when reconfigure domain 
router after start: ", e);

Review Comment:
   We can add the name of the VM to the log and pass the exception as parameter.



##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -1804,9 +1804,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) {
             networkUsage(privateIp, "create", null);
         }
 
+        if (VirtualMachineName.isValidRouterName(vmName)) {
+            reconfigureDomainRouterAfterStart(vmName);
+        }
+
         return new CheckSshAnswer(cmd);
     }
 
+    private void reconfigureDomainRouterAfterStart(String vmName) {
+        s_logger.debug("Reconfigure to remove machine.id from domain router 
after start. vmName: " + vmName);
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    ClusterMO clusterMo = new 
ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
+                    vmMo = clusterMo.findVmOnHyperHost(vmName);
+                }
+            }
+            if (vmMo == null) {
+                String msg = "VM " + vmName + " no longer exists to execute 
UnPlugNic command";
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+            VirtualMachineConfigSpec vmConfigSpec = new 
VirtualMachineConfigSpec();
+            OptionValue option = new OptionValue();
+            option.setKey("machine.id");
+            option.setValue("");
+            vmConfigSpec.getExtraConfig().add(option);
+            if (!vmMo.configureVm(vmConfigSpec)) {
+                throw new Exception("Failed to reconfigure domain router after 
start. vmName: " + vmName);

Review Comment:
   We could instantiate a more specific exception.



##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -1804,9 +1804,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) {
             networkUsage(privateIp, "create", null);
         }
 
+        if (VirtualMachineName.isValidRouterName(vmName)) {
+            reconfigureDomainRouterAfterStart(vmName);
+        }
+
         return new CheckSshAnswer(cmd);
     }
 
+    private void reconfigureDomainRouterAfterStart(String vmName) {
+        s_logger.debug("Reconfigure to remove machine.id from domain router 
after start. vmName: " + vmName);
+        VmwareContext context = getServiceContext();
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(context);
+            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
+            if (vmMo == null) {
+                if (hyperHost instanceof HostMO) {
+                    ClusterMO clusterMo = new 
ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
+                    vmMo = clusterMo.findVmOnHyperHost(vmName);
+                }
+            }
+            if (vmMo == null) {
+                String msg = "VM " + vmName + " no longer exists to execute 
UnPlugNic command";
+                s_logger.error(msg);
+                throw new Exception(msg);

Review Comment:
   We could instantiate a more specific exception.



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