use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class InstanceTypeManager method updateRngDevice.
protected void updateRngDevice(final VmBase vmBase) {
if (model.getIsRngEnabled().getIsChangable() && model.getIsRngEnabled().getIsAvailable()) {
if (!isNextRunConfigurationExists()) {
Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
deactivate();
List<VmDevice> rngDevices = returnValue.getReturnValue();
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
if (!rngDevices.isEmpty()) {
VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion());
getModel().setRngDevice(rngDevice);
}
activate();
updateVirtioScsi(vmBase);
}));
} else {
deactivate();
VmDevice rngDevice = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.RNG);
getModel().getIsRngEnabled().setEntity(rngDevice != null);
if (rngDevice != null) {
getModel().setRngDevice(new VmRngDevice(rngDevice));
}
activate();
updateVirtioScsi(vmBase);
}
} else {
updateVirtioScsi(vmBase);
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class BackendVmsResource method copyRngDeviceFromTemplateOrInstanceType.
// TODO: Move user input and template/instance-type merging code to backed
private void copyRngDeviceFromTemplateOrInstanceType(AddVmParameters params, VmStatic vmStatic, Cluster cluster, Guid templateId, Guid instanceTypeId) {
List<VmRngDevice> devices = VmHelper.getRngDevicesForEntity(this, instanceTypeId != null ? instanceTypeId : templateId);
if (devices != null && !devices.isEmpty()) {
final VmRngDevice rngDevice = devices.get(0);
final Version effectiveVersion = CommonCompatibilityVersionUtils.getEffective(vmStatic.getCustomCompatibilityVersion(), cluster.getCompatibilityVersion(), null);
rngDevice.updateSourceByVersion(effectiveVersion);
boolean supported = EnumSet.of(RngUtils.RngValidationResult.VALID, RngUtils.RngValidationResult.UNSUPPORTED_URANDOM_OR_RANDOM).contains(RngUtils.validate(cluster, rngDevice));
if (shouldCopyDevice(supported, templateId, instanceTypeId)) {
params.setUpdateRngDevice(true);
params.setRngDevice(rngDevice);
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class RunVmCommandTest method testValidateUnsupportedRng.
@Theory
public void testValidateUnsupportedRng(VmRngDevice.Source vmRngSource, Set<VmRngDevice.Source> clusterReqSources) {
final VM vm = new VM();
vm.setStatus(VMStatus.Down);
vm.setId(command.getVmId());
command.setVm(vm);
Cluster cluster = mock(Cluster.class);
when(cluster.getRequiredRngSources()).thenReturn(clusterReqSources);
command.setCluster(cluster);
VmRngDevice rngDevice = new VmRngDevice();
rngDevice.setSource(vmRngSource);
VmDevice rngAsDevice = new VmDevice();
rngAsDevice.setSpecParams(rngDevice.getSpecParams());
when(deviceDao.getVmDeviceByVmIdTypeAndDevice(command.getVmId(), VmDeviceGeneralType.RNG, VmDeviceType.VIRTIO)).thenReturn(Collections.singletonList(rngAsDevice));
assertThat(command.checkRngDeviceClusterCompatibility(), is(clusterReqSources.contains(vmRngSource)));
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class UpdateRngDeviceTest method getDevice.
private static VmRngDevice getDevice(Guid deviceId, Guid vmId) {
VmRngDevice device = new VmRngDevice();
device.setVmId(vmId);
device.setDeviceId(deviceId);
device.setBytes(12);
device.setPeriod(34);
device.setSource(VmRngDevice.Source.RANDOM);
return device;
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class RngDeviceSpecParamsTest method testGenerateFullSpecParams.
@Test
public void testGenerateFullSpecParams() {
VmRngDevice dev = new VmRngDevice();
dev.setBytes(12);
dev.setPeriod(34);
dev.setSource(VmRngDevice.Source.RANDOM);
Map<String, Object> expectedParams = new HashMap<>();
expectedParams.put("bytes", "12");
expectedParams.put("period", "34");
expectedParams.put("source", "random");
assertEquals(expectedParams, dev.getSpecParams());
}
Aggregations