Use service id for enabling/disabling vm integration services
ref: https://github.com/PlagueHO/LabBuilder/issues/183 ref service name to id: https://social.technet.microsoft.com/Forums/de-DE/154917de-f3ca-4b1e-b3f8-23dd4b4f0f06/getvmintegrationservice-sprachabhngig?forum=powershell_de
This commit is contained in:
parent
7d449e193d
commit
d5cd4da0e0
@ -10,15 +10,16 @@ module VagrantPlugins
|
||||
ERROR_REGEXP = /===Begin-Error===(.+?)===End-Error===/m
|
||||
OUTPUT_REGEXP = /===Begin-Output===(.+?)===End-Output===/m
|
||||
|
||||
# Name mapping for integration services for nicer keys
|
||||
# Name mapping for integration services for id
|
||||
# https://social.technet.microsoft.com/Forums/de-DE/154917de-f3ca-4b1e-b3f8-23dd4b4f0f06/getvmintegrationservice-sprachabhngig?forum=powershell_de
|
||||
INTEGRATION_SERVICES_MAP = {
|
||||
guest_service_interface: "Guest Service Interface",
|
||||
heartbeat: "Heartbeat",
|
||||
key_value_pair_exchange: "Key-Value Pair Exchange",
|
||||
shutdown: "Shutdown",
|
||||
time_synchronization: "Time Synchronization",
|
||||
vss: "VSS",
|
||||
}
|
||||
guest_service_interface: "6C09BB55-D683-4DA0-8931-C9BF705F6480".freeze,
|
||||
heartbeat: "84EAAE65-2F2E-45F5-9BB5-0E857DC8EB47".freeze,
|
||||
key_value_pair_exchange: "2A34B1C2-FD73-4043-8A5B-DD2159BC743F".freeze,
|
||||
shutdown: "9F8233AC-BE49-4C79-8EE3-E7E1985B2077".freeze,
|
||||
time_synchronization: "2497F4DE-E9FA-4204-80E4-4B75C46419C0".freeze,
|
||||
vss: "5CED1297-4598-4915-A5FC-AD21BB4D02A4".freeze,
|
||||
}.freeze
|
||||
|
||||
# @return [String] VM ID
|
||||
attr_reader :vm_id
|
||||
@ -203,7 +204,7 @@ module VagrantPlugins
|
||||
# to configurable even if Vagrant is not aware of them.
|
||||
def set_vm_integration_services(config)
|
||||
config.each_pair do |srv_name, srv_enable|
|
||||
args = {VMID: vm_id, Name: INTEGRATION_SERVICES_MAP.fetch(srv_name.to_sym, srv_name).to_s}
|
||||
args = {VMID: vm_id, Id: INTEGRATION_SERVICES_MAP.fetch(srv_name.to_sym, srv_name).to_s}
|
||||
args[:Enable] = true if srv_enable
|
||||
execute(:set_vm_integration_services, args)
|
||||
end
|
||||
|
||||
@ -4,7 +4,7 @@ param (
|
||||
[parameter (Mandatory=$true)]
|
||||
[string] $VMID,
|
||||
[parameter (Mandatory=$true)]
|
||||
[string] $Name,
|
||||
[string] $Id,
|
||||
[parameter (Mandatory=$false)]
|
||||
[switch] $Enable
|
||||
)
|
||||
@ -19,9 +19,9 @@ try {
|
||||
}
|
||||
|
||||
try {
|
||||
Set-VagrantVMService -VM $VM -Name $Name -Enable $Enable
|
||||
Set-VagrantVMService -VM $VM -Id $Id -Enable $Enable
|
||||
} catch {
|
||||
if($Enable){ $action = "enable" } else { $action = "disable" }
|
||||
Write-ErrorMessage "Failed to ${action} VM integration service ${Name}: ${PSItem}"
|
||||
Write-ErrorMessage "Failed to ${action} VM integration service id ${Id}: ${PSItem}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -614,15 +614,15 @@ function Set-VagrantVMService {
|
||||
[parameter (Mandatory=$true)]
|
||||
[Microsoft.HyperV.PowerShell.VirtualMachine] $VM,
|
||||
[parameter (Mandatory=$true)]
|
||||
[string] $Name,
|
||||
[string] $Id,
|
||||
[parameter (Mandatory=$true)]
|
||||
[bool] $Enable
|
||||
)
|
||||
|
||||
if($Enable) {
|
||||
Hyper-V\Enable-VMIntegrationService -VM $VM -Name $Name
|
||||
Hyper-V\Get-VMIntegrationService -VM $VM | ?{$_.Id -match $Id} | Hyper-V\Enable-VMIntegrationService
|
||||
} else {
|
||||
Hyper-V\Disable-VMIntegrationService -VM $VM -Name $Name
|
||||
Hyper-V\Get-VMIntegrationService -VM $VM | ?{$_.Id -match $Id} | Hyper-V\Disable-VMIntegrationService
|
||||
}
|
||||
return $VM
|
||||
<#
|
||||
@ -634,9 +634,9 @@ Enable or disable Hyper-V VM integration services.
|
||||
|
||||
Hyper-V VM for modification.
|
||||
|
||||
.PARAMETER Name
|
||||
.PARAMETER Id
|
||||
|
||||
Name of the integration service.
|
||||
Id of the integration service.
|
||||
|
||||
.PARAMETER Enable
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ describe VagrantPlugins::HyperV::Driver do
|
||||
describe "#set_vm_integration_services" do
|
||||
it "should map known integration services names automatically" do
|
||||
expect(subject).to receive(:execute) do |name, args|
|
||||
expect(args[:Name]).to eq("Shutdown")
|
||||
expect(args[:Id]).to eq(VagrantPlugins::HyperV::Driver::INTEGRATION_SERVICES_MAP[:shutdown])
|
||||
end
|
||||
subject.set_vm_integration_services(shutdown: true)
|
||||
end
|
||||
@ -112,7 +112,7 @@ describe VagrantPlugins::HyperV::Driver do
|
||||
|
||||
it "should pass unknown key names directly through" do
|
||||
expect(subject).to receive(:execute) do |name, args|
|
||||
expect(args[:Name]).to eq("CustomKey")
|
||||
expect(args[:Id]).to eq("CustomKey")
|
||||
end
|
||||
subject.set_vm_integration_services(CustomKey: true)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user