Skip to content
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

Backport: Fix import template from ova #310

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;

Expand Down Expand Up @@ -154,18 +153,7 @@ protected void initImportClonedTemplateDisks() {
if (!getParameters().isImagesExistOnTargetStorageDomain()) {
updateDiskSizeByQcowImageInfo(image);
} else {
Set<Guid> storageDomains = getParameters().getImageToAvailableStorageDomains().get(image.getImageId());
Guid sdToUse;

// Try to use the target SD, otherwise fallback to one of the available SDs
// for the image
if (storageDomains.contains(getStorageDomainId())) {
sdToUse = getStorageDomainId();
} else {
sdToUse = storageDomains.stream().findFirst().get();
}

updateDiskSizeByQcowImageInfo(image, sdToUse);
updateDiskSizeByQcowImageInfo(image, image.getStorageIds().get(0));
}

if (getParameters().isImportAsNewEntity()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ public AuditLogType getAuditLogTypeValue() {

@Override
protected void updateDiskSizeByQcowImageInfo(DiskImage diskImage, Guid storageId) {
Set<Guid> storageDomains = getParameters().getImageToAvailableStorageDomains().get(diskImage.getImageId());

if (storageDomains != null && !storageDomains.isEmpty()) {
// Try to use the target SD, otherwise fallback to one of the available SDs
// for the image
if (storageDomains.contains(getStorageDomainId())) {
storageId = getStorageDomainId();
} else {
storageId = storageDomains.stream().findFirst().get();
}
}

if (!Guid.isNullOrEmpty(storageId)) {
super.updateDiskSizeByQcowImageInfo(diskImage, storageId);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ImportVmTemplateFromConfParameters extends ImportVmTemplateParamete
private Map<String, String> clusterMap;
private Map<String, String> roleMap;
private Map<String, String> domainMap;
private Map<Guid, Set<Guid>> imageToAvailableStorageDomains = new HashMap<>();

private Set<DbUser> dbUsers;
private Map<String, Set<String>> userToRoles = new HashMap<>();
Expand Down Expand Up @@ -118,4 +119,12 @@ public Collection<ExternalVnicProfileMapping> getExternalVnicProfileMappings() {
public void setExternalVnicProfileMappings(Collection<ExternalVnicProfileMapping> externalVnicProfileMappings) {
this.externalVnicProfileMappings = Objects.requireNonNull(externalVnicProfileMappings);
}

public Map<Guid, Set<Guid>> getImageToAvailableStorageDomains() {
return imageToAvailableStorageDomains;
}

public void setImageToAvailableStorageDomains(Map<Guid, Set<Guid>> imageToAvailableStorageDomains) {
this.imageToAvailableStorageDomains = imageToAvailableStorageDomains;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.ovirt.engine.core.common.action;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.validation.Valid;

Expand Down Expand Up @@ -89,16 +87,6 @@ public void setDiskTemplateMap(Map<Guid, DiskImage> diskTemplateMap) {
this.diskTemplateMap = diskTemplateMap;
}

private Map<Guid, Set<Guid>> imageToAvailableStorageDomains = new HashMap<>();

public Map<Guid, Set<Guid>> getImageToAvailableStorageDomains() {
return imageToAvailableStorageDomains;
}

public void setImageToAvailableStorageDomains(Map<Guid, Set<Guid>> imageToAvailableStorageDomains) {
this.imageToAvailableStorageDomains = imageToAvailableStorageDomains;
}

public ImportVmTemplateParameters() {
privateSourceDomainId = Guid.Empty;
privateDestDomainId = Guid.Empty;
Expand Down