Search in sources :

Example 1 with VcpuPin

use of org.ovirt.engine.api.model.VcpuPin in project ovirt-engine by oVirt.

the class VmMapper method stringToVCpupin.

static VcpuPin stringToVCpupin(final String strCpu) {
    final String[] strPin = strCpu.split("#");
    if (strPin.length != 2) {
        throw new IllegalArgumentException("Bad format: " + strCpu);
    }
    final VcpuPin pin = new VcpuPin();
    try {
        pin.setVcpu(Integer.parseInt(strPin[0]));
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Bad format: " + strCpu, e);
    }
    if (strPin[1].matches("\\^?(\\d+(\\-\\d+)?)(,\\^?((\\d+(\\-\\d+)?)))*")) {
        pin.setCpuSet(strPin[1]);
    } else {
        throw new IllegalArgumentException("Bad format: " + strPin[1]);
    }
    return pin;
}
Also used : VcpuPin(org.ovirt.engine.api.model.VcpuPin)

Example 2 with VcpuPin

use of org.ovirt.engine.api.model.VcpuPin in project ovirt-engine by oVirt.

the class VmMapper method stringToCpuTune.

/**
 * Maps the stringified CPU-pinning to the API format.
 */
static CpuTune stringToCpuTune(String cpuPinning) {
    if (cpuPinning == null || cpuPinning.equals("")) {
        return null;
    }
    final CpuTune cpuTune = new CpuTune();
    VcpuPins pins = new VcpuPins();
    for (String strCpu : cpuPinning.split("_")) {
        VcpuPin pin = stringToVCpupin(strCpu);
        pins.getVcpuPins().add(pin);
    }
    cpuTune.setVcpuPins(pins);
    return cpuTune;
}
Also used : VcpuPins(org.ovirt.engine.api.model.VcpuPins) CpuTune(org.ovirt.engine.api.model.CpuTune) VcpuPin(org.ovirt.engine.api.model.VcpuPin)

Example 3 with VcpuPin

use of org.ovirt.engine.api.model.VcpuPin in project ovirt-engine by oVirt.

the class VmMapper method cpuTuneToString.

static String cpuTuneToString(final CpuTune tune) {
    final StringBuilder builder = new StringBuilder();
    VcpuPins pins = tune.getVcpuPins();
    if (pins != null) {
        boolean first = true;
        for (final VcpuPin pin : pins.getVcpuPins()) {
            if (first) {
                first = false;
            } else {
                builder.append("_");
            }
            builder.append(pin.getVcpu()).append('#').append(pin.getCpuSet());
        }
    }
    return builder.toString();
}
Also used : VcpuPins(org.ovirt.engine.api.model.VcpuPins) VcpuPin(org.ovirt.engine.api.model.VcpuPin)

Example 4 with VcpuPin

use of org.ovirt.engine.api.model.VcpuPin in project ovirt-engine by oVirt.

the class VmMapperTest method stringToVCpupinSimple.

@Test
public void stringToVCpupinSimple() {
    VcpuPin pin = VmMapper.stringToVCpupin("1#1");
    assertEquals(1, (int) pin.getVcpu());
    assertEquals("1", pin.getCpuSet());
    pin = VmMapper.stringToVCpupin("1#10");
    assertEquals(1, (int) pin.getVcpu());
    assertEquals("10", pin.getCpuSet());
    pin = VmMapper.stringToVCpupin("1#10,11,12");
    assertEquals(1, (int) pin.getVcpu());
    assertEquals("10,11,12", pin.getCpuSet());
    pin = VmMapper.stringToVCpupin("1#10-12,16");
    assertEquals(1, (int) pin.getVcpu());
    assertEquals("10-12,16", pin.getCpuSet());
}
Also used : VcpuPin(org.ovirt.engine.api.model.VcpuPin) Test(org.junit.Test)

Example 5 with VcpuPin

use of org.ovirt.engine.api.model.VcpuPin in project ovirt-engine by oVirt.

the class VmMapperTest method stringToVCpupinIntervalsList.

@Test
public void stringToVCpupinIntervalsList() {
    VcpuPin pin = VmMapper.stringToVCpupin("1#1-4,6");
    assertEquals(1, (int) pin.getVcpu());
    assertEquals("1-4,6", pin.getCpuSet());
}
Also used : VcpuPin(org.ovirt.engine.api.model.VcpuPin) Test(org.junit.Test)

Aggregations

VcpuPin (org.ovirt.engine.api.model.VcpuPin)6 VcpuPins (org.ovirt.engine.api.model.VcpuPins)3 Test (org.junit.Test)2 CpuTune (org.ovirt.engine.api.model.CpuTune)2 BootDevice (org.ovirt.engine.api.model.BootDevice)1 BootProtocol (org.ovirt.engine.api.model.BootProtocol)1 DisplayType (org.ovirt.engine.api.model.DisplayType)1 NicConfiguration (org.ovirt.engine.api.model.NicConfiguration)1 TimeZone (org.ovirt.engine.api.model.TimeZone)1 VmDeviceType (org.ovirt.engine.api.model.VmDeviceType)1 VmStorageErrorResumeBehaviour (org.ovirt.engine.api.model.VmStorageErrorResumeBehaviour)1 VmType (org.ovirt.engine.api.model.VmType)1