Skip to content

Commit 770df60

Browse files
authored
vmware,cks: fix attachiso failure with vmware drs (#6625)
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 <abhishek.mrt22@gmail.com>
1 parent a5716d9 commit 770df60

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5253,7 +5253,7 @@ public static String createDatastoreNameFromIqn(String iqn) {
52535253
protected AttachIsoAnswer execute(AttachIsoCommand cmd) {
52545254
try {
52555255
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
5256-
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
5256+
VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, cmd.getVmName());
52575257
if (vmMo == null) {
52585258
String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName();
52595259
s_logger.error(msg);

plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f
23412341
try {
23422342
VmwareContext context = hostService.getServiceContext(null);
23432343
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
2344-
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
2344+
VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, vmName);
23452345
if (vmMo == null) {
23462346
String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + vmName;
23472347
s_logger.error(msg);

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,4 +2340,15 @@ public static String getMinimumHostHardwareVersion(VmwareHypervisorHost host1, V
23402340
}
23412341
return hardwareVersion;
23422342
}
2343+
2344+
public static VirtualMachineMO findVmOnHypervisorHostOrPeer(VmwareHypervisorHost hypervisorHost, String vmName) throws Exception {
2345+
VirtualMachineMO vmMo = hypervisorHost.findVmOnHyperHost(vmName);
2346+
if (vmMo == null) {
2347+
if (s_logger.isDebugEnabled()) {
2348+
s_logger.debug(String.format("Unable to find the VM on host %s, try within datacenter", hypervisorHost.getHyperHostName()));
2349+
}
2350+
vmMo = hypervisorHost.findVmOnPeerHyperHost(vmName);
2351+
}
2352+
return vmMo;
2353+
}
23432354
}

0 commit comments

Comments
 (0)