use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.
the class OvfHelper method generateOvfConfigurationForVm.
public String generateOvfConfigurationForVm(VM vm) {
if (VMStatus.ImageLocked != vm.getStatus()) {
vmHandler.updateDisksFromDb(vm);
DiskImagesValidator validator = new DiskImagesValidator(vm.getDiskList());
if (validator.diskImagesNotLocked().isValid()) {
loadVmData(vm);
Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
// currentDbGeneration can be null in case that the vm was deleted during the run of OvfDataUpdater.
if (currentDbGeneration != null && vm.getStaticData().getDbGeneration() == currentDbGeneration) {
return buildMetadataDictionaryForVm(vm);
}
}
}
return null;
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator 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.DiskImagesValidator 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.DiskImagesValidator in project ovirt-engine by oVirt.
the class RemoveDiskSnapshotsCommand method validateAllDiskImages.
protected boolean validateAllDiskImages() {
List<DiskImage> images = diskImageDao.getAllSnapshotsForImageGroup(getDiskImage().getId());
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(images);
return validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal());
}
use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator 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