mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
kvm: Define CPU shares in domain XML
Since libvirt 0.9.0 this can be specified in the XML. This used to be set by invoking virsh after starting the instance, but this is cleaner.
This commit is contained in:
parent
64def0ef3d
commit
5fa300cd9c
@ -155,6 +155,7 @@ import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.agent.api.to.VolumeTO;
|
||||
import com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.diskProtocol;
|
||||
@ -2475,6 +2476,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
grd.setVcpuNum(vmTO.getCpus());
|
||||
vm.addComp(grd);
|
||||
|
||||
CpuTuneDef ctd = new CpuTuneDef();
|
||||
ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
|
||||
vm.addComp(ctd);
|
||||
|
||||
FeaturesDef features = new FeaturesDef();
|
||||
features.addFeatures("pae");
|
||||
features.addFeatures("apic");
|
||||
@ -2550,9 +2555,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
|
||||
s_logger.debug("starting " + vmName + ": " + vm.toString());
|
||||
startDomain(conn, vmName, vm.toString());
|
||||
Script.runSimpleBashScript("virsh schedinfo " + vmName
|
||||
+ " --set cpu_shares=" + vmSpec.getCpus()
|
||||
* vmSpec.getSpeed());
|
||||
|
||||
NicTO[] nics = vmSpec.getNics();
|
||||
for (NicTO nic : nics) {
|
||||
|
||||
@ -752,6 +752,29 @@ public class LibvirtVMDef {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CpuTuneDef {
|
||||
private int _shares = 0;
|
||||
|
||||
public void setShares(int shares) {
|
||||
_shares = shares;
|
||||
}
|
||||
|
||||
public int getShares() {
|
||||
return _shares;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder cpuTuneBuilder = new StringBuilder();
|
||||
cpuTuneBuilder.append("<cputune>\n");
|
||||
if (_shares > 0) {
|
||||
cpuTuneBuilder.append("<shares>" + _shares + "</shares>\n");
|
||||
}
|
||||
cpuTuneBuilder.append("</cputune>\n");
|
||||
return cpuTuneBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SerialDef {
|
||||
private final String _type;
|
||||
private final String _source;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user