vagrant-libvirt 0.10.6 → 0.10.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67234309e889d2254d68de7a257d1bf051bb507afcfc0ff03c28906dcceae43d
4
- data.tar.gz: 1b0f05ff1fd494b46b99715ba500a20237e2262e2de0066ddfb07c46fac5d192
3
+ metadata.gz: a8480e85c239c56fec0b2800bb26c7453c566c12c38d45d07e38f50744b2e719
4
+ data.tar.gz: 0b8970b25c17ac001a9b2d348598512b13afdef476f1078d66720df721f5631d
5
5
  SHA512:
6
- metadata.gz: eb86380ba32e7c6d93856e3d6f168a3ea93d7bb4c532063764239f2875ea9371ca6c113f3a54671c90ba51a8b38166c271794932c1ce104981f40ab45be93de2
7
- data.tar.gz: 035da37488d87c895b8f92b3bd0f616db26447edcbc7ee88fd7d4aa8b33c9f077893aef63ce6fd01e5f961349d938218aa749f0717be69becc4a2363656ac3ef
6
+ metadata.gz: de18f3d908462a69a121271ddcc919c2bb7c883591d4ca11bf4739aa5030b37ef86446ac3c92c9d0e84fefe903328df0dfe135f62bf0c29f818e57c1d1796b32
7
+ data.tar.gz: 376684defc3fd7a3b6d0f87aedb68d4ee1c040c909bf225be84dc8fc5abb85b16f3145f1a9307f5e6446a2f927e604616fd7e714abdc6af73babd4c05bfa696b
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Join the chat at https://gitter.im/vagrant-libvirt/vagrant-libvirt](https://badges.gitter.im/vagrant-libvirt/vagrant-libvirt.svg)](https://gitter.im/vagrant-libvirt/vagrant-libvirt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
6
  [![Build Status](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml)
7
- [![Coverage Status](https://coveralls.io/repos/github/vagrant-libvirt/vagrant-libvirt/badge.svg?branch=master)](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=master)
7
+ [![Coverage Status](https://coveralls.io/repos/github/vagrant-libvirt/vagrant-libvirt/badge.svg?branch=main)](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=main)
8
8
  [![Gem Version](https://badge.fury.io/rb/vagrant-libvirt.svg)](https://badge.fury.io/rb/vagrant-libvirt)
9
9
 
10
10
  This is a [Vagrant](http://www.vagrantup.com) plugin that adds a
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'log4r'
4
4
 
5
+ require 'vagrant-libvirt/util/erb_template'
5
6
  require 'vagrant-libvirt/util/resolvers'
7
+ require 'vagrant-libvirt/util/storage_util'
6
8
 
7
9
  module VagrantPlugins
8
10
  module ProviderLibvirt
@@ -2,11 +2,10 @@
2
2
 
3
3
  require 'log4r'
4
4
 
5
- begin
6
- require 'rexml'
7
- rescue LoadError
8
- require 'rexml/rexml'
9
- end
5
+ require 'rexml/document'
6
+ require 'rexml/xpath'
7
+
8
+ require 'vagrant-libvirt/util/domain_flags'
10
9
 
11
10
  module VagrantPlugins
12
11
  module ProviderLibvirt
@@ -7,19 +7,20 @@ module VagrantPlugins
7
7
  class ForwardPorts
8
8
  @@lock = Mutex.new
9
9
 
10
- def initialize(app, _env)
10
+ def initialize(app, env)
11
11
  @app = app
12
12
  @logger = Log4r::Logger.new('vagrant_libvirt::action::forward_ports')
13
+ @ui = env[:ui]
13
14
  end
14
15
 
15
16
  def call(env)
16
17
  # Get the ports we're forwarding
17
- env[:forwarded_ports] = compile_forwarded_ports(env, env[:machine].config)
18
+ env[:forwarded_ports] = compile_forwarded_ports(env[:machine])
18
19
 
19
20
  # Warn if we're port forwarding to any privileged ports
20
21
  env[:forwarded_ports].each do |fp|
21
22
  next unless fp[:host] <= 1024
22
- env[:ui].warn I18n.t(
23
+ @ui.warn I18n.t(
23
24
  'vagrant.actions.vm.forward_ports.privileged_ports'
24
25
  )
25
26
  break
@@ -29,7 +30,7 @@ module VagrantPlugins
29
30
  @app.call env
30
31
 
31
32
  if env[:forwarded_ports].any?
32
- env[:ui].info I18n.t('vagrant.actions.vm.forward_ports.forwarding')
33
+ @ui.info I18n.t('vagrant.actions.vm.forward_ports.forwarding')
33
34
  forward_ports(env)
34
35
  end
35
36
  end
@@ -42,13 +43,12 @@ module VagrantPlugins
42
43
  host_port: fp[:host]
43
44
  }
44
45
 
45
- env[:ui].info(I18n.t(
46
+ @ui.info(I18n.t(
46
47
  'vagrant.actions.vm.forward_ports.forwarding_entry',
47
48
  **message_attributes
48
49
  ))
49
50
 
50
51
  ssh_pid = redirect_port(
51
- env,
52
52
  env[:machine],
53
53
  fp[:host_ip] || '*',
54
54
  fp[:host],
@@ -62,18 +62,18 @@ module VagrantPlugins
62
62
 
63
63
  private
64
64
 
65
- def compile_forwarded_ports(env, config)
65
+ def compile_forwarded_ports(machine)
66
66
  mappings = {}
67
67
 
68
- config.vm.networks.each do |type, options|
68
+ machine.config.vm.networks.each do |type, options|
69
69
  next if options[:disabled]
70
70
 
71
71
  if options[:protocol] == 'udp'
72
- env[:ui].warn I18n.t('vagrant_libvirt.warnings.forwarding_udp')
72
+ @ui.warn I18n.t('vagrant_libvirt.warnings.forwarding_udp')
73
73
  next
74
74
  end
75
75
 
76
- next if type != :forwarded_port || ( options[:id] == 'ssh' && !env[:machine].provider_config.forward_ssh_port )
76
+ next if type != :forwarded_port || ( options[:id] == 'ssh' && !machine.provider_config.forward_ssh_port )
77
77
  if options.fetch(:host_ip, '').to_s.strip.empty?
78
78
  options.delete(:host_ip)
79
79
  end
@@ -83,7 +83,7 @@ module VagrantPlugins
83
83
  mappings.values
84
84
  end
85
85
 
86
- def redirect_port(env, machine, host_ip, host_port, guest_ip, guest_port,
86
+ def redirect_port(machine, host_ip, host_port, guest_ip, guest_port,
87
87
  gateway_ports)
88
88
  ssh_info = machine.ssh_info
89
89
  params = %W(
@@ -118,7 +118,7 @@ module VagrantPlugins
118
118
  if host_port <= 1024
119
119
  @@lock.synchronize do
120
120
  # TODO: add i18n
121
- env[:ui].info 'Requesting sudo for host port(s) <= 1024'
121
+ @ui.info 'Requesting sudo for host port(s) <= 1024'
122
122
  r = system('sudo -v')
123
123
  if r
124
124
  ssh_cmd.unshift('sudo') # add sudo prefix
@@ -128,7 +128,7 @@ module VagrantPlugins
128
128
 
129
129
  @logger.debug "Forwarding port with `#{ssh_cmd.join(' ')}`"
130
130
  log_file = ssh_forward_log_file(
131
- env[:machine], host_ip, host_port, guest_ip, guest_port,
131
+ machine, host_ip, host_port, guest_ip, guest_port,
132
132
  )
133
133
  @logger.info "Logging to #{log_file}"
134
134
  spawn(*ssh_cmd, [:out, :err] => [log_file, 'w'], :pgroup => true)
@@ -164,17 +164,18 @@ module VagrantPlugins
164
164
  class ClearForwardedPorts
165
165
  @@lock = Mutex.new
166
166
 
167
- def initialize(app, _env)
167
+ def initialize(app, env)
168
168
  @app = app
169
169
  @logger = Log4r::Logger.new(
170
170
  'vagrant_libvirt::action::clear_forward_ports'
171
171
  )
172
+ @ui = env[:ui]
172
173
  end
173
174
 
174
175
  def call(env)
175
176
  pids = ssh_pids(env[:machine])
176
177
  if pids.any?
177
- env[:ui].info I18n.t(
178
+ @ui.info I18n.t(
178
179
  'vagrant.actions.vm.clear_forward_ports.deleting'
179
180
  )
180
181
  pids.each do |tag|
@@ -5,6 +5,8 @@ require 'open3'
5
5
  require 'json'
6
6
 
7
7
  require 'vagrant-libvirt/util/byte_number'
8
+ require 'vagrant-libvirt/util/storage_util'
9
+ require 'vagrant-libvirt/util/ui'
8
10
 
9
11
  module VagrantPlugins
10
12
  module ProviderLibvirt
@@ -3,6 +3,7 @@
3
3
  require 'fileutils'
4
4
  require 'log4r'
5
5
 
6
+ require 'vagrant-libvirt/util/ui'
6
7
  require 'vagrant-libvirt/util/unindent'
7
8
 
8
9
  module VagrantPlugins
@@ -2,11 +2,8 @@
2
2
 
3
3
  require 'log4r'
4
4
 
5
- begin
6
- require 'rexml'
7
- rescue LoadError
8
- require 'rexml/rexml'
9
- end
5
+ require 'rexml/document'
6
+ require 'rexml/xpath'
10
7
 
11
8
  require 'vagrant-libvirt/util/resolvers'
12
9
 
@@ -16,6 +16,12 @@ module VagrantPlugins
16
16
  end
17
17
 
18
18
  def call(env)
19
+ # Only execute specific boot ordering if this is defined
20
+ # in the Vagrant file
21
+ unless @boot_order.count >= 1
22
+ return @app.call(env)
23
+ end
24
+
19
25
  # Get domain first
20
26
  begin
21
27
  domain = env[:machine].provider
@@ -30,53 +36,49 @@ module VagrantPlugins
30
36
  error_message: e.message
31
37
  end
32
38
 
33
- # Only execute specific boot ordering if this is defined
34
- # in the Vagrant file
35
- if @boot_order.count >= 1
36
-
37
- # If a domain is initially defined with no box or disk or
38
- # with an explicit boot order, Libvirt adds <boot dev="foo">
39
- # This conflicts with an explicit boot_order configuration,
40
- # so we need to remove it from the domain xml and feed it back.
41
- # Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514
42
- # as to why we have to do this after all devices have been defined.
43
- xml = Nokogiri::XML(domain.xml_desc)
44
- xml.search('/domain/os/boot').each(&:remove)
39
+ # If a domain is initially defined with no box or disk or
40
+ # with an explicit boot order, Libvirt adds <boot dev="foo">
41
+ # This conflicts with an explicit boot_order configuration,
42
+ # so we need to remove it from the domain xml and feed it back.
43
+ # Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514
44
+ # as to why we have to do this after all devices have been defined.
45
+ xml = Nokogiri::XML(domain.xml_desc)
46
+ xml.search('/domain/os/boot').each(&:remove)
45
47
 
46
- # Parse the XML and find each defined drive and network interfacee
47
- hd = xml.search("/domain/devices/disk[@device='disk']")
48
- cdrom = xml.search("/domain/devices/disk[@device='cdrom']")
49
- # implemented only for 1 network
50
- nets = @boot_order.flat_map do |x|
51
- x.class == Hash ? x : nil
52
- end.compact
53
- raise 'Defined only for 1 network for boot' if nets.size > 1
54
- network = search_network(nets, xml)
48
+ # Parse the XML and find each defined drive and network interfacee
49
+ hd = xml.search("/domain/devices/disk[@device='disk']")
50
+ cdrom = xml.search("/domain/devices/disk[@device='cdrom']")
51
+ # implemented only for 1 network
52
+ nets = @boot_order.flat_map do |x|
53
+ x.class == Hash ? x : nil
54
+ end.compact
55
+ raise 'Defined only for 1 network for boot' if nets.size > 1
56
+ network = search_network(nets, xml)
55
57
 
56
- # Generate an array per device group and a flattened
57
- # array from all of those
58
- devices = { 'hd' => hd,
59
- 'cdrom' => cdrom,
60
- 'network' => network }
58
+ # Generate an array per device group and a flattened
59
+ # array from all of those
60
+ devices = { 'hd' => hd,
61
+ 'cdrom' => cdrom,
62
+ 'network' => network }
61
63
 
62
- final_boot_order = final_boot_order(@boot_order, devices)
63
- # Loop over the entire defined boot order array and
64
- # create boot order entries in the domain XML
65
- final_boot_order.each_with_index do |node, index|
66
- boot = "<boot order='#{index + 1}'/>"
67
- node.add_child(boot)
68
- logger_msg(node, index)
69
- end
70
-
71
- # Finally redefine the domain XML through Libvirt
72
- # to apply the boot ordering
73
- env[:machine].provider
74
- .driver
75
- .connection
76
- .client
77
- .define_domain_xml(xml.to_s)
64
+ final_boot_order = final_boot_order(@boot_order, devices)
65
+ # Loop over the entire defined boot order array and
66
+ # create boot order entries in the domain XML
67
+ final_boot_order.each_with_index do |node, index|
68
+ next if node.nil?
69
+ boot = "<boot order='#{index + 1}'/>"
70
+ node.add_child(boot)
71
+ logger_msg(node, index)
78
72
  end
79
73
 
74
+ # Finally redefine the domain XML through Libvirt
75
+ # to apply the boot ordering
76
+ env[:machine].provider
77
+ .driver
78
+ .connection
79
+ .client
80
+ .define_domain_xml(xml.to_s)
81
+
80
82
  @app.call(env)
81
83
  end
82
84