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;
}
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;
}
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();
}
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());
}
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());
}
Aggregations