vagrant-libvirt 0.10.4 → 0.10.7

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: b5b3a11dacc2b43a80c7419af116d73d2a7e636c325296f22681f23a0d033a20
4
- data.tar.gz: 408df37e3ec6a923f884f15a73778d33408ac59169f8152822b0634e384a09a8
3
+ metadata.gz: fc5d99d59fe779e1fd30a950951b3b0719b189dc5a379a1718c386e3d7b66b15
4
+ data.tar.gz: 24a1e04469395612df972d21ab4d054fc8d0f1d871c5bb458a62a6529ffae6f3
5
5
  SHA512:
6
- metadata.gz: b890ae1fa0eb2f5ef7b212be83acc94eff485f673e3b1bdd40a1f16afbc035af0996a8e31db76148866cc51f5c9c9bf09cc61549e7c3767ba647a4db55265410
7
- data.tar.gz: 211e8ce3e5cf1088e9137fc6ec26829e1fede30b1b714388c48369ddd6d9b7cc4b2aa147776f14f5faa120df0a7a1e9d3bbee13e8f58492b4d17fd3a64afd343
6
+ metadata.gz: 1567fb63846f3666882c19a84fb09558ad1209e73c79e7314aad5a801c4ce4d91cd831bda57fb9018c8f8b327d2902110ea52e95f82013eea24c8bf0b7fddbe4
7
+ data.tar.gz: 8b0651b69a0a431e4a0ddca9be08c1a87ae19a1be3cec81dab7a58c9b7dd86495eb561afdcee2c10abe9716ac5cd28818d633771d52c4804d108b3412df8a89a
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