Introduce qemuargs (for osx quirks)

v2:
- s/commandline/qemuargs/ (as suggested by @mxl)
- update xmls for testing
- fix merging
This commit is contained in:
Azat Khuzhin 2017-01-10 20:07:15 +03:00
parent 6ddf16d24d
commit 9e7e76b509
7 changed files with 64 additions and 5 deletions

View File

@ -1220,6 +1220,20 @@ Vagrant.configure(2) do |config|
end end
``` ```
## Custom command line arguments
You can also specify multiple qemuargs arguments for qemu-system
* `value` - Value
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.qemuargs :value => "-device"
libvirt.qemuargs :value => "intel-iommu"
end
end
```
## Box Format ## Box Format
You can view an example box in the You can view an example box in the

View File

@ -102,6 +102,9 @@ module VagrantPlugins
# smartcard device # smartcard device
@smartcard_dev = config.smartcard_dev @smartcard_dev = config.smartcard_dev
# qemuargs
@qemuargs = config.qemuargs
# RNG device passthrough # RNG device passthrough
@rng = config.rng @rng = config.rng
@ -280,6 +283,14 @@ module VagrantPlugins
env[:ui].info(" -- smartcard device: mode=#{@smartcard_dev[:mode]}, type=#{@smartcard_dev[:type]}") env[:ui].info(" -- smartcard device: mode=#{@smartcard_dev[:mode]}, type=#{@smartcard_dev[:type]}")
end end
unless @qemuargs.empty?
env[:ui].info(' -- Command line args: ')
@qemuargs.each do |arg|
msg = " -> value=#{arg[:value]}, "
env[:ui].info(msg)
end
end
env[:ui].info(" -- Command line : #{@cmd_line}") env[:ui].info(" -- Command line : #{@cmd_line}")
# Create libvirt domain. # Create libvirt domain.

View File

@ -141,6 +141,9 @@ module VagrantPlugins
# Attach mgmt network # Attach mgmt network
attr_accessor :mgmt_attach attr_accessor :mgmt_attach
# Additional qemuargs arguments
attr_accessor :qemuargs
def initialize def initialize
@uri = UNSET_VALUE @uri = UNSET_VALUE
@driver = UNSET_VALUE @driver = UNSET_VALUE
@ -238,6 +241,8 @@ module VagrantPlugins
# Attach mgmt network # Attach mgmt network
@mgmt_attach = UNSET_VALUE @mgmt_attach = UNSET_VALUE
@qemuargs = UNSET_VALUE
end end
def boot(device) def boot(device)
@ -489,6 +494,11 @@ module VagrantPlugins
@disks << disk # append @disks << disk # append
end end
def qemuargs(options = {})
@qemuargs = [] if @qemuargs == UNSET_VALUE
@qemuargs.push(value: options[:value])
end
# code to generate URI from a config moved out of the connect action # code to generate URI from a config moved out of the connect action
def _generate_uri def _generate_uri
# builds the libvirt connection URI from the given driver config # builds the libvirt connection URI from the given driver config
@ -651,6 +661,8 @@ module VagrantPlugins
# Attach mgmt network # Attach mgmt network
@mgmt_attach = true if @mgmt_attach == UNSET_VALUE @mgmt_attach = true if @mgmt_attach == UNSET_VALUE
@qemuargs = [] if @qemuargs == UNSET_VALUE
end end
def validate(machine) def validate(machine)
@ -676,9 +688,14 @@ module VagrantPlugins
c = disks.dup c = disks.dup
c += other.disks c += other.disks
result.disks = c result.disks = c
c = cdroms.dup c = cdroms.dup
c += other.cdroms c += other.cdroms
result.cdroms = c result.cdroms = c
c = qemuargs.dup
c += other.qemuargs
result.qemuargs = c
end end
end end
end end

View File

@ -1,4 +1,4 @@
<domain type='<%= @domain_type %>'> <domain type='<%= @domain_type %>' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name><%= @name %></name> <name><%= @name %></name>
<uuid><%= @uuid %></uuid> <uuid><%= @uuid %></uuid>
<memory><%= @memory_size %></memory> <memory><%= @memory_size %></memory>
@ -218,4 +218,12 @@
</tpm> </tpm>
<% end -%> <% end -%>
</devices> </devices>
<% unless @qemuargs.empty? %>
<qemu:commandline>
<% @qemuargs.each do |arg| %>
<qemu:arg value='<%= arg[:value] %>'/>
<% end %>
</qemu:commandline>
<% end %>
</domain> </domain>

View File

@ -1,4 +1,4 @@
<domain type='kvm'> <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name></name> <name></name>
<uuid></uuid> <uuid></uuid>
<memory></memory> <memory></memory>
@ -125,4 +125,9 @@
</backend> </backend>
</tpm> </tpm>
</devices> </devices>
<qemu:commandline>
<qemu:arg value='-device'/>
<qemu:arg value='dummy-device'/>
</qemu:commandline>
</domain> </domain>

View File

@ -1,4 +1,4 @@
<domain type=''> <domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name></name> <name></name>
<uuid></uuid> <uuid></uuid>
<memory></memory> <memory></memory>
@ -42,4 +42,5 @@
</devices> </devices>
</domain> </domain>

View File

@ -62,6 +62,9 @@ describe 'templates/domain' do
domain.watchdog(model: 'i6300esb', action: 'reset') domain.watchdog(model: 'i6300esb', action: 'reset')
domain.smartcard(mode: 'passthrough') domain.smartcard(mode: 'passthrough')
domain.tpm_path = '/dev/tpm0' domain.tpm_path = '/dev/tpm0'
domain.qemuargs(value: '-device')
domain.qemuargs(value: 'dummy-device')
end end
let(:test_file) { 'domain_all_settings.xml' } let(:test_file) { 'domain_all_settings.xml' }
it 'renders template' do it 'renders template' do