use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator 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));
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator 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.MultipleStorageDomainsValidator 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.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class ImportValidator method validateSpaceRequirements.
public ValidationResult validateSpaceRequirements(Collection<DiskImage> diskImages) {
MultipleStorageDomainsValidator sdValidator = createMultipleStorageDomainsValidator(diskImages);
ValidationResult result = sdValidator.allDomainsExistAndActive();
if (!result.isValid()) {
return result;
}
result = sdValidator.allDomainsWithinThresholds();
if (!result.isValid()) {
return result;
}
if (params.getCopyCollapse()) {
return sdValidator.allDomainsHaveSpaceForClonedDisks(diskImages);
}
return sdValidator.allDomainsHaveSpaceForDisksWithSnapshots(diskImages);
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class AddVmAndCloneImageCommand method validate.
@Override
protected boolean validate() {
List<DiskImage> disksToCheck = getDiskImagesToValidate();
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksToCheck);
if (!validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(disksToCheck);
MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getStoragePoolId(), storageIds);
if (!validate(storageValidator.allDomainsExistAndActive())) {
return false;
}
if (!validate(new VmValidator(getSourceVmFromDb()).vmNotLocked())) {
return false;
}
// Run all checks for AddVm, now that it is determined snapshot exists
if (!super.validate()) {
return false;
}
for (DiskImage diskImage : getDiskImagesToBeCloned()) {
if (diskImage.getDiskStorageType() == DiskStorageType.IMAGE && !checkImageConfiguration(diskImage)) {
return false;
}
}
return true;
}
Aggregations