use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class RemoveVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
if (getVm().isDeleteProtected()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED);
}
vmHandler.updateDisksFromDb(getVm());
getParameters().setUseCinderCommandCallback(getParameters().isRemoveDisks() && !getCinderDisks().isEmpty());
if (!getParameters().isRemoveDisks() && !canRemoveVmWithDetachDisks()) {
return false;
}
switch(getVm().getStatus()) {
case Unassigned:
case Down:
case ImageIllegal:
case ImageLocked:
break;
case Suspended:
return failValidation(EngineMessage.VM_CANNOT_REMOVE_VM_WHEN_STATUS_IS_NOT_DOWN);
default:
return (getVm().isHostedEngine() && isInternalExecution()) || failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_RUNNING);
}
if (getVm().getVmPoolId() != null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
}
// enable to remove vms without images
if (!validate(snapshotsValidator.vmNotDuringSnapshot(getVmId()))) {
return false;
}
Collection<Disk> vmDisks = getVm().getDiskMap().values();
List<DiskImage> vmImages = DisksFilter.filterImageDisks(vmDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
if (!vmImages.isEmpty() && !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
vmImages.addAll(DisksFilter.filterCinderDisks(vmDisks));
if (!vmImages.isEmpty()) {
Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(vmImages);
MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
if (!validate(storageValidator.allDomainsExistAndActive())) {
return false;
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
if (!getParameters().getForce() && !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
}
// Handle VM status with ImageLocked
VmValidator vmValidator = new VmValidator(getVm());
ValidationResult vmLockedValidatorResult = vmValidator.vmNotLocked();
if (!vmLockedValidatorResult.isValid()) {
// without force remove, we can't remove the VM
if (!getParameters().getForce()) {
return failValidation(vmLockedValidatorResult.getMessages());
}
// If it is force, we cannot remove if there are task
if (commandCoordinatorUtil.hasTasksByStoragePoolId(getVm().getStoragePoolId())) {
return failValidation(EngineMessage.VM_CANNOT_REMOVE_HAS_RUNNING_TASKS);
}
}
if (getParameters().isRemoveDisks() && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
return false;
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class CreateSnapshotForVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
return false;
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
Set<Guid> specifiedDiskIds = getParameters().getDiskIds();
if (specifiedDiskIds != null && !specifiedDiskIds.isEmpty()) {
if (!isSpecifiedDisksExist(specifiedDiskIds)) {
return false;
}
List<Disk> allDisksForVm = diskDao.getAllForVm(getVm().getId());
String notAllowSnapshot = allDisksForVm.stream().filter(disk -> specifiedDiskIds.contains(disk.getId())).filter(disk -> !disk.isAllowSnapshot()).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
if (!notAllowSnapshot.isEmpty()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_SNAPSHOT_NOT_SUPPORTED, String.format("$diskAliases %s", notAllowSnapshot));
}
Set<Guid> guidsOfVmDisks = allDisksForVm.stream().map(BaseDisk::getId).collect(Collectors.toSet());
String notAttachedToVm = specifiedDiskIds.stream().filter(guid -> !guidsOfVmDisks.contains(guid)).map(guid -> diskDao.get(guid)).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
if (!notAttachedToVm.isEmpty()) {
String[] replacements = { ReplacementUtils.createSetVariableString("VmName", getVm().getName()), ReplacementUtils.createSetVariableString("diskAliases", notAttachedToVm) };
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISKS_NOT_ATTACHED_TO_VM, replacements);
}
}
// Initialize validators.
VmValidator vmValidator = createVmValidator();
StoragePoolValidator spValidator = createStoragePoolValidator();
if (!(validateVM(vmValidator) && validate(spValidator.existsAndUp()) && validate(vmValidator.vmNotIlegal()) && validate(vmValidator.vmNotLocked()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(vmValidator.vmNotDuringMigration()) && validate(vmValidator.vmNotRunningStateless()) && (!getParameters().isSaveMemory() || validate(vmValidator.vmNotHavingPciPassthroughDevices())))) {
return false;
}
List<DiskImage> disksList = getDisksListForChecks();
if (disksList.size() > 0) {
DiskImagesValidator diskImagesValidator = createDiskImageValidator(disksList);
if (!(validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(vmValidator.vmWithoutLocalDiskUserProperty()))) {
return false;
}
}
return validateStorage();
}
use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method validate.
@Override
protected boolean validate() {
initializeObjectState();
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
VmValidator vmValidator = createVmValidator(getVm());
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) || !validateVmSnapshotDisksNotDuringMerge() || !validateVmNotInPreview() || !validateSnapshotExists() || !validateSnapshotType() || !validate(vmValidator.vmQualifiedForSnapshotMerge()) || !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
return false;
}
if (hasImages()) {
// Check the VM's images
if (!validateImages()) {
return false;
}
// check that we are not deleting the template
if (!validateImageNotInTemplate()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_REMOVE_IMAGE_TEMPLATE);
}
if (!validateStorageDomains()) {
return false;
}
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
if (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.snapshotExists(getVmId(), getSnapshot().getId())) || !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
if (Guid.Empty.equals(getSnapshot().getId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
VmValidator vmValidator = createVmValidator(getVm());
MultipleStorageDomainsValidator storageValidator = createStorageDomainValidator();
if (!validate(storageValidator.allDomainsExistAndActive()) || !performImagesChecks() || !validate(vmValidator.vmDown()) || // if the user choose to commit a snapshot the vm can't have disk snapshots attached to other vms.
getSnapshot().getType() == SnapshotType.REGULAR && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
return false;
}
if (getSnapshot().getType() == SnapshotType.REGULAR && getSnapshot().getStatus() != SnapshotStatus.IN_PREVIEW) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW);
}
if (!canRestoreVmConfigFromSnapshot()) {
return failValidation(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class ScanStorageForUnregisteredDisksCommand method validate.
@Override
protected boolean validate() {
StoragePoolValidator validator = createStoragePoolValidator();
boolean returnValue = validate(validator.exists()) && validate(validator.isNotInStatus(StoragePoolStatus.Uninitialized)) && checkStorageDomain() && checkStorageDomainStatus(StorageDomainStatus.Active) && checkForActiveVds() != null;
return returnValue;
}
Aggregations