From 97ed948520991ed6c43dc900cced0e8b152e2605 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 10 Aug 2022 16:52:08 +0530 Subject: [PATCH] vmware,cks: fix attachiso failure with vmware drs Fixes #4314 Failure in attaching k8s ISO is seen when VMware DRS is enabled. Log reported VM is not found. This fix tries to find VM on peer hosts when the VM is not found on the given host. Signed-off-by: Abhishek Kumar --- .../hypervisor/vmware/resource/VmwareResource.java | 2 +- .../storage/resource/VmwareStorageProcessor.java | 2 +- .../hypervisor/vmware/mo/HypervisorHostHelper.java | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index f224601dfc4e..e831f6228e04 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -5253,7 +5253,7 @@ public static String createDatastoreNameFromIqn(String iqn) { protected AttachIsoAnswer execute(AttachIsoCommand cmd) { try { VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); + VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, cmd.getVmName()); if (vmMo == null) { String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName(); s_logger.error(msg); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java index d2f7fc88a3b9..bdb8eca20ed0 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -2341,7 +2341,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f try { VmwareContext context = hostService.getServiceContext(null); VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); + VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, vmName); if (vmMo == null) { String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + vmName; s_logger.error(msg); diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java index 7271725e8f4a..4d3a725efa37 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -2340,4 +2340,15 @@ public static String getMinimumHostHardwareVersion(VmwareHypervisorHost host1, V } return hardwareVersion; } + + public static VirtualMachineMO findVmOnHypervisorHostOrPeer(VmwareHypervisorHost hypervisorHost, String vmName) throws Exception { + VirtualMachineMO vmMo = hypervisorHost.findVmOnHyperHost(vmName); + if (vmMo == null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Unable to find the VM on host %s, try within datacenter", hypervisorHost.getHyperHostName())); + } + vmMo = hypervisorHost.findVmOnPeerHyperHost(vmName); + } + return vmMo; + } }