Search in sources :

Example 1 with RngDeviceParameters

use of org.ovirt.engine.core.common.action.RngDeviceParameters in project ovirt-engine by oVirt.

the class UpdateVmCommand method updateRngDevice.

private void updateRngDevice() {
    if (!getParameters().isUpdateRngDevice()) {
        return;
    }
    QueryReturnValue query = runInternalQuery(QueryType.GetRngDevice, new IdQueryParameters(getParameters().getVmId()));
    List<VmRngDevice> rngDevs = query.getReturnValue();
    ActionReturnValue rngCommandResult = null;
    if (rngDevs.isEmpty()) {
        if (getParameters().getRngDevice() != null) {
            RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
            rngCommandResult = runInternalAction(ActionType.AddRngDevice, params, cloneContextAndDetachFromParent());
        }
    } else {
        if (getParameters().getRngDevice() == null) {
            RngDeviceParameters params = new RngDeviceParameters(rngDevs.get(0), true);
            rngCommandResult = runInternalAction(ActionType.RemoveRngDevice, params, cloneContextAndDetachFromParent());
        } else {
            RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
            params.getRngDevice().setDeviceId(rngDevs.get(0).getDeviceId());
            rngCommandResult = runInternalAction(ActionType.UpdateRngDevice, params, cloneContextAndDetachFromParent());
        }
    }
    if (rngCommandResult != null && !rngCommandResult.getSucceeded()) {
        log.error("Updating RNG device of VM {} ({}) failed. Old RNG device = {}. New RNG device = {}.", getVm().getName(), getVm().getId(), rngDevs.isEmpty() ? null : rngDevs.get(0), getParameters().getRngDevice());
    }
}
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 2 with RngDeviceParameters

use of org.ovirt.engine.core.common.action.RngDeviceParameters 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 3 with RngDeviceParameters

use of org.ovirt.engine.core.common.action.RngDeviceParameters 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)

Aggregations

ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 RngDeviceParameters (org.ovirt.engine.core.common.action.RngDeviceParameters)3 VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)3 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2