You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/07/08 09:24:25 UTC

git commit: updated refs/heads/4.2 to 574f782

Updated Branches:
  refs/heads/4.2 800c9e409 -> 574f782ab


CLOUDSTACK-2592 [Automation]: Scale up VM on VMWARE without license doesn't throw appropriate error

Now ESXi server license would be fetched to see if HOTPLUG feature is license or not.
Throw Exception if the feature is not licensed.

Also added FeatureKeyConstants enum type to maintain list of various features to be checked whether licensed or not.

Signed-off-by: Sateesh Chodapuneedi <sa...@apache.org>


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

Branch: refs/heads/4.2
Commit: 574f782ab2371828a02e22b3003cd7bbdefc9777
Parents: 800c9e4
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Mon Jul 8 12:49:39 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Mon Jul 8 12:53:38 2013 +0530

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         |  4 +-
 .../cloud/hypervisor/vmware/mo/ClusterMO.java   | 12 ++-
 .../vmware/mo/FeatureKeyConstants.java          | 26 ++++++
 .../com/cloud/hypervisor/vmware/mo/HostMO.java  | 13 +++
 .../vmware/mo/LicenseAssignmentManagerMO.java   | 87 ++++++++++++++++++++
 .../hypervisor/vmware/mo/LicenseManagerMO.java  | 45 ++++++++++
 .../vmware/mo/VmwareHypervisorHost.java         |  9 +-
 .../hypervisor/vmware/util/VmwareHelper.java    | 37 +++++++--
 8 files changed, 219 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/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 c3867f4..f7d3d45 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
@@ -214,6 +214,7 @@ import com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO;
 import com.cloud.hypervisor.vmware.mo.DatacenterMO;
 import com.cloud.hypervisor.vmware.mo.DatastoreMO;
 import com.cloud.hypervisor.vmware.mo.DiskControllerType;
+import com.cloud.hypervisor.vmware.mo.FeatureKeyConstants;
 import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
 import com.cloud.hypervisor.vmware.mo.HostMO;
 import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
@@ -2430,7 +2431,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
             int ramMb = (int) (vmSpec.getMinRam()/(1024 * 1024));
-
+            // Check if license supports the feature
+            VmwareHelper.isFeatureLicensed(hyperHost, FeatureKeyConstants.HOTPLUG);
             VmwareHelper.setVmScaleUpConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024 * 1024)), ramMb, vmSpec.getLimitCpuUse());
 
             if(!vmMo.configureVm(vmConfigSpec)) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
index d112c34..04ef0f8 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
@@ -23,8 +23,6 @@ import java.util.List;
 
 import org.apache.log4j.Logger;
 
-import com.cloud.hypervisor.vmware.util.VmwareContext;
-import com.cloud.utils.Pair;
 import com.google.gson.Gson;
 import com.vmware.vim25.ArrayOfHostIpRouteEntry;
 import com.vmware.vim25.ClusterComputeResourceSummary;
@@ -49,6 +47,10 @@ import com.vmware.vim25.PropertySpec;
 import com.vmware.vim25.TraversalSpec;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 
+import com.cloud.hypervisor.vmware.util.VmwareContext;
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+
 import edu.emory.mathcs.backport.java.util.Arrays;
 
 //
@@ -575,5 +577,11 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
 
     	return portInfo;
 	}
+
+    @Override
+    public LicenseAssignmentManagerMO getLicenseAssignmentManager() throws Exception {
+        // LicenseAssignmentManager deals with only host/vcenter licenses only. Has nothing todo with cluster
+        throw new CloudRuntimeException("Unable to get LicenseAssignmentManager at cluster level");
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/FeatureKeyConstants.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/FeatureKeyConstants.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/FeatureKeyConstants.java
new file mode 100644
index 0000000..b326348
--- /dev/null
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/FeatureKeyConstants.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.hypervisor.vmware.mo;
+
+public interface FeatureKeyConstants {
+    public final static String HOTPLUG = "hotplug";
+    public final static String DVS = "dvs";
+    public final static String DRS = "drs";
+    public final static String STORAGEDRS = "storagedrs";
+    public final static String SVMOTION = "svmotion";
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
index e7fd922..2735fb0 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
@@ -972,4 +972,17 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
 
         return false;
     }
+
+    public LicenseAssignmentManagerMO getLicenseAssignmentManager() throws Exception {
+        ManagedObjectReference licenseMgr;
+        ManagedObjectReference licenseAssignmentManager;
+        LicenseManagerMO licenseMgrMo;
+
+        licenseMgr = _context.getServiceContent().getLicenseManager();
+        licenseMgrMo = new LicenseManagerMO(_context, licenseMgr);
+        licenseAssignmentManager = licenseMgrMo.getLicenseAssignmentManager();
+
+        return new LicenseAssignmentManagerMO(_context, licenseAssignmentManager);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseAssignmentManagerMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseAssignmentManagerMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseAssignmentManagerMO.java
new file mode 100644
index 0000000..0a86b97
--- /dev/null
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseAssignmentManagerMO.java
@@ -0,0 +1,87 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+package com.cloud.hypervisor.vmware.mo;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.vmware.vim25.KeyAnyValue;
+import com.vmware.vim25.KeyValue;
+import com.vmware.vim25.LicenseAssignmentManagerLicenseAssignment;
+import com.vmware.vim25.LicenseManagerLicenseInfo;
+import com.vmware.vim25.ManagedObjectReference;
+
+import com.cloud.hypervisor.vmware.util.VmwareContext;
+
+public class LicenseAssignmentManagerMO extends BaseMO {
+
+    private static final Logger s_logger = Logger.getLogger(LicenseAssignmentManagerMO.class);
+    private static final String LICENSE_INFO_PRODUCT_VERSION = "ProductVersion";
+    private static final String LICENSE_INFO_PRODUCT_NAME = "ProductName";
+    private static final String LICENSE_INFO_NAME = "Name";
+    private static final String LICENSE_INFO_FEATURE = "feature";
+
+    public LicenseAssignmentManagerMO(VmwareContext context, ManagedObjectReference mor) {
+        super(context, mor);
+    }
+
+    public LicenseAssignmentManagerMO(VmwareContext context, String morType, String morValue) {
+        super(context, morType, morValue);
+    }
+
+    public LicenseAssignmentManagerLicenseAssignment getAssignedLicenseToHost(ManagedObjectReference hostMor) throws Exception {
+        List<LicenseAssignmentManagerLicenseAssignment> licenses = _context.getVimClient().getService().queryAssignedLicenses(_mor, hostMor.getValue());
+        return licenses.get(0);
+    }
+
+    public boolean isFeatureSupported(String featureKey, ManagedObjectReference hostMor) throws Exception {
+        boolean featureSupported = false;
+
+        // Retrieve host license properties
+        List<KeyAnyValue> props = getHostLicenseProperties(hostMor);
+
+        // Check host license properties to see if specified feature is supported by the license.
+        for (KeyAnyValue prop : props) {
+            String key = prop.getKey();
+            if (key.equalsIgnoreCase(LICENSE_INFO_FEATURE)) {
+                KeyValue propValue = (KeyValue)prop.getValue();
+                if (propValue.getKey().equalsIgnoreCase(featureKey)) {
+                    featureSupported = true;
+                    break;
+                }
+            }
+        }
+
+        return featureSupported;
+    }
+
+    public LicenseManagerLicenseInfo getHostLicenseInfo(ManagedObjectReference hostMor) throws Exception {
+        // Retrieve license assigned to specified host
+        LicenseAssignmentManagerLicenseAssignment license = getAssignedLicenseToHost(hostMor);
+        return license.getAssignedLicense();
+    }
+
+    public List<KeyAnyValue> getHostLicenseProperties(ManagedObjectReference hostMor) throws Exception {
+        return getHostLicenseInfo(hostMor).getProperties();
+    }
+
+    public String getHostLicenseName(ManagedObjectReference hostMor) throws Exception {
+        return getHostLicenseInfo(hostMor).getName();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseManagerMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseManagerMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseManagerMO.java
new file mode 100644
index 0000000..5b45403
--- /dev/null
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/LicenseManagerMO.java
@@ -0,0 +1,45 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+package com.cloud.hypervisor.vmware.mo;
+
+import org.apache.log4j.Logger;
+
+import com.vmware.vim25.ManagedObjectReference;
+
+import com.cloud.hypervisor.vmware.util.VmwareContext;
+
+public class LicenseManagerMO extends BaseMO {
+
+    private static final Logger s_logger = Logger.getLogger(LicenseManagerMO.class);
+    private ManagedObjectReference _licenseAssignmentManager = null;
+    
+    public LicenseManagerMO(VmwareContext context, ManagedObjectReference mor) {
+        super(context, mor);
+    }
+
+    public LicenseManagerMO(VmwareContext context, String morType, String morValue) {
+        super(context, morType, morValue);
+    }
+
+    public ManagedObjectReference getLicenseAssignmentManager() throws Exception {
+        if (_licenseAssignmentManager == null) {
+            _licenseAssignmentManager = (ManagedObjectReference)_context.getVimClient().getDynamicProperty(_mor, "licenseAssignmentManager");
+        }
+        return _licenseAssignmentManager;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VmwareHypervisorHost.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VmwareHypervisorHost.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VmwareHypervisorHost.java
index 39464e8..ac14328 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VmwareHypervisorHost.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VmwareHypervisorHost.java
@@ -16,15 +16,16 @@
 // under the License.
 package com.cloud.hypervisor.vmware.mo;
 
-import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.vmware.vim25.ClusterDasConfigInfo;
 import com.vmware.vim25.ComputeResourceSummary;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.ObjectContent;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 
+import com.cloud.hypervisor.vmware.util.VmwareContext;
+
 /**
- * Interface to consolidate ESX(i) hosts and HA/FT clusters into a common interface used by CloudStack Hypervisor resources  
+ * Interface to consolidate ESX(i) hosts and HA/FT clusters into a common interface used by CloudStack Hypervisor resources
  */
 public interface VmwareHypervisorHost {
 	VmwareContext getContext();
@@ -52,7 +53,7 @@ public interface VmwareHypervisorHost {
 	ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception;
 	ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception;
 	
-	ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress, 
+	ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress,
 		int poolHostPort, String poolPath, String poolUuid) throws Exception;
 	void unmountDatastore(String poolUuid) throws Exception;
 	
@@ -66,4 +67,6 @@ public interface VmwareHypervisorHost {
 	VmwareHypervisorHostResourceSummary getHyperHostResourceSummary() throws Exception;
 	VmwareHypervisorHostNetworkSummary getHyperHostNetworkSummary(String esxServiceConsolePort) throws Exception;
 	ComputeResourceSummary getHyperHostHardwareSummary() throws Exception;
+
+    LicenseAssignmentManagerMO getLicenseAssignmentManager() throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/574f782a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index 4a6a135..5a8cdc4 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -30,14 +30,6 @@ import java.util.Random;
 
 import org.apache.log4j.Logger;
 
-import com.cloud.hypervisor.vmware.mo.DatacenterMO;
-import com.cloud.hypervisor.vmware.mo.DatastoreMO;
-import com.cloud.hypervisor.vmware.mo.HostMO;
-import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
-import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
-import com.cloud.utils.Pair;
-import com.cloud.utils.Ternary;
-import com.cloud.utils.exception.ExceptionUtil;
 import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
 import com.vmware.vim25.DynamicProperty;
 import com.vmware.vim25.ManagedObjectReference;
@@ -68,6 +60,17 @@ import com.vmware.vim25.VirtualPCNet32;
 import com.vmware.vim25.VirtualVmxnet2;
 import com.vmware.vim25.VirtualVmxnet3;
 
+import com.cloud.hypervisor.vmware.mo.DatacenterMO;
+import com.cloud.hypervisor.vmware.mo.DatastoreMO;
+import com.cloud.hypervisor.vmware.mo.HostMO;
+import com.cloud.hypervisor.vmware.mo.LicenseAssignmentManagerMO;
+import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
+import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
+import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
+import com.cloud.utils.Pair;
+import com.cloud.utils.Ternary;
+import com.cloud.utils.exception.ExceptionUtil;
+
 public class VmwareHelper {
     private static final Logger s_logger = Logger.getLogger(VmwareHelper.class);
 
@@ -673,4 +676,22 @@ public class VmwareHelper {
     public static boolean isDvPortGroup(ManagedObjectReference networkMor) {
          return "DistributedVirtualPortgroup".equalsIgnoreCase(networkMor.getType());
     }
+
+    public static boolean isFeatureLicensed(VmwareHypervisorHost hyperHost, String featureKey) throws Exception {
+        boolean hotplugSupportedByLicense = false;
+        String licenseName;
+        LicenseAssignmentManagerMO licenseAssignmentMgrMo;
+
+        licenseAssignmentMgrMo = hyperHost.getLicenseAssignmentManager();
+        // Check if license supports the feature
+        hotplugSupportedByLicense = licenseAssignmentMgrMo.isFeatureSupported(featureKey, hyperHost.getMor());
+        // Fetch license name
+        licenseName = licenseAssignmentMgrMo.getHostLicenseName(hyperHost.getMor());
+
+        if (!hotplugSupportedByLicense) {
+            throw new Exception("hotplug feature is not supported by license : [" + licenseName + "] assigned to host : " + hyperHost.getHyperHostName());
+        }
+
+        return hotplugSupportedByLicense;
+    }
 }