use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class VmTemplateManagementCommand method updateRngDevice.
protected void updateRngDevice(Guid templateId) {
// do not update if this flag is not set
if (getParameters().isUpdateRngDevice()) {
QueryReturnValue query = runInternalQuery(QueryType.GetRngDevice, new IdQueryParameters(templateId));
List<VmRngDevice> rngDevs = query.getReturnValue();
if (getParameters().getRngDevice() != null) {
getParameters().getRngDevice().setVmId(templateId);
}
ActionReturnValue rngCommandResult = null;
if (rngDevs.isEmpty()) {
if (getParameters().getRngDevice() != null) {
RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), false);
rngCommandResult = runInternalAction(ActionType.AddRngDevice, params, cloneContextAndDetachFromParent());
}
} else {
if (getParameters().getRngDevice() == null) {
RngDeviceParameters params = new RngDeviceParameters(rngDevs.get(0), false);
rngCommandResult = runInternalAction(ActionType.RemoveRngDevice, params, cloneContextAndDetachFromParent());
} else {
RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), false);
params.getRngDevice().setDeviceId(rngDevs.get(0).getDeviceId());
rngCommandResult = runInternalAction(ActionType.UpdateRngDevice, params, cloneContextAndDetachFromParent());
}
}
if (rngCommandResult != null && !rngCommandResult.getSucceeded()) {
getReturnValue().setSucceeded(false);
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class RunVmCommand method checkRngDeviceClusterCompatibility.
/**
* Checks whether rng device of vm is required by cluster, which is requirement for running vm.
*
* @return true if the source of vm rng device is required by cluster (and therefore supported by hosts in cluster)
*/
boolean checkRngDeviceClusterCompatibility() {
List<VmDevice> rngDevs = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(getVmId(), VmDeviceGeneralType.RNG, VmDeviceType.VIRTIO);
if (rngDevs.isEmpty()) {
return true;
}
VmRngDevice rngDevice = new VmRngDevice(rngDevs.get(0));
final RngUtils.RngValidationResult rngValidationResult = RngUtils.validate(getCluster(), rngDevice);
switch(rngValidationResult) {
case VALID:
return true;
case UNSUPPORTED_URANDOM_OR_RANDOM:
log.warn("Running VM {}({}) with rng source {} that is not supported in cluster {}.", getVm().getName(), getVm().getId(), rngDevice.getSource(), getCluster().getName());
return true;
case INVALID:
return false;
default:
throw new RuntimeException("Unknown enum constant " + rngValidationResult);
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class AddVmCommand method addVmRngDevice.
private void addVmRngDevice() {
VmRngDevice rngDev = getParameters().getRngDevice();
if (rngDev != null) {
rngDev.setVmId(getVmId());
RngDeviceParameters params = new RngDeviceParameters(rngDev, true);
ActionReturnValue result = runInternalAction(ActionType.AddRngDevice, params, cloneContextAndDetachFromParent());
if (!result.getSucceeded()) {
log.error("Couldn't add RNG device for new VM.");
throw new IllegalArgumentException("Couldn't add RNG device for new VM.");
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class AddRngDeviceCommand method executeCommand.
@Override
protected void executeCommand() {
VmRngDevice rngDevice = getParameters().getRngDevice();
if (rngDevice.getDeviceId() == null) {
rngDevice.setDeviceId(Guid.newGuid());
}
vmDeviceDao.save(rngDevice);
setActionReturnValue(rngDevice.getDeviceId());
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method buildAddVmParameters.
private AddVmParameters buildAddVmParameters(String vmName) {
VmStatic currVm = new VmStatic(getParameters().getVmStaticData());
currVm.setName(vmName);
currVm.setStateless(!getVmPool().isStateful());
if (getParameters().getVmLargeIcon() != null) {
final VmIconIdSizePair iconIds = iconUtils.ensureIconPairInDatabase(getParameters().getVmLargeIcon());
currVm.setSmallIconId(iconIds.getSmall());
currVm.setLargeIconId(iconIds.getLarge());
}
AddVmParameters parameters = new AddVmParameters(currVm);
parameters.setPoolId(getVmPool().getVmPoolId());
if (getVmPool().isAutoStorageSelect()) {
parameters.setDiskInfoDestinationMap(autoSelectTargetDomainAndVolumeFormat());
} else {
parameters.setDiskInfoDestinationMap(diskInfoDestinationMap);
}
if (StringUtils.isEmpty(getParameters().getSessionId())) {
parameters.setParametersCurrentUser(getCurrentUser());
} else {
parameters.setSessionId(getParameters().getSessionId());
}
parameters.setParentCommand(getActionType());
parameters.setParentParameters(getParameters());
// check if device is enabled or we need to override it to true
parameters.setSoundDeviceEnabled(Boolean.TRUE.equals(getParameters().isSoundDeviceEnabled()) || vmDeviceUtils.shouldOverrideSoundDevice(getParameters().getVmStaticData(), getEffectiveCompatibilityVersion(), getParameters().isSoundDeviceEnabled()));
parameters.setConsoleEnabled(getParameters().isConsoleEnabled());
parameters.setVirtioScsiEnabled(getParameters().isVirtioScsiEnabled());
parameters.setBalloonEnabled(getParameters().isBalloonEnabled());
parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
VmRngDevice rngDevice = getParameters().getRngDevice();
if (rngDevice != null) {
parameters.setUpdateRngDevice(true);
parameters.setRngDevice(rngDevice);
}
parameters.getGraphicsDevices().putAll(getParameters().getGraphicsDevices());
return parameters;
}
Aggregations