diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index d841242ff..6c11a2105 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -21,10 +21,12 @@ module VagrantPlugins differencing_disk = env[:machine].provider_config.differencing_disk auto_start_action = env[:machine].provider_config.auto_start_action auto_stop_action = env[:machine].provider_config.auto_stop_action + enable_virtualization_extensions = env[:machine].provider_config.enable_virtualization_extensions env[:ui].output("Configured Dynamic memory allocation, maxmemory is #{maxmemory}") if maxmemory env[:ui].output("Configured startup memory is #{memory}") if memory env[:ui].output("Configured cpus number is #{cpus}") if cpus + env[:ui].output("Configured enable virtualization extensions is #{enable_virtualization_extensions}") if enable_virtualization_extensions env[:ui].output("Configured vmname is #{vmname}") if vmname env[:ui].output("Configured differencing disk instead of cloning") if differencing_disk env[:ui].output("Configured automatic start action is #{auto_start_action}") if auto_start_action @@ -145,6 +147,7 @@ module VagrantPlugins options[:auto_start_action] = auto_start_action if auto_start_action options[:auto_stop_action] = auto_stop_action if auto_stop_action options[:differencing_disk] = differencing_disk if differencing_disk + options[:enable_virtualization_extensions] = "$True" if enable_virtualization_extensions and enable_virtualization_extensions == true env[:ui].detail("Creating and registering the VM...") server = env[:machine].provider.driver.import(options) diff --git a/plugins/providers/hyperv/config.rb b/plugins/providers/hyperv/config.rb index 1726bd45f..eec67d1b3 100644 --- a/plugins/providers/hyperv/config.rb +++ b/plugins/providers/hyperv/config.rb @@ -14,6 +14,7 @@ module VagrantPlugins attr_accessor :differencing_disk # Create differencing disk instead of cloning whole VHD [Boolean] attr_accessor :auto_start_action #action on automatic start of VM. Values: Nothing, StartIfRunning, Start attr_accessor :auto_stop_action #action on automatic stop of VM. Values: ShutDown, TurnOff, Save + attr_accessor :enable_virtualization_extensions # Enable virtualization extensions (nested virtualization). Values: true, false def initialize @ip_address_timeout = UNSET_VALUE @@ -26,6 +27,7 @@ module VagrantPlugins @differencing_disk = UNSET_VALUE @auto_start_action = UNSET_VALUE @auto_stop_action = UNSET_VALUE + @enable_virtualization_extensions = UNSET_VALUE end def finalize! @@ -41,6 +43,7 @@ module VagrantPlugins @differencing_disk = false if @differencing_disk == UNSET_VALUE @auto_start_action = nil if @auto_start_action == UNSET_VALUE @auto_stop_action = nil if @auto_stop_action == UNSET_VALUE + @enable_virtualization_extensions = false if @enable_virtualization_extensions == UNSET_VALUE # TODO will this work? end def validate(machine) diff --git a/plugins/providers/hyperv/scripts/import_vm_xml.ps1 b/plugins/providers/hyperv/scripts/import_vm_xml.ps1 index 16055e135..c7aca6b34 100644 --- a/plugins/providers/hyperv/scripts/import_vm_xml.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm_xml.ps1 @@ -10,7 +10,8 @@ Param( [string]$cpus=$null, [string]$vmname=$null, [string]$auto_start_action=$null, - [string]$auto_stop_action=$null + [string]$auto_stop_action=$null, + [string]$enable_virtualization_extensions=$False ) # Include the following modules @@ -170,6 +171,11 @@ if ($generation -ne 1) { } } +# Enable nested virtualization if configured +if ($enable_virtualization_extensions) { + Set-VMProcessor -VM $vm -ExposeVirtualizationExtensions $true +} + # A regular expression pattern to pull the number from controllers [regex]$rx="\d" diff --git a/website/source/docs/hyperv/configuration.html.md b/website/source/docs/hyperv/configuration.html.md index c6002ec34..59f12e54c 100644 --- a/website/source/docs/hyperv/configuration.html.md +++ b/website/source/docs/hyperv/configuration.html.md @@ -29,3 +29,6 @@ you may set. A complete reference is shown below: virtual machine to report an IP address. This defaults to 120 seconds. This may have to be increased if your VM takes longer to boot. * `differencing_disk` (boolean) - Switch to use differencing disk intead of cloning whole VHD. + * `enable_virtualization_extensions` (boolean) - Enable virtualization extensions for the virtual CPUs. + This allows Hyper-V to be nested and run inside another Hyper-VM VM. It requires Windows 10 - 1511 (build 10586) or newer. + Default is not defined. This will be disabled if not set. \ No newline at end of file diff --git a/website/source/docs/hyperv/index.html.md b/website/source/docs/hyperv/index.html.md index 02f12b2bc..b847b9ab2 100644 --- a/website/source/docs/hyperv/index.html.md +++ b/website/source/docs/hyperv/index.html.md @@ -14,7 +14,7 @@ Vagrant comes with support out of the box for [Hyper-V](https://en.wikipedia.org a native hypervisor written by Microsoft. Hyper-V is available by default for almost all Windows 8.1 installs. -The Hyper-V provider is compatible with Windows 8.1 only. Prior versions +The Hyper-V provider is compatible with Windows 8.1 and later only. Prior versions of Hyper-V do not include the necessary APIs for Vagrant to work. Hyper-V must be enabled prior to using the provider. Most Windows installations