Search in sources :

Example 21 with DiskImage

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

the class AddVmTemplateCommand method validateSpaceRequirements.

protected boolean validateSpaceRequirements() {
    // update vm snapshots for storage free space check
    imagesHandler.fillImagesBySnapshots(getVm());
    List<DiskImage> disksList = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
    List<DiskImage> disksListForStorageChecks = createDiskDummiesForSpaceValidations(disksList);
    MultipleStorageDomainsValidator multipleSdValidator = getStorageDomainsValidator(getVm().getStoragePoolId(), getStorageGuidSet());
    return validate(multipleSdValidator.allDomainsWithinThresholds()) && validate(multipleSdValidator.allDomainsHaveSpaceForClonedDisks(disksListForStorageChecks));
}
Also used : MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 22 with DiskImage

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

the class ImportVmCommandBase method createDiskDummiesForSpaceValidations.

/**
 * Space Validations are done using data extracted from the disks. The disks in question in this command
 * don't have all the needed data, and in order not to contaminate the command's data structures, an alter
 * one is created specifically fo this validation - hence dummy.
 */
protected List<DiskImage> createDiskDummiesForSpaceValidations(List<DiskImage> disksList) {
    List<DiskImage> dummies = new ArrayList<>(disksList.size());
    for (DiskImage image : disksList) {
        Guid targetSdId = imageToDestinationDomainMap.get(image.getId());
        DiskImage dummy = imagesHandler.createDiskImageWithExcessData(image, targetSdId);
        dummies.add(dummy);
    }
    return dummies;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 23 with DiskImage

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

the class ImportVmFromExternalProviderCommand method createDiskDummiesForSpaceValidations.

@Override
protected List<DiskImage> createDiskDummiesForSpaceValidations(List<DiskImage> disksList) {
    List<DiskImage> dummies = new ArrayList<>(disksList.size());
    ArrayList<Guid> emptyStorageIds = new ArrayList<>();
    for (DiskImage image : disksList) {
        image.setStorageIds(emptyStorageIds);
        dummies.add(imagesHandler.createDiskImageWithExcessData(image, getStorageDomainId()));
    }
    return dummies;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 24 with DiskImage

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

the class ImportVmTemplateCommand method validate.

@Override
protected boolean validate() {
    if (getVmTemplate() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (getCluster() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
    }
    if (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
    }
    setDescription(getVmTemplateName());
    // check that the storage pool is valid
    if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
        return false;
    }
    // set the source domain and check that it is ImportExport type and active
    setSourceDomainId(getParameters().getSourceDomainId());
    StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
    if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
    }
    if (!getParameters().isImagesExistOnTargetStorageDomain()) {
        // Set the template images from the Export domain and change each image id storage is to the import domain
        GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
        QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
        if (!qretVal.getSucceeded()) {
            return false;
        }
        Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
        ArrayList<DiskImage> images = new ArrayList<>();
        for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
            if (entry.getKey().getId().equals(getVmTemplate().getId())) {
                images = new ArrayList<>(entry.getValue());
                getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
                getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
                break;
            }
        }
        getParameters().setImages(images);
        getVmTemplate().setImages(images);
        ensureDomainMap(getImages(), getParameters().getDestDomainId());
        HashMap<Guid, DiskImage> imageMap = new HashMap<>();
        for (DiskImage image : images) {
            if (Guid.Empty.equals(image.getVmSnapshotId())) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
            }
            StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
            StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
            if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
                return false;
            }
            StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
            changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
            if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
                return false;
            }
            image.setStoragePoolId(getParameters().getStoragePoolId());
            image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
            imageMap.put(image.getImageId(), image);
        }
        getVmTemplate().setDiskImageMap(imageMap);
    }
    sourceTemplateId = getVmTemplateId();
    if (getParameters().isImportAsNewEntity()) {
        initImportClonedTemplate();
    }
    VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
    // check that the template does not exists in the target domain
    if (duplicateTemplate != null) {
        return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
    }
    if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
        return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
    }
    if (!validateNoDuplicateDiskImages(getImages())) {
        return false;
    }
    if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
        if (!validateSpaceRequirements(getImages())) {
            return false;
        }
    }
    List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
    vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
    if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
        return false;
    }
    // if this is a template version, check base template exist
    if (!getVmTemplate().isBaseTemplate()) {
        VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
        if (baseTemplate == null) {
            return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
        }
    }
    if (!setAndValidateDiskProfiles()) {
        return false;
    }
    if (!setAndValidateCpuProfile()) {
        return false;
    }
    if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
        return false;
    }
    List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
    if (!CollectionUtils.isEmpty(msgs)) {
        return failValidation(msgs);
    }
    return true;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) HashMap(java.util.HashMap) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Map(java.util.Map) HashMap(java.util.HashMap) ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters)

Example 25 with DiskImage

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

the class ImportVmTemplateCommand method moveOrCopyAllImageGroups.

@Override
protected void moveOrCopyAllImageGroups(final Guid containerID, final Iterable<DiskImage> disks) {
    TransactionSupport.executeInNewTransaction(() -> {
        for (DiskImage disk : disks) {
            Guid originalDiskId = newDiskIdForDisk.get(disk.getId()).getId();
            Guid destinationDomain = imageToDestinationDomainMap.get(originalDiskId);
            MoveOrCopyImageGroupParameters p = new MoveOrCopyImageGroupParameters(containerID, originalDiskId, newDiskIdForDisk.get(disk.getId()).getImageId(), disk.getId(), disk.getImageId(), destinationDomain, ImageOperation.Copy);
            p.setParentCommand(getActionType());
            p.setUseCopyCollapse(true);
            p.setVolumeType(disk.getVolumeType());
            p.setVolumeFormat(disk.getVolumeFormat());
            p.setCopyVolumeType(CopyVolumeType.SharedVol);
            p.setSourceDomainId(getParameters().getSourceDomainId());
            p.setForceOverride(getParameters().getForceOverride());
            p.setImportEntity(true);
            p.setEntityInfo(new EntityInfo(VdcObjectType.VmTemplate, containerID));
            p.setRevertDbOperationScope(ImageDbOperationScope.IMAGE);
            for (DiskImage diskImage : getParameters().getVmTemplate().getDiskList()) {
                if (originalDiskId.equals(diskImage.getId())) {
                    p.setQuotaId(diskImage.getQuotaId());
                    p.setDiskProfileId(diskImage.getDiskProfileId());
                    break;
                }
            }
            p.setParentParameters(getParameters());
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, p);
            if (!vdcRetValue.getSucceeded()) {
                throw vdcRetValue.getFault() != null ? new EngineException(vdcRetValue.getFault().getError()) : new EngineException(EngineError.ENGINE);
            }
            getReturnValue().getVdsmTaskIdList().addAll(vdcRetValue.getInternalVdsmTaskIdList());
        }
        return null;
    });
}
Also used : MoveOrCopyImageGroupParameters(org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) 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