vagrant-libvirt 0.0.36 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +171 -13
  5. data/lib/vagrant-libvirt/action/create_domain.rb +44 -19
  6. data/lib/vagrant-libvirt/action/create_domain_volume.rb +12 -12
  7. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +37 -39
  8. data/lib/vagrant-libvirt/action/create_networks.rb +34 -34
  9. data/lib/vagrant-libvirt/action/destroy_domain.rb +7 -8
  10. data/lib/vagrant-libvirt/action/destroy_networks.rb +12 -13
  11. data/lib/vagrant-libvirt/action/forward_ports.rb +21 -23
  12. data/lib/vagrant-libvirt/action/halt_domain.rb +8 -9
  13. data/lib/vagrant-libvirt/action/handle_box_image.rb +28 -27
  14. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +8 -8
  15. data/lib/vagrant-libvirt/action/is_created.rb +1 -1
  16. data/lib/vagrant-libvirt/action/is_running.rb +2 -2
  17. data/lib/vagrant-libvirt/action/is_suspended.rb +4 -4
  18. data/lib/vagrant-libvirt/action/message_already_created.rb +2 -2
  19. data/lib/vagrant-libvirt/action/message_not_created.rb +2 -2
  20. data/lib/vagrant-libvirt/action/message_not_running.rb +2 -2
  21. data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -2
  22. data/lib/vagrant-libvirt/action/package_domain.rb +6 -5
  23. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +7 -6
  24. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -2
  25. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +3 -3
  26. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +8 -10
  27. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +4 -4
  28. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +8 -7
  29. data/lib/vagrant-libvirt/action/resume_domain.rb +5 -5
  30. data/lib/vagrant-libvirt/action/set_boot_order.rb +70 -27
  31. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +10 -12
  32. data/lib/vagrant-libvirt/action/share_folders.rb +16 -18
  33. data/lib/vagrant-libvirt/action/start_domain.rb +59 -64
  34. data/lib/vagrant-libvirt/action/suspend_domain.rb +5 -5
  35. data/lib/vagrant-libvirt/action/wait_till_up.rb +24 -26
  36. data/lib/vagrant-libvirt/action.rb +18 -23
  37. data/lib/vagrant-libvirt/cap/mount_p9.rb +11 -10
  38. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +1 -1
  39. data/lib/vagrant-libvirt/cap/synced_folder.rb +20 -19
  40. data/lib/vagrant-libvirt/config.rb +164 -136
  41. data/lib/vagrant-libvirt/driver.rb +10 -13
  42. data/lib/vagrant-libvirt/errors.rb +4 -3
  43. data/lib/vagrant-libvirt/plugin.rb +4 -6
  44. data/lib/vagrant-libvirt/provider.rb +23 -24
  45. data/lib/vagrant-libvirt/templates/domain.xml.erb +14 -1
  46. data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -0
  47. data/lib/vagrant-libvirt/util/collection.rb +0 -3
  48. data/lib/vagrant-libvirt/util/erb_template.rb +6 -10
  49. data/lib/vagrant-libvirt/util/error_codes.rb +32 -33
  50. data/lib/vagrant-libvirt/util/network_util.rb +29 -21
  51. data/lib/vagrant-libvirt/util.rb +3 -4
  52. data/lib/vagrant-libvirt/version.rb +1 -1
  53. data/locales/en.yml +3 -0
  54. data/spec/spec_helper.rb +3 -0
  55. data/spec/support/environment_helper.rb +5 -7
  56. data/spec/support/libvirt_context.rb +13 -11
  57. data/spec/support/sharedcontext.rb +9 -10
  58. data/spec/unit/action/destroy_domain_spec.rb +38 -37
  59. data/spec/unit/action/set_name_of_domain_spec.rb +4 -4
  60. data/spec/unit/action/wait_till_up_spec.rb +45 -46
  61. data/spec/unit/config_spec.rb +106 -0
  62. data/spec/unit/templates/domain_all_settings.xml +125 -0
  63. data/spec/unit/templates/domain_defaults.xml +44 -0
  64. data/spec/unit/templates/domain_spec.rb +69 -0
  65. data/tools/create_box.sh +8 -2
  66. metadata +12 -3
@@ -6,14 +6,13 @@ require 'vagrant/util/retryable'
6
6
  module VagrantPlugins
7
7
  module ProviderLibvirt
8
8
  module Action
9
-
10
9
  # Wait till domain is started, till it obtains an IP address and is
11
10
  # accessible via ssh.
12
11
  class WaitTillUp
13
12
  include Vagrant::Util::Retryable
14
13
 
15
- def initialize(app, env)
16
- @logger = Log4r::Logger.new("vagrant_libvirt::action::wait_till_up")
14
+ def initialize(app, _env)
15
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::wait_till_up')
17
16
  @app = app
18
17
  end
19
18
 
@@ -23,63 +22,63 @@ module VagrantPlugins
23
22
 
24
23
  # Get domain object
25
24
  domain = env[:machine].provider.driver.get_domain(env[:machine].id.to_s)
26
- if domain == nil
25
+ if domain.nil?
27
26
  raise Errors::NoDomainError,
28
- :error_message => "Domain #{env[:machine].id} not found"
27
+ error_message: "Domain #{env[:machine].id} not found"
29
28
  end
30
29
 
31
30
  # Wait for domain to obtain an ip address. Ip address is searched
32
31
  # from arp table, either localy or remotely via ssh, if libvirt
33
32
  # connection was done via ssh.
34
33
  env[:ip_address] = nil
35
- env[:metrics]["instance_ip_time"] = Util::Timer.time do
34
+ env[:metrics]['instance_ip_time'] = Util::Timer.time do
36
35
  @logger.debug("Searching for IP for MAC address: #{domain.mac}")
37
- env[:ui].info(I18n.t("vagrant_libvirt.waiting_for_ip"))
38
- retryable(:on => Fog::Errors::TimeoutError, :tries => 300) do
36
+ env[:ui].info(I18n.t('vagrant_libvirt.waiting_for_ip'))
37
+ retryable(on: Fog::Errors::TimeoutError, tries: 300) do
39
38
  # If we're interrupted don't worry about waiting
40
39
  return terminate(env) if env[:interrupted]
41
40
 
42
41
  # Wait for domain to obtain an ip address
43
- domain.wait_for(2) {
44
- addresses.each_pair do |type, ip|
45
- env[:ip_address] = ip[0] if ip[0] != nil
42
+ domain.wait_for(2) do
43
+ addresses.each_pair do |_type, ip|
44
+ env[:ip_address] = ip[0] unless ip[0].nil?
46
45
  end
47
- env[:ip_address] != nil
48
- }
46
+ !env[:ip_address].nil?
47
+ end
49
48
  end
50
49
  end
51
50
  @logger.info("Got IP address #{env[:ip_address]}")
52
- @logger.info("Time for getting IP: #{env[:metrics]["instance_ip_time"]}")
53
-
51
+ @logger.info("Time for getting IP: #{env[:metrics]['instance_ip_time']}")
52
+
54
53
  # Machine has ip address assigned, now wait till we are able to
55
54
  # connect via ssh.
56
- env[:metrics]["instance_ssh_time"] = Util::Timer.time do
57
- env[:ui].info(I18n.t("vagrant_libvirt.waiting_for_ssh"))
58
- retryable(:on => Fog::Errors::TimeoutError, :tries => 60) do
55
+ env[:metrics]['instance_ssh_time'] = Util::Timer.time do
56
+ env[:ui].info(I18n.t('vagrant_libvirt.waiting_for_ssh'))
57
+ retryable(on: Fog::Errors::TimeoutError, tries: 60) do
59
58
  # If we're interrupted don't worry about waiting
60
59
  next if env[:interrupted]
61
60
 
62
61
  # Wait till we are able to connect via ssh.
63
- while true
62
+ loop do
64
63
  # If we're interrupted then just back out
65
64
  break if env[:interrupted]
66
65
  break if env[:machine].communicate.ready?
67
66
  sleep 2
68
- end
67
+ end
69
68
  end
70
69
  end
71
70
  # if interrupted above, just terminate immediately
72
71
  return terminate(env) if env[:interrupted]
73
- @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
72
+ @logger.info("Time for SSH ready: #{env[:metrics]['instance_ssh_time']}")
74
73
 
75
74
  # Booted and ready for use.
76
- #env[:ui].info(I18n.t("vagrant_libvirt.ready"))
77
-
75
+ # env[:ui].info(I18n.t("vagrant_libvirt.ready"))
76
+
78
77
  @app.call(env)
79
78
  end
80
79
 
81
80
  def recover(env)
82
- return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
81
+ return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
83
82
 
84
83
  # Undo the import
85
84
  terminate(env)
@@ -88,7 +87,7 @@ module VagrantPlugins
88
87
  def terminate(env)
89
88
  if env[:machine].provider.state.id != :not_created
90
89
  # If we're not supposed to destroy on error then just return
91
- return if !env[:destroy_on_error]
90
+ return unless env[:destroy_on_error]
92
91
 
93
92
  destroy_env = env.dup
94
93
  destroy_env.delete(:interrupted)
@@ -101,4 +100,3 @@ module VagrantPlugins
101
100
  end
102
101
  end
103
102
  end
104
-
@@ -105,7 +105,7 @@ module VagrantPlugins
105
105
  b3.use ForwardPorts
106
106
  b3.use PrepareNFSSettings
107
107
  b3.use ShareFolders
108
- end
108
+ end
109
109
  end
110
110
  end
111
111
  end
@@ -118,7 +118,7 @@ module VagrantPlugins
118
118
  b.use ConfigValidate
119
119
  b.use ClearForwardedPorts
120
120
  b.use Call, IsCreated do |env, b2|
121
- if !env[:result]
121
+ unless env[:result]
122
122
  b2.use MessageNotCreated
123
123
  next
124
124
  end
@@ -128,7 +128,7 @@ module VagrantPlugins
128
128
  end
129
129
 
130
130
  b2.use Call, IsRunning do |env2, b3|
131
- next if !env2[:result]
131
+ next unless env2[:result]
132
132
 
133
133
  # VM is running, halt it.
134
134
  b3.use HaltDomain
@@ -142,7 +142,7 @@ module VagrantPlugins
142
142
  def self.action_reload
143
143
  Vagrant::Action::Builder.new.tap do |b|
144
144
  b.use Call, IsCreated do |env, b2|
145
- if !env[:result]
145
+ unless env[:result]
146
146
  b2.use MessageNotCreated
147
147
  next
148
148
  end
@@ -168,15 +168,11 @@ module VagrantPlugins
168
168
  Vagrant::Action::Builder.new.tap do |b|
169
169
  b.use ConfigValidate
170
170
  b.use Call, IsCreated do |env, b2|
171
- if !env[:result]
171
+ unless env[:result]
172
172
  # Try to remove stale volumes anyway
173
173
  b2.use SetNameOfDomain
174
- if env[:machine].config.vm.box
175
- b2.use RemoveStaleVolume
176
- end
177
- if !env[:result]
178
- b2.use MessageNotCreated
179
- end
174
+ b2.use RemoveStaleVolume if env[:machine].config.vm.box
175
+ b2.use MessageNotCreated unless env[:result]
180
176
 
181
177
  next
182
178
  end
@@ -195,13 +191,13 @@ module VagrantPlugins
195
191
  Vagrant::Action::Builder.new.tap do |b|
196
192
  b.use ConfigValidate
197
193
  b.use Call, IsCreated do |env, b2|
198
- if !env[:result]
194
+ unless env[:result]
199
195
  b2.use MessageNotCreated
200
196
  next
201
197
  end
202
198
 
203
199
  b2.use Call, IsRunning do |env2, b3|
204
- if !env2[:result]
200
+ unless env2[:result]
205
201
  b3.use MessageNotRunning
206
202
  next
207
203
  end
@@ -217,13 +213,13 @@ module VagrantPlugins
217
213
  Vagrant::Action::Builder.new.tap do |b|
218
214
  b.use ConfigValidate
219
215
  b.use Call, IsCreated do |env, b2|
220
- if !env[:result]
216
+ unless env[:result]
221
217
  b2.use MessageNotCreated
222
218
  next
223
219
  end
224
220
 
225
221
  b2.use Call, IsRunning do |env2, b3|
226
- if !env2[:result]
222
+ unless env2[:result]
227
223
  b3.use MessageNotRunning
228
224
  next
229
225
  end
@@ -241,13 +237,13 @@ module VagrantPlugins
241
237
  Vagrant::Action::Builder.new.tap do |b|
242
238
  b.use ConfigValidate
243
239
  b.use Call, IsCreated do |env, b2|
244
- if !env[:result]
240
+ unless env[:result]
245
241
  b2.use MessageNotCreated
246
242
  next
247
243
  end
248
244
 
249
245
  b2.use Call, IsRunning do |env2, b3|
250
- if !env2[:result]
246
+ unless env2[:result]
251
247
  b3.use MessageNotRunning
252
248
  next
253
249
  end
@@ -263,13 +259,13 @@ module VagrantPlugins
263
259
  Vagrant::Action::Builder.new.tap do |b|
264
260
  b.use ConfigValidate
265
261
  b.use Call, IsCreated do |env, b2|
266
- if !env[:result]
262
+ unless env[:result]
267
263
  b2.use MessageNotCreated
268
264
  next
269
265
  end
270
266
 
271
267
  b2.use Call, IsSuspended do |env2, b3|
272
- if !env2[:result]
268
+ unless env2[:result]
273
269
  b3.use MessageNotSuspended
274
270
  next
275
271
  end
@@ -291,13 +287,13 @@ module VagrantPlugins
291
287
  Vagrant::Action::Builder.new.tap do |b|
292
288
  b.use ConfigValidate
293
289
  b.use Call, IsCreated do |env, b2|
294
- if !env[:result]
290
+ unless env[:result]
295
291
  b2.use MessageNotCreated
296
292
  next
297
293
  end
298
294
 
299
295
  b2.use Call, IsRunning do |env2, b3|
300
- if !env2[:result]
296
+ unless env2[:result]
301
297
  b3.use MessageNotRunning
302
298
  next
303
299
  end
@@ -305,7 +301,6 @@ module VagrantPlugins
305
301
  b3.use SSHRun
306
302
  end
307
303
  end
308
-
309
304
  end
310
305
  end
311
306
 
@@ -351,7 +346,7 @@ module VagrantPlugins
351
346
  autoload :WaitTillUp, action_root.join('wait_till_up')
352
347
  autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
353
348
 
354
- autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
349
+ autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
355
350
  autoload :HandleBox, 'vagrant/action/builtin/handle_box'
356
351
  autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders'
357
352
  autoload :SyncedFolderCleanup, 'vagrant/action/builtin/synced_folder_cleanup'
@@ -1,5 +1,5 @@
1
- require "digest/md5"
2
- require "vagrant/util/retryable"
1
+ require 'digest/md5'
2
+ require 'vagrant/util/retryable'
3
3
 
4
4
  module VagrantPlugins
5
5
  module ProviderLibvirt
@@ -8,30 +8,31 @@ module VagrantPlugins
8
8
  extend Vagrant::Util::Retryable
9
9
 
10
10
  def self.mount_p9_shared_folder(machine, folders)
11
- folders.each do |name, opts|
11
+ folders.each do |_name, opts|
12
12
  # Expand the guest path so we can handle things like "~/vagrant"
13
13
  expanded_guest_path = machine.guest.capability(
14
- :shell_expand_guest_path, opts[:guestpath])
14
+ :shell_expand_guest_path, opts[:guestpath]
15
+ )
15
16
 
16
17
  # Do the actual creating and mounting
17
18
  machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
18
19
 
19
20
  # Mount
20
- mount_tag = Digest::MD5.new.update(opts[:hostpath]).to_s[0,31]
21
+ mount_tag = Digest::MD5.new.update(opts[:hostpath]).to_s[0, 31]
21
22
 
22
- mount_opts="-o trans=virtio"
23
+ mount_opts = '-o trans=virtio'
23
24
  mount_opts += ",access=#{opts[:owner]}" if opts[:owner]
24
25
  mount_opts += ",version=#{opts[:version]}" if opts[:version]
25
26
  mount_opts += ",#{opts[:mount_opts]}" if opts[:mount_opts]
26
27
 
27
28
  mount_command = "mount -t 9p #{mount_opts} '#{mount_tag}' #{expanded_guest_path}"
28
- retryable(:on => Vagrant::Errors::LinuxMountFailed,
29
- :tries => 5,
30
- :sleep => 3) do
29
+ retryable(on: Vagrant::Errors::LinuxMountFailed,
30
+ tries: 5,
31
+ sleep: 3) do
31
32
  machine.communicate.sudo('modprobe 9p')
32
33
  machine.communicate.sudo('modprobe 9pnet_virtio')
33
34
  machine.communicate.sudo(mount_command,
34
- :error_class => Vagrant::Errors::LinuxMountFailed)
35
+ error_class: Vagrant::Errors::LinuxMountFailed)
35
36
  end
36
37
  end
37
38
  end
@@ -7,7 +7,7 @@ module VagrantPlugins
7
7
  # and the mac as uppercase string without colons as value
8
8
  nic_macs = {}
9
9
  machine.provider.mac_addresses.each do |index, mac|
10
- nic_macs[index+1] = mac.upcase.gsub(':','')
10
+ nic_macs[index + 1] = mac.upcase.delete(':')
11
11
  end
12
12
  nic_macs
13
13
  end
@@ -1,7 +1,7 @@
1
1
  require 'log4r'
2
2
  require 'ostruct'
3
3
  require 'nokogiri'
4
- require "digest/md5"
4
+ require 'digest/md5'
5
5
 
6
6
  require 'vagrant/util/subprocess'
7
7
  require 'vagrant/errors'
@@ -19,7 +19,7 @@ module VagrantPlugins
19
19
  @logger = Log4r::Logger.new('vagrant_libvirt::synced_folders::9p')
20
20
  end
21
21
 
22
- def usable?(machine, raise_error = false)
22
+ def usable?(machine, _raise_error = false)
23
23
  # bail now if not using libvirt since checking version would throw error
24
24
  return false unless machine.provider_name == :libvirt
25
25
 
@@ -36,43 +36,43 @@ module VagrantPlugins
36
36
  begin
37
37
  # loop through folders
38
38
  folders.each do |id, folder_opts|
39
- folder_opts.merge!({ target: id,
40
- accessmode: 'passthrough',
41
- mount: true,
42
- readonly: nil }) { |_k, ov, _nv| ov }
39
+ folder_opts.merge!(target: id,
40
+ accessmode: 'passthrough',
41
+ mount: true,
42
+ readonly: nil) { |_k, ov, _nv| ov }
43
43
 
44
- mount_tag = Digest::MD5.new.update(folder_opts[:hostpath]).to_s[0,31]
44
+ mount_tag = Digest::MD5.new.update(folder_opts[:hostpath]).to_s[0, 31]
45
45
  folder_opts[:mount_tag] = mount_tag
46
-
46
+
47
47
  machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}"
48
-
49
- xml = to_xml('filesystem', folder_opts)
48
+
49
+ xml = to_xml('filesystem', folder_opts)
50
50
  # puts "<<<<< XML:\n #{xml}\n >>>>>"
51
51
  @conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0)
52
52
  end
53
53
  rescue => e
54
54
  machine.ui.error("could not attach device because: #{e}")
55
55
  raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,
56
- error_message: e.message
56
+ error_message: e.message
57
57
  end
58
58
  end
59
59
 
60
- # TODO once up, mount folders
60
+ # TODO: once up, mount folders
61
61
  def enable(machine, folders, _opts)
62
62
  # Go through each folder and mount
63
63
  machine.ui.info('mounting p9 share in guest')
64
64
  # Only mount folders that have a guest path specified.
65
65
  mount_folders = {}
66
66
  folders.each do |id, opts|
67
- if opts[:mount] && opts[:guestpath] && ! opts[:guestpath].empty?
68
- mount_folders[id] = opts.dup
69
- # merge common options if not given
70
- mount_folders[id].merge!(version: '9p2000.L') { |_k, ov, _nv| ov }
71
- end
67
+ next unless opts[:mount] && opts[:guestpath] && !opts[:guestpath].empty?
68
+ mount_folders[id] = opts.dup
69
+ # merge common options if not given
70
+ mount_folders[id].merge!(version: '9p2000.L') { |_k, ov, _nv| ov }
72
71
  end
73
72
  # Mount the actual folder
74
73
  machine.guest.capability(
75
- :mount_p9_shared_folder, mount_folders)
74
+ :mount_p9_shared_folder, mount_folders
75
+ )
76
76
  end
77
77
 
78
78
  def cleanup(machine, _opts)
@@ -84,7 +84,8 @@ module VagrantPlugins
84
84
  if machine.id && machine.id != ''
85
85
  dom = @conn.lookup_domain_by_uuid(machine.id)
86
86
  Nokogiri::XML(dom.xml_desc).xpath(
87
- '/domain/devices/filesystem').each do |xml|
87
+ '/domain/devices/filesystem'
88
+ ).each do |xml|
88
89
  dom.detach_device(xml.to_s)
89
90
  machine.ui.info 'Cleaned up shared folders'
90
91
  end