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 c3867f48543..f7d3d4533bf 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)) { 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 d112c34fb9e..04ef0f8c47b 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"); + } } 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 00000000000..b326348604c --- /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"; +} 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 e7fd922c322..2735fb03f77 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); + } + } 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 00000000000..0a86b978305 --- /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 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 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 getHostLicenseProperties(ManagedObjectReference hostMor) throws Exception { + return getHostLicenseInfo(hostMor).getProperties(); + } + + public String getHostLicenseName(ManagedObjectReference hostMor) throws Exception { + return getHostLicenseInfo(hostMor).getName(); + } + +} 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 00000000000..5b454038665 --- /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; + } +} + 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 39464e8aaf8..ac143283477 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; } 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 4a6a135a5b8..5a8cdc44a55 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; + } }