diff --git a/plugins/providers/hyperv/action/configure.rb b/plugins/providers/hyperv/action/configure.rb index f25737f8a..1d05c2f72 100644 --- a/plugins/providers/hyperv/action/configure.rb +++ b/plugins/providers/hyperv/action/configure.rb @@ -97,6 +97,11 @@ module VagrantPlugins env[:machine].provider_config.vm_integration_services) end + if !env[:machine].provider_config.enhanced_session_transport_type.empty? + env[:ui].detail("Setting VM Enhanced session transport type") + env[:machine].provider.driver.set_enhanced_session_transport_type(env[:machine].provider_config.enhanced_session_transport_type) + end + @app.call(env) end end diff --git a/plugins/providers/hyperv/config.rb b/plugins/providers/hyperv/config.rb index 96014258c..4b7e05294 100644 --- a/plugins/providers/hyperv/config.rb +++ b/plugins/providers/hyperv/config.rb @@ -48,6 +48,8 @@ module VagrantPlugins attr_accessor :enable_virtualization_extensions # @return [Hash] Options for VMServiceIntegration attr_accessor :vm_integration_services + # @return [String] Set Enhanced session transport type + attr_accessor :enhanced_session_transport_type def initialize @ip_address_timeout = UNSET_VALUE @@ -65,6 +67,7 @@ module VagrantPlugins @enable_automatic_checkpoints = UNSET_VALUE @enable_checkpoints = UNSET_VALUE @vm_integration_services = {} + @enhanced_session_transport_type = UNSET_VALUE end def finalize! @@ -102,6 +105,8 @@ module VagrantPlugins # If automatic checkpoints are enabled, checkpoints will automatically be enabled @enable_checkpoints ||= @enable_automatic_checkpoints + + @enhanced_session_transport_type = nil if @enhanced_session_transport_type == UNSET_VALUE end def validate(machine) diff --git a/plugins/providers/hyperv/driver.rb b/plugins/providers/hyperv/driver.rb index e200a8224..8c65f5d58 100644 --- a/plugins/providers/hyperv/driver.rb +++ b/plugins/providers/hyperv/driver.rb @@ -217,6 +217,14 @@ module VagrantPlugins execute(:set_name, VMID: vm_id, VMName: vmname) end + # Set enhanced session transport type of the VM + # + # @param [String] enhanced session transport type of the VM + # @return [nil] + def set_enhanced_session_transport_type(transport_type) + execute(:set_enhanced_session_transport_type, VmID: vm_id, type: transport_type) + end + protected def execute_powershell(path, options, &block) diff --git a/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 b/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 new file mode 100644 index 000000000..29191db37 --- /dev/null +++ b/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 @@ -0,0 +1,24 @@ +#Requires -Modules VagrantMessages + +param ( + [parameter (Mandatory=$true)] + [Guid] $VMID, + [parameter (Mandatory=$true)] + [string] $Type +) + +$ErrorActionPreference = "Stop" + +try { + $VM = Hyper-V\Get-VM -Id $VMID +} catch { + Write-ErrorMessage "Failed to locate VM: ${PSItem}" + exit 1 +} + +try { + Hyper-V\Set-VM -VM $VM -EnhancedSessionTransportType $Type +} catch { + Write-ErrorMessage "Failed to assign EnhancedSessionTransportType to ${Type}: ${PSItem}" + exit 1 +} diff --git a/test/unit/plugins/providers/hyperv/action/configure_test.rb b/test/unit/plugins/providers/hyperv/action/configure_test.rb index 504e416ef..0c695181c 100644 --- a/test/unit/plugins/providers/hyperv/action/configure_test.rb +++ b/test/unit/plugins/providers/hyperv/action/configure_test.rb @@ -28,7 +28,8 @@ describe VagrantPlugins::HyperV::Action::Configure do enable_checkpoints: false, enable_automatic_checkpoints: true, enable_virtualization_extensions: false, - vm_integration_services: vm_integration_services + vm_integration_services: vm_integration_services, + enhanced_session_transport_type: "HvSocket" ) } let(:vm_integration_services){ {} } diff --git a/website/source/docs/hyperv/configuration.html.md b/website/source/docs/hyperv/configuration.html.md index 992e69818..c8967d3a9 100644 --- a/website/source/docs/hyperv/configuration.html.md +++ b/website/source/docs/hyperv/configuration.html.md @@ -19,6 +19,7 @@ you may set. A complete reference is shown below: * `enable_virtualization_extensions` (boolean) - Enable virtualization extensions for the virtual CPUs. Default: false * `enable_checkpoints` (boolean) Enable checkpoints of the VM. Default: false * `enable_automatic_checkpoints` (boolean) Enable automatic checkpoints of the VM. Default: false +* `enhanced_session_transport_type` (VMBus, HvSocket) - Enhanced session transport type for the VM. Default: Hyper-V Default (currently VMBus). * `ip_address_timeout` (integer) - Number of seconds to wait for the VM to report an IP address. Default: 120. * `linked_clone` (boolean) - Use differencing disk instead of cloning entire VHD. Default: false * `mac` (string) - MAC address for the guest network interface