Add qemu commandline environment variable support. (#961)

Make it easier to tweak some qemu options by allowing passthru of
command line environment variables.

- Also cleans up weird variable indirection used for qemu commandline args
  variable through `qargs` in various constructors.
- Addresses some functionality discussed in #776.
This commit is contained in:
Julio Lajara
2020-05-10 09:37:31 -04:00
committed by GitHub
parent f5f9e34da0
commit f00bc0eaae
6 changed files with 62 additions and 10 deletions

View File

@@ -110,6 +110,12 @@ module VagrantPlugins
@redirdevs = config.redirdevs
@redirfilters = config.redirfilters
# Additional QEMU commandline arguments
@qemu_args = config.qemu_args
# Additional QEMU commandline environment variables
@qemu_env = config.qemu_env
# smartcard device
@smartcard_dev = config.smartcard_dev
@@ -322,15 +328,22 @@ module VagrantPlugins
env[:ui].info(" -- smartcard device: mode=#{@smartcard_dev[:mode]}, type=#{@smartcard_dev[:type]}")
end
@qargs = config.qemu_args
if not @qargs.empty?
unless @qemu_args.empty?
env[:ui].info(' -- Command line args: ')
@qargs.each do |arg|
@qemu_args.each do |arg|
msg = " -> value=#{arg[:value]}, "
env[:ui].info(msg)
end
end
unless @qemu_env.empty?
env[:ui].info(' -- Command line environment variables: ')
@qemu_env.each do |env_var, env_value|
msg = " -> #{env_var}=#{env_value}, "
env[:ui].info(msg)
end
end
env[:ui].info(" -- Command line : #{@cmd_line}") unless @cmd_line.empty?
# Create Libvirt domain.

View File

@@ -165,6 +165,9 @@ module VagrantPlugins
# Additional qemuargs arguments
attr_accessor :qemu_args
# Additional qemuenv arguments
attr_accessor :qemu_env
# Use QEMU session instead of system
attr_accessor :qemu_use_session
@@ -284,7 +287,12 @@ module VagrantPlugins
# Attach mgmt network
@mgmt_attach = UNSET_VALUE
@qemu_args = []
# Additional QEMU commandline arguments
@qemu_args = UNSET_VALUE
# Additional QEMU commandline environment variables
@qemu_env = UNSET_VALUE
@qemu_use_session = UNSET_VALUE
end
@@ -599,9 +607,17 @@ module VagrantPlugins
end
def qemuargs(options = {})
@qemu_args = [] if @qemu_args == UNSET_VALUE
@qemu_args << options if options[:value]
end
def qemuenv(options = {})
@qemu_env = {} if @qemu_env == UNSET_VALUE
@qemu_env.merge!(options)
end
# code to generate URI from a config moved out of the connect action
def _generate_uri
# builds the Libvirt connection URI from the given driver config
@@ -788,7 +804,11 @@ module VagrantPlugins
# Attach mgmt network
@mgmt_attach = true if @mgmt_attach == UNSET_VALUE
# Additional QEMU commandline arguments
@qemu_args = [] if @qemu_args == UNSET_VALUE
# Additional QEMU commandline environment variables
@qemu_env = {} if @qemu_env == UNSET_VALUE
end
def validate(machine)
@@ -824,6 +844,10 @@ module VagrantPlugins
c = cdroms.dup
c += other.cdroms
result.cdroms = c
c = qemu_env != UNSET_VALUE ? qemu_env.dup : {}
c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE
result.qemu_env = c
end
end
end

View File

@@ -266,11 +266,14 @@
<% end %>
</devices>
<% unless @qargs.empty? %>
<% if not @qemu_args.empty? or not @qemu_env.empty? %>
<qemu:commandline>
<% @qargs.each do |arg| %>
<% @qemu_args.each do |arg| %>
<qemu:arg value='<%= arg[:value] %>'/>
<% end %>
<% @qemu_env.each do |env_var, env_value| %>
<qemu:env name='<%= env_var.to_s %>' value='<%= env_value %>'/>
<% end %>
</qemu:commandline>
<% end %>
</domain>