Search in sources :

Example 11 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.

the class InstanceTypeManager method updateRngDevice.

protected void updateRngDevice(final VmBase vmBase) {
    if (model.getIsRngEnabled().getIsChangable() && model.getIsRngEnabled().getIsAvailable()) {
        if (!isNextRunConfigurationExists()) {
            Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
                deactivate();
                List<VmDevice> rngDevices = returnValue.getReturnValue();
                getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
                if (!rngDevices.isEmpty()) {
                    VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
                    rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion());
                    getModel().setRngDevice(rngDevice);
                }
                activate();
                updateVirtioScsi(vmBase);
            }));
        } else {
            deactivate();
            VmDevice rngDevice = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.RNG);
            getModel().getIsRngEnabled().setEntity(rngDevice != null);
            if (rngDevice != null) {
                getModel().setRngDevice(new VmRngDevice(rngDevice));
            }
            activate();
            updateVirtioScsi(vmBase);
        }
    } else {
        updateVirtioScsi(vmBase);
    }
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 12 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.

the class BackendVmsResource method copyRngDeviceFromTemplateOrInstanceType.

// TODO: Move user input and template/instance-type merging code to backed
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 = CommonCompatibilityVersionUtils.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);
        }
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 13 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.

the class RunVmCommandTest method testValidateUnsupportedRng.

@Theory
public void testValidateUnsupportedRng(VmRngDevice.Source vmRngSource, Set<VmRngDevice.Source> clusterReqSources) {
    final VM vm = new VM();
    vm.setStatus(VMStatus.Down);
    vm.setId(command.getVmId());
    command.setVm(vm);
    Cluster cluster = mock(Cluster.class);
    when(cluster.getRequiredRngSources()).thenReturn(clusterReqSources);
    command.setCluster(cluster);
    VmRngDevice rngDevice = new VmRngDevice();
    rngDevice.setSource(vmRngSource);
    VmDevice rngAsDevice = new VmDevice();
    rngAsDevice.setSpecParams(rngDevice.getSpecParams());
    when(deviceDao.getVmDeviceByVmIdTypeAndDevice(command.getVmId(), VmDeviceGeneralType.RNG, VmDeviceType.VIRTIO)).thenReturn(Collections.singletonList(rngAsDevice));
    assertThat(command.checkRngDeviceClusterCompatibility(), is(clusterReqSources.contains(vmRngSource)));
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Theory(org.junit.experimental.theories.Theory)

Example 14 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.

the class UpdateRngDeviceTest method getDevice.

private static VmRngDevice getDevice(Guid deviceId, Guid vmId) {
    VmRngDevice device = new VmRngDevice();
    device.setVmId(vmId);
    device.setDeviceId(deviceId);
    device.setBytes(12);
    device.setPeriod(34);
    device.setSource(VmRngDevice.Source.RANDOM);
    return device;
}
Also used : VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 15 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.

the class RngDeviceSpecParamsTest method testGenerateFullSpecParams.

@Test
public void testGenerateFullSpecParams() {
    VmRngDevice dev = new VmRngDevice();
    dev.setBytes(12);
    dev.setPeriod(34);
    dev.setSource(VmRngDevice.Source.RANDOM);
    Map<String, Object> expectedParams = new HashMap<>();
    expectedParams.put("bytes", "12");
    expectedParams.put("period", "34");
    expectedParams.put("source", "random");
    assertEquals(expectedParams, dev.getSpecParams());
}
Also used : HashMap(java.util.HashMap) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Test(org.junit.Test)

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