use of org.ovirt.engine.core.bll.validator.storage.DiskValidator in project ovirt-engine by oVirt.
the class SparsifyImageCommand method validate.
@Override
protected boolean validate() {
DiskValidator diskValidator = new DiskValidator(getDiskImage());
if (!validate(diskValidator.isDiskExists()) || !validate(diskValidator.isDiskPluggedToAnyNonDownVm(false)) || !validate(diskValidator.isSparsifySupported())) {
return false;
}
if (diskImageDao.getAllSnapshotsForImageGroup(getDiskImage().getId()).size() > 1) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_HAS_SNAPSHOTS);
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(getDiskImage()));
return validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesHaveNoDerivedDisks(null));
}
use of org.ovirt.engine.core.bll.validator.storage.DiskValidator 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);
}
use of org.ovirt.engine.core.bll.validator.storage.DiskValidator 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;
}
use of org.ovirt.engine.core.bll.validator.storage.DiskValidator 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();
}
Aggregations