Search in sources :

Example 6 with UsbPolicy

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

the class VmDeviceUtils method updateUsbSlots.

/*
     * USB slot
     */
/**
 * Update USB slots and controllers in the new VM, if USB policy of the new VM differs from one of the old VM.
 * @param oldVm old configuration, may not be null, won't be modified
 * @param newVm new configuration, may not be null, only devices if this entity will be modified
 */
public void updateUsbSlots(VmBase oldVm, VmBase newVm, Supplier<Cluster> clusterSupplier) {
    final UsbPolicy oldUsbPolicy = oldVm.getUsbPolicy();
    final UsbPolicy newUsbPolicy = newVm.getUsbPolicy();
    final int oldNumberOfSlots = getUsbSlots(oldVm.getId()).size();
    final int newNumberOfUsbSlots = Config.<Integer>getValue(ConfigValues.NumberOfUSBSlots);
    if (UsbPolicy.DISABLED == newUsbPolicy && newVm.getVmType() == VmType.HighPerformance) {
        disableAnyUsb(oldVm, newVm);
        return;
    }
    if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) {
        disableNormalUsb(newVm.getId());
        enableSpiceUsb(newVm.getId(), newNumberOfUsbSlots);
        return;
    }
    if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.ENABLED_NATIVE == newUsbPolicy) {
        updateSpiceUsb(newVm.getId(), oldNumberOfSlots, newNumberOfUsbSlots);
        return;
    }
    ChipsetType chipset = EmulatedMachineUtils.getEffectiveChipset(newVm, clusterSupplier);
    if (UsbPolicy.ENABLED_NATIVE == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) {
        disableSpiceUsb(newVm.getId());
        enableNormalUsb(newVm, chipset);
        return;
    }
    if (UsbPolicy.DISABLED == oldUsbPolicy && UsbPolicy.DISABLED == newUsbPolicy) {
        updateNormalUsb(newVm, chipset);
        return;
    }
    throw new RuntimeException(format("Unexpected state: oldUsbPolicy=%s, newUsbPolicy=%s", oldUsbPolicy, newUsbPolicy));
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType)

Example 7 with UsbPolicy

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

the class VmMapperTest method getUsbPolicyOnUpdateCurrentlyNativeGotNullUsb.

@Test
public void getUsbPolicyOnUpdateCurrentlyNativeGotNullUsb() {
    Usb usb = null;
    UsbPolicy currentPolicy = UsbPolicy.ENABLED_NATIVE;
    assertEquals(VmMapper.getUsbPolicyOnUpdate(usb, currentPolicy), currentPolicy);
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) Usb(org.ovirt.engine.api.model.Usb) Test(org.junit.Test)

Example 8 with UsbPolicy

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

the class VmMapperTest method getUsbPolicyOnUpdateCurrentlyDisabledGotEnabledNotSetPolicyNotSetUsb.

@Test
public void getUsbPolicyOnUpdateCurrentlyDisabledGotEnabledNotSetPolicyNotSetUsb() {
    Usb usb = new Usb();
    UsbPolicy currentPolicy = UsbPolicy.DISABLED;
    assertEquals(VmMapper.getUsbPolicyOnUpdate(usb, currentPolicy), currentPolicy);
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) Usb(org.ovirt.engine.api.model.Usb) Test(org.junit.Test)

Example 9 with UsbPolicy

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

the class UsbMapperUtilsTest method getIsUsbEnabledDisabled.

@Test
public void getIsUsbEnabledDisabled() {
    UsbPolicy usbPolicy = UsbPolicy.DISABLED;
    assertFalse(UsbMapperUtils.getIsUsbEnabled(usbPolicy));
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) Test(org.junit.Test)

Example 10 with UsbPolicy

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

the class UsbMapperUtilsTest method getUsbTypeDisabled.

@Test
public void getUsbTypeDisabled() {
    UsbPolicy usbPolicy = UsbPolicy.DISABLED;
    assertNull(UsbMapperUtils.getUsbType(usbPolicy));
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) Test(org.junit.Test)

Aggregations

UsbPolicy (org.ovirt.engine.core.common.businessentities.UsbPolicy)10 Test (org.junit.Test)8 Usb (org.ovirt.engine.api.model.Usb)4 ChipsetType (org.ovirt.engine.core.common.businessentities.ChipsetType)1