From 0cb24ba8967e14e9577dde7754eeb4a93e6e23e7 Mon Sep 17 00:00:00 2001 From: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com> Date: Thu, 17 Sep 2026 22:10:10 +0530 Subject: [PATCH] Don't try to find the vmtemplate from db as it is already passed in importVM. findByID will fail for dummy template as it is stored in the deleted state. --- .../src/main/java/com/cloud/vm/UserVmManagerImpl.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index a10218269ed7..7636ef6b152c 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -9608,11 +9608,10 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach } // Ensure template details are loaded so that commitUserVm can copy them into the VM's details map - VMTemplateVO vmTemplateVO = _templateDao.findById(template.getId()); - if (vmTemplateVO == null) { - throw new InvalidParameterValueException("Unable to find template with id " + template.getId() + " for virtual machine import"); + if (template instanceof VMTemplateVO) { + VMTemplateVO vmTemplateVO = (VMTemplateVO) template; + _templateDao.loadDetails(vmTemplateVO); } - _templateDao.loadDetails(vmTemplateVO); final long id = _vmDao.getNextInSequence(Long.class, "id"); String instanceName = StringUtils.isBlank(instanceNameInternal) ? @@ -9626,8 +9625,8 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach final String uuidName = _uuidMgr.generateUuid(UserVm.class, null); final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn ? host : null; - final boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, vmTemplateVO, zone.getId()); - return commitUserVm(true, zone, host, lastHost, vmTemplateVO, hostName, displayName, owner, + final boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId()); + return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner, null, null, userData, null, null, isDisplayVm, keyboard, accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), guestOsId, sshPublicKeys, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters,