diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index b07e7714646..fc76bc11830 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1858,7 +1858,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } String deployAsIsTemplate = deployAsIsInfo.getTemplatePath(); 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); } else { Pair rootDiskDataStoreDetails = null; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java index fe9262310e0..fab928c0520 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -3729,10 +3729,9 @@ public class VmwareStorageProcessor implements StorageProcessor { /** * 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 { - VmwareContext context = hostService.getServiceContext(null); - VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null); + VmwareContext context = hyperHost.getContext(); DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); VirtualMachineMO templateMo = dcMo.findVm(templateName); if (templateMo == null) { @@ -3744,7 +3743,7 @@ public class VmwareStorageProcessor implements StorageProcessor { if (morDatastore == null) { 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) { createVMLinkedClone(templateMo, dcMo, cloneName, morDatastore, morPool); } else {