Search in sources :

Example 26 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class ImportVmTemplateFromConfigurationCommand method populateDisksCopies.

private void populateDisksCopies(List<ImageStorageDomainMap> copiedTemplateDisks, List<DiskImage> originalTemplateImages, Guid storageDomainId) {
    List<Guid> imagesContainedInStorageDomain = getImagesGuidFromStorage(storageDomainId, getStoragePoolId());
    for (DiskImage templateDiskImage : originalTemplateImages) {
        if (storageDomainId.equals(templateDiskImage.getStorageIds().get(0))) {
            // The original Storage Domain was already saved. skipping it.
            continue;
        }
        if (imagesContainedInStorageDomain.contains(templateDiskImage.getId())) {
            log.info("Found a copied image of '{}' on Storage Domain id '{}'", templateDiskImage.getId(), storageDomainId);
            ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(templateDiskImage.getImageId(), storageDomainId, templateDiskImage.getQuotaId(), templateDiskImage.getDiskProfileId());
            copiedTemplateDisks.add(imageStorageDomainMap);
        }
    }
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 27 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class ImportVmTemplateFromConfigurationCommand method validateUnregisteredEntity.

private boolean validateUnregisteredEntity(VmTemplate entityFromConfiguration, OvfEntityData ovfEntityData) {
    if (ovfEntityData == null && !getParameters().isImportAsNewEntity()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_UNSUPPORTED_OVF);
    }
    if (entityFromConfiguration == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED);
    }
    ImportValidator importValidator = new ImportValidator(getParameters());
    if (!validate(importValidator.validateDiskNotAlreadyExistOnDB(getImages(), getParameters().isAllowPartialImport(), imageToDestinationDomainMap, failedDisksToImportForAuditLog))) {
        return false;
    }
    for (DiskImage image : new ArrayList<>(getImages())) {
        DiskImage fromIrs = null;
        Guid storageDomainId = image.getStorageIds().get(0);
        Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
        try {
            fromIrs = (DiskImage) runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getStoragePool().getId(), storageDomainId, imageGroupId, image.getImageId())).getReturnValue();
        } catch (Exception e) {
            log.debug("Unable to get image info from storage", e);
        }
        if (fromIrs == null) {
            if (!getParameters().isAllowPartialImport()) {
                return failValidation(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
            }
            log.warn("Disk image '{}/{}' doesn't exist on storage domain '{}'. Ignoring since force flag in on", imageGroupId, image.getImageId(), storageDomainId);
            getImages().remove(image);
            failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
        }
    }
    for (DiskImage image : getImages()) {
        StorageDomain sd = storageDomainDao.getForStoragePool(image.getStorageIds().get(0), getStoragePool().getId());
        ValidationResult result = new StorageDomainValidator(sd).isDomainExistAndActive();
        if (!result.isValid()) {
            if (!getParameters().isAllowPartialImport()) {
                return validate(result);
            } else {
                log.warn("storage domain '{}' does not exists. Ignoring since force flag in on", image.getStorageIds().get(0));
                getImages().remove(image);
                failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
            }
        }
    }
    if (!getStorageDomain().getStorageDomainType().isDataDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_UNSUPPORTED, String.format("$domainId %1$s", getParameters().getStorageDomainId()), String.format("$domainType %1$s", getStorageDomain().getStorageDomainType()));
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) ImportValidator(org.ovirt.engine.core.bll.validator.ImportValidator) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 28 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class ImportVmCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    for (Disk disk : getParameters().getVm().getDiskMap().values()) {
        // TODO: handle import more than once;
        if (disk instanceof DiskImage) {
            DiskImage diskImage = (DiskImage) disk;
            list.add(new QuotaStorageConsumptionParameter(diskImage.getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.CONSUME, imageToDestinationDomainMap.get(diskImage.getId()), (double) diskImage.getSizeInGigabytes()));
        }
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 29 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class ImportVmCommand method createMemoryDisk.

private DiskImage createMemoryDisk(Snapshot snapshot) {
    StorageDomainStatic sd = validateStorageDomainExistsInDb(snapshot, memoryDiskDomainMap.get(snapshot.getMemoryDiskId()));
    DiskImage disk = isMemoryDiskAlreadyExistsInDb(snapshot, snapshot.getMemoryDiskId());
    if (sd == null || disk != null) {
        return null;
    }
    VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
    DiskImage memoryDisk = MemoryUtils.createSnapshotMemoryDisk(vm, sd.getStorageType(), vmOverheadCalculator, MemoryUtils.generateMemoryDiskDescription(vm, snapshot.getDescription()));
    memoryDisk.setId(snapshot.getMemoryDiskId());
    memoryDisk.setImageId(getMemoryDiskImageId(snapshot.getMemoryDiskId()));
    memoryDisk.setStorageIds(new ArrayList<>(Collections.singletonList(sd.getId())));
    memoryDisk.setStoragePoolId(getStoragePoolId());
    memoryDisk.setCreationDate(snapshot.getCreationDate());
    memoryDisk.setActive(true);
    memoryDisk.setWipeAfterDelete(vm.getDiskList().stream().anyMatch(DiskImage::isWipeAfterDelete));
    return memoryDisk;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 30 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class ImportVmCommand method createMetadataDisk.

private DiskImage createMetadataDisk(VM vm, Snapshot snapshot) {
    StorageDomainStatic sd = validateStorageDomainExistsInDb(snapshot, memoryDiskDomainMap.get(snapshot.getMetadataDiskId()));
    DiskImage disk = isMemoryDiskAlreadyExistsInDb(snapshot, snapshot.getMetadataDiskId());
    if (sd == null || disk != null) {
        return null;
    }
    DiskImage memoryDisk = MemoryUtils.createSnapshotMetadataDisk(MemoryUtils.generateMemoryDiskDescription(vm, snapshot.getDescription()));
    memoryDisk.setId(snapshot.getMetadataDiskId());
    memoryDisk.setImageId(getMemoryDiskImageId(snapshot.getMetadataDiskId()));
    memoryDisk.setStorageIds(new ArrayList<>(Collections.singletonList(sd.getId())));
    memoryDisk.setStoragePoolId(getStoragePoolId());
    memoryDisk.setCreationDate(snapshot.getCreationDate());
    memoryDisk.setActive(true);
    memoryDisk.setWipeAfterDelete(vm.getDiskList().stream().anyMatch(DiskImage::isWipeAfterDelete));
    return memoryDisk;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) 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