use of org.ovirt.engine.core.bll.validator.VmValidator in project ovirt-engine by oVirt.
the class AddVmFromSnapshotCommandTest method testCannotDisableVirtioScsiCanDisableIDE.
@Test
public void testCannotDisableVirtioScsiCanDisableIDE() {
cmd.getParameters().setVirtioScsiEnabled(false);
VM vm = new VM();
doReturn(vm).when(cmd).getVmFromConfiguration();
DiskImage disk = new DiskImage();
disk.setPlugged(true);
DiskVmElement dve = new DiskVmElement(disk.getId(), vm.getId());
dve.setDiskInterface(DiskInterface.VirtIO_SCSI);
disk.setDiskVmElements(Collections.singletonList(dve));
doReturn(Collections.singletonList(disk)).when(cmd).getAdjustedDiskImagesFromConfiguration();
VmValidator vmValidator = spy(new VmValidator(vm));
doReturn(vmValidator).when(cmd).createVmValidator(vm);
assertFalse(cmd.checkCanDisableVirtIoScsi());
ValidateTestUtils.assertValidationMessages("Validation should prevent disabling of virtIO-scsi.", cmd, EngineMessage.CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS);
dve.setDiskInterface(DiskInterface.IDE);
assertTrue(cmd.checkCanDisableVirtIoScsi());
}
use of org.ovirt.engine.core.bll.validator.VmValidator 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;
}
use of org.ovirt.engine.core.bll.validator.VmValidator in project ovirt-engine by oVirt.
the class ExportVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
setDescription(getVmName());
setStoragePoolId(getVm().getStoragePoolId());
// check that target domain exists
StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
return false;
}
// load the disks of vm from database
vmHandler.updateDisksFromDb(getVm());
List<DiskImage> disksForExport = getDisksBasedOnImage();
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
// update vm snapshots for storage free space check
imagesHandler.fillImagesBySnapshots(getVm());
// check that the target and source domain are in the same storage_pool
if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
}
// check if template exists only if asked for
if (getParameters().getTemplateMustExists()) {
if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
}
}
Map<Guid, ? extends Disk> images = getVm().getDiskMap();
if (getParameters().getCopyCollapse()) {
for (DiskImage img : disksForExport) {
if (images.containsKey(img.getId())) {
// check that no RAW format exists (we are in collapse mode)
if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
}
}
}
}
// check destination storage is Export domain
if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
}
// get the snapshots that are going to be exported and have memory
snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
// check destination storage have free space
if (!handleDestStorageDomain(disksForExport)) {
return false;
}
if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
return false;
}
return true;
}
use of org.ovirt.engine.core.bll.validator.VmValidator in project ovirt-engine by oVirt.
the class AddDiskCommand method checkIfImageDiskCanBeAdded.
protected boolean checkIfImageDiskCanBeAdded(VM vm, DiskVmElementValidator diskVmElementValidator) {
if (Guid.Empty.equals(getStorageDomainId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_SPECIFIED);
}
boolean returnValue;
StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
// vm agnostic checks
returnValue = (getParameters().isSkipDomainCheck() || validate(storageDomainValidator.isDomainExistAndActive())) && validateShareableDiskOnGlusterDomain() && checkImageConfiguration() && validate(storageDomainValidator.hasSpaceForNewDisk(getDiskImageInfo())) && validate(storageDomainValidator.isDomainWithinThresholds()) && checkExceedingMaxBlockDiskSize() && canAddShareableDisk() && validate(diskVmElementValidator.isVirtIoScsiValid(vm)) && validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()));
if (returnValue && vm != null) {
// Note this is done according to the VM's spId.
StoragePool sp = getStoragePool();
returnValue = validate(new StoragePoolValidator(sp).existsAndUp()) && isStoragePoolMatching(vm) && validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot();
}
return returnValue;
}
use of org.ovirt.engine.core.bll.validator.VmValidator 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;
}
Aggregations