use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method autoSelectTargetDomainAndVolumeFormat.
private HashMap<Guid, DiskImage> autoSelectTargetDomainAndVolumeFormat() {
HashMap<Guid, DiskImage> destinationMap = new HashMap<>();
for (Disk disk : templateDisks) {
DiskImage diskImage = (DiskImage) disk;
ArrayList<Guid> storageIds = new ArrayList<>();
Guid storageId = findAvailableStorageDomain(disk.getSize(), diskToStorageIds.get(disk.getId()));
storageIds.add(storageId);
List<Guid> profileIds = diskToProfileMap.get(disk.getId());
for (Guid profileId : profileIds) {
DiskProfile profile = diskProfileDao.get(profileId);
if (profile.getStorageDomainId().equals(storageId)) {
diskImage.setDiskProfileId(profile.getId());
break;
}
}
// Set target domain
diskImage.setStorageIds(storageIds);
// validation
if (diskImage.getDiskStorageType() == DiskStorageType.CINDER) {
diskImage.setVolumeFormat(VolumeFormat.RAW);
} else {
diskImage.setVolumeFormat(VolumeFormat.COW);
}
destinationMap.put(disk.getId(), diskImage);
}
return destinationMap;
}
use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.
the class DiskProfileHelper method setAndValidateDiskProfiles.
public ValidationResult setAndValidateDiskProfiles(Map<DiskImage, Guid> map, DbUser user) {
if (map == null) {
return ValidationResult.VALID;
}
Map<Guid, List<DiskProfile>> storageDiskProfilesMap = new HashMap<>();
// caching disk profile ids that was already checked.
Set<Guid> permittedDiskProfilesIds = new HashSet<>();
for (Entry<DiskImage, Guid> entry : map.entrySet()) {
DiskImage diskImage = entry.getKey();
Guid storageDomainId = entry.getValue();
if (diskImage.getDiskStorageType() != DiskStorageType.IMAGE) {
log.info("Disk profiles is not supported for storage type '{}' (Disk '{}')", diskImage.getDiskStorageType(), diskImage.getDiskAlias());
continue;
}
if (diskImage.getDiskProfileId() == null && storageDomainId != null) {
List<DiskProfile> diskProfilesList = storageDiskProfilesMap.get(storageDomainId);
if (diskProfilesList == null) {
diskProfilesList = diskProfileDao.getAllForStorageDomain(storageDomainId);
storageDiskProfilesMap.put(storageDomainId, diskProfilesList);
}
// Set Disk Profile according to permissions
if (!updateDiskProfileForBackwardCompatibility(diskImage, diskProfilesList, permittedDiskProfilesIds, user)) {
return new ValidationResult(EngineMessage.USER_NOT_AUTHORIZED_TO_ATTACH_DISK_PROFILE);
}
} else {
DiskProfile diskProfile = updateDiskImageProfilesList(diskImage, storageDomainId);
if (diskProfile == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_NOT_FOUND_FOR_STORAGE_DOMAIN, String.format("$storageDomainId %s", storageDomainId));
}
ValidationResult result = isDiskProfileParentEntityValid(diskProfile, storageDomainId);
if (result != ValidationResult.VALID) {
return result;
}
if (!isDiskProfilePermitted(diskProfile, permittedDiskProfilesIds, user)) {
return new ValidationResult(EngineMessage.USER_NOT_AUTHORIZED_TO_ATTACH_DISK_PROFILE);
}
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.
the class DiskProfileValidator method isParentEntityValid.
public ValidationResult isParentEntityValid(Guid storageDomainId) {
if (storageDomainId == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED);
}
Guid id = getProfile().getId();
if (id == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_EMPTY);
}
DiskProfile fetchedDiskProfile = getProfileDao().get(id);
if (fetchedDiskProfile == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND);
}
if (!storageDomainId.equals(fetchedDiskProfile.getStorageDomainId())) {
String diskProfileName = fetchedDiskProfile.getName();
StorageDomain targetStorageDomain = getStorageDomain(storageDomainId);
String targetStorageDomainName = targetStorageDomain != null ? getStorageDomain(storageDomainId).getName() : "Unknown";
return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN, String.format("$diskProfile %s", diskProfileName), String.format("$diskProfileId %s", fetchedDiskProfile.getId().toString()), String.format("$storageDomain %s", targetStorageDomainName));
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.
the class DiskProfilesListModelTable method initTable.
@Override
public void initTable() {
getTable().enableColumnResizing();
AbstractTextColumn<DiskProfile> nameColumn = new AbstractTextColumn<DiskProfile>() {
@Override
public String getValue(DiskProfile object) {
return object.getName();
}
};
// $NON-NLS-1$
getTable().addColumn(nameColumn, constants.profileNameLabel(), "200px");
nameColumn.makeSortable();
AbstractTextColumn<DiskProfile> descriptionColumn = new AbstractTextColumn<DiskProfile>() {
@Override
public String getValue(DiskProfile object) {
return object.getDescription();
}
};
// $NON-NLS-1$
getTable().addColumn(descriptionColumn, constants.profileDescriptionLabel(), "200px");
descriptionColumn.makeSortable();
AbstractTextColumn<DiskProfile> qosColumn = new AbstractTextColumn<DiskProfile>() {
@Override
public String getValue(DiskProfile object) {
String name = constants.unlimitedQos();
if (object.getQosId() != null) {
StorageQos storageQos = getModel().getQos(object.getQosId());
if (storageQos != null) {
name = storageQos.getName();
}
}
return name;
}
};
// $NON-NLS-1$
getTable().addColumn(qosColumn, constants.qosName(), "200px");
qosColumn.makeSortable();
// Add selection listener
getModel().getSelectedItemChangedEvent().addListener((ev, sender, args) -> updatePermissionPanel());
getModel().getItemsChangedEvent().addListener((ev, sender, args) -> updatePermissionPanel());
}
Aggregations