Relocate deploy-as-is cloned VM if does not end on the host receiving the start command and restore deployment logs

This commit is contained in:
nvazquez 2020-09-22 01:03:19 -03:00 committed by Harikrishna Patnala
parent edfbed34ad
commit acf872cdab
2 changed files with 9 additions and 5 deletions

View File

@ -1858,7 +1858,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
} }
String deployAsIsTemplate = deployAsIsInfo.getTemplatePath(); String deployAsIsTemplate = deployAsIsInfo.getTemplatePath();
String destDatastore = deployAsIsInfo.getDestStoragePool(); String destDatastore = deployAsIsInfo.getDestStoragePool();
vmMo = _storageProcessor.cloneVMFromTemplate(deployAsIsTemplate, vmInternalCSName, destDatastore); _storageProcessor.cloneVMFromTemplate(hyperHost, deployAsIsTemplate, vmInternalCSName, destDatastore);
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
if (vmMo == null) {
s_logger.info("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it");
vmMo = takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
}
mapSpecDisksToClonedDisks(vmMo, vmInternalCSName, specDisks); mapSpecDisksToClonedDisks(vmMo, vmInternalCSName, specDisks);
} else { } else {
Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null; Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;

View File

@ -3729,10 +3729,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
/** /**
* Return the cloned VM from the template * Return the cloned VM from the template
*/ */
public VirtualMachineMO cloneVMFromTemplate(String templateName, String cloneName, String templatePrimaryStoreUuid) { public VirtualMachineMO cloneVMFromTemplate(VmwareHypervisorHost hyperHost, String templateName, String cloneName, String templatePrimaryStoreUuid) {
try { try {
VmwareContext context = hostService.getServiceContext(null); VmwareContext context = hyperHost.getContext();
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
VirtualMachineMO templateMo = dcMo.findVm(templateName); VirtualMachineMO templateMo = dcMo.findVm(templateName);
if (templateMo == null) { if (templateMo == null) {
@ -3744,7 +3743,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
if (morDatastore == null) { if (morDatastore == null) {
throw new CloudRuntimeException("Unable to find datastore in vSphere"); throw new CloudRuntimeException("Unable to find datastore in vSphere");
} }
s_logger.info("Cloning VM " + cloneName + " from template " + templatePrimaryStoreUuid); s_logger.info("Cloning VM " + cloneName + " from template " + templateName + " into datastore " + templatePrimaryStoreUuid);
if (!_fullCloneFlag) { if (!_fullCloneFlag) {
createVMLinkedClone(templateMo, dcMo, cloneName, morDatastore, morPool); createVMLinkedClone(templateMo, dcMo, cloneName, morDatastore, morPool);
} else { } else {