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 +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 +393 -379
- 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/driver.rb +1 -1
- 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/version +1 -1
- data/locales/en.yml +2 -0
- data/spec/acceptance/support-skeletons/package_complex/scripts/sysprep.sh +0 -0
- data/spec/spec_helper.rb +18 -5
- 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/existing_reordered.xml +62 -0
- data/spec/unit/action/start_domain_spec.rb +41 -18
- data/spec/unit/plugin_spec.rb +1 -0
- metadata +80 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8480e85c239c56fec0b2800bb26c7453c566c12c38d45d07e38f50744b2e719
|
4
|
+
data.tar.gz: 0b8970b25c17ac001a9b2d348598512b13afdef476f1078d66720df721f5631d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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=
|
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
|
@@ -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
|
|