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
@@ -1,64 +1,107 @@
1
- require "log4r"
1
+ require 'log4r'
2
2
  require 'nokogiri'
3
3
 
4
4
  module VagrantPlugins
5
5
  module ProviderLibvirt
6
6
  module Action
7
+ # boot order useful for pxe in discovery workflow
7
8
  class SetBootOrder
8
9
  def initialize(app, env)
9
10
  @app = app
10
- @logger = Log4r::Logger.new("vagrant_libvirt::action::set_boot_order")
11
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::set_boot_order')
11
12
  config = env[:machine].provider_config
12
13
  @boot_order = config.boot_order
13
14
  end
14
15
 
15
16
  def call(env)
16
- # Get domain first
17
+ # Get domain first
17
18
  begin
18
- domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
19
- env[:machine].id.to_s)
19
+ domain = env[:machine].provider
20
+ .driver
21
+ .connection
22
+ .client
23
+ .lookup_domain_by_uuid(
24
+ env[:machine].id.to_s
25
+ )
20
26
  rescue => e
21
27
  raise Errors::NoDomainError,
22
- :error_message => e.message
28
+ error_message: e.message
23
29
  end
24
30
 
25
- # Only execute specific boot ordering if this is defined in the Vagrant file
31
+ # Only execute specific boot ordering if this is defined
32
+ # in the Vagrant file
26
33
  if @boot_order.count >= 1
27
-
28
- # If a domain is initially defined with no box or disk or with an explicit boot order, libvirt adds <boot dev="foo">
29
- # This conflicts with an explicit boot_order configuration, so we need to remove it from the domain xml and feed it back.
30
- # Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514 as to why we have to do this after all devices have been defined.
34
+
35
+ # If a domain is initially defined with no box or disk or
36
+ # with an explicit boot order, libvirt adds <boot dev="foo">
37
+ # This conflicts with an explicit boot_order configuration,
38
+ # so we need to remove it from the domain xml and feed it back.
39
+ # Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514
40
+ # as to why we have to do this after all devices have been defined.
31
41
  xml = Nokogiri::XML(domain.xml_desc)
32
- xml.search("/domain/os/boot").each do |node|
33
- node.remove
34
- end
42
+ xml.search('/domain/os/boot').each(&:remove)
35
43
 
36
44
  # Parse the XML and find each defined drive and network interfacee
37
45
  hd = xml.search("/domain/devices/disk[@device='disk']")
38
46
  cdrom = xml.search("/domain/devices/disk[@device='cdrom']")
39
- network = xml.search("/domain/devices/interface[@type='network' or @type='udp']")
47
+ # implemented only for 1 network
48
+ nets = @boot_order.flat_map do |x|
49
+ x.class == Hash ? x : nil
50
+ end.compact
51
+ raise 'Defined only for 1 network for boot' if nets.size > 1
52
+ network = search_network(nets, xml)
40
53
 
41
- # Generate an array per device group and a flattened array from all of those
42
- devices = {"hd" => hd, "cdrom" => cdrom, "network" => network}
43
- final_boot_order = @boot_order.flat_map {|category| devices[category] }
54
+ # Generate an array per device group and a flattened
55
+ # array from all of those
56
+ devices = { 'hd' => hd,
57
+ 'cdrom' => cdrom,
58
+ 'network' => network }
44
59
 
45
- # Loop over the entire defined boot order array and create boot order entries in the domain XML
60
+ final_boot_order = final_boot_order(@boot_order, devices)
61
+ # Loop over the entire defined boot order array and
62
+ # create boot order entries in the domain XML
46
63
  final_boot_order.each_with_index do |node, index|
47
- boot = "<boot order='#{index+1}'/>"
64
+ boot = "<boot order='#{index + 1}'/>"
48
65
  node.add_child(boot)
49
- if node.name == 'disk'
50
- @logger.debug "Setting #{node['device']} to boot index #{index+1}"
51
- elsif node.name == 'interface'
52
- @logger.debug "Setting #{node.name} to boot index #{index+1}"
53
- end
66
+ logger_msg(node, index)
54
67
  end
55
68
 
56
- # Finally redefine the domain XML through libvirt to apply the boot ordering
57
- env[:machine].provider.driver.connection.client.define_domain_xml(xml.to_s)
69
+ # Finally redefine the domain XML through libvirt
70
+ # to apply the boot ordering
71
+ env[:machine].provider
72
+ .driver
73
+ .connection
74
+ .client
75
+ .define_domain_xml(xml.to_s)
58
76
  end
59
77
 
60
78
  @app.call(env)
79
+ end
80
+
81
+ def final_boot_order(boot_order, devices)
82
+ boot_order.flat_map do |category|
83
+ devices[category.class == Hash ? category.keys.first : category]
84
+ end
85
+ end
86
+
87
+ def search_network(nets, xml)
88
+ str = '/domain/devices/interface'
89
+ str += "[(@type='network' or @type='udp' or @type='bridge')"
90
+ unless nets.empty?
91
+ str += " and source[@network='#{nets.first['network']}']"
92
+ end
93
+ str += ']'
94
+ @logger.debug(str)
95
+ xml.search(str)
96
+ end
61
97
 
98
+ def logger_msg(node, index)
99
+ name = if node.name == 'disk'
100
+ node['device']
101
+ elsif node.name == 'interface'
102
+ node.name
103
+ end
104
+ @logger.debug "Setting #{name} to boot index #{index + 1}"
62
105
  end
63
106
  end
64
107
  end
@@ -2,11 +2,10 @@ require 'securerandom'
2
2
  module VagrantPlugins
3
3
  module ProviderLibvirt
4
4
  module Action
5
-
6
5
  # Setup name for domain and domain volumes.
7
6
  class SetNameOfDomain
8
- def initialize(app, env)
9
- @logger = Log4r::Logger.new("vagrant_libvirt::action::set_name_of_domain")
7
+ def initialize(app, _env)
8
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::set_name_of_domain')
10
9
  @app = app
11
10
  end
12
11
 
@@ -14,14 +13,15 @@ module VagrantPlugins
14
13
  env[:domain_name] = build_domain_name(env)
15
14
 
16
15
  begin
17
- @logger.info("Looking for domain #{env[:domain_name]} through list " +
16
+ @logger.info("Looking for domain #{env[:domain_name]} through list " \
18
17
  "#{env[:machine].provider.driver.connection.servers.all}")
19
18
  # Check if the domain name is not already taken
20
19
 
21
20
  domain = ProviderLibvirt::Util::Collection.find_matching(
22
- env[:machine].provider.driver.connection.servers.all, env[:domain_name])
21
+ env[:machine].provider.driver.connection.servers.all, env[:domain_name]
22
+ )
23
23
  rescue Fog::Errors::Error => e
24
- @logger.info("#{e}")
24
+ @logger.info(e.to_s)
25
25
  domain = nil
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ module VagrantPlugins
29
29
 
30
30
  unless domain.nil?
31
31
  raise ProviderLibvirt::Errors::DomainNameExists,
32
- :domain_name => env[:domain_name]
32
+ domain_name: env[:domain_name]
33
33
  end
34
34
 
35
35
  @app.call(env)
@@ -46,21 +46,19 @@ module VagrantPlugins
46
46
  config = env[:machine].provider_config
47
47
  domain_name =
48
48
  if config.default_prefix.nil?
49
- env[:root_path].basename.to_s.dup.concat("_")
49
+ env[:root_path].basename.to_s.dup.concat('_')
50
50
  elsif config.default_prefix.empty?
51
51
  # don't have any prefix, not even "_"
52
- ""
52
+ ''
53
53
  else
54
- config.default_prefix.to_s.concat("_")
54
+ config.default_prefix.to_s.dup.concat('_')
55
55
  end
56
56
  domain_name << env[:machine].name.to_s
57
57
  domain_name.gsub!(/[^-a-z0-9_\.]/i, '')
58
58
  domain_name << "_#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}" if config.random_hostname
59
59
  domain_name
60
60
  end
61
-
62
61
  end
63
-
64
62
  end
65
63
  end
66
64
  end
@@ -1,13 +1,13 @@
1
1
  require 'pathname'
2
2
 
3
- require "log4r"
3
+ require 'log4r'
4
4
 
5
5
  module VagrantPlugins
6
6
  module ProviderLibvirt
7
7
  module Action
8
8
  class ShareFolders
9
- def initialize(app, env)
10
- @logger = Log4r::Logger.new("vagrant::action::vm::share_folders")
9
+ def initialize(app, _env)
10
+ @logger = Log4r::Logger.new('vagrant::action::vm::share_folders')
11
11
  @app = app
12
12
  end
13
13
 
@@ -37,36 +37,34 @@ module VagrantPlugins
37
37
  # Prepares the shared folders by verifying they exist and creating them
38
38
  # if they don't.
39
39
  def prepare_folders
40
- shared_folders.each do |id, options|
40
+ shared_folders.each do |_id, options|
41
41
  hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])
42
42
 
43
- if !hostpath.directory? && options[:create]
44
- # Host path doesn't exist, so let's create it.
45
- @logger.debug("Host path doesn't exist, creating: #{hostpath}")
43
+ next unless !hostpath.directory? && options[:create]
44
+ # Host path doesn't exist, so let's create it.
45
+ @logger.debug("Host path doesn't exist, creating: #{hostpath}")
46
46
 
47
- begin
48
- hostpath.mkpath
49
- rescue Errno::EACCES
50
- raise Vagrant::Errors::SharedFolderCreateFailed,
51
- :path => hostpath.to_s
52
- end
47
+ begin
48
+ hostpath.mkpath
49
+ rescue Errno::EACCES
50
+ raise Vagrant::Errors::SharedFolderCreateFailed,
51
+ path: hostpath.to_s
53
52
  end
54
53
  end
55
54
  end
56
55
 
57
56
  def create_metadata
58
- @env[:ui].info I18n.t("vagrant.actions.vm.share_folders.creating")
57
+ @env[:ui].info I18n.t('vagrant.actions.vm.share_folders.creating')
59
58
 
60
59
  folders = []
61
60
  shared_folders.each do |id, data|
62
61
  folders << {
63
- :name => id,
64
- :hostpath => File.expand_path(data[:hostpath], @env[:root_path]),
65
- :transient => data[:transient]
62
+ name: id,
63
+ hostpath: File.expand_path(data[:hostpath], @env[:root_path]),
64
+ transient: data[:transient]
66
65
  }
67
66
  end
68
67
  end
69
-
70
68
  end
71
69
  end
72
70
  end
@@ -6,25 +6,25 @@ module VagrantPlugins
6
6
  module Action
7
7
  # Just start the domain.
8
8
  class StartDomain
9
- def initialize(app, env)
10
- @logger = Log4r::Logger.new("vagrant_libvirt::action::start_domain")
9
+ def initialize(app, _env)
10
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::start_domain')
11
11
  @app = app
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[:ui].info(I18n.t("vagrant_libvirt.starting_domain"))
15
+ env[:ui].info(I18n.t('vagrant_libvirt.starting_domain'))
16
16
 
17
17
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
18
- raise Errors::NoDomainError if domain == nil
18
+ raise Errors::NoDomainError if domain.nil?
19
19
  config = env[:machine].provider_config
20
20
 
21
21
  begin
22
22
  # update domain settings on change.
23
23
 
24
- libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
24
+ libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
25
25
 
26
- if config.memory.to_i*1024 != libvirt_domain.max_memory
27
- libvirt_domain.max_memory = config.memory.to_i*1024
26
+ if config.memory.to_i * 1024 != libvirt_domain.max_memory
27
+ libvirt_domain.max_memory = config.memory.to_i * 1024
28
28
  libvirt_domain.memory = libvirt_domain.max_memory
29
29
  end
30
30
  begin
@@ -34,46 +34,44 @@ module VagrantPlugins
34
34
  descr_changed = false
35
35
 
36
36
  # additional disk bus
37
- config.disks.each {|disk|
37
+ config.disks.each do |disk|
38
38
  device = disk[:device]
39
39
  bus = disk[:bus]
40
- REXML::XPath.each(xml_descr,'/domain/devices/disk[@device="disk"]/target[@dev="'+device+'"]') {|disk_target|
41
- if disk_target.attributes['bus'] != bus
42
- descr_changed = true
43
- disk_target.attributes['bus'] = bus
44
- disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
45
- end
46
- }
47
- }
48
-
49
- # disk_bus
50
- REXML::XPath.each(xml_descr,'/domain/devices/disk[@device="disk"]/target[@dev="vda"]') {|disk_target|
51
- if disk_target.attributes['bus'] != config.disk_bus
40
+ REXML::XPath.each(xml_descr, '/domain/devices/disk[@device="disk"]/target[@dev="' + device + '"]') do |disk_target|
41
+ next unless disk_target.attributes['bus'] != bus
52
42
  descr_changed = true
53
- disk_target.attributes['bus'] = config.disk_bus
43
+ disk_target.attributes['bus'] = bus
54
44
  disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
55
45
  end
56
- }
46
+ end
47
+
48
+ # disk_bus
49
+ REXML::XPath.each(xml_descr, '/domain/devices/disk[@device="disk"]/target[@dev="vda"]') do |disk_target|
50
+ next unless disk_target.attributes['bus'] != config.disk_bus
51
+ descr_changed = true
52
+ disk_target.attributes['bus'] = config.disk_bus
53
+ disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
54
+ end
57
55
 
58
56
  # Iterface type
59
- REXML::XPath.each(xml_descr,'/domain/devices/interface/model') {|iface_model|
57
+ REXML::XPath.each(xml_descr, '/domain/devices/interface/model') do |iface_model|
60
58
  if iface_model.attributes['type'] != config.nic_model_type
61
59
  descr_changed = true
62
60
  iface_model.attributes['type'] = config.nic_model_type
63
61
  end
64
- }
62
+ end
65
63
 
66
64
  # vCpu count
67
65
  if config.cpus.to_i != libvirt_domain.vcpus.length
68
66
  descr_changed = true
69
- REXML::XPath.first(xml_descr,'/domain/vcpu').text = config.cpus
67
+ REXML::XPath.first(xml_descr, '/domain/vcpu').text = config.cpus
70
68
  end
71
69
 
72
70
  # cpu_mode
73
- cpu = REXML::XPath.first(xml_descr,'/domain/cpu')
71
+ cpu = REXML::XPath.first(xml_descr, '/domain/cpu')
74
72
  if cpu.nil?
75
73
  descr_changed = true
76
- cpu = REXML::Element.new('cpu', REXML::XPath.first(xml_descr,'/domain'))
74
+ cpu = REXML::Element.new('cpu', REXML::XPath.first(xml_descr, '/domain'))
77
75
  cpu.attributes['mode'] = config.cpu_mode
78
76
  else
79
77
  if cpu.attributes['mode'] != config.cpu_mode
@@ -83,10 +81,10 @@ module VagrantPlugins
83
81
  end
84
82
 
85
83
  if config.cpu_mode != 'host-passthrough'
86
- cpu_model = REXML::XPath.first(xml_descr,'/domain/cpu/model')
84
+ cpu_model = REXML::XPath.first(xml_descr, '/domain/cpu/model')
87
85
  if cpu_model.nil?
88
86
  descr_changed = true
89
- cpu_model = REXML::Element.new('model', REXML::XPath.first(xml_descr,'/domain/cpu'))
87
+ cpu_model = REXML::Element.new('model', REXML::XPath.first(xml_descr, '/domain/cpu'))
90
88
  cpu_model.attributes['fallback'] = 'allow'
91
89
  cpu_model.text = config.cpu_model
92
90
  else
@@ -99,46 +97,46 @@ module VagrantPlugins
99
97
  cpu_model.attributes['fallback'] = config.cpu_fallback
100
98
  end
101
99
  end
102
- vmx_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="vmx"]')
103
- svm_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="svm"]')
100
+ vmx_feature = REXML::XPath.first(xml_descr, '/domain/cpu/feature[@name="vmx"]')
101
+ svm_feature = REXML::XPath.first(xml_descr, '/domain/cpu/feature[@name="svm"]')
104
102
  if config.nested
105
103
  if vmx_feature.nil?
106
104
  descr_changed = true
107
- vmx_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr,'/domain/cpu'))
105
+ vmx_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr, '/domain/cpu'))
108
106
  vmx_feature.attributes['policy'] = 'optional'
109
107
  vmx_feature.attributes['name'] = 'vmx'
110
108
  end
111
109
  if svm_feature.nil?
112
110
  descr_changed = true
113
- svm_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr,'/domain/cpu'))
111
+ svm_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr, '/domain/cpu'))
114
112
  svm_feature.attributes['policy'] = 'optional'
115
113
  svm_feature.attributes['name'] = 'svm'
116
114
  end
117
115
  else
118
- if !vmx_feature.nil?
116
+ unless vmx_feature.nil?
119
117
  descr_changed = true
120
118
  cpu.delete_element(vmx_feature)
121
119
  end
122
- if !svm_feature.nil?
120
+ unless svm_feature.nil?
123
121
  descr_changed = true
124
122
  cpu.delete_element(svm_feature)
125
123
  end
126
124
  end
127
125
  else
128
- if cpu.elements.to_a.length > 0
126
+ unless cpu.elements.to_a.empty?
129
127
  descr_changed = true
130
- cpu.elements.each {|elem|
128
+ cpu.elements.each do |elem|
131
129
  cpu.delete_element(elem)
132
- }
130
+ end
133
131
  end
134
132
  end
135
133
 
136
134
  # Graphics
137
- graphics = REXML::XPath.first(xml_descr,'/domain/devices/graphics')
135
+ graphics = REXML::XPath.first(xml_descr, '/domain/devices/graphics')
138
136
  if config.graphics_type != 'none'
139
- if graphics.nil?
137
+ if graphics.nil?
140
138
  descr_changed = true
141
- graphics = REXML::Element.new('graphics', REXML::XPath.first(xml_descr,'/domain/devices'))
139
+ graphics = REXML::Element.new('graphics', REXML::XPath.first(xml_descr, '/domain/devices'))
142
140
  end
143
141
  if graphics.attributes['type'] != config.graphics_type
144
142
  descr_changed = true
@@ -168,21 +166,19 @@ module VagrantPlugins
168
166
  graphics.attributes['passwd'] = config.graphics_passwd
169
167
  end
170
168
  end
171
- else
172
- # graphics_type = none, remove entire element
173
- if !graphics.nil?
174
- graphics.parent.delete_element(graphics)
175
- end
169
+ else
170
+ # graphics_type = none, remove entire element
171
+ graphics.parent.delete_element(graphics) unless graphics.nil?
176
172
  end
177
173
 
178
- #TPM
174
+ # TPM
179
175
  if config.tpm_path
180
- raise Errors::FogCreateServerError, "The TPM Path must be fully qualified" unless config.tpm_path[0].chr == '/'
176
+ raise Errors::FogCreateServerError, 'The TPM Path must be fully qualified' unless config.tpm_path[0].chr == '/'
181
177
 
182
- tpm = REXML::XPath.first(xml_descr,'/domain/devices/tpm')
178
+ tpm = REXML::XPath.first(xml_descr, '/domain/devices/tpm')
183
179
  if tpm.nil?
184
180
  descr_changed = true
185
- tpm = REXML::Element.new('tpm', REXML::XPath.first(xml_descr,'/domain/devices/tpm/model'))
181
+ tpm = REXML::Element.new('tpm', REXML::XPath.first(xml_descr, '/domain/devices/tpm/model'))
186
182
  tpm.attributes['model'] = config.tpm_model
187
183
  tpm_backend_type = tpm.add_element('backend')
188
184
  tpm_backend_type.attributes['type'] = config.tpm_type
@@ -205,15 +201,15 @@ module VagrantPlugins
205
201
  end
206
202
 
207
203
  # Video device
208
- video = REXML::XPath.first(xml_descr,'/domain/devices/video')
209
- if !video.nil? and config.graphics_type == 'none'
204
+ video = REXML::XPath.first(xml_descr, '/domain/devices/video')
205
+ if !video.nil? && (config.graphics_type == 'none')
210
206
  # graphics_type = none, video devices are removed since there is no possible output
211
207
  descr_changed = true
212
208
  video.parent.delete_element(video)
213
209
  else
214
- video_model = REXML::XPath.first(xml_descr,'/domain/devices/video/model')
210
+ video_model = REXML::XPath.first(xml_descr, '/domain/devices/video/model')
215
211
  if video_model.nil?
216
- video_model = REXML::Element.new('model', REXML::XPath.first(xml_descr,'/domain/devices/video'))
212
+ video_model = REXML::Element.new('model', REXML::XPath.first(xml_descr, '/domain/devices/video'))
217
213
  video_model.attributes['type'] = config.video_type
218
214
  video_model.attributes['vram'] = config.video_vram
219
215
  else
@@ -227,10 +223,10 @@ module VagrantPlugins
227
223
 
228
224
  # dtb
229
225
  if config.dtb
230
- dtb = REXML::XPath.first(xml_descr,'/domain/os/dtb')
226
+ dtb = REXML::XPath.first(xml_descr, '/domain/os/dtb')
231
227
  if dtb.nil?
232
228
  descr_changed = true
233
- dtb = REXML::Element.new('dtb', REXML::XPath.first(xml_descr,'/domain/os'))
229
+ dtb = REXML::Element.new('dtb', REXML::XPath.first(xml_descr, '/domain/os'))
234
230
  dtb.text = config.dtb
235
231
  else
236
232
  if dtb.text != config.dtb
@@ -242,10 +238,10 @@ module VagrantPlugins
242
238
 
243
239
  # kernel and initrd
244
240
  if config.kernel
245
- kernel= REXML::XPath.first(xml_descr,'/domain/os/kernel')
241
+ kernel = REXML::XPath.first(xml_descr, '/domain/os/kernel')
246
242
  if kernel.nil?
247
243
  descr_changed = true
248
- kernel = REXML::Element.new('kernel', REXML::XPath.first(xml_descr,'/domain/os'))
244
+ kernel = REXML::Element.new('kernel', REXML::XPath.first(xml_descr, '/domain/os'))
249
245
  kernel.text = config.kernel
250
246
  else
251
247
  if kernel.text != config.kernel
@@ -255,10 +251,10 @@ module VagrantPlugins
255
251
  end
256
252
  end
257
253
  if config.initrd
258
- initrd = REXML::XPath.first(xml_descr,'/domain/os/initrd')
254
+ initrd = REXML::XPath.first(xml_descr, '/domain/os/initrd')
259
255
  if initrd.nil?
260
256
  descr_changed = true
261
- initrd = REXML::Element.new('initrd', REXML::XPath.first(xml_descr,'/domain/os'))
257
+ initrd = REXML::Element.new('initrd', REXML::XPath.first(xml_descr, '/domain/os'))
262
258
  initrd.text = config.initrd
263
259
  else
264
260
  if initrd.text != config.initrd
@@ -272,12 +268,12 @@ module VagrantPlugins
272
268
  if descr_changed
273
269
  begin
274
270
  libvirt_domain.undefine
275
- new_descr = ""
271
+ new_descr = ''
276
272
  xml_descr.write new_descr
277
273
  server = env[:machine].provider.driver.connection.servers.create(xml: new_descr)
278
274
  rescue Fog::Errors::Error => e
279
275
  server = env[:machine].provider.driver.connection.servers.create(xml: descr)
280
- raise Errors::FogCreateServerError, error_message: e.message
276
+ raise Errors::FogCreateServerError, error_message: e.message
281
277
  end
282
278
  end
283
279
  rescue => e
@@ -288,13 +284,12 @@ module VagrantPlugins
288
284
  # Actually start the domain
289
285
  domain.start
290
286
  rescue => e
291
- raise Errors::FogError, :message => e.message
287
+ raise Errors::FogError, message: e.message
292
288
  end
293
289
 
294
290
  @app.call(env)
295
291
  end
296
292
  end
297
-
298
293
  end
299
294
  end
300
295
  end
@@ -5,21 +5,21 @@ module VagrantPlugins
5
5
  module Action
6
6
  # Suspend domain.
7
7
  class SuspendDomain
8
- def initialize(app, env)
9
- @logger = Log4r::Logger.new("vagrant_libvirt::action::suspend_domain")
8
+ def initialize(app, _env)
9
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::suspend_domain')
10
10
  @app = app
11
11
  end
12
12
 
13
13
  # make pause
14
14
  def call(env)
15
- env[:ui].info(I18n.t("vagrant_libvirt.suspending_domain"))
15
+ env[:ui].info(I18n.t('vagrant_libvirt.suspending_domain'))
16
16
 
17
17
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
18
- raise Errors::NoDomainError if domain == nil
18
+ raise Errors::NoDomainError if domain.nil?
19
19
 
20
20
  config = env[:machine].provider_config
21
21
  if config.suspend_mode == 'managedsave'
22
- libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
22
+ libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
23
23
  begin
24
24
  libvirt_domain.managed_save
25
25
  rescue => e