Skip to content

Commit 46ca853

Browse files
Added Worker VM tags for few cloned VMs, created while performing some volume operations. (#5377)
Worker VM tags are missed for few cloned VMs in VMware, and so these are skipped when tracking / cleaning up of Worker VMs. Adding proper Worker VM tags to these VMs would make them trackable from CloudStack.
1 parent 41f6f0e commit 46ca853

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,20 +1242,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VmwareContext conte
12421242
vmMo.createFullCloneWithSpecificDisk(templateUniqueName, dcMo.getVmFolder(), morPool, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), volumeDeviceInfo);
12431243
clonedVm = dcMo.findVm(templateUniqueName);
12441244

1245-
/* FR41 THIS IS OLD way of creating template using snapshot
1246-
if (!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) {
1247-
String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath;
1248-
s_logger.error(msg);
1249-
throw new Exception(msg);
1250-
}
1251-
1252-
String hardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
1253-
1254-
// 4 MB is the minimum requirement for VM memory in VMware
1255-
Pair<VirtualMachineMO, String[]> cloneResult =
1256-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), hardwareVersion);
1257-
clonedVm = cloneResult.first();
1258-
* */
1245+
clonedVm.tagAsWorkerVM();
12591246
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
12601247

12611248
// Get VMDK filename
@@ -1848,6 +1835,7 @@ private Pair<String, String[]> exportVolumeToSecondaryStorage(VmwareContext cont
18481835
s_logger.error(msg);
18491836
throw new Exception(msg);
18501837
}
1838+
clonedVm.tagAsWorkerVM();
18511839
vmMo = clonedVm;
18521840
}
18531841
vmMo.exportVm(exportPath, exportName, false, false);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,7 @@ public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, Da
17271727
}
17281728

17291729
if (workingVM != null) {
1730-
workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
1731-
String workerTag = String.format("%d-%s", System.currentTimeMillis(), hyperHost.getContext().getStockObject("noderuninfo"));
1732-
workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
1730+
workingVM.tagAsWorkerVM();
17331731
}
17341732
return workingVM;
17351733
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,4 +3553,10 @@ public String acquireVncTicket() throws InvalidStateFaultMsg, RuntimeFaultFaultM
35533553
VirtualMachineTicket ticket = _context.getService().acquireTicket(_mor, "webmks");
35543554
return ticket.getTicket();
35553555
}
3556+
3557+
public void tagAsWorkerVM() throws Exception {
3558+
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
3559+
String workerTag = String.format("%d-%s", System.currentTimeMillis(), getContext().getStockObject("noderuninfo"));
3560+
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
3561+
}
35563562
}

0 commit comments

Comments
 (0)