vagrant-libvirt 0.10.4 → 0.10.7
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/vagrant-libvirt/action/create_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +4 -5
- data/lib/vagrant-libvirt/action/forward_ports.rb +16 -15
- data/lib/vagrant-libvirt/action/handle_box_image.rb +2 -0
- data/lib/vagrant-libvirt/action/package_domain.rb +1 -0
- data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +2 -5
- data/lib/vagrant-libvirt/action/set_boot_order.rb +44 -42
- data/lib/vagrant-libvirt/action/start_domain.rb +384 -393
- data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +2 -0
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +3 -1
- data/lib/vagrant-libvirt/config.rb +1 -2
- data/lib/vagrant-libvirt/errors.rb +4 -0
- data/lib/vagrant-libvirt/util/compat.rb +1 -1
- data/lib/vagrant-libvirt/util/network_util.rb +1 -1
- data/lib/vagrant-libvirt/util/xml.rb +47 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/locales/en.yml +2 -0
- data/spec/spec_helper.rb +13 -6
- data/spec/unit/action/set_boot_order_spec/default.xml +76 -0
- data/spec/unit/action/set_boot_order_spec/explicit_boot_order.xml +77 -0
- data/spec/unit/action/set_boot_order_spec.rb +67 -0
- data/spec/unit/action/start_domain_spec.rb +26 -0
- data/spec/unit/plugin_spec.rb +1 -0
- metadata +92 -85
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc5d99d59fe779e1fd30a950951b3b0719b189dc5a379a1718c386e3d7b66b15
|
4
|
+
data.tar.gz: 24a1e04469395612df972d21ab4d054fc8d0f1d871c5bb458a62a6529ffae6f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1567fb63846f3666882c19a84fb09558ad1209e73c79e7314aad5a801c4ce4d91cd831bda57fb9018c8f8b327d2902110ea52e95f82013eea24c8bf0b7fddbe4
|
7
|
+
data.tar.gz: 8b0651b69a0a431e4a0ddca9be08c1a87ae19a1be3cec81dab7a58c9b7dd86495eb561afdcee2c10abe9716ac5cd28818d633771d52c4804d108b3412df8a89a
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
[](https://gitter.im/vagrant-libvirt/vagrant-libvirt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6
6
|
[](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml)
|
7
|
-
[](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=main)
|
8
8
|
[](https://badge.fury.io/rb/vagrant-libvirt)
|
9
9
|
|
10
10
|
This is a [Vagrant](http://www.vagrantup.com) plugin that adds a
|
@@ -7,19 +7,20 @@ module VagrantPlugins
|
|
7
7
|
class ForwardPorts
|
8
8
|
@@lock = Mutex.new
|
9
9
|
|
10
|
-
def initialize(app,
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
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' && !
|
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(
|
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
|
-
|
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
|
-
|
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,
|
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
|
-
|
178
|
+
@ui.info I18n.t(
|
178
179
|
'vagrant.actions.vm.clear_forward_ports.deleting'
|
179
180
|
)
|
180
181
|
pids.each do |tag|
|
@@ -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
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
|