use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class VmPoolHandler method isNonPrestartedVmFree.
/**
* Check if a specific VM is free. A VM is considered free if it isn't attached to a user and not during preview
* @param vmId The VM ID
* @param errorProcessor the error messages processor object or lambda expression (may be <code>null</code>)
* @return True if the VM is free, false otherwise
*/
public boolean isNonPrestartedVmFree(Guid vmId, ErrorProcessor errorProcessor) {
List<String> messages = new ArrayList<>();
// check that there is no user already attached to this VM
if (vmAssignedToUser(vmId, messages)) {
return failVmFree(errorProcessor, vmId, messages);
}
// check that VN can be run
if (!canRunPoolVm(vmId, messages)) {
return failVmFree(errorProcessor, vmId, messages);
}
// check VM images
ValidationResult vmDuringSnapshotResult = snapshotsValidator.vmNotDuringSnapshot(vmId);
if (!vmDuringSnapshotResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmDuringSnapshotResult.getMessagesAsStrings());
}
ValidationResult vmInPreviewResult = snapshotsValidator.vmNotInPreview(vmId);
if (!vmInPreviewResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmInPreviewResult.getMessagesAsStrings());
}
List<Disk> disks = diskDao.getAllForVm(vmId);
List<DiskImage> vmImages = DisksFilter.filterImageDisks(disks, ONLY_NOT_SHAREABLE, ONLY_SNAPABLE);
VM vm = vmDao.get(vmId);
StoragePool sp = storagePoolDao.get(vm.getStoragePoolId());
ValidationResult spUpResult = new StoragePoolValidator(sp).existsAndUp();
if (!spUpResult.isValid()) {
return failVmFree(errorProcessor, vmId, spUpResult.getMessagesAsStrings());
}
Guid storageDomainId = vmImages.size() > 0 ? vmImages.get(0).getStorageIds().get(0) : Guid.Empty;
if (!Guid.Empty.equals(storageDomainId)) {
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, sp.getId()));
ValidationResult domainActiveResult = storageDomainValidator.isDomainExistAndActive();
if (!domainActiveResult.isValid()) {
return failVmFree(errorProcessor, vmId, domainActiveResult.getMessagesAsStrings());
}
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
ValidationResult disksNotLockedResult = diskImagesValidator.diskImagesNotLocked();
if (!disksNotLockedResult.isValid()) {
messages.addAll(disksNotLockedResult.getMessagesAsStrings());
messages.addAll(disksNotLockedResult.getVariableReplacements());
return failVmFree(errorProcessor, vmId, messages);
}
ValidationResult vmNotLockResult = new VmValidator(vm).vmNotLocked();
if (!vmNotLockResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmNotLockResult.getMessagesAsStrings());
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class MigrateVmCommand method validateImpl.
@Override
protected boolean validateImpl() {
final VM vm = getVm();
if (vm == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
VmValidator vmValidator = getVmValidator();
if (!validate(vmValidator.isVmPluggedDiskNotUsingScsiReservation())) {
return false;
}
if (!FeatureSupported.isMigrationSupported(getCluster().getArchitecture(), getCluster().getCompatibilityVersion())) {
return failValidation(EngineMessage.MIGRATION_IS_NOT_SUPPORTED);
}
// If VM is pinned to host, no migration can occur
if (vm.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST);
}
if (vm.getMigrationSupport() == MigrationSupport.IMPLICITLY_NON_MIGRATABLE && !getParameters().isForceMigrationForNonMigratableVm()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE);
}
switch(vm.getStatus()) {
case MigratingFrom:
return failValidation(EngineMessage.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);
case NotResponding:
return failVmStatusIllegal();
case Paused:
if (vm.getVmPauseStatus() == VmPauseStatus.EIO) {
return failValidation(EngineMessage.MIGRATE_PAUSED_EIO_VM_IS_NOT_SUPPORTED);
}
break;
default:
}
if (!vm.isQualifyToMigrate()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NOT_RUNNING);
}
if (!validate(new MultipleVmsValidator(vm).vmNotHavingPluggedDiskSnapshots(EngineMessage.ACTION_TYPE_FAILED_VM_HAS_PLUGGED_DISK_SNAPSHOT)) || !validate(vmValidator.allPassthroughVnicsMigratable())) {
return false;
}
if (getParameters().getTargetClusterId() != null) {
ChangeVmClusterValidator changeVmClusterValidator = ChangeVmClusterValidator.create(this, getParameters().getTargetClusterId(), getVm().getCustomCompatibilityVersion());
if (!changeVmClusterValidator.validate()) {
return false;
}
}
if (isInternalExecution() && getVm().getMigrationSupport() != MigrationSupport.MIGRATABLE) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE);
}
return validate(snapshotsValidator.vmNotDuringSnapshot(vm.getId())) && // TODO: replace it with a better solution
validate(new DiskImagesValidator(callFilterImageDisks(vm)).diskImagesNotLocked()) && !schedulingManager.canSchedule(getCluster(), getVm(), getVdsBlackList(), getVdsWhiteList(), getReturnValue().getValidationMessages()).isEmpty();
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method validateImages.
protected boolean validateImages() {
// images related checks
if (!images.isEmpty()) {
if (!validateVmNotDuringSnapshot()) {
return false;
}
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
List<CinderDisk> cinderDisks = getCinderDisks();
CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisks);
if (!validate(cinderDisksValidator.validateCinderDiskLimits())) {
return false;
}
if (!validate(isPassDiscardSupportedForImagesDestSds())) {
return false;
}
List<DiskImage> diskImagesToCheck = DisksFilter.filterImageDisks(images, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
diskImagesToCheck.addAll(cinderDisks);
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImagesToCheck);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
MultipleStorageDomainsValidator storageDomainsValidator = getStorageDomainsValidator(getStoragePoolId(), sourceImageDomainsImageMap.keySet());
if (!validate(storageDomainsValidator.allDomainsExistAndActive())) {
return false;
}
Set<Guid> destImageDomains = getStorageGuidSet();
destImageDomains.removeAll(sourceImageDomainsImageMap.keySet());
for (Guid destImageDomain : destImageDomains) {
StorageDomain storage = storageDomainDao.getForStoragePool(destImageDomain, getVm().getStoragePoolId());
if (storage == null) {
// domain is not in the same storage pool as the vm
if (storageDomainStaticDao.get(destImageDomain) == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
} else {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL);
}
return false;
}
if (storage.getStatus() == null || storage.getStatus() != StorageDomainStatus.Active) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL);
return false;
}
if (storage.getStorageDomainType().isIsoOrImportExportDomain()) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
return false;
}
}
return validateSpaceRequirements();
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class VmValidator method vmNotHavingDeviceSnapshotsAttachedToOtherVms.
/**
* @return ValidationResult indicating whether snapshots of disks are attached to other vms.
*/
public ValidationResult vmNotHavingDeviceSnapshotsAttachedToOtherVms(boolean onlyPlugged) {
List<Disk> vmDisks = getDbFacade().getDiskDao().getAllForVm(vm.getId());
ValidationResult result = new DiskImagesValidator(DisksFilter.filterImageDisks(vmDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE)).diskImagesSnapshotsNotAttachedToOtherVms(onlyPlugged);
if (result != ValidationResult.VALID) {
return result;
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class RemoveDiskSnapshotsCommandTest method setUp.
@Before
public void setUp() {
doReturn(storageDomainValidator).when(cmd).getStorageDomainValidator();
doReturn(STORAGE_POOLD_ID).when(cmd).getStoragePoolId();
doReturn(mockImages()).when(cmd).getImages();
mockVm();
vmValidator = spy(new VmValidator(cmd.getVm()));
doReturn(vmValidator).when(cmd).createVmValidator(any());
DiskImagesValidator diskImagesValidator = spy(new DiskImagesValidator(mockImages()));
doReturn(diskImagesValidator).when(cmd).createDiskImageValidator(any());
doReturn(ValidationResult.VALID).when(diskImagesValidator).diskImagesSnapshotsNotAttachedToOtherVms(false);
}
Aggregations