use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class RemoveVmFromImportExportCommand method removeDiskImages.
private void removeDiskImages() {
List<DiskImage> images = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
boolean shouldWipe = false;
for (DiskImage image : images) {
image.setStorageIds(new ArrayList<>(Arrays.asList(getParameters().getStorageDomainId())));
image.setStoragePoolId(getParameters().getStoragePoolId());
shouldWipe |= image.isWipeAfterDelete();
}
Set<Guid> allMemoryDisks = MemoryUtils.getMemoryDiskIdsFromSnapshots(getVm().getSnapshots());
for (Guid memoryDiskId : allMemoryDisks) {
DiskImage metadataDisk = createMemoryDisk(memoryDiskId, shouldWipe);
images.add(metadataDisk);
}
removeVmImages(images);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class RemoveVmTemplateFromImportExportCommand method validate.
@Override
protected boolean validate() {
if (!validate(templateExists())) {
return false;
}
List<DiskImage> images = templatesFromExport.get(templatesFromExport.keySet().stream().filter(t -> t.getId().equals(getParameters().getVmTemplateId())).findFirst().orElse(null));
if (images != null) {
getParameters().setImages(images);
} else {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST);
}
StorageDomainValidator validator = new StorageDomainValidator(getStorageDomain());
if (!validate(validator.isDomainExistAndActive())) {
return false;
}
if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
// We fetch from DB instead of using the VmTemplate property because
// it's the one from the export domain and not from database
VmTemplate tmpl = vmTemplateDao.get(getVmTemplateId());
if (tmpl != null) {
if (tmpl.getStatus() == VmTemplateStatus.Locked) {
return failValidation(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
}
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class OpenStackImageProviderProxy method createImageFromDiskImage.
public String createImageFromDiskImage(DiskImage diskImage) {
Image glanceImage = new Image();
glanceImage.setName(diskImage.getDiskAlias());
if (diskImage.getVolumeFormat() == VolumeFormat.RAW) {
glanceImage.setDiskFormat(GlanceImageFormat.RAW.getValue());
} else if (diskImage.getVolumeFormat() == VolumeFormat.COW) {
glanceImage.setDiskFormat(GlanceImageFormat.COW.getValue());
} else {
throw new OpenStackImageException(OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, "Unknown disk format: " + diskImage.getVolumeFormat());
}
glanceImage.setContainerFormat(GlanceImageContainer.BARE.getValue());
Image retGlanceImage = getClient().images().create(glanceImage).execute();
return retGlanceImage.getId();
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class DiskProfileHelper method updateDiskImageProfilesList.
/**
* Updates the disk profiles list of the given disk image according to the storageDomainID.
* The disk profiles list will be set with the first disk profile that matches the storage domain id.
*
* @param diskImage disk image to be updated with the relevant disk profiles list
* @param storageDomainId storage domain id to match a disk profile with
* @return valid disk profile in case there is a match with the given storage domain ID. otherwise return an
* invalid disk profile.
*/
private DiskProfile updateDiskImageProfilesList(DiskImage diskImage, Guid storageDomainId) {
DiskProfile diskProfile = null;
if (storageDomainId != null) {
List<Guid> diskProfileIds = diskImage.getDiskProfileIds();
List<DiskProfile> diskProfilesListByStorageDomain = diskProfileDao.getAllForStorageDomain(storageDomainId);
Optional<DiskProfile> match = diskProfilesListByStorageDomain.stream().filter(profile -> diskProfileIds.contains(profile.getId())).findFirst();
if (match.isPresent()) {
diskProfile = match.get();
diskImage.setDiskProfileIds(new ArrayList<Guid>(Arrays.asList(diskProfile.getId())));
}
}
return diskProfile;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class DiskProfileValidator method validateUnattachedDisks.
private ValidationResult validateUnattachedDisks() {
List<DiskImage> entities = diskImageDao.getAllForDiskProfiles(Collections.singletonList(getProfile().getId()));
if (entities.isEmpty()) {
return ValidationResult.VALID;
}
List<Object> nameList = new ArrayList<>();
for (DiskImage diskImage : entities) {
nameList.add(diskImage.getDiskAlias());
}
Collection<String> replacements = ReplacementUtils.replaceWith("ENTITIES_USING_PROFILE", nameList);
replacements.add(EngineMessage.VAR__ENTITIES__DISKS.name());
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_PROFILE_IN_USE, replacements);
}
Aggregations