String uuid = vmTO.getUuid();
uuid = getUuid(uuid);
vm.setDomUUID(uuid);
vm.setDomDescription(vmTO.getOs());
GuestDef guest = new GuestDef();
if (HypervisorType.LXC == _hypervisorType &&
VirtualMachine.Type.User == vmTO.getType()) {
// LXC domain is only valid for user VMs. Use KVM for system VMs.
guest.setGuestType(GuestDef.guestType.LXC);
vm.setHvsType(HypervisorType.LXC.toString().toLowerCase());
} else {
guest.setGuestType(GuestDef.guestType.KVM);
vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
vm.setLibvirtVersion(_hypervisorLibvirtVersion);
vm.setQemuVersion(_hypervisorQemuVersion);
}
guest.setGuestArch(vmTO.getArch());
guest.setMachineType("pc");
guest.setBootOrder(GuestDef.bootOrder.CDROM);
guest.setBootOrder(GuestDef.bootOrder.HARDISK);
vm.addComp(guest);
GuestResourceDef grd = new GuestResourceDef();
if (vmTO.getMinRam() != vmTO.getMaxRam() && !_noMemBalloon) {
grd.setMemBalloning(true);
grd.setCurrentMem(vmTO.getMinRam()/1024);
grd.setMemorySize(vmTO.getMaxRam()/1024);
}
else{
grd.setMemorySize(vmTO.getMaxRam() / 1024);
}
int vcpus = vmTO.getCpus();
grd.setVcpuNum(vcpus);
vm.addComp(grd);
CpuModeDef cmd = new CpuModeDef();
cmd.setMode(_guestCpuMode);
cmd.setModel(_guestCpuModel);
// multi cores per socket, for larger core configs
if (vcpus % 6 == 0) {
int sockets = vcpus / 6;
cmd.setTopology(6, sockets);
} else if (vcpus % 4 == 0) {
int sockets = vcpus / 4;
cmd.setTopology(4, sockets);
}
vm.addComp(cmd);
if (_hypervisorLibvirtVersion >= 9000) {
CpuTuneDef ctd = new CpuTuneDef();
/**
A 4.0.X/4.1.X management server doesn't send the correct JSON
command for getMinSpeed, it only sends a 'speed' field.
So if getMinSpeed() returns null we fall back to getSpeed().
This way a >4.1 agent can work communicate a <=4.1 management server
This change is due to the overcommit feature in 4.2
*/
if (vmTO.getMinSpeed() != null) {
ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed());
} else {
ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
}
vm.addComp(ctd);
}
FeaturesDef features = new FeaturesDef();
features.addFeatures("pae");
features.addFeatures("apic");
features.addFeatures("acpi");
vm.addComp(features);
TermPolicy term = new TermPolicy();
term.setCrashPolicy("destroy");
term.setPowerOffPolicy("destroy");
term.setRebootPolicy("restart");
vm.addComp(term);
ClockDef clock = new ClockDef();
if (vmTO.getOs().startsWith("Windows")) {
clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
clock.setTimer("rtc", "catchup", null);
}
vm.addComp(clock);
DevicesDef devices = new DevicesDef();
devices.setEmulatorPath(_hypervisorPath);
devices.setGuestType(guest.getGuestType());
SerialDef serial = new SerialDef("pty", null, (short) 0);
devices.addDevice(serial);
if (vmTO.getType() != VirtualMachine.Type.User) {