Skip to content

Commit accfccd

Browse files
committed
Summary: Add support for nested hypervisors to the VmWare resource.
Add a flag VmDetailConstants.NESTED_VIRTUALIZATION_FLAG Add an advanced config uption VmwareEnableNestedVirtualization Depending on the settings of the flags and the capabilities of the target hypervisor the nested virtualization option will be set on guest VMs. It's a global setting intended only for developers to support cloud-in-a-cloud deployments.
1 parent c041979 commit accfccd

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎core/src/com/cloud/vm/VmDetailConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public interface VmDetailConstants {
2020
public static final String KEYBOARD = "keyboard";
2121
public static final String NIC_ADAPTER = "nicAdapter";
2222
public static final String ROOK_DISK_CONTROLLER = "rootDiskController";
23+
public static final String NESTED_VIRTUALIZATION_FLAG = "nestedVirtualizationFlag";
2324
}

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.ejb.Local;
2828
import javax.inject.Inject;
2929

30+
import org.apache.cloudstack.api.ApiConstants.VMDetails;
3031
import org.apache.log4j.Logger;
3132
import org.springframework.stereotype.Component;
3233

@@ -40,6 +41,8 @@
4041
import com.cloud.agent.api.to.NicTO;
4142
import com.cloud.agent.api.to.VirtualMachineTO;
4243
import com.cloud.cluster.ClusterManager;
44+
import com.cloud.configuration.Config;
45+
import com.cloud.configuration.dao.ConfigurationDao;
4346
import com.cloud.exception.InsufficientAddressCapacityException;
4447
import com.cloud.host.HostVO;
4548
import com.cloud.host.dao.HostDao;
@@ -84,6 +87,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
8487
@Inject VmwareManager _vmwareMgr;
8588
@Inject SecondaryStorageVmManager _secStorageMgr;
8689
@Inject NetworkModel _networkMgr;
90+
@Inject ConfigurationDao _configDao;
8791

8892
protected VMwareGuru() {
8993
super();
@@ -212,8 +216,21 @@ public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfi
212216
sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
213217
String bootArgs = to.getBootArgs();
214218
to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
219+
220+
}
221+
222+
// Don't do this if the virtual machine is one of the special types
223+
// Should only be done on user machines
224+
if(!(vm.getVirtualMachine() instanceof DomainRouterVO || vm.getVirtualMachine() instanceof ConsoleProxyVO
225+
|| vm.getVirtualMachine() instanceof SecondaryStorageVmVO)) {
226+
String nestedVirt = _configDao.getValue(Config.VmwareEnableNestedVirtualization.key());
227+
if (nestedVirt != null) {
228+
s_logger.debug("Nested virtualization requested, adding flag to vm configuration");
229+
details.put(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG, nestedVirt);
230+
to.setDetails(details);
231+
232+
}
215233
}
216-
217234
// Determine the VM's OS description
218235
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
219236
to.setOs(guestOS.getDisplayName());

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
import com.vmware.vim25.ComputeResourceSummary;
233233
import com.vmware.vim25.DatastoreSummary;
234234
import com.vmware.vim25.DynamicProperty;
235+
import com.vmware.vim25.HostCapability;
235236
import com.vmware.vim25.HostFirewallInfo;
236237
import com.vmware.vim25.HostFirewallRuleset;
237238
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
@@ -2147,6 +2148,23 @@ protected StartAnswer execute(StartCommand cmd) {
21472148
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
21482149
vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
21492150
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
2151+
2152+
if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
2153+
s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");
2154+
ManagedObjectReference hostMor = vmMo.getRunningHost().getMor();
2155+
ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent");
2156+
ManagedObjectReference environmentBrowser =
2157+
context.getVimClient().getMoRefProp(computeMor, "environmentBrowser");
2158+
HostCapability hostCapability = context.getService().queryTargetCapabilities(environmentBrowser, hostMor);
2159+
if (hostCapability.isNestedHVSupported()) {
2160+
s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName());
2161+
vmConfigSpec.setNestedHVEnabled(true);
2162+
}
2163+
else {
2164+
s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
2165+
vmConfigSpec.setNestedHVEnabled(false);
2166+
}
2167+
}
21502168

21512169
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
21522170
int i = 0;

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public enum Config {
276276
VmwareRootDiskControllerType("Advanced", ManagementServer.class, String.class, "vmware.root.disk.controller", "ide", "Specify the default disk controller for root volumes, valid values are scsi, ide", null),
277277
VmwareSystemVmNicDeviceType("Advanced", ManagementServer.class, String.class, "vmware.systemvm.nic.device.type", "E1000", "Specify the default network device type for system VMs, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null),
278278
VmwareRecycleHungWorker("Advanced", ManagementServer.class, Boolean.class, "vmware.recycle.hung.wokervm", "false", "Specify whether or not to recycle hung worker VMs", null),
279+
VmwareEnableNestedVirtualization("Advanced", ManagementServer.class, Boolean.class, "vmware.nested.virtualization", "false", "When set to true this will enable nested virtualization when this is supported by the hypervisor", null),
279280

280281
// Midonet
281282
MidoNetAPIServerAddress("Network", ManagementServer.class, String.class, "midonet.apiserver.address", "http://localhost:8081", "Specify the address at which the Midonet API server can be contacted (if using Midonet)", null),

0 commit comments

Comments
 (0)