Search in sources :

Example 36 with DiskImage

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);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 37 with DiskImage

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;
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) NonTransactiveCommandAttribute(org.ovirt.engine.core.bll.NonTransactiveCommandAttribute) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) RemoveVMVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.RemoveVMVDSCommandParameters) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) Map(java.util.Map) VmTemplateImportExportParameters(org.ovirt.engine.core.common.action.VmTemplateImportExportParameters) RemoveAllVmImagesParameters(org.ovirt.engine.core.common.action.RemoveAllVmImagesParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VmTemplateStatus(org.ovirt.engine.core.common.businessentities.VmTemplateStatus) List(java.util.List) RemoveVmTemplateCommand(org.ovirt.engine.core.bll.RemoveVmTemplateCommand) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) Collections(java.util.Collections) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 38 with DiskImage

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();
}
Also used : Image(com.woorea.openstack.glance.model.Image) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage)

Example 39 with DiskImage

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;
}
Also used : Arrays(java.util.Arrays) Guid(org.ovirt.engine.core.compat.Guid) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) DiskProfileDao(org.ovirt.engine.core.dao.profiles.DiskProfileDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) Logger(org.slf4j.Logger) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) List(java.util.List) Injector(org.ovirt.engine.core.di.Injector) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Entry(java.util.Map.Entry) Optional(java.util.Optional) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) Guid(org.ovirt.engine.core.compat.Guid) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile)

Example 40 with DiskImage

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);
}
Also used : ArrayList(java.util.ArrayList) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)635 Guid (org.ovirt.engine.core.compat.Guid)212 ArrayList (java.util.ArrayList)167 Test (org.junit.Test)132 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)80 VM (org.ovirt.engine.core.common.businessentities.VM)77 HashMap (java.util.HashMap)64 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)62 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)62 List (java.util.List)56 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)48 Map (java.util.Map)39 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)38 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)35 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)34 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)31 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)31 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 ActionType (org.ovirt.engine.core.common.action.ActionType)22 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)22