public void updateSourceByVersion(Version clusterVersion) { final Source source = getSource(); if (source == Source.URANDOM || source == Source.RANDOM) { setSource(Source.getUrandomOrRandomFor(clusterVersion)); } }
/** * 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 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(); } }
@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; }