Search in sources :

Example 1 with DiskVmElementValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator 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 2 with DiskVmElementValidator

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

the class AddDiskCommand method checkIfLunDiskCanBeAdded.

protected boolean checkIfLunDiskCanBeAdded(DiskValidator diskValidator) {
    LunDisk lunDisk = (LunDisk) getParameters().getDiskInfo();
    LUNs lun = lunDisk.getLun();
    if (!validate(diskValidator.validateConnectionsInLun(lun.getLunType()))) {
        return false;
    }
    if (!validate(diskValidator.validateLunAlreadyInUse())) {
        return false;
    }
    if (getVm() != null && !(validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot())) {
        return false;
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
    if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
        return false;
    }
    if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
        return false;
    }
    if (getVds() != null) {
        lunFromStorage = getLunDisk(lun, getVds());
        if (lunFromStorage == null) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_INVALID);
        }
    }
    if (!validate(diskValidator.isUsingScsiReservationValid(getVm(), getDiskVmElement(), lunDisk))) {
        return false;
    }
    return true;
}
Also used : DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 3 with DiskVmElementValidator

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

the class UpdateVmDiskCommand method validate.

@Override
protected boolean validate() {
    if (!validate(new VmValidator(getVm()).isVmExists()) || !isDiskExistAndAttachedToVm(getOldDisk()) || !validateDiskVmData()) {
        return false;
    }
    boolean isDiskImageOrCinder = DiskStorageType.IMAGE == getOldDisk().getDiskStorageType() || DiskStorageType.CINDER == getOldDisk().getDiskStorageType();
    if (isDiskImageOrCinder) {
        ValidationResult imagesNotLocked = new DiskImagesValidator((DiskImage) getOldDisk()).diskImagesNotLocked();
        if (!imagesNotLocked.isValid()) {
            return validate(imagesNotLocked);
        }
    }
    DiskValidator oldDiskValidator = getDiskValidator(getOldDisk());
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
        return validate(isHostedEngineDisk);
    }
    if (!checkOperationAllowedOnDiskContentType(getOldDisk())) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    boolean isDiskInterfaceUpdated = getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface();
    if (!vmsDiskOrSnapshotPluggedTo.isEmpty()) {
        // only virtual drive size can be updated when VMs is running
        if (isAtLeastOneVmIsNotDown(vmsDiskOrSnapshotPluggedTo) && updateParametersRequiringVmDownRequested()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NOT_DOWN);
        }
        boolean isUpdatedAsBootable = !getOldDiskVmElement().isBoot() && getDiskVmElement().isBoot();
        // multiple boot disk snapshot can be attached to a single vm
        if (isUpdatedAsBootable && !validate(oldDiskValidator.isVmNotContainsBootDisk(getVm()))) {
            return false;
        }
        if (isDiskInterfaceUpdated && !isDiskPassPciAndIdeLimit()) {
            return false;
        }
    }
    if (isDiskImageOrCinder && !validateCanResizeDisk()) {
        return false;
    }
    if (resizeDiskImageRequested() && amendDiskRequested()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_AMEND_AND_EXTEND_IN_ONE_OPERATION);
    }
    if (isQcowCompatChangedOnRawDisk()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANT_AMEND_RAW_DISK);
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getNewDisk(), getDiskVmElement());
    return validateCanUpdateShareable() && validateCanUpdateReadOnly() && validateVmPoolProperties() && validateQuota() && validate(diskVmElementValidator.isVirtIoScsiValid(getVm())) && (!isDiskInterfaceUpdated || validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) && setAndValidateDiskProfiles() && validatePassDiscardSupported(diskVmElementValidator);
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 4 with DiskVmElementValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator 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)

Example 5 with DiskVmElementValidator

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

the class ImportVmCommand method validateLunDisk.

private List<EngineMessage> validateLunDisk(LunDisk lunDisk) {
    DiskValidator diskValidator = getDiskValidator(lunDisk);
    LUNs lun = lunDisk.getLun();
    StorageType storageType;
    if (lun.getLunConnections() != null && !lun.getLunConnections().isEmpty()) {
        // We set the storage type based on the first connection since connections should be with the same
        // storage type
        storageType = lun.getLunConnections().get(0).getStorageType();
    } else {
        storageType = StorageType.FCP;
    }
    if (storageType == StorageType.ISCSI) {
        ValidationResult connectionsInLunResult = diskValidator.validateConnectionsInLun(storageType);
        if (!connectionsInLunResult.isValid()) {
            return connectionsInLunResult.getMessages();
        }
    }
    ValidationResult lunAlreadyInUseResult = diskValidator.validateLunAlreadyInUse();
    if (!lunAlreadyInUseResult.isValid()) {
        return lunAlreadyInUseResult.getMessages();
    }
    DiskVmElementValidator diskVmElementValidator = new DiskVmElementValidator(lunDisk, lunDisk.getDiskVmElementForVm(getVmId()));
    ValidationResult virtIoScsiResult = isVirtIoScsiValid(getVm(), diskVmElementValidator);
    if (!virtIoScsiResult.isValid()) {
        return virtIoScsiResult.getMessages();
    }
    ValidationResult diskInterfaceResult = diskVmElementValidator.isDiskInterfaceSupported(getVm());
    if (!diskInterfaceResult.isValid()) {
        return diskInterfaceResult.getMessages();
    }
    Guid vdsId = vdsCommandsHelper.getHostForExecution(getStoragePoolId());
    if (vdsId == null || !validateLunExistsAndInitDeviceData(lun, storageType, vdsId)) {
        return Arrays.asList(EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_INVALID);
    }
    ValidationResult usingScsiReservationResult = diskValidator.isUsingScsiReservationValid(getVm(), lunDisk.getDiskVmElementForVm(getVmId()), lunDisk);
    if (!usingScsiReservationResult.isValid()) {
        return usingScsiReservationResult.getMessages();
    }
    return Collections.emptyList();
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs)

Aggregations

DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)5 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)4 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)3 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)2 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 LUNs (org.ovirt.engine.core.common.businessentities.storage.LUNs)2 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)2 Guid (org.ovirt.engine.core.compat.Guid)2 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)1 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)1 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)1