Skip to content

Commit 60eaad7

Browse files
committed
honor templateId passed in importVM API
1 parent 0cbebbd commit 60eaad7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,8 @@ protected VMTemplateVO getTemplateForImportInstance(Long templateId, Hypervisor.
14941494
if (templateId == null) {
14951495
template = templateDao.findByName(VM_IMPORT_DEFAULT_TEMPLATE_NAME);
14961496
if (template == null) {
1497-
template = createDefaultDummyVmImportTemplate(false);
1497+
boolean isKVM = Hypervisor.HypervisorType.KVM == hypervisorType;
1498+
template = createDefaultDummyVmImportTemplate(isKVM);
14981499
if (template == null) {
14991500
throw new InvalidParameterValueException(String.format("Default VM import template with unique name: %s for hypervisor: %s cannot be created. Please use templateid parameter for import", VM_IMPORT_DEFAULT_TEMPLATE_NAME, hypervisorType.toString()));
15001501
}
@@ -2342,14 +2343,7 @@ private UserVmResponse importKvmInstance(ImportVmCmd cmd) {
23422343
if (CollectionUtils.isNotEmpty(userVOs)) {
23432344
userId = userVOs.get(0).getId();
23442345
}
2345-
VMTemplateVO template = templateDao.findByName(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME);
2346-
if (template == null) {
2347-
template = createDefaultDummyVmImportTemplate(true);
2348-
if (template == null) {
2349-
throw new InvalidParameterValueException("Error while creating default Import Vm Template");
2350-
}
2351-
}
2352-
2346+
VMTemplateVO template = getTemplateForImportInstance(cmd.getTemplateId(), Hypervisor.HypervisorType.KVM);
23532347
final Long serviceOfferingId = cmd.getServiceOfferingId();
23542348
if (serviceOfferingId == null) {
23552349
throw new InvalidParameterValueException(String.format("Service offering ID cannot be null"));

0 commit comments

Comments
 (0)