vagrant-libvirt 0.8.2 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -2079
  3. data/lib/vagrant-libvirt/action/create_domain.rb +57 -94
  4. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -1
  5. data/lib/vagrant-libvirt/action/create_networks.rb +3 -3
  6. data/lib/vagrant-libvirt/action/destroy_domain.rb +21 -5
  7. data/lib/vagrant-libvirt/action/destroy_networks.rb +2 -2
  8. data/lib/vagrant-libvirt/action/handle_box_image.rb +3 -1
  9. data/lib/vagrant-libvirt/action/package_domain.rb +1 -5
  10. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +3 -1
  11. data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +181 -0
  12. data/lib/vagrant-libvirt/action/snapshot_delete.rb +26 -0
  13. data/lib/vagrant-libvirt/action/snapshot_restore.rb +22 -0
  14. data/lib/vagrant-libvirt/action/snapshot_save.rb +27 -0
  15. data/lib/vagrant-libvirt/action/start_domain.rb +80 -11
  16. data/lib/vagrant-libvirt/action.rb +53 -1
  17. data/lib/vagrant-libvirt/cap/snapshots.rb +12 -0
  18. data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +4 -4
  19. data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +4 -4
  20. data/lib/vagrant-libvirt/config.rb +104 -6
  21. data/lib/vagrant-libvirt/driver.rb +108 -46
  22. data/lib/vagrant-libvirt/errors.rb +23 -3
  23. data/lib/vagrant-libvirt/plugin.rb +7 -3
  24. data/lib/vagrant-libvirt/provider.rb +1 -1
  25. data/lib/vagrant-libvirt/templates/domain.xml.erb +32 -6
  26. data/lib/vagrant-libvirt/util/byte_number.rb +0 -1
  27. data/lib/vagrant-libvirt/util/compat.rb +23 -0
  28. data/lib/vagrant-libvirt/util/domain_flags.rb +15 -0
  29. data/lib/vagrant-libvirt/util/unindent.rb +7 -0
  30. data/lib/vagrant-libvirt/util.rb +1 -0
  31. data/lib/vagrant-libvirt/version +1 -1
  32. data/locales/en.yml +28 -4
  33. data/spec/acceptance/additional_storage_spec.rb +32 -0
  34. data/spec/acceptance/package_domain_spec.rb +90 -0
  35. data/spec/acceptance/provider_settings_spec.rb +54 -0
  36. data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +31 -0
  37. data/spec/acceptance/snapshots_spec.rb +41 -0
  38. data/spec/acceptance/support-skeletons/package_complex/Vagrantfile.testbox +14 -0
  39. data/spec/acceptance/support-skeletons/package_complex/scripts/sysprep.sh +32 -0
  40. data/spec/acceptance/support-skeletons/package_simple/Vagrantfile.testbox +10 -0
  41. data/spec/acceptance/two_disks_spec.rb +29 -0
  42. data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +35 -0
  43. data/spec/spec_helper.rb +3 -0
  44. data/spec/support/acceptance/configuration.rb +21 -0
  45. data/spec/support/acceptance/context.rb +70 -0
  46. data/spec/support/acceptance/isolated_environment.rb +41 -0
  47. data/spec/support/libvirt_acceptance_context.rb +64 -0
  48. data/spec/support/libvirt_context.rb +4 -0
  49. data/spec/support/sharedcontext.rb +1 -0
  50. data/spec/unit/action/cleanup_on_failure_spec.rb +0 -2
  51. data/spec/unit/action/create_domain_spec/sysinfo.xml +66 -0
  52. data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +49 -0
  53. data/spec/unit/action/create_domain_spec.rb +188 -140
  54. data/spec/unit/action/create_domain_volume_spec.rb +0 -3
  55. data/spec/unit/action/destroy_domain_spec.rb +43 -10
  56. data/spec/unit/action/forward_ports_spec.rb +0 -1
  57. data/spec/unit/action/handle_box_image_spec.rb +31 -14
  58. data/spec/unit/action/package_domain_spec.rb +0 -5
  59. data/spec/unit/action/remove_libvirt_image_spec.rb +43 -0
  60. data/spec/unit/action/resolve_disk_settings_spec/default_domain.xml +43 -0
  61. data/spec/unit/action/resolve_disk_settings_spec/default_no_aliases.xml +42 -0
  62. data/spec/unit/action/{create_domain_spec → resolve_disk_settings_spec}/default_system_storage_pool.xml +0 -0
  63. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box.xml +55 -0
  64. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_and_custom_no_aliases.xml +67 -0
  65. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_storage.xml +67 -0
  66. data/spec/unit/action/resolve_disk_settings_spec.rb +385 -0
  67. data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +38 -0
  68. data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +39 -0
  69. data/spec/unit/action/start_domain_spec/existing_added_nvram.xml +62 -0
  70. data/spec/unit/action/start_domain_spec/nvram_domain.xml +64 -0
  71. data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +64 -0
  72. data/spec/unit/action/start_domain_spec/nvram_domain_removed.xml +64 -0
  73. data/spec/unit/action/start_domain_spec.rb +122 -22
  74. data/spec/unit/action/wait_till_up_spec.rb +0 -2
  75. data/spec/unit/action_spec.rb +88 -3
  76. data/spec/unit/cap/synced_folder_9p_spec.rb +120 -0
  77. data/spec/unit/cap/synced_folder_virtiofs_spec.rb +120 -0
  78. data/spec/unit/config_spec.rb +153 -6
  79. data/spec/unit/driver_spec.rb +3 -1
  80. data/spec/unit/plugin_spec.rb +42 -0
  81. data/spec/unit/templates/domain_all_settings.xml +15 -6
  82. data/spec/unit/templates/domain_scsi_bus_storage.xml +44 -0
  83. data/spec/unit/templates/domain_scsi_device_storage.xml +44 -0
  84. data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +130 -0
  85. data/spec/unit/templates/domain_spec.rb +105 -21
  86. data/spec/unit/util/byte_number_spec.rb +1 -1
  87. metadata +169 -79
  88. data/spec/unit/provider_spec.rb +0 -11
@@ -32,16 +32,17 @@ module VagrantPlugins
32
32
  config = @machine.provider_config
33
33
  uri = config.uri
34
34
 
35
- conn_attr = {}
36
- conn_attr[:provider] = 'libvirt'
37
- conn_attr[:libvirt_uri] = uri
38
- conn_attr[:libvirt_username] = config.username if config.username
39
- conn_attr[:libvirt_password] = config.password if config.password
40
-
41
35
  # Setup command for retrieving IP address for newly created machine
42
36
  # with some MAC address. Get it from dnsmasq leases table
43
37
  ip_command = %q( awk "/$mac/ {print \$1}" /proc/net/arp )
44
- conn_attr[:libvirt_ip_command] = ip_command
38
+
39
+ conn_attr = {
40
+ provider: 'libvirt',
41
+ libvirt_uri: uri,
42
+ libvirt_ip_command: ip_command,
43
+ }
44
+ conn_attr[:libvirt_username] = config.username if config.username
45
+ conn_attr[:libvirt_password] = config.password if config.password
45
46
 
46
47
  @logger.info("Connecting to Libvirt (#{uri}) ...")
47
48
  begin
@@ -61,7 +62,7 @@ module VagrantPlugins
61
62
 
62
63
  config = @machine.provider_config
63
64
 
64
- @system_connection = Libvirt::open_read_only(config.system_uri)
65
+ @system_connection = Libvirt.open_read_only(config.system_uri)
65
66
  @system_connection
66
67
  end
67
68
 
@@ -69,12 +70,10 @@ module VagrantPlugins
69
70
  begin
70
71
  domain = connection.servers.get(machine.id)
71
72
  rescue Libvirt::RetrieveError => e
72
- if e.libvirt_code == ProviderLibvirt::Util::ErrorCodes::VIR_ERR_NO_DOMAIN
73
- @logger.debug("machine #{machine.name} domain not found #{e}.")
74
- return nil
75
- else
76
- raise e
77
- end
73
+ raise e unless e.libvirt_code == ProviderLibvirt::Util::ErrorCodes::VIR_ERR_NO_DOMAIN
74
+
75
+ @logger.debug("machine #{machine.name} domain not found #{e}.")
76
+ return nil
78
77
  end
79
78
 
80
79
  domain
@@ -99,32 +98,82 @@ module VagrantPlugins
99
98
 
100
99
  def get_domain_ipaddress(machine, domain)
101
100
  # attempt to get ip address from qemu agent
102
- if @machine.provider_config.qemu_use_agent == true
101
+ if machine.provider_config.qemu_use_agent == true
103
102
  @logger.info('Get IP via qemu agent')
104
- return get_ipaddress_from_qemu_agent(domain, machine.id)
103
+ return get_ipaddress_from_qemu_agent(domain, machine.id, machine.config.vm.boot_timeout)
105
104
  end
106
105
 
107
- if @machine.provider_config.qemu_use_session
108
- return get_ipaddress_from_system domain.mac
109
- end
106
+ return get_ipaddress_from_system domain.mac if machine.provider_config.qemu_use_session
110
107
 
111
108
  # Get IP address from dhcp leases table
112
109
  begin
113
110
  ip_address = get_ipaddress_from_domain(domain)
114
111
  rescue Fog::Errors::TimeoutError
115
- @logger.info('Timeout at waiting for an ip address for machine %s' % machine.name)
112
+ @logger.info("Timeout at waiting for an ip address for machine #{machine.name}")
116
113
 
117
114
  raise
118
115
  end
119
116
 
120
117
  unless ip_address
121
- @logger.info('No arp table entry found for machine %s' % machine.name)
118
+ @logger.info("No arp table entry found for machine #{machine.name}")
122
119
  return nil
123
120
  end
124
121
 
125
122
  ip_address
126
123
  end
127
124
 
125
+ def restore_snapshot(machine, snapshot_name)
126
+ domain = get_libvirt_domain(machine)
127
+ snapshot = get_snapshot_if_exists(machine, snapshot_name)
128
+ begin
129
+ # 4 is VIR_DOMAIN_SNAPSHOT_REVERT_FORCE
130
+ # needed due to https://bugzilla.redhat.com/show_bug.cgi?id=1006886
131
+ domain.revert_to_snapshot(snapshot, 4)
132
+ rescue Fog::Errors::Error => e
133
+ raise Errors::SnapshotReversionError, error_message: e.message
134
+ end
135
+ end
136
+
137
+ def list_snapshots(machine)
138
+ get_libvirt_domain(machine).list_snapshots
139
+ rescue Fog::Errors::Error => e
140
+ raise Errors::SnapshotListError, error_message: e.message
141
+ end
142
+
143
+ def delete_snapshot(machine, snapshot_name)
144
+ get_snapshot_if_exists(machine, snapshot_name).delete
145
+ rescue Errors::SnapshotMissing => e
146
+ raise Errors::SnapshotDeletionError, error_message: e.message
147
+ end
148
+
149
+ def create_new_snapshot(machine, snapshot_name)
150
+ snapshot_desc = <<-EOF
151
+ <domainsnapshot>
152
+ <name>#{snapshot_name}</name>
153
+ <description>Snapshot for vagrant sandbox</description>
154
+ </domainsnapshot>
155
+ EOF
156
+ get_libvirt_domain(machine).snapshot_create_xml(snapshot_desc)
157
+ rescue Fog::Errors::Error => e
158
+ raise Errors::SnapshotCreationError, error_message: e.message
159
+ end
160
+
161
+ def create_snapshot(machine, snapshot_name)
162
+ begin
163
+ delete_snapshot(machine, snapshot_name)
164
+ rescue Errors::SnapshotDeletionError
165
+ end
166
+ create_new_snapshot(machine, snapshot_name)
167
+ end
168
+
169
+ # if we can get snapshot description without exception it exists
170
+ def get_snapshot_if_exists(machine, snapshot_name)
171
+ snapshot = get_libvirt_domain(machine).lookup_snapshot_by_name(snapshot_name)
172
+ return snapshot if snapshot.xml_desc
173
+ rescue Libvirt::RetrieveError => e
174
+ raise Errors::SnapshotMissing, error_message: e.message
175
+ end
176
+
128
177
  def state(machine)
129
178
  # may be other error states with initial retreival we can't handle
130
179
  begin
@@ -149,7 +198,7 @@ module VagrantPlugins
149
198
  end
150
199
  end
151
200
 
152
- return state
201
+ state
153
202
  end
154
203
 
155
204
  private
@@ -160,43 +209,44 @@ module VagrantPlugins
160
209
  system_connection.list_all_networks.each do |net|
161
210
  leases = net.dhcp_leases(mac, 0)
162
211
  # Assume the lease expiring last is the current IP address
163
- ip_address = leases.sort_by { |lse| lse["expirytime"] }.last["ipaddr"] if !leases.empty?
212
+ ip_address = leases.max_by { |lse| lse['expirytime'] }['ipaddr'] unless leases.empty?
164
213
  break if ip_address
165
214
  end
166
215
 
167
216
  ip_address
168
217
  end
169
218
 
170
- def get_ipaddress_from_qemu_agent(domain, machine_id)
219
+ def get_ipaddress_from_qemu_agent(domain, machine_id, timeout)
171
220
  ip_address = nil
172
221
  addresses = nil
173
222
  libvirt_domain = connection.client.lookup_domain_by_uuid(machine_id)
174
223
  begin
175
- response = libvirt_domain.qemu_agent_command('{"execute":"guest-network-get-interfaces"}', timeout=10)
176
- @logger.debug("Got Response from qemu agent")
224
+ response = libvirt_domain.qemu_agent_command('{"execute":"guest-network-get-interfaces"}', timeout)
225
+ @logger.debug('Got Response from qemu agent')
177
226
  @logger.debug(response)
178
227
  addresses = JSON.parse(response)
179
- rescue => e
180
- @logger.debug("Unable to receive IP via qemu agent: [%s]" % e.message)
228
+ rescue StandardError => e
229
+ puts "Unable to receive IP via qemu agent: [#{e.message}]"
230
+ @logger.debug("Unable to receive IP via qemu agent: [#{e.message}]")
181
231
  end
182
232
 
183
233
  unless addresses.nil?
184
- addresses["return"].each{ |interface|
185
- if domain.mac.downcase == interface["hardware-address"].downcase
186
- @logger.debug("Found mathing interface: [%s]" % interface["name"])
187
- if interface.has_key?("ip-addresses")
188
- interface["ip-addresses"].each{ |ip|
189
- # returning ipv6 addresses might break windows guests because
190
- # winrm cant handle connection, winrm fails with "invalid uri"
191
- if ip["ip-address-type"] == "ipv4"
192
- ip_address = ip["ip-address"]
193
- @logger.debug("Return IP: [%s]" % ip_address)
194
- break
195
- end
196
- }
197
- end
234
+ addresses['return'].each do |interface|
235
+ next unless domain.mac.downcase == interface['hardware-address'].downcase
236
+
237
+ @logger.debug("Found matching interface: [#{interface['name']}]")
238
+ next unless interface.key?('ip-addresses')
239
+
240
+ interface['ip-addresses'].each do |ip|
241
+ # returning ipv6 addresses might break windows guests because
242
+ # winrm can't handle connection, winrm fails with "invalid uri"
243
+ next unless ip['ip-address-type'] == 'ipv4'
244
+
245
+ ip_address = ip['ip-address']
246
+ @logger.debug("Return IP: [#{ip_address}]")
247
+ break
198
248
  end
199
- }
249
+ end
200
250
  end
201
251
  ip_address
202
252
  end
@@ -204,18 +254,30 @@ module VagrantPlugins
204
254
  def get_ipaddress_from_domain(domain)
205
255
  ip_address = nil
206
256
  domain.wait_for(2) do
207
- addresses.each_pair do |type, ip|
257
+ addresses.each_pair do |_type, ip|
208
258
  # Multiple leases are separated with a newline, return only
209
259
  # the most recent address
210
- ip_address = ip[0].split("\n").first if ip[0] != nil
260
+ ip_address = ip[0].split("\n").first unless ip[0].nil?
211
261
  end
212
262
 
213
- ip_address != nil
263
+ !ip_address.nil?
214
264
  end
215
265
 
216
266
  ip_address
217
267
  end
218
268
 
269
+ def get_libvirt_domain(machine)
270
+ begin
271
+ libvirt_domain = connection.client.lookup_domain_by_uuid(machine.id)
272
+ rescue Libvirt::RetrieveError => e
273
+ raise e unless e.libvirt_code == ProviderLibvirt::Util::ErrorCodes::VIR_ERR_NO_DOMAIN
274
+
275
+ @logger.debug("machine #{machine.name} not found #{e}.")
276
+ return nil
277
+ end
278
+
279
+ libvirt_domain
280
+ end
219
281
  end
220
282
  end
221
283
  end
@@ -109,7 +109,7 @@ module VagrantPlugins
109
109
  end
110
110
 
111
111
  class FogCreateServerError < VagrantLibvirtError
112
- error_key(:fog_create_server_error)
112
+ error_key(:create_server_error)
113
113
  end
114
114
 
115
115
  # Network exceptions
@@ -154,6 +154,10 @@ module VagrantPlugins
154
154
  end
155
155
 
156
156
  # Other exceptions
157
+ class UpdateServerError < VagrantLibvirtError
158
+ error_key(:create_server_error)
159
+ end
160
+
157
161
  class InterfaceSlotNotAvailable < VagrantLibvirtError
158
162
  error_key(:interface_slot_not_available)
159
163
  end
@@ -186,8 +190,24 @@ module VagrantPlugins
186
190
  error_key(:no_ip_address_error)
187
191
  end
188
192
 
189
- class DeleteSnapshotError < VagrantLibvirtError
190
- error_key(:delete_snapshot_error)
193
+ class SnapshotMissing < VagrantLibvirtError
194
+ error_key(:snapshot_missing)
195
+ end
196
+
197
+ class SnapshotDeletionError < VagrantLibvirtError
198
+ error_key(:snapshot_deletion_error)
199
+ end
200
+
201
+ class SnapshotListError < VagrantLibvirtError
202
+ error_key(:snapshot_list_error)
203
+ end
204
+
205
+ class SnapshotCreationError < VagrantLibvirtError
206
+ error_key(:snapshot_creation_error)
207
+ end
208
+
209
+ class SnapshotReversionError < VagrantLibvirtError
210
+ error_key(:snapshot_reversion_error)
191
211
  end
192
212
 
193
213
  class SerialCannotCreatePathError < VagrantLibvirtError
@@ -6,8 +6,7 @@ rescue LoadError
6
6
  raise 'The Vagrant Libvirt plugin must be run within Vagrant.'
7
7
  end
8
8
 
9
- # compatibility fix to define constant not available Vagrant <1.6
10
- ::Vagrant::MachineState::NOT_CREATED_ID ||= :not_created
9
+ require 'vagrant-libvirt/util/compat'
11
10
 
12
11
  module VagrantPlugins
13
12
  module ProviderLibvirt
@@ -27,7 +26,7 @@ module VagrantPlugins
27
26
  Provider
28
27
  end
29
28
 
30
- action_hook(:remove_libvirt_image) do |hook|
29
+ action_hook(*(Util::Compat.action_hook_args(:remove_libvirt_image, :box_remove))) do |hook|
31
30
  require_relative 'action'
32
31
  hook.after Vagrant::Action::Builtin::BoxRemove, Action.remove_libvirt_image
33
32
  end
@@ -51,6 +50,11 @@ module VagrantPlugins
51
50
  Cap::PublicAddress
52
51
  end
53
52
 
53
+ provider_capability(:libvirt, :snapshot_list) do
54
+ require_relative 'cap/snapshots'
55
+ Cap::Snapshots
56
+ end
57
+
54
58
  # lower priority than nfs or rsync
55
59
  # https://github.com/vagrant-libvirt/vagrant-libvirt/pull/170
56
60
  synced_folder('9p', 4) do
@@ -52,7 +52,7 @@ module VagrantPlugins
52
52
  # :username => "mitchellh",
53
53
  # :private_key_path => "/path/to/my/key"
54
54
  # }
55
- # note that modifing @machine.id or accessing @machine.state is not
55
+ # note that modifying @machine.id or accessing @machine.state is not
56
56
  # thread safe, so be careful to avoid these here as this method may
57
57
  # be called from other threads of execution.
58
58
  return nil if state.id != :running
@@ -81,8 +81,28 @@
81
81
  <cmdline><%= @cmd_line %></cmdline>
82
82
  <%- if @dtb -%>
83
83
  <dtb><%= @dtb %></dtb>
84
+ <% end -%>
85
+ <%- unless @sysinfo.empty? -%>
86
+ <smbios mode='sysinfo'/>
84
87
  <% end -%>
85
88
  </os>
89
+ <%- unless @sysinfo.empty? -%>
90
+ <sysinfo type='smbios'>
91
+ <%- @sysinfo.each_pair do |block, values| -%>
92
+ <<%= @sysinfo_blocks[block.to_s][:xml] %>>
93
+ <%- if values.respond_to?(:each_pair) -%>
94
+ <%- values.each do |name, value| -%>
95
+ <entry name='<%= name %>'><%= value %></entry>
96
+ <% end -%>
97
+ <%- else -%>
98
+ <%- values.each do |value| -%>
99
+ <entry><%= value %></entry>
100
+ <% end -%>
101
+ <% end -%>
102
+ </<%= @sysinfo_blocks[block.to_s][:xml] %>>
103
+ <% end -%>
104
+ </sysinfo>
105
+ <% end -%>
86
106
  <features>
87
107
  <%- @features.each do |feature| -%>
88
108
  <<%= feature %>/>
@@ -117,11 +137,17 @@
117
137
  @disk_driver_opts.reject { |k,v| v.nil? }
118
138
  .map { |k,v| "#{k}='#{v}'"}
119
139
  .join(' ') -%>/>
120
- <source file='<%= volume[:path] %>'/>
140
+ <source file='<%= volume[:absolute_path] %>'/>
121
141
  <%# we need to ensure a unique target dev -%>
122
- <target dev='<%= volume[:dev] %>' bus='<%= volume[:bus] %>'/>
142
+ <target dev='<%= volume[:device] %>' bus='<%= volume[:bus] %>'/>
123
143
  </disk>
124
144
  <%- end -%>
145
+ <%- scsi_volumes = @domain_volumes.select { |x| x[:bus] == 'scsi' } %>
146
+ <%- if !scsi_volumes.empty? and !@disk_controller_model.nil? %>
147
+ <%- for idx in 0..(scsi_volumes.length / 7) do %>
148
+ <controller type='scsi' model='<%= @disk_controller_model %>' index='<%= idx -%>'/>
149
+ <%- end -%>
150
+ <%- end -%>
125
151
  <%# additional disks -%>
126
152
  <%- @disks.each_with_index do |d, index| -%>
127
153
  <disk type='file' device='disk'>
@@ -220,7 +246,7 @@
220
246
  </graphics><% end -%>
221
247
  <video>
222
248
  <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'<% if not @video_accel3d %>/><% else %>>
223
- <acceleration accel3d='yes'/>
249
+ <acceleration accel3d='yes'/>
224
250
  </model><% end -%>
225
251
  </video>
226
252
  <%#End Video -%>
@@ -250,13 +276,13 @@
250
276
  <hostdev mode='subsystem' type='usb'>
251
277
  <source startupPolicy='<%= usb[:startupPolicy] || "mandatory" %>'>
252
278
  <%- if usb[:vendor] -%>
253
- <vendor id='<%= usb[:vendor] %>'/>
279
+ <vendor id='<%= usb[:vendor] %>'/>
254
280
  <%- end -%>
255
281
  <%- if usb[:product] -%>
256
- <product id='<%= usb[:product] %>'/>
282
+ <product id='<%= usb[:product] %>'/>
257
283
  <%- end -%>
258
284
  <%- if usb[:bus] && usb[:device] -%>
259
- <address bus='<%= usb[:bus] %>' device='<%= usb[:device] %>'/>
285
+ <address bus='<%= usb[:bus] %>' device='<%= usb[:device] %>'/>
260
286
  <%- end -%>
261
287
  </source>
262
288
  </hostdev>
@@ -68,4 +68,3 @@ class ByteNumber < Numeric
68
68
  (to_f/(1024 ** n)).ceil
69
69
  end
70
70
  end
71
-
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vagrant'
4
+
5
+ # compatibility fix to define constant not available Vagrant <1.6
6
+ ::Vagrant::MachineState::NOT_CREATED_ID ||= :not_created
7
+
8
+ module VagrantPlugins
9
+ module ProviderLibvirt
10
+ module Util
11
+ module Compat
12
+ def self.action_hook_args(name, action)
13
+ # handle different number of arguments for action_hook depending on vagrant version
14
+ if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('2.2.11')
15
+ return name, action
16
+ end
17
+
18
+ return name
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # Ripped from https://libvirt.org/html/libvirt-libvirt-domain.html#types
2
+ module VagrantPlugins
3
+ module ProviderLibvirt
4
+ module Util
5
+ module DomainFlags
6
+ # virDomainUndefineFlagsValues
7
+ VIR_DOMAIN_UNDEFINE_MANAGED_SAVE = 1 # Also remove any managed save
8
+ VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA = 2 # If last use of domain, then also remove any snapshot metadata
9
+ VIR_DOMAIN_UNDEFINE_NVRAM = 4 # Also remove any nvram file
10
+ VIR_DOMAIN_UNDEFINE_KEEP_NVRAM = 8 # Keep nvram file
11
+ VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA = 16 # If last use of domain, then also remove any checkpoint metadata Future undefine control flags should come here.
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def unindent
5
+ gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
6
+ end
7
+ end
@@ -9,6 +9,7 @@ module VagrantPlugins
9
9
  autoload :NetworkUtil, 'vagrant-libvirt/util/network_util'
10
10
  autoload :StorageUtil, 'vagrant-libvirt/util/storage_util'
11
11
  autoload :ErrorCodes, 'vagrant-libvirt/util/error_codes'
12
+ autoload :DomainFlags, 'vagrant-libvirt/util/domain_flags'
12
13
  autoload :Ui, 'vagrant-libvirt/util/ui'
13
14
  end
14
15
  end
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.10.1
data/locales/en.yml CHANGED
@@ -16,7 +16,7 @@ en:
16
16
  Created volume larger than box defaults, will require manual resizing of
17
17
  filesystems to utilize.
18
18
  box_version_missing: |-
19
- No verison detected for %{name}, using timestamp to watch for modifications. Consider
19
+ No version detected for %{name}, using timestamp to watch for modifications. Consider
20
20
  generating a local metadata for the box with a version to allow better handling.
21
21
  See https://www.vagrantup.com/docs/boxes/format#box-metadata for further details.
22
22
  uploading_volume: |-
@@ -25,6 +25,8 @@ en:
25
25
  Creating image (snapshot of base box volume).
26
26
  removing_domain_volume: |-
27
27
  Removing image (snapshot of base box volume).
28
+ updating_domain: |-
29
+ Updating domain definition due to configuration change
28
30
  starting_domain: |-
29
31
  Starting domain.
30
32
  terminating: |-
@@ -58,9 +60,11 @@ en:
58
60
  remove_stale_volume: |-
59
61
  Remove stale volume...
60
62
 
61
- destroy:
63
+ domain_xml:
62
64
  obsolete_method: |
63
- Destroying machine that was originally created without device aliases (pre 0.6.0), using fallback approach.
65
+ Machine that was originally created without device aliases (pre 0.6.0), using fall-back approach for device identification.
66
+
67
+ destroy:
64
68
  unexpected_volumes: |
65
69
  Unexpected number of volumes detected, possibly additional volumes attached outside of vagrant-libvirt.
66
70
  Attempting to handle this correctly, however may experience unexpected behaviour in the domain destroy.
@@ -136,7 +140,7 @@ en:
136
140
  Error while creating a storage pool volume: %{error_message}
137
141
  fog_create_domain_volume_error: |-
138
142
  Error while creating volume for domain: %{error_message}
139
- fog_create_server_error: |-
143
+ create_server_error: |-
140
144
  Error while creating domain: %{error_message}
141
145
  domain_name_exists: |-
142
146
  Name `%{domain_name}` of domain about to create is already taken. Please try to run
@@ -181,6 +185,16 @@ en:
181
185
  management_network_required: |-
182
186
  Management network can't be disabled when VM use box.
183
187
  Please fix your configuration and run vagrant again.
188
+ snapshot_deletion_error: |-
189
+ Error while deleting snapshot: %{error_message}.
190
+ snapshot_missing: |-
191
+ Snapshot not found: %{error_message}.
192
+ snapshot_list_error: |-
193
+ Cannot list snapshots: %{error_message}.
194
+ snapshot_creation_error: |-
195
+ Cannot create snapshot(s): %{error_message}.
196
+ snapshot_reversion_error: |-
197
+ Cannot revert snapshot(s): %{error_message}.
184
198
  serial_cannot_create_path_error: |-
185
199
  Error creating path for serial port output log: %{path}
186
200
 
@@ -200,3 +214,13 @@ en:
200
214
  preparing: |-
201
215
  The vagrant machine is being prepared for creation, please wait for
202
216
  it to reach a steady state before issuing commands on it.
217
+
218
+ cap:
219
+ virtiofs:
220
+ preparing: Configuring virtiofs devices for shared folders...
221
+ mounting: Mounting virtiofs shared folders...
222
+ cleanup: Removing virtiofs devices for shared folders...
223
+ 9p:
224
+ preparing: Configuring 9p devices for shared folders...
225
+ mounting: Mounting 9p shared folders...
226
+ cleanup: Removing 9p devices for shared folders...
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'additional storage configured', acceptance: true do
6
+ include_context 'libvirt_acceptance'
7
+
8
+ before do
9
+ environment.skeleton('additional_storage')
10
+ end
11
+
12
+ after do
13
+ assert_execute('vagrant', 'destroy', '--force')
14
+ end
15
+
16
+ it 'should succeed' do
17
+ status('Test: machine is created successfully')
18
+ result = environment.execute('vagrant', 'up')
19
+ expect(result).to exit_with(0)
20
+
21
+ status('Test: additional storage configured')
22
+ expect(result.stdout).to match(/\(vda\).*work_default.img/)
23
+ expect(result.stdout).to match(/\(vdb\).*work_default-vdb\.qcow2/)
24
+
25
+ status('Test: reload handles additional storage correctly')
26
+ result = environment.execute('vagrant', 'reload')
27
+ expect(result).to exit_with(0)
28
+
29
+ status('Test: additional storage reported correctly')
30
+ expect(result.stdout).to match(/\(vdb\).*work_default-vdb\.qcow2/)
31
+ end
32
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'package domain', acceptance: true do
6
+ include_context 'libvirt_acceptance'
7
+
8
+ before(:all) do
9
+ expect(Vagrant::Util::Which.which('virt-sysprep')).to be_truthy,
10
+ 'packaging tests require virt-sysprep, please install'
11
+ expect(Vagrant::Util::Which.which('virt-sparsify')).to be_truthy,
12
+ 'packaging tests require virt-sparsify, please install'
13
+
14
+ result = (File.exist?('C:\\') ? `dir /-C #{Dir.tmpdir}` : `df #{Dir.tmpdir}`).split("\n").last
15
+ expect(result.split[3].to_i).to be > 6 * 1024 * 1024,
16
+ "packaging tests require more than 6GiB of space under #{Dir.tmpdir}"
17
+ end
18
+
19
+ after(:each) do
20
+ assert_execute('vagrant', 'destroy', '--force')
21
+ end
22
+
23
+ let(:testbox_envvars) { { VAGRANT_VAGRANTFILE: 'Vagrantfile.testbox' } }
24
+
25
+ context 'simple' do
26
+ before do
27
+ environment.skeleton('package_simple')
28
+ end
29
+
30
+ after do
31
+ result = environment.execute('vagrant', 'destroy', '--force', extra_env: testbox_envvars)
32
+ expect(result).to exit_with(0)
33
+
34
+ assert_execute('vagrant', 'box', 'remove', '--force', 'test-package-simple-domain')
35
+ end
36
+
37
+ it 'should succeed' do
38
+ status('Test: machine is created successfully')
39
+ expect(environment.execute('vagrant', 'up')).to exit_with(0)
40
+
41
+ status('Test: package machine successfully')
42
+ expect(environment.execute('vagrant', 'package')).to exit_with(0)
43
+
44
+ status('Test: add packaged box')
45
+ expect(environment.execute(
46
+ 'vagrant', 'box', 'add', '--force', '--name', 'test-package-simple-domain', 'package.box'
47
+ )).to exit_with(0)
48
+
49
+ status('Test: machine from packaged box is created successfully')
50
+ result = environment.execute('vagrant', 'up', extra_env: testbox_envvars)
51
+ expect(result).to exit_with(0)
52
+ expect(result.stdout).to match(/test-package-complex-domain/)
53
+ end
54
+ end
55
+
56
+ context 'complex' do
57
+ before do
58
+ environment.skeleton('package_complex')
59
+ extra_env.merge!(
60
+ {
61
+ VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS: 'defaults,-ssh-userdir,customize',
62
+ VAGRANT_LIBVIRT_VIRT_SYSPREP_OPTIONS: '--run $(pwd)/scripts/sysprep.sh',
63
+ }
64
+ )
65
+ end
66
+
67
+ after do
68
+ expect(environment.execute('vagrant', 'destroy', '--force', extra_env: testbox_envvars)).to exit_with(0)
69
+ assert_execute('vagrant', 'box', 'remove', '--force', 'test-package-complex-domain')
70
+ end
71
+
72
+ it 'should succeed' do
73
+ status('Test: machine is created successfully')
74
+ expect(environment.execute('vagrant', 'up')).to exit_with(0)
75
+
76
+ status('Test: package machine successfully')
77
+ expect(environment.execute('vagrant', 'package')).to exit_with(0)
78
+
79
+ status('Test: add packaged box')
80
+ expect(environment.execute(
81
+ 'vagrant', 'box', 'add', '--force', '--name', 'test-package-complex-domain', 'package.box'
82
+ )).to exit_with(0)
83
+
84
+ status('Test: machine from packaged box is created successfully')
85
+ result = environment.execute('vagrant', 'up', extra_env: testbox_envvars)
86
+ expect(result).to exit_with(0)
87
+ expect(result.stdout).to match(/test-package-complex-domain/)
88
+ end
89
+ end
90
+ end