vagrant-libvirt 0.6.3 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -13
  3. data/lib/vagrant-libvirt/action/cleanup_on_failure.rb +76 -0
  4. data/lib/vagrant-libvirt/action/create_domain.rb +56 -10
  5. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +5 -1
  6. data/lib/vagrant-libvirt/action/create_networks.rb +24 -0
  7. data/lib/vagrant-libvirt/action/destroy_domain.rb +106 -21
  8. data/lib/vagrant-libvirt/action/destroy_networks.rb +1 -1
  9. data/lib/vagrant-libvirt/action/forward_ports.rb +12 -11
  10. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +1 -1
  11. data/lib/vagrant-libvirt/action/start_domain.rb +36 -0
  12. data/lib/vagrant-libvirt/action/wait_till_up.rb +6 -32
  13. data/lib/vagrant-libvirt/action.rb +72 -83
  14. data/lib/vagrant-libvirt/config.rb +85 -30
  15. data/lib/vagrant-libvirt/driver.rb +11 -9
  16. data/lib/vagrant-libvirt/errors.rb +12 -0
  17. data/lib/vagrant-libvirt/templates/domain.xml.erb +228 -218
  18. data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -1
  19. data/lib/vagrant-libvirt/util/network_util.rb +15 -3
  20. data/lib/vagrant-libvirt/util/nfs.rb +2 -0
  21. data/lib/vagrant-libvirt/util/resolvers.rb +80 -0
  22. data/lib/vagrant-libvirt/version +1 -1
  23. data/locales/en.yml +17 -0
  24. data/spec/spec_helper.rb +36 -23
  25. data/spec/support/libvirt_context.rb +7 -4
  26. data/spec/support/sharedcontext.rb +1 -1
  27. data/spec/unit/action/cleanup_on_failure_spec.rb +131 -0
  28. data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +6 -18
  29. data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +43 -0
  30. data/spec/unit/action/create_domain_spec/default_domain.xml +6 -18
  31. data/spec/unit/action/create_domain_spec/two_disk_settings.xml +49 -0
  32. data/spec/unit/action/create_domain_spec.rb +51 -7
  33. data/spec/unit/action/create_domain_volume_spec.rb +5 -3
  34. data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +47 -0
  35. data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +55 -0
  36. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +72 -0
  37. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +67 -0
  38. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +67 -0
  39. data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +48 -0
  40. data/spec/unit/action/destroy_domain_spec.rb +134 -30
  41. data/spec/unit/action/forward_ports_spec.rb +10 -2
  42. data/spec/unit/action/prepare_nfs_settings_spec.rb +59 -0
  43. data/spec/unit/action/shutdown_domain_spec.rb +1 -1
  44. data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +6 -18
  45. data/spec/unit/action/start_domain_spec/default.xml +6 -18
  46. data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +6 -18
  47. data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +6 -18
  48. data/spec/unit/action/start_domain_spec/existing.xml +1 -1
  49. data/spec/unit/action/wait_till_up_spec.rb +4 -43
  50. data/spec/unit/action_spec.rb +2 -0
  51. data/spec/unit/config_spec.rb +133 -26
  52. data/spec/unit/driver_spec.rb +154 -10
  53. data/spec/unit/templates/domain_all_settings.xml +56 -77
  54. data/spec/unit/templates/domain_cpu_mode_passthrough.xml +39 -0
  55. data/spec/unit/templates/domain_custom_cpu_model.xml +6 -18
  56. data/spec/unit/templates/domain_defaults.xml +6 -18
  57. data/spec/unit/templates/domain_spec.rb +39 -13
  58. data/spec/unit/templates/tpm/version_1.2.xml +6 -18
  59. data/spec/unit/templates/tpm/version_2.0.xml +6 -18
  60. data/spec/unit/util/resolvers_spec.rb +116 -0
  61. metadata +40 -41
@@ -5,115 +5,111 @@
5
5
  <uuid><%= @uuid %></uuid>
6
6
  <memory><%= @memory_size %></memory>
7
7
  <vcpu<% if @cpuset %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %></vcpu>
8
-
9
-
10
8
  <cpu mode='<%= @cpu_mode %>'>
11
- <% if @cpu_mode != 'host-passthrough' %>
12
- <model fallback='<%= @cpu_fallback %>'><% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %></model>
13
- <% if @nested %>
14
- <% if @cpu_features.select{|x| x[:name] == 'vmx'}.empty? %>
15
- <feature policy='optional' name='vmx'/>
16
- <% end %>
17
- <% if @cpu_features.select{|x| x[:name] == 'svm'}.empty? %>
18
- <feature policy='optional' name='svm'/>
19
- <% end %>
20
- <% end %>
21
- <% @cpu_features.each do |cpu_feature| %>
22
- <feature name='<%= cpu_feature[:name] %>' policy='<%= cpu_feature[:policy] %>'/>
23
- <% end %>
24
- <% unless @cpu_topology.empty? %>
25
- <%# CPU topology -%>
26
- <topology sockets='<%= @cpu_topology[:sockets] %>' cores='<%= @cpu_topology[:cores] %>' threads='<%= @cpu_topology[:threads] %>'/>
27
- <% end %>
28
- <% end %>
29
- <% if @numa_nodes %>
30
- <numa>
31
- <% @numa_nodes.each_with_index do |node, index| %>
32
- <cell id='<%= index %>' cpus='<%= node[:cpus] %>' memory='<%= node[:memory] %>'/>
33
- <% end %>
34
- </numa>
35
- <% end %>
9
+ <%- if @cpu_mode != 'host-passthrough' -%>
10
+ <model fallback='<%= @cpu_fallback %>'><% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %></model>
11
+ <%- end -%>
12
+ <%- if @nested -%>
13
+ <%- if @cpu_features.select{|x| x[:name] == 'vmx'}.empty? -%>
14
+ <feature policy='optional' name='vmx'/>
15
+ <%- end -%>
16
+ <%- if @cpu_features.select{|x| x[:name] == 'svm'}.empty? -%>
17
+ <feature policy='optional' name='svm'/>
18
+ <%- end -%>
19
+ <%- end -%>
20
+ <%- @cpu_features.each do |cpu_feature| -%>
21
+ <feature name='<%= cpu_feature[:name] %>' policy='<%= cpu_feature[:policy] %>'/>
22
+ <%- end -%>
23
+ <%- unless @cpu_topology.empty? -%>
24
+ <%# CPU topology -%>
25
+ <topology sockets='<%= @cpu_topology[:sockets] %>' cores='<%= @cpu_topology[:cores] %>' threads='<%= @cpu_topology[:threads] %>'/>
26
+ <%- end -%>
27
+ <%- if @numa_nodes -%>
28
+ <numa>
29
+ <%- @numa_nodes.each_with_index do |node, index| -%>
30
+ <cell id='<%= index %>' cpus='<%= node[:cpus] %>' memory='<%= node[:memory] %>'<% if node.key?(:memAccess) %> memAccess='<%= node[:memAccess] %>'<% end %>/>
31
+ <%- end -%>
32
+ </numa>
33
+ <%- end -%>
36
34
  </cpu>
37
-
38
35
  <%- if @nodeset -%>
39
36
  <numatune>
40
37
  <memory nodeset='<%= @nodeset %>'/>
41
38
  </numatune>
42
39
  <%- end -%>
43
- <% unless @memory_backing.empty? %>
40
+ <%- unless @memory_backing.empty? -%>
44
41
  <memoryBacking>
45
- <% @memory_backing.each do |backing| %>
42
+ <%- @memory_backing.each do |backing| -%>
46
43
  <<%= backing[:name] %> <%= backing[:config].map { |k,v| "#{k}='#{v}'"}.join(' ') %>/>
47
- <% end %>
44
+ <%- end -%>
48
45
  </memoryBacking>
49
- <% end%>
50
- <% if @shares %>
46
+ <%- end%>
47
+ <%- if @shares -%>
51
48
  <cputune>
52
49
  <shares><%= @shares %></shares>
53
50
  </cputune>
54
- <% end %>
55
-
51
+ <%- end -%>
56
52
  <os>
57
- <% if @machine_type %>
58
- <% if @machine_arch %>
59
- <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
60
- <% else %>
61
- <type machine='<%= @machine_type %>'>hvm</type>
62
- <% end %>
63
- <% else %>
64
- <% if @machine_arch %>
65
- <type arch='<%= @machine_arch %>'>hvm</type>
66
- <% else %>
67
- <type>hvm</type>
68
- <% end %>
69
- <% end %>
70
- <% if @loader %>
71
- <% if @nvram %>
72
- <loader readonly='yes' type='pflash'><%= @loader %></loader>
73
- <% else %>
74
- <loader readonly='yes' type='rom'><%= @loader %></loader>
75
- <% end %>
76
- <% end %>
77
- <% if @nvram %>
78
- <nvram><%= @nvram %></nvram>
79
- <% end %>
80
- <% if @boot_order.count >= 1 %>
81
- <bootmenu enable='yes'/>
82
- <% end %>
53
+ <%- if @machine_type -%>
54
+ <%- if @machine_arch -%>
55
+ <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
56
+ <%- else -%>
57
+ <type machine='<%= @machine_type %>'>hvm</type>
58
+ <%- end -%>
59
+ <%- else -%>
60
+ <%- if @machine_arch -%>
61
+ <type arch='<%= @machine_arch %>'>hvm</type>
62
+ <%- else -%>
63
+ <type>hvm</type>
64
+ <%- end -%>
65
+ <%- end -%>
66
+ <%- if @loader -%>
67
+ <%- if @nvram -%>
68
+ <loader readonly='yes' type='pflash'><%= @loader %></loader>
69
+ <%- else -%>
70
+ <loader readonly='yes' type='rom'><%= @loader %></loader>
71
+ <%- end -%>
72
+ <%- end -%>
73
+ <%- if @nvram -%>
74
+ <nvram><%= @nvram %></nvram>
75
+ <%- end -%>
76
+ <%- if @boot_order.count >= 1 -%>
77
+ <bootmenu enable='yes'/>
78
+ <%- end -%>
83
79
  <kernel><%= @kernel %></kernel>
84
80
  <initrd><%= @initrd %></initrd>
85
81
  <cmdline><%= @cmd_line %></cmdline>
86
- <% if @dtb %>
87
- <dtb><%= @dtb %></dtb>
88
- <% end %>
82
+ <%- if @dtb -%>
83
+ <dtb><%= @dtb %></dtb>
84
+ <% end -%>
89
85
  </os>
90
86
  <features>
91
- <% @features.each do |feature| %>
87
+ <%- @features.each do |feature| -%>
92
88
  <<%= feature %>/>
93
- <% end %>
94
- <% if @kvm_hidden %>
95
- <kvm>
96
- <hidden state='on'/>
97
- </kvm>
98
- <% end %>
99
- <% if !@features_hyperv.empty? %>
89
+ <%- end -%>
90
+ <%- if @kvm_hidden -%>
91
+ <kvm>
92
+ <hidden state='on'/>
93
+ </kvm>
94
+ <%- end -%>
95
+ <%- if !@features_hyperv.empty? -%>
100
96
  <hyperv>
101
- <% @features_hyperv.each do |feature| %>
97
+ <%- @features_hyperv.each do |feature| -%>
102
98
  <<%= feature[:name] %> state='<%= feature[:state] %>'<% if feature[:name] == 'spinlocks' %> retries='<%= feature[:retries] %>'<% end %> />
103
- <% end %>
99
+ <%- end -%>
104
100
  </hyperv>
105
- <% end %>
101
+ <%- end -%>
106
102
  </features>
107
103
  <clock offset='<%= @clock_offset %>'>
108
- <% @clock_timers.each do |clock_timer| %>
104
+ <%- @clock_timers.each do |clock_timer| -%>
109
105
  <timer<% clock_timer.each do |attr, value| %> <%= attr %>='<%= value %>'<% end %>/>
110
- <% end %>
106
+ <%- end -%>
111
107
  </clock>
112
108
  <devices>
113
- <% if @emulator_path %>
109
+ <%- if @emulator_path -%>
114
110
  <emulator><%= @emulator_path %></emulator>
115
- <% end %>
116
- <% @domain_volumes.each_with_index do |volume, index| -%>
111
+ <%- end -%>
112
+ <%- @domain_volumes.each_with_index do |volume, index| -%>
117
113
  <disk type='file' device='disk'>
118
114
  <alias name='ua-box-volume-<%= index -%>'/>
119
115
  <driver name='qemu' type='qcow2' <%=
@@ -125,9 +121,9 @@
125
121
  <%# we need to ensure a unique target dev -%>
126
122
  <target dev='<%= volume[:dev] %>' bus='<%= volume[:bus] %>'/>
127
123
  </disk>
128
- <% end -%>
124
+ <%- end -%>
129
125
  <%# additional disks -%>
130
- <% @disks.each_with_index do |d, index| -%>
126
+ <%- @disks.each_with_index do |d, index| -%>
131
127
  <disk type='file' device='disk'>
132
128
  <alias name='ua-disk-volume-<%= index -%>'/>
133
129
  <driver name='qemu' type='<%= d[:type] %>' <%=
@@ -138,174 +134,188 @@
138
134
  -%>/>
139
135
  <source file='<%= d[:absolute_path] %>'/>
140
136
  <target dev='<%= d[:device] %>' bus='<%= d[:bus] %>'/>
141
- <% if d[:shareable] %>
142
- <shareable/>
143
- <% end %>
144
- <% if d[:serial] %>
145
- <serial><%= d[:serial] %></serial>
146
- <% end %>
147
- <% if d[:wwn] %>
148
- <wwn><%= d[:wwn] %></wwn>
149
- <% end %>
137
+ <%- if d[:shareable] -%>
138
+ <shareable/>
139
+ <%- end -%>
140
+ <%- if d[:serial] -%>
141
+ <serial><%= d[:serial] %></serial>
142
+ <%- end -%>
143
+ <%- if d[:wwn] -%>
144
+ <wwn><%= d[:wwn] %></wwn>
145
+ <%- end -%>
150
146
  <%# this will get auto generated by Libvirt
151
147
  <address type='pci' domain='0x0000' bus='0x00' slot='???' function='0x0'/>
152
148
  -%>
153
149
  </disk>
154
150
  <% end -%>
155
-
156
- <% @cdroms.each do |c| %>
151
+ <%- @cdroms.each do |c| -%>
157
152
  <disk type='file' device='cdrom'>
158
153
  <driver name='qemu' type='<%= c[:type] %>' />
159
154
  <source file='<%= c[:path] %>'/>
160
155
  <target dev='<%= c[:dev] %>' bus='<%= c[:bus] %>'/>
161
156
  <readonly/>
162
157
  </disk>
163
- <% end %>
164
-
165
- <serial type='pty'>
166
- <target port='0'/>
158
+ <%- end -%>
159
+ <%- @serials.each_with_index do |serial, port| -%>
160
+ <serial type='<%= serial[:type] %>'>
161
+ <%- unless serial[:source].nil? -%>
162
+ <source path='<%= serial[:source][:path] %>'/>
163
+ <%- end -%>
164
+ <target port='<%= port %>'/>
167
165
  </serial>
168
- <console type='pty'>
166
+ <%- end -%>
167
+ <%- unless @serials.empty? -%>
168
+ <%- console_log = @serials.first -%>
169
+ <console type='<%= console_log[:type] %>'>
170
+ <%- unless console_log[:source].nil? -%>
171
+ <source path='<%= console_log[:source][:path] %>'/>
172
+ <%- end -%>
169
173
  <target port='0'/>
170
174
  </console>
171
-
172
- <% @channels.each do |channel| %>
173
- <channel type='<%= channel[:type] %>' >
174
- <%if channel[:source_mode] or channel[:source_path] %>
175
- <source
176
- <% if channel[:source_mode] %>
177
- mode='<%= channel[:source_mode] %>'
178
- <% end %>
179
- <% if channel[:source_path] %>
180
- path="<%= channel[:source_path] %>"
181
- <% end %>
182
- />
183
- <% end %>
184
- <target type='<%= channel[:target_type] %>'
185
- <% if channel[:target_name] %>
186
- name="<%= channel[:target_name] %>"
187
- <% end %>
188
- <% if channel[:target_address] %>
189
- address="<%= channel[:target_address] %>"
190
- <% end %>
191
- <% if channel[:target_port] %>
192
- port="<%= channel[:target_port] %>"
193
- <% end %>
194
- />
195
- </channel>
196
- <% end %>
197
-
198
- <% @inputs.each do |input| %>
175
+ <%- end -%>
176
+ <%- @channels.each do |channel| -%>
177
+ <channel type='<%= channel[:type] %>' >
178
+ <%-if channel[:source_mode] or channel[:source_path] -%>
179
+ <source <%=
180
+ channel.select { |k,_| [:source_mode, :source_path].include? k }
181
+ .reject { |k,v| v.nil? }
182
+ .map { |k,v| "#{k.to_s.split('_').last}='#{v}'"}
183
+ .join(' ')
184
+ -%>/>
185
+ <%- end -%>
186
+ <target type='<%= channel[:target_type] %>' <%=
187
+ channel.select { |k,_| [:target_name, :target_address, :target_port].include? k }
188
+ .reject { |k,v| v.nil? }
189
+ .map { |k,v| "#{k.to_s.split('_').last}='#{v}'"}
190
+ .join(' ')
191
+ -%>/>
192
+ </channel>
193
+ <%- end -%>
194
+ <%- @inputs.each do |input| -%>
199
195
  <input type='<%= input[:type] %>' bus='<%= input[:bus] %>'/>
200
- <% end %>
201
-
202
- <% if !@sound_type.nil? %>
203
- <%# Sound device-%>
204
- <sound model='<%= @sound_type %>'>
205
- </sound>
206
- <%# End Sound%>
207
- <% end %>
208
- <% if @graphics_type != 'none' %>
209
- <%# Video device -%>
210
- <graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd%> />
211
- <video>
212
- <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
213
- </video>
214
- <%#End Video -%>
215
- <% end %>
216
- <% if @rng[:model] == "random"%>
217
- <rng model='virtio'>
218
- <backend model='random'>/dev/random</backend>
219
- </rng>
220
- <% end %>
221
- <% @pcis.each do |pci| %>
222
- <hostdev mode='subsystem' type='pci' managed='yes'>
223
- <source>
224
- <address domain='<%= pci[:domain] %>'
225
- bus='<%= pci[:bus] %>'
226
- slot='<%= pci[:slot] %>'
227
- function='<%= pci[:function] %>'/>
228
- </source>
229
- </hostdev>
230
- <% end %>
231
- <% @usbs.each do |usb| %>
232
- <hostdev mode='subsystem' type='usb'>
233
- <source startupPolicy='<%= usb[:startupPolicy] || "mandatory" %>'>
234
- <% if usb[:vendor] %>
235
- <vendor id='<%= usb[:vendor] %>'/>
236
- <% end %>
237
- <% if usb[:product] %>
238
- <product id='<%= usb[:product] %>'/>
239
- <% end %>
240
- <% if usb[:bus] && usb[:device] %>
241
- <address bus='<%= usb[:bus] %>' device='<%= usb[:device] %>'/>
242
- <% end %>
243
- </source>
244
- </hostdev>
245
- <% end %>
246
- <% unless @redirdevs.empty? %>
247
- <% @redirdevs.each do |redirdev| %>
248
- <redirdev bus='usb' type='<%= redirdev[:type] %>'>
249
- </redirdev>
250
- <% end %>
251
- <% unless @redirfilters.empty? %>
252
- <redirfilter>
253
- <% @redirfilters.each do |usbdev| %>
254
- <usbdev class='<%= usbdev[:class] %>' vendor='<%= usbdev[:vendor] %>' product='<%= usbdev[:product] %>' version='<%= usbdev[:version] %>' allow='<%= usbdev[:allow] %>'/>
255
- <% end %>
256
- </redirfilter>
257
- <% end %>
258
- <% end %>
259
- <% unless @watchdog_dev.empty? %>
196
+ <%- end -%>
197
+ <%- if !@sound_type.nil? -%>
198
+ <%# Sound device-%>
199
+ <sound model='<%= @sound_type %>'>
200
+ </sound>
201
+ <%# End Sound%>
202
+ <%- end -%>
203
+ <%- if @graphics_type != 'none'
204
+ graphics = {
205
+ 'type' => @graphics_type,
206
+ 'port' => @graphics_port,
207
+ 'autoport' => @graphics_autoport,
208
+ 'listen' => @graphics_ip,
209
+ 'keymap' => @keymap,
210
+ 'passwd' => @graphics_passwd,
211
+ }
212
+ -%>
213
+ <%# Video device -%>
214
+ <graphics <%=
215
+ graphics.reject { |k,v| v.nil? }
216
+ .map { |k,v| "#{k}='#{v}'" }
217
+ .join(' ')
218
+ -%><%- if not @graphics_gl %>/><% else %>>
219
+ <gl enable='yes'/>
220
+ </graphics><% end -%>
221
+ <video>
222
+ <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'<% if not @video_accel3d %>/><% else %>>
223
+ <acceleration accel3d='yes'/>
224
+ </model><% end -%>
225
+ </video>
226
+ <%#End Video -%>
227
+ <%- end -%>
228
+ <%- if @rng[:model] == "random"%>
229
+ <rng model='virtio'>
230
+ <backend model='random'>/dev/random</backend>
231
+ </rng>
232
+ <%- end -%>
233
+ <%- @pcis.each do |pci| -%>
234
+ <hostdev mode='subsystem' type='pci' managed='yes'>
235
+ <source>
236
+ <address <%= pci.select { |k,_| [:domain, :bus, :slot, :function].include? k }
237
+ .reject { |k,v| v.nil? }
238
+ .map { |k,v| "#{k.to_s}='#{v}'" }
239
+ .join(' ')
240
+ -%>/>
241
+ </source>
242
+ </hostdev>
243
+ <%- end -%>
244
+ <%- @usbs.each do |usb| -%>
245
+ <hostdev mode='subsystem' type='usb'>
246
+ <source startupPolicy='<%= usb[:startupPolicy] || "mandatory" %>'>
247
+ <%- if usb[:vendor] -%>
248
+ <vendor id='<%= usb[:vendor] %>'/>
249
+ <%- end -%>
250
+ <%- if usb[:product] -%>
251
+ <product id='<%= usb[:product] %>'/>
252
+ <%- end -%>
253
+ <%- if usb[:bus] && usb[:device] -%>
254
+ <address bus='<%= usb[:bus] %>' device='<%= usb[:device] %>'/>
255
+ <%- end -%>
256
+ </source>
257
+ </hostdev>
258
+ <%- end -%>
259
+ <%- unless @redirdevs.empty? -%>
260
+ <%- @redirdevs.each do |redirdev| -%>
261
+ <redirdev bus='usb' type='<%= redirdev[:type] %>'>
262
+ </redirdev>
263
+ <%- end -%>
264
+ <%- unless @redirfilters.empty? -%>
265
+ <redirfilter>
266
+ <%- @redirfilters.each do |usbdev| -%>
267
+ <usbdev class='<%= usbdev[:class] %>' vendor='<%= usbdev[:vendor] %>' product='<%= usbdev[:product] %>' version='<%= usbdev[:version] %>' allow='<%= usbdev[:allow] %>'/>
268
+ <%- end -%>
269
+ </redirfilter>
270
+ <%- end -%>
271
+ <%- end -%>
272
+ <%- unless @watchdog_dev.empty? -%>
260
273
  <%# Watchdog Device -%>
261
274
  <watchdog model='<%= @watchdog_dev[:model] %>' action='<%= @watchdog_dev[:action] %>'/>
262
- <% end %>
263
-
264
- <% unless @smartcard_dev.empty? -%>
265
- <% if @smartcard_dev[:mode] == 'passthrough' %>
266
- <% if @smartcard_dev[:type] == 'tcp' %>
267
- <smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'>
268
- <source mode='<%= @smartcard_dev[:source_mode] %>' host='<%= @smartcard_dev[:source_host] %>' service='<%= @smartcard_dev[:source_service] %>'/>
269
- </smartcard>
270
- <% else %>
271
- <smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'/>
272
- <% end %>
273
- <% end %>
274
- <% end -%>
275
-
276
- <% if @tpm_path || @tpm_version -%>
275
+ <%- end -%>
276
+ <%- unless @smartcard_dev.empty? -%>
277
+ <%- if @smartcard_dev[:mode] == 'passthrough' -%>
278
+ <%- if @smartcard_dev[:type] == 'tcp' -%>
279
+ <smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'>
280
+ <source mode='<%= @smartcard_dev[:source_mode] %>' host='<%= @smartcard_dev[:source_host] %>' service='<%= @smartcard_dev[:source_service] %>'/>
281
+ </smartcard>
282
+ <%- else -%>
283
+ <smartcard mode='<%= @smartcard_dev[:mode] %>' type='<%= @smartcard_dev[:type] %>'/>
284
+ <%- end -%>
285
+ <%- end -%>
286
+ <%- end -%>
287
+ <%- if @tpm_path || @tpm_version -%>
277
288
  <%# TPM Device -%>
278
289
  <tpm model='<%= @tpm_model %>'>
279
290
  <backend type='<%= @tpm_type %>'<% if @tpm_version %> version='<%= @tpm_version %>'<% end %>>
280
- <% if @tpm_path -%>
291
+ <%- if @tpm_path -%>
281
292
  <device path='<%= @tpm_path %>'/>
282
- <% end -%>
293
+ <%- end -%>
283
294
  </backend>
284
295
  </tpm>
285
- <% end -%>
286
- <% if not @usbctl_dev.empty? %>
296
+ <%- end -%>
297
+ <%- if not @usbctl_dev.empty? -%>
287
298
  <%# USB Controller -%>
288
299
  <controller type='usb' model='<%= @usbctl_dev[:model] %>' <%= "ports=\"#{@usbctl_dev[:ports]}\" " if @usbctl_dev[:ports] %>/>
289
- <% end %>
290
- <% unless @memballoon_enabled.nil? %>
291
- <% if @memballoon_enabled %>
300
+ <%- end -%>
301
+ <%- unless @memballoon_enabled.nil? -%>
302
+ <%- if @memballoon_enabled -%>
292
303
  <memballoon model='<%= @memballoon_model %>'>
293
304
  <address type='pci' domain='0x0000' bus='<%= @memballoon_pci_bus %>' slot='<%= @memballoon_pci_slot %>' function='0x0'/>
294
305
  </memballoon>
295
- <% else %>
306
+ <%- else -%>
296
307
  <memballoon model='none'/>
297
- <% end %>
298
- <% end %>
308
+ <%- end -%>
309
+ <%- end -%>
299
310
  </devices>
300
-
301
- <% if not @qemu_args.empty? or not @qemu_env.empty? %>
311
+ <%- if not @qemu_args.empty? or not @qemu_env.empty? -%>
302
312
  <qemu:commandline>
303
- <% @qemu_args.each do |arg| %>
313
+ <%- @qemu_args.each do |arg| -%>
304
314
  <qemu:arg value='<%= arg[:value] %>'/>
305
- <% end %>
306
- <% @qemu_env.each do |env_var, env_value| %>
315
+ <%- end -%>
316
+ <%- @qemu_env.each do |env_var, env_value| -%>
307
317
  <qemu:env name='<%= env_var.to_s %>' value='<%= env_value %>'/>
308
- <% end %>
318
+ <%- end -%>
309
319
  </qemu:commandline>
310
- <% end %>
320
+ <%- end -%>
311
321
  </domain>
@@ -18,8 +18,11 @@
18
18
  <% end %>
19
19
  <% end %>
20
20
 
21
- <% if @network_forward_mode != 'veryisolated' %>
21
+ <% if @network_forward_mode != 'veryisolated' && !@network_address.nil? %>
22
22
  <ip address="<%= @network_address %>" netmask="<%= @network_netmask %>">
23
+ <% if @tftp_root %>
24
+ <tftp root="<%= @tftp_root %>" />
25
+ <% end %>
23
26
  <% if @network_dhcp_enabled %>
24
27
  <dhcp>
25
28
  <range start="<%= @network_range_start %>" end="<%= @network_range_stop %>" />
@@ -32,6 +32,7 @@ module VagrantPlugins
32
32
  management_network_pci_slot = env[:machine].provider_config.management_network_pci_slot
33
33
  management_network_domain = env[:machine].provider_config.management_network_domain
34
34
  management_network_mtu = env[:machine].provider_config.management_network_mtu
35
+ management_network_keep = env[:machine].provider_config.management_network_keep
35
36
  logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode"
36
37
 
37
38
  begin
@@ -92,8 +93,18 @@ module VagrantPlugins
92
93
  management_network_options[:slot] = management_network_pci_slot
93
94
  end
94
95
 
95
- if (env[:machine].config.vm.box &&
96
- !env[:machine].provider_config.mgmt_attach)
96
+ if management_network_keep
97
+ management_network_options[:always_destroy] = false
98
+ end
99
+
100
+ # if there is a box and management network is disabled
101
+ # need qemu agent enabled and at least one network that can be accessed
102
+ if (
103
+ env[:machine].config.vm.box &&
104
+ !env[:machine].provider_config.mgmt_attach &&
105
+ !env[:machine].provider_config.qemu_use_agent &&
106
+ !env[:machine].config.vm.networks.any? { |type, _| ["private_network", "public_network"].include?(type.to_s) }
107
+ )
97
108
  raise Errors::ManagementNetworkRequired
98
109
  end
99
110
 
@@ -119,7 +130,8 @@ module VagrantPlugins
119
130
  IPAddr.new(options[:network_address]).get_mask :
120
131
  '255.255.255.0',
121
132
  dhcp_enabled: true,
122
- forward_mode: 'nat'
133
+ forward_mode: 'nat',
134
+ always_destroy: true
123
135
  }.merge(options)
124
136
 
125
137
  if options[:type].to_s == 'dhcp' && options[:ip].nil?
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'vagrant/action/builtin/mixin_synced_folders'
4
+
3
5
  module VagrantPlugins
4
6
  module ProviderLibvirt
5
7
  module Util