From 0a5e3fa60778ccd4ac22a99809498372399405f6 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Thu, 30 May 2013 15:10:41 +0530 Subject: [PATCH] CLOUDSTACK-2060 Global config to turn off dynamically scale vm functionality --- .../xen/resource/CitrixResourceBase.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 4680fde9980..7626d1205c7 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -627,6 +627,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected void scaleVM(Connection conn, VM vm, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { + Long staticMemoryMax = vm.getMemoryStaticMax(conn); + Long staticMemoryMin = vm.getMemoryStaticMin(conn); + Long newDynamicMemoryMin = vmSpec.getMinRam() * 1024 * 1024; + Long newDynamicMemoryMax = vmSpec.getMaxRam() * 1024 * 1024; + if (staticMemoryMin > newDynamicMemoryMin || newDynamicMemoryMax > staticMemoryMax) { + throw new CloudRuntimeException("Cannot scale up the vm because of memory constraint violation: 0 <= memory-static-min <= memory-dynamic-min <= memory-dynamic-max <= memory-static-max "); + } + vm.setMemoryDynamicRange(conn, vmSpec.getMinRam() * 1024 * 1024, vmSpec.getMaxRam() * 1024 * 1024); vm.setVCPUsNumberLive(conn, (long)vmSpec.getCpus()); @@ -663,10 +671,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // If DMC is not enable then don't execute this command. if (!isDmcEnabled(conn, host)) { - String msg = "Unable to scale the vm: " + vmName + " as DMC - Dynamic memory control is not enabled for the XenServer:" + _host.uuid + " ,check your license and hypervisor version."; - s_logger.info(msg); - return new ScaleVmAnswer(cmd, false, msg); + throw new CloudRuntimeException("Unable to scale the vm: " + vmName + " as DMC - Dynamic memory control is not enabled for the XenServer:" + _host.uuid + " ,check your license and hypervisor version."); } + // stop vm which is running on this host or is in halted state Iterator iter = vms.iterator(); while ( iter.hasNext() ) { @@ -686,13 +693,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe for (VM vm : vms) { VM.Record vmr = vm.getRecord(conn); try { - Map hostParams = new HashMap(); - hostParams = host.getLicenseParams(conn); - if (hostParams.get("restrict_dmc").equalsIgnoreCase("true")) { - throw new CloudRuntimeException("Host "+ _host.uuid + " does not support Dynamic Memory Control, so we cannot scale up the vm"); - } scaleVM(conn, vm, vmSpec, host); - } catch (Exception e) { String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString(); s_logger.debug(msg);