Skip to content

Commit 0ed525a

Browse files
committed
apply suggestions
1 parent a00adaa commit 0ed525a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9508,13 +9508,16 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
95089508
if (host == null && hypervisorType == HypervisorType.VMware) {
95099509
throw new InvalidParameterValueException("Unable to import virtual machine with invalid host");
95109510
}
9511+
if (template == null) {
9512+
throw new InvalidParameterValueException("Unable to import virtual machine without a template");
9513+
}
95119514

95129515
// Ensure template details are loaded so that commitUserVm can copy them into the VM's details map
9513-
VMTemplateVO vmTemplateVO = null;
9514-
if (template != null) {
9515-
vmTemplateVO = _templateDao.findById(template.getId());
9516-
_templateDao.loadDetails(vmTemplateVO);
9516+
VMTemplateVO vmTemplateVO = _templateDao.findById(template.getId());
9517+
if (vmTemplateVO == null) {
9518+
throw new InvalidParameterValueException("Unable to find template with id " + template.getId() + " for virtual machine import");
95179519
}
9520+
_templateDao.loadDetails(vmTemplateVO);
95189521

95199522
final long id = _vmDao.getNextInSequence(Long.class, "id");
95209523
String instanceName = StringUtils.isBlank(instanceNameInternal) ?
@@ -9531,7 +9534,7 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
95319534
final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, vmTemplateVO, zone.getId());
95329535
return commitUserVm(true, zone, host, lastHost, vmTemplateVO, hostName, displayName, owner,
95339536
null, null, userData, null, null, isDisplayVm, keyboard,
9534-
accountId, userId, serviceOffering, vmTemplateVO.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap,
9537+
accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap,
95359538
id, instanceName, uuidName, hypervisorType, customParameters,
95369539
null, null, null, powerState, dynamicScalingEnabled, null, serviceOffering.getDiskOfferingId(), null, null, null, null);
95379540
});

0 commit comments

Comments
 (0)