Skip to content

Commit eafec0e

Browse files
[VMware] Added Worker VM tags for few cloned VMs, created while performing some volume operations.
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 8e0e5ac commit eafec0e

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

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
@@ -1252,20 +1252,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VmwareContext conte
12521252
vmMo.createFullCloneWithSpecificDisk(templateUniqueName, dcMo.getVmFolder(), morPool, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), volumeDeviceInfo);
12531253
clonedVm = dcMo.findVm(templateUniqueName);
12541254

1255-
/* FR41 THIS IS OLD way of creating template using snapshot
1256-
if (!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) {
1257-
String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath;
1258-
s_logger.error(msg);
1259-
throw new Exception(msg);
1260-
}
1261-
1262-
String hardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
1263-
1264-
// 4 MB is the minimum requirement for VM memory in VMware
1265-
Pair<VirtualMachineMO, String[]> cloneResult =
1266-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), hardwareVersion);
1267-
clonedVm = cloneResult.first();
1268-
* */
1255+
clonedVm.tagAsWorkerVM();
12691256
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
12701257

12711258
// Get VMDK filename
@@ -1858,6 +1845,7 @@ private Pair<String, String[]> exportVolumeToSecondaryStorage(VmwareContext cont
18581845
s_logger.error(msg);
18591846
throw new Exception(msg);
18601847
}
1848+
clonedVm.tagAsWorkerVM();
18611849
vmMo = clonedVm;
18621850
}
18631851
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
@@ -3593,4 +3593,10 @@ public String acquireVncTicket() throws InvalidStateFaultMsg, RuntimeFaultFaultM
35933593
VirtualMachineTicket ticket = _context.getService().acquireTicket(_mor, "webmks");
35943594
return ticket.getTicket();
35953595
}
3596+
3597+
public void tagAsWorkerVM() throws Exception {
3598+
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
3599+
String workerTag = String.format("%d-%s", System.currentTimeMillis(), getContext().getStockObject("noderuninfo"));
3600+
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
3601+
}
35963602
}

0 commit comments

Comments
 (0)