CLOUDSTACK-3303 Vmware - Put a mechanism to disable hot add vcpu if the number of cores per socket is not 1 and virtual machine hardware version=7

Following Hotadd memory checks are included now.
1) Check if guest operating system supports memory hotadd
2) Check if virtual machine is using hardware version 7 or later before enabling memory hotadd

Following Hotadd CPU checks are included now.
1) Check if guest operating system supports cpu hotadd
2) Check if virtual machine is using hardware version 8 or later.
3) Check if virtual machine has only 1 core per socket. If hardware version is 7, then only 1 core per socket is supported. Hot adding multi-core vcpus is not allowed if hardware version is 7.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
This commit is contained in:
Sateesh Chodapuneedi 2013-07-10 17:52:15 +05:30
parent 033d05fa20
commit 664dc17b0b
2 changed files with 75 additions and 11 deletions

View File

@ -53,7 +53,6 @@ import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.DatastoreSummary; import com.vmware.vim25.DatastoreSummary;
import com.vmware.vim25.DynamicProperty; import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.GuestInfo; import com.vmware.vim25.GuestInfo;
import com.vmware.vim25.GuestOsDescriptor;
import com.vmware.vim25.HostCapability; import com.vmware.vim25.HostCapability;
import com.vmware.vim25.HostFirewallInfo; import com.vmware.vim25.HostFirewallInfo;
import com.vmware.vim25.HostFirewallRuleset; import com.vmware.vim25.HostFirewallRuleset;
@ -2575,16 +2574,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb, vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse()); translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(); String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
boolean guestSupportsCpuHotAdd = false; // Check for hotadd settings
boolean guestSupportsMemoryHotAdd = false; vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId));
GuestOsDescriptor vmGuestOsDescriptor = vmMo.getGuestOsDescriptor(guestOsId); vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId));
if (vmGuestOsDescriptor != null) {
guestSupportsCpuHotAdd = vmGuestOsDescriptor.isSupportsCpuHotAdd();
guestSupportsMemoryHotAdd = vmGuestOsDescriptor.isSupportsMemoryHotAdd();
}
vmConfigSpec.setMemoryHotAddEnabled(guestSupportsMemoryHotAdd);
vmConfigSpec.setCpuHotAddEnabled(guestSupportsCpuHotAdd);
if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) { if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability"); s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");

View File

@ -71,6 +71,7 @@ import com.vmware.vim25.VirtualDiskSparseVer2BackingInfo;
import com.vmware.vim25.VirtualDiskType; import com.vmware.vim25.VirtualDiskType;
import com.vmware.vim25.VirtualEthernetCard; import com.vmware.vim25.VirtualEthernetCard;
import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo; import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
import com.vmware.vim25.VirtualHardwareOption;
import com.vmware.vim25.VirtualIDEController; import com.vmware.vim25.VirtualIDEController;
import com.vmware.vim25.VirtualLsiLogicController; import com.vmware.vim25.VirtualLsiLogicController;
import com.vmware.vim25.VirtualMachineCloneSpec; import com.vmware.vim25.VirtualMachineCloneSpec;
@ -103,6 +104,7 @@ import edu.emory.mathcs.backport.java.util.Arrays;
public class VirtualMachineMO extends BaseMO { public class VirtualMachineMO extends BaseMO {
private static final Logger s_logger = Logger.getLogger(VirtualMachineMO.class); private static final Logger s_logger = Logger.getLogger(VirtualMachineMO.class);
private ManagedObjectReference _vmEnvironmentBrowser = null;
public VirtualMachineMO(VmwareContext context, ManagedObjectReference morVm) { public VirtualMachineMO(VmwareContext context, ManagedObjectReference morVm) {
super(context, morVm); super(context, morVm);
@ -2190,4 +2192,74 @@ public class VirtualMachineMO extends BaseMO {
public long getHotAddMemoryLimitInMb() throws Exception { public long getHotAddMemoryLimitInMb() throws Exception {
return (Long)_context.getVimClient().getDynamicProperty(_mor, "config.hotPlugMemoryLimit"); return (Long)_context.getVimClient().getDynamicProperty(_mor, "config.hotPlugMemoryLimit");
} }
public int getCoresPerSocket() throws Exception {
return (Integer)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.numCoresPerSocket");
}
public int getVirtualHardwareVersion() throws Exception {
VirtualHardwareOption vhOption = getVirtualHardwareOption();
return vhOption.getHwVersion();
}
public VirtualHardwareOption getVirtualHardwareOption() throws Exception {
VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null);
return vmConfigOption.getHardwareOptions();
}
private ManagedObjectReference getEnvironmentBrowser() throws Exception {
if (_vmEnvironmentBrowser == null) {
_vmEnvironmentBrowser = _context.getVimClient().getMoRefProp(_mor, "environmentBrowser");
}
return _vmEnvironmentBrowser;
}
public boolean isCpuHotAddSupported(String guestOsId) throws Exception {
boolean guestOsSupportsCpuHotAdd = false;
boolean virtualHardwareSupportsCpuHotAdd = false;
GuestOsDescriptor guestOsDescriptor;
int virtualHardwareVersion;
int numCoresPerSocket;
guestOsDescriptor = getGuestOsDescriptor(guestOsId);
virtualHardwareVersion = getVirtualHardwareVersion();
// Check if guest operating system supports cpu hotadd
if (guestOsDescriptor.isSupportsCpuHotAdd()) {
guestOsSupportsCpuHotAdd = true;
}
// Check if virtual machine is using hardware version 8 or later.
// If hardware version is 7, then only 1 core per socket is supported. Hot adding multi-core vcpus is not allowed if hardware version is 7.
if (virtualHardwareVersion >= 8) {
virtualHardwareSupportsCpuHotAdd = true;
} else if (virtualHardwareVersion == 7) {
// Check if virtual machine has only 1 core per socket.
numCoresPerSocket = getCoresPerSocket();
if (numCoresPerSocket == 1) {
virtualHardwareSupportsCpuHotAdd = true;
}
}
return guestOsSupportsCpuHotAdd && virtualHardwareSupportsCpuHotAdd;
}
public boolean isMemoryHotAddSupported(String guestOsId) throws Exception {
boolean guestOsSupportsMemoryHotAdd = false;
boolean virtualHardwareSupportsMemoryHotAdd = false;
GuestOsDescriptor guestOsDescriptor;
int virtualHardwareVersion;
guestOsDescriptor = getGuestOsDescriptor(guestOsId);
virtualHardwareVersion = getVirtualHardwareVersion();
// Check if guest operating system supports memory hotadd
if (guestOsDescriptor.isSupportsMemoryHotAdd()) {
guestOsSupportsMemoryHotAdd = true;
}
// Check if virtual machine is using hardware version 7 or later.
if (virtualHardwareVersion >= 7) {
virtualHardwareSupportsMemoryHotAdd = true;
}
return guestOsSupportsMemoryHotAdd && virtualHardwareSupportsMemoryHotAdd;
}
} }