@Mapping(from = VmRngDevice.class, to = RngDevice.class) public static RngDevice map(VmRngDevice entity, RngDevice template) { RngDevice model = (template == null) ? new RngDevice() : template; if (entity.getBytes() != null) { model.setRate(new Rate()); model.getRate().setBytes(entity.getBytes()); if (entity.getPeriod() != null) { model.getRate().setPeriod(entity.getPeriod()); } } RngSource restSource = map(entity.getSource(), null); model.setSource(restSource); return model; }
public VmRngDevice generateRngDevice() { VmRngDevice dev = new VmRngDevice(); dev.setBytes(rngBytes.getEntity()); dev.setPeriod(rngPeriod.getEntity()); dev.setSource(Boolean.TRUE.equals(rngSourceUrandom.getEntity()) ? getBehavior().getUrandomOrRandomRngSource() : VmRngDevice.Source.HWRNG); return dev; }
protected void updateRngDevice(Guid templateId) { Frontend.getInstance().runQuery( QueryType.GetRngDevice, new IdQueryParameters(templateId), new AsyncQuery<QueryReturnValue>(returnValue -> { List<VmRngDevice> devs = returnValue.getReturnValue(); getModel().getIsRngEnabled().setEntity(!devs.isEmpty()); final VmRngDevice rngDevice = devs.isEmpty() ? new VmRngDevice() : devs.get(0); rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion()); getModel().setRngDevice(rngDevice); } )); }
/** * Checks whether it is ok to have {@code rngDevice} assigned to a VM / Template with {@code effectiveVersion} * in {@code cluster}. */ public static RngValidationResult validate(Cluster cluster, VmRngDevice rngDevice) { VmRngDevice.Source source = rngDevice.getSource(); if (cluster == null) { return validateForNonClusterEntity(source); } // This can be dropped when we stop to support 4.0 compatibility level if (cluster.getCompatibilityVersion() != null && EnumSet.of(VmRngDevice.Source.URANDOM, VmRngDevice.Source.RANDOM).contains(source) && containsAtLeastOne(cluster.getRequiredRngSources(), VmRngDevice.Source.URANDOM, VmRngDevice.Source.RANDOM) && !cluster.getRequiredRngSources().contains(source)) { return RngValidationResult.UNSUPPORTED_URANDOM_OR_RANDOM; } final boolean valid = cluster.getRequiredRngSources().contains(source); return valid ? RngValidationResult.VALID : RngValidationResult.INVALID; }
public void doBuild() { buildModel(entity, (source, destination) -> { Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(entity.getId()), new AsyncQuery<>( (QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue()) )); getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), entity.getId()); getInstance().getWatchdogByVmId(new AsyncQuery<QueryReturnValue>(returnValue -> { @SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue(); for (VmWatchdog watchdog : watchdogs) { getModel().getWatchdogAction().setSelectedItem(watchdog.getAction()); getModel().getWatchdogModel().setSelectedItem(watchdog.getModel()); } }), entity.getId()); Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> { List<VmDevice> rngDevices = returnValue.getReturnValue(); getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty()); if (!rngDevices.isEmpty()) { VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0)); getModel().setRngDevice(rngDevice); } } )); getModel().getEmulatedMachine().setSelectedItem(entity.getCustomEmulatedMachine()); getModel().getCustomCpu().setSelectedItem(entity.getCustomCpuName()); getModel().getMigrationMode().setSelectedItem(entity.getMigrationSupport()); postBuild(); }); }
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 = CompatibilityVersionUtils.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); } } }
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty()); if (!rngDevices.isEmpty()) { VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0)); getModel().setRngDevice(rngDevice);
@Mapping(from = RngDevice.class, to = VmRngDevice.class) public static VmRngDevice map(RngDevice model, VmRngDevice template) { if (model != null && model.isSetSource()) { VmRngDevice dev = new VmRngDevice(); if (model.isSetRate()) { dev.setBytes(model.getRate().getBytes()); if (model.getRate().isSetPeriod()) { dev.setPeriod(model.getRate().getPeriod()); } } VmRngDevice.Source source = VmRngDevice.Source.valueOf(model.getSource().name()); if (source != null) { dev.setSource(source); return dev; } } return null; }
public void setRngDevice(VmRngDevice dev) { maybeSetEntity(rngBytes, dev.getBytes() == null ? null : dev.getBytes()); maybeSetEntity(rngPeriod, dev.getPeriod() == null ? null : dev.getPeriod()); maybeSetEntity(rngSourceUrandom, dev.getSource() == VmRngDevice.Source.RANDOM); maybeSetEntity(rngSourceHwrng, dev.getSource() == VmRngDevice.Source.HWRNG); // post check - at least one source must be selected // if, for example, instance type has forbidden source checked, maybeSetEntity doesn't select any source, which // is invalid if (!Boolean.TRUE.equals(rngSourceUrandom.getEntity()) && !Boolean.TRUE.equals(rngSourceHwrng.getEntity())) { getBehavior().deactivateInstanceTypeManager(); EntityModel[] entityModels = { rngSourceUrandom, rngSourceHwrng }; for (EntityModel entityModel : entityModels) { if (entityModel.getIsAvailable() && entityModel.getIsChangable()) { entityModel.setEntity(Boolean.TRUE); // select first available break; } } getBehavior().activateInstanceTypeManager(); } }
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty()); if (!rngDevices.isEmpty()) { VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0)); rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion()); getModel().setRngDevice(rngDevice); getModel().getIsRngEnabled().setEntity(rngDevice != null); if (rngDevice != null) { getModel().setRngDevice(new VmRngDevice(rngDevice));
@Test public void testMapFromRestToBackend() { RngDevice model = new RngDevice(); model.setSource(RngSource.HWRNG); model.setRate(new Rate()); model.getRate().setBytes(10); model.getRate().setPeriod(11); VmRngDevice expected = new VmRngDevice(); expected.setBytes(10); expected.setPeriod(11); expected.setSource(VmRngDevice.Source.HWRNG); assertEquals(expected, RngDeviceMapper.map(model, null)); } }
@Test public void testMapFromBackendToRest() { VmRngDevice entity = new VmRngDevice(); entity.setBytes(11); entity.setPeriod(10); entity.setSource(VmRngDevice.Source.RANDOM); RngDevice expected = new RngDevice(); expected.setRate(new Rate()); expected.getRate().setBytes(11); expected.getRate().setPeriod(10); expected.setSource(RngSource.RANDOM); assertEquals(expected.getRate().getBytes(), RngDeviceMapper.map(entity, null).getRate().getBytes()); assertEquals(expected.getRate().getPeriod(), RngDeviceMapper.map(entity, null).getRate().getPeriod()); assertEquals(expected.getSource(), RngDeviceMapper.map(entity, null).getSource()); }