diff --git a/README.md b/README.md index f990ecd..30703ad 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ can help a lot :-) - [Customized Graphics](#customized-graphics) - [TPM Devices](#tpm-devices) - [Libvirt communication channels](#libvirt-communication-channels) -- [Custom command line arguments](#custom-command-line-arguments) +- [Custom command line arguments and environment variables](#custom-command-line-arguments-and-environment-variables) - [Box Format](#box-format) - [Create Box](#create-box) - [Package Box from VM](#package-box-from-vm) @@ -1413,8 +1413,8 @@ Vagrant.configure(2) do |config| end ``` -## Custom command line arguments -You can also specify multiple qemuargs arguments for qemu-system +## Custom command line arguments and environment variables +You can also specify multiple qemuargs arguments or qemuenv environment variables for qemu-system * `value` - Value @@ -1423,6 +1423,9 @@ Vagrant.configure("2") do |config| config.vm.provider :libvirt do |libvirt| libvirt.qemuargs :value => "-device" libvirt.qemuargs :value => "intel-iommu" + libvirt.qemuenv QEMU_AUDIO_DRV: 'pa' + libvirt.qemuenv QEMU_AUDIO_TIMER_PERIOD: '150' + libvirt.qemuenv QEMU_PA_SAMPLES: '1024', QEMU_PA_SERVER: '/run/user/1000/pulse/native' end end ``` diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 843ce39..e9e5f04 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -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. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 8bd2294..b8c3f37 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -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 diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index a4c7284..7118987 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -266,11 +266,14 @@ <% end %> - <% unless @qargs.empty? %> + <% if not @qemu_args.empty? or not @qemu_env.empty? %> - <% @qargs.each do |arg| %> + <% @qemu_args.each do |arg| %> <% end %> + <% @qemu_env.each do |env_var, env_value| %> + + <% end %> <% end %> diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index fee8081..5344051 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -143,5 +143,9 @@ + + + + diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index 0eb83fa..0bd647b 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -11,7 +11,6 @@ describe 'templates/domain' do def finalize! super - @qargs = @qemu_args end end @@ -76,6 +75,12 @@ describe 'templates/domain' do domain.qemuargs(value: '-device') domain.qemuargs(value: 'dummy-device') + + domain.qemuenv(QEMU_AUDIO_DRV: 'pa') + domain.qemuenv(QEMU_AUDIO_TIMER_PERIOD: '150') + domain.qemuenv(QEMU_PA_SAMPLES: '1024') + domain.qemuenv(QEMU_PA_SERVER: '/run/user/1000/pulse/native') + domain.shares = '1024' domain.cpuset = '1-4,^3,6' domain.nodeset = '1-4,^3,6'