Search in sources :

Example 16 with VmRngDevice

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);
        }
    }
}
Also used : RngDeviceParameters(org.ovirt.engine.core.common.action.RngDeviceParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 17 with VmRngDevice

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);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) RngUtils(org.ovirt.engine.core.utils.RngUtils) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 18 with VmRngDevice

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.");
        }
    }
}
Also used : RngDeviceParameters(org.ovirt.engine.core.common.action.RngDeviceParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 19 with VmRngDevice

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);
}
Also used : VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 20 with VmRngDevice

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;
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) AddVmParameters(org.ovirt.engine.core.common.action.AddVmParameters) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Aggregations

VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)24 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)5 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)5 Test (org.junit.Test)4 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)4 Guid (org.ovirt.engine.core.compat.Guid)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Rate (org.ovirt.engine.api.model.Rate)3 RngDevice (org.ovirt.engine.api.model.RngDevice)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 RngDeviceParameters (org.ovirt.engine.core.common.action.RngDeviceParameters)3 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)3