use of org.ovirt.engine.core.bll.validator.RunVmValidator in project ovirt-engine by oVirt.
the class RunVmCommandTest method mockSuccessfulRunVmValidator.
private RunVmValidator mockSuccessfulRunVmValidator() {
RunVmValidator runVmValidator = mock(RunVmValidator.class);
when(runVmValidator.canRunVm(any(), any(), any(), any(), any(), anyBoolean())).thenReturn(true);
doReturn(runVmValidator).when(command).getRunVmValidator();
return runVmValidator;
}
use of org.ovirt.engine.core.bll.validator.RunVmValidator in project ovirt-engine by oVirt.
the class RunVmCommand method validateImpl.
@Override
protected boolean validateImpl() {
VM vm = getVm();
if (vm == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (!validateObject(vm.getStaticData())) {
return false;
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
if (getVm().getCustomCompatibilityVersion() != null && vm.getCustomCompatibilityVersion().less(getStoragePool().getCompatibilityVersion())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_COMATIBILITY_VERSION_NOT_SUPPORTED, String.format("$VmName %1$s", getVm().getName()), String.format("$VmVersion %1$s", getVm().getCustomCompatibilityVersion().toString()), String.format("$DcVersion %1$s", getStoragePool().getCompatibilityVersion()));
}
RunVmValidator runVmValidator = getRunVmValidator();
if (!runVmValidator.canRunVm(getReturnValue().getValidationMessages(), getStoragePool(), getRunVdssList(), getVdsWhiteList(), getCluster(), getParameters().isRunInUnknownStatus())) {
return false;
}
if (!validate(runVmValidator.validateNetworkInterfaces())) {
return false;
}
if (!validate(runVmValidator.validateVmLease())) {
return false;
}
if (!checkRngDeviceClusterCompatibility()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_RNG_SOURCE_NOT_SUPPORTED);
}
if (!validate(checkDisksInBackupStorage())) {
return false;
}
boolean isWindowsOs = osRepository.isWindows(getVm().getVmOsId());
boolean isCloudInitEnabled = (!getVm().isInitialized() && getVm().getVmInit() != null && !isWindowsOs) || (getParameters().getInitializationType() == InitializationType.CloudInit);
if (isCloudInitEnabled && hasMaximumNumberOfDisks()) {
return failValidation(EngineMessage.VMPAYLOAD_CDROM_OR_CLOUD_INIT_MAXIMUM_DEVICES);
}
if (!validate(vmHandler.isCpuSupported(getVm().getVmOsId(), getVm().getCompatibilityVersion(), getCluster().getCpuName()))) {
return false;
}
try {
acquireHostDevicesLock();
if (!checkRequiredHostDevicesAvailability()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_HOST_DEVICE_NOT_AVAILABLE);
}
} finally {
releaseHostDevicesLock();
}
if (!validate(runVmValidator.validateUsbDevices(getVm().getStaticData()))) {
return false;
}
return true;
}
use of org.ovirt.engine.core.bll.validator.RunVmValidator in project ovirt-engine by oVirt.
the class VmPoolHandler method canRunPoolVm.
private boolean canRunPoolVm(Guid vmId, List<String> messages) {
VM vm = vmDao.get(vmId);
if (vm == null) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND.name());
return false;
}
// TODO: This is done to keep consistency with VmDao.getById.
// It can probably be removed, but that requires some more research
vmHandler.updateNetworkInterfacesFromDb(vm);
RunVmParams runVmParams = new RunVmParams(vmId);
return Injector.injectMembers(new RunVmValidator(vm, runVmParams, false, findActiveISODomain(vm.getStoragePoolId()))).canRunVm(messages, fetchStoragePool(vm.getStoragePoolId()), Collections.emptyList(), Collections.emptyList(), clusterDao.get(vm.getClusterId()), false);
}
Aggregations