Merge pull request #11014 from camjjack/hyper-v-enhanced-session-transport-type

hyper-v: add support for EnhancedSessionTransportType.
This commit is contained in:
Chris Roberts 2020-08-07 08:42:49 -07:00 committed by GitHub
commit 211aa73c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 1 deletions

View File

@ -97,6 +97,14 @@ module VagrantPlugins
env[:machine].provider_config.vm_integration_services)
end
if env[:machine].provider_config.enable_enhanced_session_mode
env[:ui].detail(I18n.t("vagrant.hyperv_enable_enhanced_session"))
env[:machine].provider.driver.set_enhanced_session_transport_type("HvSocket")
else
env[:ui].detail(I18n.t("vagrant.hyperv_disable_enhanced_session"))
env[:machine].provider.driver.set_enhanced_session_transport_type("VMBus")
end
@app.call(env)
end
end

View File

@ -48,6 +48,8 @@ module VagrantPlugins
attr_accessor :enable_virtualization_extensions
# @return [Hash] Options for VMServiceIntegration
attr_accessor :vm_integration_services
# @return [Boolean] Enable Enhanced session mode
attr_accessor :enable_enhanced_session_mode
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 = {}
@enable_enhanced_session_mode = 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
@enable_enhanced_session_mode = false if @enable_enhanced_session_mode == UNSET_VALUE
end
def validate(machine)

View File

@ -289,6 +289,14 @@ module VagrantPlugins
DiskSize: size_bytes)
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)

View File

@ -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
}

View File

@ -165,6 +165,10 @@ en:
-- Detected newer image for container '%{name}', restarting...
docker_starting_containers: |-
Starting Docker containers...
hyperv_enable_enhanced_session: |-
Setting VM Enhanced session transport type to HvSocket
hyperv_disable_enhanced_session: |-
Setting VM Enhanced session transport type to disabled/default (VMBus)
inserted_key: |-
Key inserted! Disconnecting and reconnecting using new SSH key...
inserting_insecure_detected: |-

View File

@ -28,10 +28,12 @@ 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,
enable_enhanced_session_mode: enable_enhanced_session_mode
)
}
let(:vm_integration_services){ {} }
let(:enable_enhanced_session_mode){ false }
let(:subject){ described_class.new(app, env) }
@ -45,6 +47,7 @@ describe VagrantPlugins::HyperV::Action::Configure do
allow(data_dir).to receive(:join).and_return(sentinel)
allow(sentinel).to receive(:file?).and_return(false)
allow(sentinel).to receive(:open)
allow(driver).to receive(:set_enhanced_session_transport_type).with("VMBus")
end
it "should call the app on success" do
@ -116,6 +119,22 @@ describe VagrantPlugins::HyperV::Action::Configure do
end
end
context "without enhanced session transport type" do
it "should call the driver to set enhanced session transport type back to default" do
expect(driver).to receive(:set_enhanced_session_transport_type).with("VMBus")
subject.call(env)
end
end
context "with enhanced session transport type" do
let(:enable_enhanced_session_mode) { true }
it "should call the driver to set enhanced session transport type" do
expect(driver).to receive(:set_enhanced_session_transport_type).with("HvSocket")
subject.call(env)
end
end
context "without available switches" do
let(:switches){ [] }

View File

@ -241,4 +241,18 @@ describe VagrantPlugins::HyperV::Config do
expect(result["Hyper-V"]).not_to be_empty
end
end
describe "#enable_enhanced_session_mode" do
it "is false by default" do
subject.finalize!
expect(subject.enable_enhanced_session_mode).to eq(false)
end
it "can be set" do
subject.enable_enhanced_session_mode = true
subject.finalize!
expect(subject.enable_enhanced_session_mode).to eq(true)
end
end
end

View File

@ -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: true
- `enable_automatic_checkpoints` (boolean) Enable automatic checkpoints of the VM. Default: false
- `enable_enhanced_session_mode` (boolean) - Enable enhanced session transport type for the VM. Default: false
- `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