Search in sources :

Example 21 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.

the class RemoveDiskCommand method canRemoveDiskBasedOnImageStorageCheck.

protected boolean canRemoveDiskBasedOnImageStorageCheck() {
    boolean retValue = true;
    DiskImage diskImage = getDiskImage();
    boolean isVmTemplateType = diskImage.getVmEntityType() != null && diskImage.getVmEntityType().isTemplateType();
    if (Guid.isNullOrEmpty(getParameters().getStorageDomainId())) {
        if (isVmTemplateType) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANT_DELETE_TEMPLATE_DISK_WITHOUT_SPECIFYING_DOMAIN);
        }
        getParameters().setStorageDomainId(diskImage.getStorageIds().get(0));
        setStorageDomainId(diskImage.getStorageIds().get(0));
    }
    if (isVmTemplateType) {
        diskImage.setStorageIds(diskImageDao.get(diskImage.getImageId()).getStorageIds());
    }
    if (!diskImage.getStorageIds().contains(getParameters().getStorageDomainId())) {
        retValue = false;
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_IS_WRONG);
    }
    StorageDomainValidator validator = new StorageDomainValidator(getStorageDomain());
    retValue = retValue && validate(validator.isDomainExistAndActive()) && validate(validator.domainIsValidDestination());
    if (retValue && diskImage.getImageStatus() == ImageStatus.LOCKED) {
        retValue = false;
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED);
    }
    if (retValue && getDisk().getVmEntityType() != null) {
        if (getDisk().getVmEntityType().isVmType()) {
            retValue = canRemoveVmImageDisk();
        } else if (getDisk().getVmEntityType().isTemplateType()) {
            retValue = canRemoveTemplateDisk();
        }
    }
    return retValue;
}
Also used : StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 22 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.

the class AddDiskCommand method checkIfImageDiskCanBeAdded.

protected boolean checkIfImageDiskCanBeAdded(VM vm, DiskVmElementValidator diskVmElementValidator) {
    if (Guid.Empty.equals(getStorageDomainId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_SPECIFIED);
    }
    boolean returnValue;
    StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
    // vm agnostic checks
    returnValue = (getParameters().isSkipDomainCheck() || validate(storageDomainValidator.isDomainExistAndActive())) && validateShareableDiskOnGlusterDomain() && checkImageConfiguration() && validate(storageDomainValidator.hasSpaceForNewDisk(getDiskImageInfo())) && validate(storageDomainValidator.isDomainWithinThresholds()) && checkExceedingMaxBlockDiskSize() && canAddShareableDisk() && validate(diskVmElementValidator.isVirtIoScsiValid(vm)) && validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()));
    if (returnValue && vm != null) {
        // Note this is done according to the VM's spId.
        StoragePool sp = getStoragePool();
        returnValue = validate(new StoragePoolValidator(sp).existsAndUp()) && isStoragePoolMatching(vm) && validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot();
    }
    return returnValue;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 23 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.

the class AddDiskCommand method validate.

@Override
protected boolean validate() {
    if (!isFloatingDisk() && (!validate(new VmValidator(getVm()).isVmExists()) || !validateDiskVmData())) {
        return false;
    }
    Disk diskInfo = getParameters().getDiskInfo();
    if (diskInfo.getDiskStorageType() == DiskStorageType.IMAGE || diskInfo.getDiskStorageType() == DiskStorageType.CINDER) {
        getDiskImageInfo().setDiskSnapshot(false);
    }
    VM vm = getVm();
    DiskValidator diskValidator = getDiskValidator(getParameters().getDiskInfo());
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
    if (vm != null) {
        if (!validateDiskVmData() || !canRunActionOnNonManagedVm()) {
            return false;
        }
        updateDisksFromDb();
        if (getDiskVmElement().isBoot() && !validate(diskValidator.isVmNotContainsBootDisk(vm))) {
            return false;
        }
        if (!validatePassDiscardSupported(diskVmElementValidator)) {
            return false;
        }
        // if user sent drive check that its not in use
        if (!isDiskPassPciAndIdeLimit()) {
            return false;
        }
        if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
            return false;
        }
    } else if (Boolean.TRUE.equals(getParameters().getPlugDiskToVm())) {
        return failValidation(EngineMessage.CANNOT_ADD_FLOATING_DISK_WITH_PLUG_VM_SET);
    }
    if (!validateQuota()) {
        return false;
    }
    if (DiskStorageType.IMAGE == getParameters().getDiskInfo().getDiskStorageType()) {
        if (!checkIfImageDiskCanBeAdded(vm, diskVmElementValidator)) {
            return false;
        }
        return setAndValidateDiskProfiles();
    }
    if (DiskStorageType.LUN == getParameters().getDiskInfo().getDiskStorageType()) {
        return checkIfLunDiskCanBeAdded(diskValidator);
    }
    if (DiskStorageType.CINDER == getParameters().getDiskInfo().getDiskStorageType()) {
        CinderDisk cinderDisk = (CinderDisk) getParameters().getDiskInfo();
        cinderDisk.setStorageIds(new ArrayList<>(Collections.singletonList(getStorageDomainId())));
        StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
        CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisk);
        return validate(storageDomainValidator.isDomainExistAndActive()) && validate(cinderDisksValidator.validateCinderDiskLimits()) && validate(cinderDisksValidator.validateCinderVolumeTypesExist());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VM(org.ovirt.engine.core.common.businessentities.VM) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 24 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.

the class UpdateVmDiskCommand method validateCanResizeDisk.

protected boolean validateCanResizeDisk() {
    DiskImage newDiskImage = (DiskImage) getNewDisk();
    DiskImage oldDiskImage = (DiskImage) getOldDisk();
    if (newDiskImage.getSize() != oldDiskImage.getSize()) {
        if (Boolean.TRUE.equals(getVmDeviceForVm().getReadOnly())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_RESIZE_READ_ONLY_DISK);
        }
        if (vmDeviceForVm.getSnapshotId() != null) {
            DiskImage snapshotDisk = diskImageDao.getDiskSnapshotForVmSnapshot(getParameters().getDiskInfo().getId(), vmDeviceForVm.getSnapshotId());
            if (snapshotDisk.getSize() != newDiskImage.getSize()) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_RESIZE_DISK_SNAPSHOT);
            }
        }
        if (oldDiskImage.getSize() > newDiskImage.getSize()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_REQUESTED_DISK_SIZE_IS_TOO_SMALL);
        }
        StorageDomain storageDomain = storageDomainDao.get(newDiskImage.getStorageIds().get(0));
        if (storageDomain.getStorageType().isBlockDomain()) {
            Integer maxBlockDiskSize = Config.<Integer>getValue(ConfigValues.MaxBlockDiskSize);
            if (newDiskImage.getSize() / BYTES_IN_GB > maxBlockDiskSize) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_MAX_SIZE_EXCEEDED, String.format("$max_disk_size %1$s", maxBlockDiskSize));
            }
        }
        for (VM vm : getVmsDiskPluggedTo()) {
            if (!ActionUtils.canExecute(Collections.singletonList(vm), VM.class, ActionType.ExtendImageSize)) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_STATUS_ILLEGAL, LocalizedVmStatus.from(vm.getStatus()));
            }
        }
        StorageDomainValidator storageDomainValidator = getStorageDomainValidator((DiskImage) getNewDisk());
        if (!validate(storageDomainValidator.isDomainExistAndActive())) {
            return false;
        }
        // For size allocation validation, we'll create a dummy with the additional size required.
        // That way, the validator can hold all the logic about storage types.
        long additionalDiskSpaceInGB = newDiskImage.getSizeInGigabytes() - oldDiskImage.getSizeInGigabytes();
        DiskImage dummyForValidation = DiskImage.copyOf(newDiskImage);
        dummyForValidation.setSizeInGigabytes(additionalDiskSpaceInGB);
        return validate(storageDomainValidator.hasSpaceForNewDisk(dummyForValidation));
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 25 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.

the class AttachDiskToVmCommand method validate.

@Override
protected boolean validate() {
    if (disk == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
    }
    DiskValidator oldDiskValidator = new DiskValidator(disk);
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
        return validate(isHostedEngineDisk);
    }
    if (!checkOperationAllowedOnDiskContentType(disk)) {
        return false;
    }
    if (isOperationPerformedOnDiskSnapshot() && (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.isRegularSnapshot(getSnapshot())))) {
        return false;
    }
    boolean isImageDisk = disk.getDiskStorageType().isInternal();
    if (isImageDisk) {
        // TODO : this load and check of the active disk will be removed
        // after inspecting upgrade
        Disk activeDisk = diskHandler.loadActiveDisk(disk.getId());
        if (((DiskImage) activeDisk).getImageStatus() == ImageStatus.ILLEGAL) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION);
        }
        if (((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED) {
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
            addValidationMessageVariable("diskAliases", disk.getDiskAlias());
            return false;
        }
    }
    if (!validate(new VmValidator(getVm()).isVmExists()) || !isVmInUpPausedDownStatus()) {
        return false;
    }
    if (!validateDiskVmData()) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    updateDisksFromDb();
    if (getDiskVmElement().isBoot() && !validate(getDiskValidator(disk).isVmNotContainsBootDisk(getVm()))) {
        return false;
    }
    if (!isDiskPassPciAndIdeLimit()) {
        return false;
    }
    if (vmDeviceDao.exists(new VmDeviceId(disk.getId(), getVmId()))) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED);
    }
    if (!isOperationPerformedOnDiskSnapshot() && !disk.isShareable() && disk.getNumberOfVms() > 0) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NOT_SHAREABLE_DISK_ALREADY_ATTACHED);
    }
    if (isImageDisk && storagePoolIsoMapDao.get(new StoragePoolIsoMapId(((DiskImage) disk).getStorageIds().get(0), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    if (isImageDisk) {
        StorageDomain storageDomain = storageDomainDao.getForStoragePool(((DiskImage) disk).getStorageIds().get(0), ((DiskImage) disk).getStoragePoolId());
        StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomain);
        if (!validate(storageDomainValidator.isDomainExistAndActive())) {
            return false;
        }
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(disk, getDiskVmElement());
    if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
        return false;
    }
    if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
        return false;
    }
    if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
        return false;
    }
    Guid storageDomainId = disk.getDiskStorageType() == DiskStorageType.IMAGE ? ((DiskImage) disk).getStorageIds().get(0) : null;
    if (!validate(diskVmElementValidator.isPassDiscardSupported(storageDomainId))) {
        return false;
    }
    if (!isVmNotInPreviewSnapshot()) {
        return false;
    }
    if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
        return isDiskSupportedForPlugUnPlug(getDiskVmElement(), disk.getDiskAlias());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)36 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)17 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Guid (org.ovirt.engine.core.compat.Guid)11 ArrayList (java.util.ArrayList)7 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)7 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)6 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)5 HashMap (java.util.HashMap)4 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)4 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)4 List (java.util.List)3 Map (java.util.Map)3 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)3 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)2