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.
This commit is contained in:
sureshanaparti 2021-08-31 04:52:06 +05:30 committed by GitHub
parent 41f6f0e568
commit 46ca853e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 17 deletions

View File

@ -1242,20 +1242,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
vmMo.createFullCloneWithSpecificDisk(templateUniqueName, dcMo.getVmFolder(), morPool, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), volumeDeviceInfo);
clonedVm = dcMo.findVm(templateUniqueName);
/* FR41 THIS IS OLD way of creating template using snapshot
if (!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) {
String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath;
s_logger.error(msg);
throw new Exception(msg);
}
String hardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
// 4 MB is the minimum requirement for VM memory in VMware
Pair<VirtualMachineMO, String[]> cloneResult =
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), hardwareVersion);
clonedVm = cloneResult.first();
* */
clonedVm.tagAsWorkerVM();
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
// Get VMDK filename
@ -1848,6 +1835,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
s_logger.error(msg);
throw new Exception(msg);
}
clonedVm.tagAsWorkerVM();
vmMo = clonedVm;
}
vmMo.exportVm(exportPath, exportName, false, false);

View File

@ -1727,9 +1727,7 @@ public class HypervisorHostHelper {
}
if (workingVM != null) {
workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
String workerTag = String.format("%d-%s", System.currentTimeMillis(), hyperHost.getContext().getStockObject("noderuninfo"));
workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
workingVM.tagAsWorkerVM();
}
return workingVM;
}

View File

@ -3553,4 +3553,10 @@ public class VirtualMachineMO extends BaseMO {
VirtualMachineTicket ticket = _context.getService().acquireTicket(_mor, "webmks");
return ticket.getTicket();
}
public void tagAsWorkerVM() throws Exception {
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true");
String workerTag = String.format("%d-%s", System.currentTimeMillis(), getContext().getStockObject("noderuninfo"));
setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag);
}
}