Skip to content

Commit

Permalink
core: correctly set parent and template ID
Browse files Browse the repository at this point in the history
Currently image tempalte was either missing
or reset during the cloning of the VM.

This patch fixes it by correctly setting template
and parent IDs to ensure thin VMs are kept that
way when cloned

Change-Id: I4bc2437164d58a108e7cfdfd132b439ceb15b954
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
  • Loading branch information
bennyz authored and rollandf committed Nov 17, 2019
1 parent 8939bd1 commit 9957082
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Expand Up @@ -322,7 +322,10 @@ protected DiskImage getDiskImageToRemoveByParam(MoveOrCopyImageGroupParameters p
protected void executeVmCommand() {
super.executeVmCommand();
setVm(null);
getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
if (getActionType() != ActionType.CloneVmNoCollapse) {
getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
}

vmStaticDao.update(getVm().getStaticData());
}

Expand Down
Expand Up @@ -303,6 +303,7 @@ protected boolean validate() {
protected void updateOriginalTemplate(VmStatic vmStatic) {
vmStatic.setOriginalTemplateGuid(getVm().getOriginalTemplateGuid());
vmStatic.setOriginalTemplateName(getVm().getOriginalTemplateName());
vmStatic.setVmtGuid(getVm().getVmtGuid());
}

private VmManagementParametersBase createUpdateVmParameters() {
Expand Down
Expand Up @@ -160,6 +160,9 @@ private VM initClonedVm(VM oldVm) {
oldVm.setId(getVmId());
oldVm.setDiskMap(getVm().getDiskMap());
oldVm.setName(getVm().getName());
oldVm.setOriginalTemplateGuid(getVm().getOriginalTemplateGuid());
oldVm.setOriginalTemplateName(getVm().getOriginalTemplateName());
oldVm.setVmtGuid(getVm().getVmtGuid());
oldVm.getInterfaces().forEach(iface -> {
iface.setId(Guid.newGuid());
iface.setVmId(getVmId());
Expand Down
Expand Up @@ -121,13 +121,13 @@ public boolean performNextOperation(int completedChildren) {
private Guid determineSourceImageGroup(DiskImage image) {
if (Guid.Empty.equals(image.getParentId())) {
return Guid.Empty;
} else if (image.getImageTemplateId().equals(image.getParentId())) {
return imageDao.get(image.getImageTemplateId()).getDiskId();
} else if (!getParameters().getDestImages().isEmpty()) {
return getParameters().getDestImageGroupId();
}

return image.getImageTemplateId().equals(image.getParentId()) ?
imageDao.get(image.getImageTemplateId()).getDiskId()
: getParameters().getImageGroupID();
return getParameters().getImageGroupID();

}

Expand Down
Expand Up @@ -1073,7 +1073,7 @@ public Map<DiskImage, DiskImage> mapChainToNewIDs(Guid sourceImageGroupID,
DbUser user) {
List<DiskImage> oldChain = diskImageDao.getAllSnapshotsForImageGroup(sourceImageGroupID);
Map<DiskImage, DiskImage> oldToNewChain = new HashMap<>(oldChain.size());
Guid nextParentId = Guid.Empty;
Guid nextParentId = oldChain.get(0).getImageTemplateId() != Guid.Empty ? oldChain.get(0).getParentId() : Guid.Empty;
sortImageList(oldChain);

for (DiskImage diskImage : oldChain) {
Expand Down

0 comments on commit 9957082

Please sign in to comment.