This is an automated email from the ASF dual-hosted git repository.
weizhouapache pushed a commit to branch 4.22
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.22 by this push:
new a01fb0be34b server: copy template details to vm instance details when
import VM (#12793)
a01fb0be34b is described below
commit a01fb0be34b2774d8fb7853703b36364444398e4
Author: Wei Zhou <[email protected]>
AuthorDate: Mon Sep 14 08:05:13 2026 +0200
server: copy template details to vm instance details when import VM (#12793)
---
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index aeb7059b03e..a10218269ed 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -9603,6 +9603,16 @@ public class UserVmManagerImpl extends ManagerBase
implements UserVmManager, Vir
if (host == null && hypervisorType == HypervisorType.VMware) {
throw new InvalidParameterValueException("Unable to import
virtual machine with invalid host");
}
+ if (template == null) {
+ throw new InvalidParameterValueException("Unable to import
virtual machine without a template");
+ }
+
+ // 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");
+ }
+ _templateDao.loadDetails(vmTemplateVO);
final long id = _vmDao.getNextInSequence(Long.class, "id");
String instanceName = StringUtils.isBlank(instanceNameInternal) ?
@@ -9616,8 +9626,8 @@ public class UserVmManagerImpl extends ManagerBase
implements UserVmManager, Vir
final String uuidName = _uuidMgr.generateUuid(UserVm.class, null);
final Host lastHost = powerState !=
VirtualMachine.PowerState.PowerOn ? host : null;
- final boolean dynamicScalingEnabled =
checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template,
zone.getId());
- return commitUserVm(true, zone, host, lastHost, template,
hostName, displayName, owner,
+ final boolean dynamicScalingEnabled =
checkIfDynamicScalingCanBeEnabled(null, serviceOffering, vmTemplateVO,
zone.getId());
+ return commitUserVm(true, zone, host, lastHost, vmTemplateVO,
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,