Merge pull request #12280 from RudiMT/bugfix20210302/hyperv-enhanced-sessionmode-crash-2012R2

HyperV enhanced sessionmode crash on Windows Server 2012R2
This commit is contained in:
Sophia Castellarin 2023-02-21 16:47:11 -08:00 committed by GitHub
commit a5983aabe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -1,4 +1,5 @@
require "json"
require "log4r"
require "vagrant/util/powershell"
@ -26,6 +27,7 @@ module VagrantPlugins
def initialize(id)
@vm_id = id
@logger = Log4r::Logger.new("vagrant::hyperv::driver")
end
# @return [Boolean] Supports VMCX
@ -294,7 +296,10 @@ module VagrantPlugins
# @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)
result = execute(:set_enhanced_session_transport_type, VmID: vm_id, type: transport_type)
if !result.nil?
@logger.debug("EnhancedSessionTransportType is not supported by this version of hyperv, ignoring")
end
end
protected

View File

@ -17,7 +17,16 @@ try {
}
try {
# HyperV 1.1 (Windows Server 2012R2) crashes on this call. Vagrantfiles before 2.2.10 do break without skipping this.
$present = Get-Command Hyper-V\Set-VM -ParameterName EnhancedSessionTransportType -ErrorAction SilentlyContinue
if($present) {
Hyper-V\Set-VM -VM $VM -EnhancedSessionTransportType $Type
}else{
$message = @{
"EnhancedSessionTransportTypeSupportPresent"=$false;
} | ConvertTo-Json
Write-OutputMessage $message
}
} catch {
Write-ErrorMessage "Failed to assign EnhancedSessionTransportType to ${Type}:${PSItem}"
exit 1