You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ja...@apache.org on 2013/12/11 08:37:39 UTC

[2/2] git commit: updated refs/heads/4.3 to d221efc

CLOUDSTACK-4498 Do not reserve memory and cpu for vmware VMs, if
the vmware.reserve.cpu and vmware.reserve.mem are set to false while not over committing.

Signed-off-by: Jayapal <ja...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/903af43b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/903af43b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/903af43b

Branch: refs/heads/4.3
Commit: 903af43be45c5b0e215c3c7ca9ce3ac56692d213
Parents: 3af903f
Author: Bharat Kumar <bh...@citrix.com>
Authored: Mon Dec 9 15:22:27 2013 +0530
Committer: Jayapal <ja...@apache.org>
Committed: Wed Dec 11 13:07:22 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/hypervisor/guru/VMwareGuru.java   | 28 +++++++++++++++++-
 .../vmware/manager/VmwareManagerImpl.java       |  2 --
 .../vmware/resource/VmwareResource.java         | 31 ++++++++++++++++----
 3 files changed, 52 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/903af43b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index eb3cb6b..326a950 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -96,9 +96,13 @@ import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VmDetailConstants;
 import com.cloud.vm.dao.NicDao;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value=HypervisorGuru.class)
-public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
+public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable {
     private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
 
     @Inject NetworkDao _networkDao;
@@ -117,11 +121,20 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
     @Inject
     PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
     @Inject ClusterManager _clusterMgr;
+    @Inject
+    VMInstanceDao _vmDao;
+    @Inject
+    ClusterDao _clusterDao;
 
     protected VMwareGuru() {
         super();
     }
 
+    static final ConfigKey<Boolean> VmwareReserveCpu = new ConfigKey<Boolean>(Boolean.class, "vmware.reserve.cpu", "Advanced", "false",
+            "Specify whether or not to reserve CPU when not overprovisioning, In case of cpu overprovisioning we will always reserve cpu.", true, ConfigKey.Scope.Cluster, null);
+    static final ConfigKey<Boolean> VmwareReserveMemory = new ConfigKey<Boolean>(Boolean.class, "vmware.reserve.cpu", "Advanced", "false",
+            "Specify whether or not to reserve memory when not overprovisioning, In case of memory overprovisioning we will always reserve memory.", true, ConfigKey.Scope.Cluster, null);
+
     @Override
     public HypervisorType getHypervisorType() {
         return HypervisorType.VMware;
@@ -184,6 +197,9 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
             }
         }
 
+        long clusterId = _hostDao.findById( _vmDao.findById(vm.getId()).getHostId()).getClusterId();
+        details.put(Config.VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
+        details.put(Config.VmwareReserveMem.key(), VmwareReserveMemory.valueIn(clusterId).toString());
         to.setDetails(details);
 
         if(vm.getVirtualMachine() instanceof DomainRouterVO) {
@@ -440,4 +456,14 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
         }
         return commands;
     }
+
+    @Override
+    public String getConfigComponentName() {
+        return VMwareGuru.class.getSimpleName();
+    }
+
+    @Override
+    public ConfigKey<?>[] getConfigKeys() {
+        return new ConfigKey<?>[] {VmwareReserveCpu, VmwareReserveMemory};
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/903af43b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index d306b74..bf56c54 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -533,8 +533,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
         params.put("vm.instancename.flag", _instanceNameFlag);
         params.put("service.console.name", _serviceConsoleName);
         params.put("management.portgroup.name", _managemetPortGroupName);
-        params.put("vmware.reserve.cpu", _reserveCpu);
-        params.put("vmware.reserve.mem", _reserveMem);
         params.put("vmware.root.disk.controller", _rootDiskController);
         params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
         params.put("ports.per.dvportgroup", _portsPerDvPortGroup);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/903af43b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 69f1b74..d5f3035 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -47,6 +47,7 @@ import javax.naming.ConfigurationException;
 
 import com.cloud.agent.api.routing.*;
 
+import com.cloud.configuration.Config;
 import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
 
@@ -341,10 +342,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
     protected int _portsPerDvPortGroup;
     protected boolean _fullCloneFlag = false;
     protected boolean _instanceNameFlag = false;
+    protected boolean  _reserveCpu;
+    protected boolean  _reserveMem;
 
-    protected boolean _reserveCpu = false;
-
-    protected boolean _reserveMem = false;
     protected boolean _recycleHungWorker = false;
     protected DiskControllerType _rootDiskController = DiskControllerType.ide;
 
@@ -2688,7 +2688,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     	vmMo.tearDownDevices(new Class<?>[] { VirtualEthernetCard.class });
                     vmMo.ensureScsiDeviceController();
                 } else {
-                    int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
                     Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
                     for (DiskTO vol : disks) {
                         if (vol.getType() == Volume.Type.ROOT) {
@@ -2706,7 +2705,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                     }
                     
                     if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
-                            vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
+                            getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
                             translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
                         throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
                     }
@@ -2735,7 +2734,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
             
             VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
-                    vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
+                    getReservedCpuMHZ(vmSpec),(int) (vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
                     guestOsId, vmSpec.getLimitCpuUse());
             
             // Check for hotadd settings
@@ -2995,6 +2994,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
         }
     }
+
+    int getReservedMemoryMb(VirtualMachineTO vmSpec) {
+         if (vmSpec.getDetails().get(Config.VmwareReserveMem.key()).equalsIgnoreCase("true")) {
+            return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+         }else if (vmSpec.getMinRam() != vmSpec.getMaxRam()) {
+            s_logger.warn("memory overprovisioning factor is set to "+ (vmSpec.getMaxRam()/vmSpec.getMinRam())+" ignoring the flag vmware.reserve.mem");
+            return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+         }
+         return 0;
+    }
+
+    int getReservedCpuMHZ(VirtualMachineTO vmSpec) {
+        if (vmSpec.getDetails().get(Config.VmwareReserveCpu.key()).equalsIgnoreCase("true")) {
+            return vmSpec.getMinSpeed();
+        }else if (vmSpec.getMinSpeed().intValue() != vmSpec.getMaxSpeed().intValue()) {
+            s_logger.warn("cpu overprovisioning factor is set to "+ (vmSpec.getMaxSpeed().intValue()/vmSpec.getMinSpeed().intValue())+" ignoring the flag vmware.reserve.cpu");
+            return vmSpec.getMinSpeed();
+        }
+        return 0;
+        }
     
     // return the finalized disk chain for startup, from top to bottom
     private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec,