From 2e28f69d3ea540f29c2634c1726b2bb3d0689ec2 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Wed, 27 Feb 2013 16:11:04 +0100 Subject: [PATCH] CLOUDSTACK-1410: >4.1 agents should be able to communicatie with <=4.1 management servers The recently added overcommit feature breaks compatibility between older management servers and 4.2 agents. This patch fixes that by falling back if needed. --- .../com/cloud/agent/api/to/VirtualMachineTO.java | 16 ++++++++++++++++ .../kvm/resource/LibvirtComputingResource.java | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java index bdd636e727b..99eac6bf8c1 100644 --- a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java +++ b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java @@ -28,8 +28,20 @@ public class VirtualMachineTO { private BootloaderType bootloader; Type type; int cpus; + + /** + 'speed' is still here since 4.0.X/4.1.X management servers do not support + the overcommit feature yet. + + The overcommit feature sends minSpeed and maxSpeed + + So this is here for backwards compatibility with 4.0.X/4.1.X management servers + and newer agents. + */ + Integer speed; Integer minSpeed; Integer maxSpeed; + long minRam; long maxRam; String hostName; @@ -103,6 +115,10 @@ public class VirtualMachineTO { this.cpus = cpus; } + public Integer getSpeed() { + return speed; + } + public Integer getMinSpeed() { return minSpeed; } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 99b8723c26e..805de408996 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2934,7 +2934,21 @@ ServerResource { vm.addComp(grd); CpuTuneDef ctd = new CpuTuneDef(); - ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed()); + /** + 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();