-
Notifications
You must be signed in to change notification settings - Fork 1.3k
server: copy template details to vm instance details when import VM #12793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9509,6 +9509,13 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach | |
| throw new InvalidParameterValueException("Unable to import virtual machine with invalid host"); | ||
| } | ||
|
|
||
| // Ensure template details are loaded so that commitUserVm can copy them into the VM's details map | ||
| VMTemplateVO vmTemplateVO = null; | ||
| if (template != null) { | ||
| vmTemplateVO = _templateDao.findById(template.getId()); | ||
| _templateDao.loadDetails(vmTemplateVO); | ||
| } | ||
|
|
||
| final long id = _vmDao.getNextInSequence(Long.class, "id"); | ||
| String instanceName = StringUtils.isBlank(instanceNameInternal) ? | ||
| getInternalName(owner.getAccountId(), id) : | ||
|
|
@@ -9521,10 +9528,10 @@ 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, 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), sshPublicKeys, networkNicMap, | ||
| accountId, userId, serviceOffering, vmTemplateVO.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap, | ||
|
Comment on lines
+9531
to
+9534
|
||
| id, instanceName, uuidName, hypervisorType, customParameters, | ||
| null, null, null, powerState, dynamicScalingEnabled, null, serviceOffering.getDiskOfferingId(), null, null, null, null); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vmTemplateVOcan remain null (whentemplate == null), but it’s used unconditionally incheckIfDynamicScalingCanBeEnabled(...),commitUserVm(...), andvmTemplateVO.getFormat(), which will throw a NullPointerException. Iftemplateis required for VM import, fail fast with a clear exception when it’s null and/or when_templateDao.findById(...)returns null; otherwise, keep usingtemplatefor the ISO check (and avoid passing null intocommitUserVm) by deriving anisIsoboolean safely.