Skip to content

Commit 273b2ea

Browse files
authored
Fix importVM for use with dummy template (#14195)
findByID will fail for dummy template as it is stored in the deleted state.
1 parent a8c8c18 commit 273b2ea

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎server/src/main/java/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9608,11 +9608,10 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
96089608
}
96099609

96109610
// Ensure template details are loaded so that commitUserVm can copy them into the VM's details map
9611-
VMTemplateVO vmTemplateVO = _templateDao.findById(template.getId());
9612-
if (vmTemplateVO == null) {
9613-
throw new InvalidParameterValueException("Unable to find template with id " + template.getId() + " for virtual machine import");
9611+
if (template instanceof VMTemplateVO) {
9612+
VMTemplateVO vmTemplateVO = (VMTemplateVO) template;
9613+
_templateDao.loadDetails(vmTemplateVO);
96149614
}
9615-
_templateDao.loadDetails(vmTemplateVO);
96169615

96179616
final long id = _vmDao.getNextInSequence(Long.class, "id");
96189617
String instanceName = StringUtils.isBlank(instanceNameInternal) ?
@@ -9626,8 +9625,8 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
96269625

96279626
final String uuidName = _uuidMgr.generateUuid(UserVm.class, null);
96289627
final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn ? host : null;
9629-
final boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, vmTemplateVO, zone.getId());
9630-
return commitUserVm(true, zone, host, lastHost, vmTemplateVO, hostName, displayName, owner,
9628+
final boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId());
9629+
return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner,
96319630
null, null, userData, null, null, isDisplayVm, keyboard,
96329631
accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), guestOsId, sshPublicKeys, networkNicMap,
96339632
id, instanceName, uuidName, hypervisorType, customParameters,

0 commit comments

Comments
 (0)