Inject default qemu_agent allowing for explicit disable (#1408)

Facilitate the injection of a default channel when qemu_agent is set to
true to make enabling it's use a simple `qemu_agent = true` for most
cases.

Where custom values are needed, they can be provided and the code will
skip adding a corresponding entry, or if necessary the user can add an
entry and mark it disabled similar to how synced folders work.

Closes: #1341
This commit is contained in:
Darragh Bailey
2021-11-26 18:12:21 +00:00
committed by GitHub
parent 2908888934
commit cf3b81bfc5
4 changed files with 69 additions and 3 deletions

View File

@@ -498,7 +498,9 @@ module VagrantPlugins
target_address: options[:target_address],
target_name: options[:target_name],
target_port: options[:target_port],
target_type: options[:target_type])
target_type: options[:target_type],
disabled: options[:disabled],
)
end
def random(options = {})
@@ -906,7 +908,18 @@ module VagrantPlugins
@inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE
# Channels
@channels = [] if @channels == UNSET_VALUE
if @channels == UNSET_VALUE
@channels = []
if @qemu_use_agent == true
if @channels.all? { |channel| !channel.fetch(:target_name, '').start_with?('org.qemu.guest_agent.') }
channel(:type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio')
end
end
end
# filter channels of anything explicitly disabled so it's possible to inject an entry to
# avoid the automatic addition of the guest_agent above, and disable it from subsequent use.
@channels = @channels.reject { |channel| channel[:disabled] }.tap {|channel| channel.delete(:disabled) }
# PCI device passthrough
@pcis = [] if @pcis == UNSET_VALUE