vagrant-libvirt 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/Gemfile +1 -0
- data/README.md +171 -13
- data/lib/vagrant-libvirt/action/create_domain.rb +44 -19
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +12 -12
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +37 -39
- data/lib/vagrant-libvirt/action/create_networks.rb +34 -34
- data/lib/vagrant-libvirt/action/destroy_domain.rb +7 -8
- data/lib/vagrant-libvirt/action/destroy_networks.rb +12 -13
- data/lib/vagrant-libvirt/action/forward_ports.rb +21 -23
- data/lib/vagrant-libvirt/action/halt_domain.rb +8 -9
- data/lib/vagrant-libvirt/action/handle_box_image.rb +28 -27
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +8 -8
- data/lib/vagrant-libvirt/action/is_created.rb +1 -1
- data/lib/vagrant-libvirt/action/is_running.rb +2 -2
- data/lib/vagrant-libvirt/action/is_suspended.rb +4 -4
- data/lib/vagrant-libvirt/action/message_already_created.rb +2 -2
- data/lib/vagrant-libvirt/action/message_not_created.rb +2 -2
- data/lib/vagrant-libvirt/action/message_not_running.rb +2 -2
- data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -2
- data/lib/vagrant-libvirt/action/package_domain.rb +6 -5
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +7 -6
- data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -2
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +3 -3
- data/lib/vagrant-libvirt/action/read_mac_addresses.rb +8 -10
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +4 -4
- data/lib/vagrant-libvirt/action/remove_stale_volume.rb +8 -7
- data/lib/vagrant-libvirt/action/resume_domain.rb +5 -5
- data/lib/vagrant-libvirt/action/set_boot_order.rb +70 -27
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +10 -12
- data/lib/vagrant-libvirt/action/share_folders.rb +16 -18
- data/lib/vagrant-libvirt/action/start_domain.rb +59 -64
- data/lib/vagrant-libvirt/action/suspend_domain.rb +5 -5
- data/lib/vagrant-libvirt/action/wait_till_up.rb +24 -26
- data/lib/vagrant-libvirt/action.rb +18 -23
- data/lib/vagrant-libvirt/cap/mount_p9.rb +11 -10
- data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +1 -1
- data/lib/vagrant-libvirt/cap/synced_folder.rb +20 -19
- data/lib/vagrant-libvirt/config.rb +164 -136
- data/lib/vagrant-libvirt/driver.rb +10 -13
- data/lib/vagrant-libvirt/errors.rb +4 -3
- data/lib/vagrant-libvirt/plugin.rb +4 -6
- data/lib/vagrant-libvirt/provider.rb +23 -24
- data/lib/vagrant-libvirt/templates/domain.xml.erb +14 -1
- data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -0
- data/lib/vagrant-libvirt/util/collection.rb +0 -3
- data/lib/vagrant-libvirt/util/erb_template.rb +6 -10
- data/lib/vagrant-libvirt/util/error_codes.rb +32 -33
- data/lib/vagrant-libvirt/util/network_util.rb +29 -21
- data/lib/vagrant-libvirt/util.rb +3 -4
- data/lib/vagrant-libvirt/version.rb +1 -1
- data/locales/en.yml +3 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/environment_helper.rb +5 -7
- data/spec/support/libvirt_context.rb +13 -11
- data/spec/support/sharedcontext.rb +9 -10
- data/spec/unit/action/destroy_domain_spec.rb +38 -37
- data/spec/unit/action/set_name_of_domain_spec.rb +4 -4
- data/spec/unit/action/wait_till_up_spec.rb +45 -46
- data/spec/unit/config_spec.rb +106 -0
- data/spec/unit/templates/domain_all_settings.xml +125 -0
- data/spec/unit/templates/domain_defaults.xml +44 -0
- data/spec/unit/templates/domain_spec.rb +69 -0
- data/tools/create_box.sh +8 -2
- metadata +12 -3
@@ -5,7 +5,6 @@ require 'vagrant/util/scoped_hash_override'
|
|
5
5
|
module VagrantPlugins
|
6
6
|
module ProviderLibvirt
|
7
7
|
module Action
|
8
|
-
|
9
8
|
# Create network interfaces for domain, before domain is running.
|
10
9
|
# Networks for connecting those interfaces should be already prepared.
|
11
10
|
class CreateNetworkInterfaces
|
@@ -27,10 +26,11 @@ module VagrantPlugins
|
|
27
26
|
# Get domain first.
|
28
27
|
begin
|
29
28
|
domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
|
30
|
-
env[:machine].id.to_s
|
29
|
+
env[:machine].id.to_s
|
30
|
+
)
|
31
31
|
rescue => e
|
32
32
|
raise Errors::NoDomainError,
|
33
|
-
|
33
|
+
error_message: e.message
|
34
34
|
end
|
35
35
|
|
36
36
|
# Setup list of interfaces before creating them.
|
@@ -39,11 +39,10 @@ module VagrantPlugins
|
|
39
39
|
# Vagrant gives you adapter 0 by default
|
40
40
|
# Assign interfaces to slots.
|
41
41
|
configured_networks(env, @logger).each do |options|
|
42
|
-
|
43
42
|
# dont need to create interface for this type
|
44
43
|
next if options[:iface_type] == :forwarded_port
|
45
44
|
|
46
|
-
# TODO fill first ifaces with adapter option specified.
|
45
|
+
# TODO: fill first ifaces with adapter option specified.
|
47
46
|
if options[:adapter]
|
48
47
|
if adapters[options[:adapter]]
|
49
48
|
raise Errors::InterfaceSlotNotAvailable
|
@@ -54,13 +53,14 @@ module VagrantPlugins
|
|
54
53
|
else
|
55
54
|
free_slot = find_empty(adapters)
|
56
55
|
@logger.debug "Adapter not specified so found slot #{free_slot}"
|
57
|
-
raise Errors::InterfaceSlotNotAvailable if free_slot
|
56
|
+
raise Errors::InterfaceSlotNotAvailable if free_slot.nil?
|
58
57
|
end
|
59
58
|
|
60
59
|
# We have slot for interface, fill it with interface configuration.
|
61
60
|
adapters[free_slot] = options
|
62
61
|
adapters[free_slot][:network_name] = interface_network(
|
63
|
-
env[:machine].provider.driver.connection.client, adapters[free_slot]
|
62
|
+
env[:machine].provider.driver.connection.client, adapters[free_slot]
|
63
|
+
)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Create each interface as new domain device.
|
@@ -95,18 +95,17 @@ module VagrantPlugins
|
|
95
95
|
end
|
96
96
|
# default mcast tunnel to 239.255.1.1. Web search says this
|
97
97
|
# 239.255.x.x is a safe range to use for general use mcast
|
98
|
-
if @type == 'mcast'
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
default_ip = if @type == 'mcast'
|
99
|
+
'239.255.1.1'
|
100
|
+
else
|
101
|
+
'127.0.0.1'
|
102
|
+
end
|
103
103
|
@tunnel_ip = iface_configuration.fetch(:tunnel_ip, default_ip)
|
104
104
|
@model_type = iface_configuration.fetch(:model_type, @nic_model_type)
|
105
105
|
template_name = 'tunnel_interface'
|
106
106
|
@logger.info("Setting up #{@type} tunnel interface using #{@tunnel_ip} port #{@tunnel_port}")
|
107
107
|
end
|
108
108
|
|
109
|
-
|
110
109
|
message = "Creating network interface eth#{@iface_number}"
|
111
110
|
message << " connected to network #{@network_name}."
|
112
111
|
if @mac
|
@@ -119,31 +118,29 @@ module VagrantPlugins
|
|
119
118
|
domain.attach_device(to_xml(template_name))
|
120
119
|
rescue => e
|
121
120
|
raise Errors::AttachDeviceError,
|
122
|
-
|
121
|
+
error_message: e.message
|
123
122
|
end
|
124
123
|
|
125
124
|
# Re-read the network configuration and grab the MAC address
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
133
|
-
else
|
134
|
-
@mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address")
|
135
|
-
end
|
136
|
-
else
|
125
|
+
next if @mac
|
126
|
+
xml = Nokogiri::XML(domain.xml_desc)
|
127
|
+
if iface_configuration[:iface_type] == :public_network
|
128
|
+
if @type == 'direct'
|
129
|
+
@mac = xml.xpath("/domain/devices/interface[source[@dev='#{@device}']]/mac/@address")
|
130
|
+
elsif !@portgroup.nil?
|
137
131
|
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
132
|
+
else
|
133
|
+
@mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address")
|
138
134
|
end
|
139
|
-
|
135
|
+
else
|
136
|
+
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
140
137
|
end
|
138
|
+
iface_configuration[:mac] = @mac.to_s
|
141
139
|
end
|
142
140
|
|
143
141
|
# Continue the middleware chain.
|
144
142
|
@app.call(env)
|
145
143
|
|
146
|
-
|
147
144
|
if env[:machine].config.vm.box
|
148
145
|
# Configure interfaces that user requested. Machine should be up and
|
149
146
|
# running now.
|
@@ -158,17 +155,17 @@ module VagrantPlugins
|
|
158
155
|
@logger.debug "Configuring interface slot_number #{slot_number} options #{options}"
|
159
156
|
|
160
157
|
network = {
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
158
|
+
interface: slot_number,
|
159
|
+
use_dhcp_assigned_default_route: options[:use_dhcp_assigned_default_route],
|
160
|
+
mac_address: options[:mac]
|
164
161
|
}
|
165
162
|
|
166
163
|
if options[:ip]
|
167
164
|
network = {
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
-
:
|
165
|
+
type: :static,
|
166
|
+
ip: options[:ip],
|
167
|
+
netmask: options[:netmask],
|
168
|
+
gateway: options[:gateway]
|
172
169
|
}.merge(network)
|
173
170
|
else
|
174
171
|
network[:type] = :dhcp
|
@@ -182,18 +179,19 @@ module VagrantPlugins
|
|
182
179
|
|
183
180
|
env[:ui].info I18n.t('vagrant.actions.vm.network.configuring')
|
184
181
|
env[:machine].guest.capability(
|
185
|
-
:configure_networks, networks_to_configure
|
182
|
+
:configure_networks, networks_to_configure
|
183
|
+
)
|
186
184
|
|
187
185
|
end
|
188
186
|
end
|
189
187
|
|
190
188
|
private
|
191
189
|
|
192
|
-
def find_empty(array, start=0, stop
|
190
|
+
def find_empty(array, start = 0, stop = @nic_adapter_count)
|
193
191
|
(start..stop).each do |i|
|
194
192
|
return i unless array[i]
|
195
193
|
end
|
196
|
-
|
194
|
+
nil
|
197
195
|
end
|
198
196
|
|
199
197
|
# Return network name according to interface options.
|
@@ -202,7 +200,7 @@ module VagrantPlugins
|
|
202
200
|
return 'tunnel_interface' if options.fetch(:tunnel_type, nil)
|
203
201
|
|
204
202
|
if options[:network_name]
|
205
|
-
@logger.debug
|
203
|
+
@logger.debug 'Found network by name'
|
206
204
|
return options[:network_name]
|
207
205
|
end
|
208
206
|
|
@@ -215,7 +213,7 @@ module VagrantPlugins
|
|
215
213
|
address = network_address(options[:ip], options[:netmask])
|
216
214
|
available_networks.each do |network|
|
217
215
|
if address == network[:network_address]
|
218
|
-
@logger.debug
|
216
|
+
@logger.debug 'Found network by ip'
|
219
217
|
return network[:name]
|
220
218
|
end
|
221
219
|
end
|
@@ -36,7 +36,7 @@ module VagrantPlugins
|
|
36
36
|
configured_networks(env, @logger).each do |options|
|
37
37
|
# Only need to create private networks
|
38
38
|
next if options[:iface_type] != :private_network ||
|
39
|
-
|
39
|
+
options.fetch(:tunnel_type, nil)
|
40
40
|
@logger.debug "Searching for network with options #{options}"
|
41
41
|
|
42
42
|
# should fix other methods so this doesn't have to be instance var
|
@@ -46,7 +46,8 @@ module VagrantPlugins
|
|
46
46
|
# list is used throughout this class and should be easier to
|
47
47
|
# process than libvirt API calls.
|
48
48
|
@available_networks = libvirt_networks(
|
49
|
-
|
49
|
+
env[:machine].provider.driver.connection.client
|
50
|
+
)
|
50
51
|
|
51
52
|
# Prepare a hash describing network for this specific interface.
|
52
53
|
@interface_network = {
|
@@ -55,9 +56,11 @@ module VagrantPlugins
|
|
55
56
|
netmask: @options[:netmask],
|
56
57
|
network_address: nil,
|
57
58
|
bridge_name: nil,
|
59
|
+
ipv6_address: options[:ipv6_address] || nil,
|
60
|
+
ipv6_prefix: options[:ipv6_prefix] || nil,
|
58
61
|
created: false,
|
59
62
|
active: false,
|
60
|
-
autostart: false,
|
63
|
+
autostart: options[:autostart] || false,
|
61
64
|
guest_ipv6: @options[:guest_ipv6] || 'yes',
|
62
65
|
libvirt_network: nil
|
63
66
|
}
|
@@ -129,24 +132,22 @@ module VagrantPlugins
|
|
129
132
|
@interface_network[:network_address] = net_address
|
130
133
|
|
131
134
|
# if network is veryisolated, search by name
|
132
|
-
if @options[:libvirt__forward_mode] ==
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
135
|
+
network = if @options[:libvirt__forward_mode] == 'veryisolated'
|
136
|
+
lookup_network_by_name(@options[:network_name])
|
137
|
+
elsif net_address
|
138
|
+
# otherwise, search by ip (if set)
|
139
|
+
lookup_network_by_ip(net_address)
|
140
|
+
else
|
141
|
+
# leaving this here to mimic prior behavior. If we get
|
142
|
+
# here, something's probably broken.
|
143
|
+
lookup_network_by_name(@options[:network_name])
|
144
|
+
end
|
142
145
|
@interface_network = network if network
|
143
146
|
|
144
|
-
if @interface_network[:created]
|
145
|
-
verify_dhcp
|
146
|
-
end
|
147
|
+
verify_dhcp if @interface_network[:created]
|
147
148
|
|
148
149
|
if @options[:network_name]
|
149
|
-
@logger.debug
|
150
|
+
@logger.debug 'Checking that network name does not clash with ip'
|
150
151
|
if @interface_network[:created]
|
151
152
|
# Just check for mismatch error here - if name and ip from
|
152
153
|
# config match together.
|
@@ -178,7 +179,7 @@ module VagrantPlugins
|
|
178
179
|
# Is name for new network set? If not, generate a unique one.
|
179
180
|
count = 0
|
180
181
|
while @interface_network[:name].nil?
|
181
|
-
@logger.debug
|
182
|
+
@logger.debug 'generating name for network'
|
182
183
|
|
183
184
|
# Generate a network name.
|
184
185
|
network_name = env[:root_path].basename.to_s.dup
|
@@ -205,12 +206,12 @@ module VagrantPlugins
|
|
205
206
|
def handle_network_name_option(env)
|
206
207
|
return if @options[:ip] || \
|
207
208
|
!@options[:network_name] || \
|
208
|
-
!@options[:libvirt__forward_mode] ==
|
209
|
+
!@options[:libvirt__forward_mode] == 'veryisolated'
|
209
210
|
|
210
211
|
network = lookup_network_by_name(@options[:network_name])
|
211
212
|
@interface_network = network if network
|
212
213
|
|
213
|
-
if @options[:libvirt__forward_mode] ==
|
214
|
+
if @options[:libvirt__forward_mode] == 'veryisolated'
|
214
215
|
# if this interface has a network address, something's wrong.
|
215
216
|
if @interface_network[:network_address]
|
216
217
|
raise Errors::NetworkNotAvailableError,
|
@@ -228,6 +229,7 @@ module VagrantPlugins
|
|
228
229
|
# Do we need to create new network?
|
229
230
|
unless @interface_network[:created]
|
230
231
|
@interface_network[:name] = @options[:network_name]
|
232
|
+
@interface_network[:ip_address] ||= @options[:host_ip]
|
231
233
|
|
232
234
|
# Generate a unique name for network bridge.
|
233
235
|
@interface_network[:bridge_name] = generate_bridge_name
|
@@ -266,7 +268,7 @@ module VagrantPlugins
|
|
266
268
|
|
267
269
|
# Return the first available virbr interface name
|
268
270
|
def generate_bridge_name
|
269
|
-
@logger.debug
|
271
|
+
@logger.debug 'generating name for bridge'
|
270
272
|
count = 0
|
271
273
|
while lookup_bridge_by_name(bridge_name = "virbr#{count}")
|
272
274
|
count += 1
|
@@ -282,6 +284,9 @@ module VagrantPlugins
|
|
282
284
|
@network_netmask = @interface_network[:netmask]
|
283
285
|
@guest_ipv6 = @interface_network[:guest_ipv6]
|
284
286
|
|
287
|
+
@network_ipv6_address = @interface_network[:ipv6_address]
|
288
|
+
@network_ipv6_prefix = @interface_network[:ipv6_prefix]
|
289
|
+
|
285
290
|
@network_forward_mode = @options[:forward_mode]
|
286
291
|
if @options[:forward_device]
|
287
292
|
@network_forward_device = @options[:forward_device]
|
@@ -290,7 +295,7 @@ module VagrantPlugins
|
|
290
295
|
if @options[:dhcp_enabled]
|
291
296
|
# Find out DHCP addresses pool range.
|
292
297
|
network_address = "#{@interface_network[:network_address]}/"
|
293
|
-
network_address <<
|
298
|
+
network_address << (@interface_network[:netmask]).to_s
|
294
299
|
net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil
|
295
300
|
|
296
301
|
# First is address of network, second is gateway (by default).
|
@@ -313,7 +318,7 @@ module VagrantPlugins
|
|
313
318
|
begin
|
314
319
|
@interface_network[:libvirt_network] = \
|
315
320
|
@libvirt_client.define_network_xml(to_xml('private_network'))
|
316
|
-
@logger.debug
|
321
|
+
@logger.debug 'created network'
|
317
322
|
rescue => e
|
318
323
|
raise Errors::CreateNetworkError, error_message: e.message
|
319
324
|
end
|
@@ -332,21 +337,16 @@ module VagrantPlugins
|
|
332
337
|
end
|
333
338
|
|
334
339
|
def autostart_network
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
raise Errors::AutostartNetworkError, error_message: e.message
|
339
|
-
end
|
340
|
+
@interface_network[:libvirt_network].autostart = true
|
341
|
+
rescue => e
|
342
|
+
raise Errors::AutostartNetworkError, error_message: e.message
|
340
343
|
end
|
341
344
|
|
342
345
|
def activate_network
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
raise Errors::ActivateNetworkError, error_message: e.message
|
347
|
-
end
|
346
|
+
@interface_network[:libvirt_network].create
|
347
|
+
rescue => e
|
348
|
+
raise Errors::ActivateNetworkError, error_message: e.message
|
348
349
|
end
|
349
|
-
|
350
350
|
end
|
351
351
|
end
|
352
352
|
end
|
@@ -17,8 +17,9 @@ module VagrantPlugins
|
|
17
17
|
# Fog libvirt currently doesn't support snapshots. Use
|
18
18
|
# ruby-libvirt client directly. Note this is racy, see
|
19
19
|
# http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames
|
20
|
-
libvirt_domain =
|
21
|
-
|
20
|
+
libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
|
21
|
+
env[:machine].id
|
22
|
+
)
|
22
23
|
libvirt_domain.list_snapshots.each do |name|
|
23
24
|
@logger.info("Deleting snapshot '#{name}'")
|
24
25
|
begin
|
@@ -29,14 +30,12 @@ module VagrantPlugins
|
|
29
30
|
end
|
30
31
|
|
31
32
|
# must remove managed saves
|
32
|
-
if libvirt_domain.has_managed_save?
|
33
|
-
libvirt_domain.managed_save_remove
|
34
|
-
end
|
33
|
+
libvirt_domain.managed_save_remove if libvirt_domain.has_managed_save?
|
35
34
|
|
36
35
|
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
37
36
|
|
38
|
-
if env[:machine].provider_config.disks.empty?
|
39
|
-
|
37
|
+
if env[:machine].provider_config.disks.empty? &&
|
38
|
+
env[:machine].provider_config.cdroms.empty?
|
40
39
|
# if using default configuration of disks and cdroms
|
41
40
|
# cdroms are consider volumes, but cannot be destroyed
|
42
41
|
domain.destroy(destroy_volumes: true)
|
@@ -56,7 +55,7 @@ module VagrantPlugins
|
|
56
55
|
elsif disk[:path]
|
57
56
|
poolname = env[:machine].provider_config.storage_pool_name
|
58
57
|
libvirt_disk = domain.volumes.select do |x|
|
59
|
-
# FIXME can remove pool/target.img and pool/123/target.img
|
58
|
+
# FIXME: can remove pool/target.img and pool/123/target.img
|
60
59
|
x.path =~ /\/#{disk[:path]}$/ && x.pool_name == poolname
|
61
60
|
end.first
|
62
61
|
libvirt_disk.destroy if libvirt_disk
|
@@ -7,8 +7,7 @@ module VagrantPlugins
|
|
7
7
|
# Destroy all networks created for this specific domain. Skip
|
8
8
|
# removing if network has still active connections.
|
9
9
|
class DestroyNetworks
|
10
|
-
|
11
|
-
def initialize(app, env)
|
10
|
+
def initialize(app, _env)
|
12
11
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_networks')
|
13
12
|
@app = app
|
14
13
|
end
|
@@ -37,11 +36,12 @@ module VagrantPlugins
|
|
37
36
|
# if there is an error or if the network just doesn't exist
|
38
37
|
begin
|
39
38
|
libvirt_network = env[:machine].provider.driver.connection.client.lookup_network_by_uuid(
|
40
|
-
network_uuid
|
39
|
+
network_uuid
|
40
|
+
)
|
41
41
|
rescue Libvirt::RetrieveError => e
|
42
42
|
# this network is already destroyed, so move on
|
43
43
|
if e.message =~ /Network not found/
|
44
|
-
@logger.info
|
44
|
+
@logger.info 'It is already undefined'
|
45
45
|
next
|
46
46
|
# some other error occured, so raise it again
|
47
47
|
else
|
@@ -52,38 +52,37 @@ module VagrantPlugins
|
|
52
52
|
# Skip removing if network has still active connections.
|
53
53
|
xml = Nokogiri::XML(libvirt_network.xml_desc)
|
54
54
|
connections = xml.xpath('/network/@connections').first
|
55
|
-
|
56
|
-
@logger.info
|
55
|
+
unless connections.nil?
|
56
|
+
@logger.info 'Still has connections so will not undefine'
|
57
57
|
created_networks << network_uuid
|
58
58
|
next
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
61
|
# Shutdown network first.
|
63
62
|
# Undefine network.
|
64
63
|
begin
|
65
64
|
libvirt_network.destroy
|
66
65
|
libvirt_network.undefine
|
67
|
-
@logger.info
|
66
|
+
@logger.info 'Undefined it'
|
68
67
|
rescue => e
|
69
68
|
raise Errors::DestroyNetworkError,
|
70
|
-
|
71
|
-
|
69
|
+
network_name: libvirt_network.name,
|
70
|
+
error_message: e.message
|
72
71
|
end
|
73
72
|
end
|
74
73
|
file.close
|
75
74
|
|
76
75
|
# Update status of created networks after removing some/all of them.
|
77
76
|
# Not sure why we are doing this, something else seems to always delete the file
|
78
|
-
if created_networks.
|
77
|
+
if !created_networks.empty?
|
79
78
|
File.open(created_networks_file, 'w') do |file|
|
80
|
-
@logger.info
|
79
|
+
@logger.info 'Writing new created_networks file'
|
81
80
|
created_networks.each do |network_uuid|
|
82
81
|
file.puts network_uuid
|
83
82
|
end
|
84
83
|
end
|
85
84
|
else
|
86
|
-
@logger.info
|
85
|
+
@logger.info 'Deleting created_networks file'
|
87
86
|
File.delete(created_networks_file)
|
88
87
|
end
|
89
88
|
|
@@ -5,7 +5,7 @@ module VagrantPlugins
|
|
5
5
|
class ForwardPorts
|
6
6
|
@@lock = Mutex.new
|
7
7
|
|
8
|
-
def initialize(app,
|
8
|
+
def initialize(app, _env)
|
9
9
|
@app = app
|
10
10
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::forward_ports')
|
11
11
|
end
|
@@ -18,12 +18,11 @@ module VagrantPlugins
|
|
18
18
|
|
19
19
|
# Warn if we're port forwarding to any privileged ports
|
20
20
|
env[:forwarded_ports].each do |fp|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
21
|
+
next unless fp[:host] <= 1024
|
22
|
+
env[:ui].warn I18n.t(
|
23
|
+
'vagrant.actions.vm.forward_ports.privileged_ports'
|
24
|
+
)
|
25
|
+
break
|
27
26
|
end
|
28
27
|
|
29
28
|
# Continue, we need the VM to be booted in order to grab its IP
|
@@ -44,8 +43,8 @@ module VagrantPlugins
|
|
44
43
|
}
|
45
44
|
|
46
45
|
@env[:ui].info(I18n.t(
|
47
|
-
|
48
|
-
|
46
|
+
'vagrant.actions.vm.forward_ports.forwarding_entry',
|
47
|
+
message_attributes
|
49
48
|
))
|
50
49
|
|
51
50
|
ssh_pid = redirect_port(
|
@@ -68,12 +67,11 @@ module VagrantPlugins
|
|
68
67
|
config.vm.networks.each do |type, options|
|
69
68
|
next if options[:disabled]
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
mappings[options[:host]] = options
|
70
|
+
next unless type == :forwarded_port && options[:id] != 'ssh'
|
71
|
+
if options.fetch(:host_ip, '').to_s.strip.empty?
|
72
|
+
options.delete(:host_ip)
|
76
73
|
end
|
74
|
+
mappings[options[:host]] = options
|
77
75
|
end
|
78
76
|
|
79
77
|
mappings.values
|
@@ -98,8 +96,8 @@ module VagrantPlugins
|
|
98
96
|
PasswordAuthentication=no
|
99
97
|
ForwardX11=#{ssh_info[:forward_x11] ? 'yes' : 'no'}
|
100
98
|
) + ssh_info[:private_key_path].map do |pk|
|
101
|
-
|
102
|
-
|
99
|
+
"IdentityFile='\"#{pk}\"'"
|
100
|
+
end).map { |s| s.prepend('-o ') }.join(' ')
|
103
101
|
|
104
102
|
options += " -o ProxyCommand=\"#{ssh_info[:proxy_command]}\"" if machine.provider_config.connect_via_ssh
|
105
103
|
|
@@ -111,7 +109,7 @@ module VagrantPlugins
|
|
111
109
|
@env[:ui].info 'Requesting sudo for host port(s) <= 1024'
|
112
110
|
r = system('sudo -v')
|
113
111
|
if r
|
114
|
-
ssh_cmd << 'sudo '
|
112
|
+
ssh_cmd << 'sudo ' # add sudo prefix
|
115
113
|
end
|
116
114
|
end
|
117
115
|
end
|
@@ -122,7 +120,7 @@ module VagrantPlugins
|
|
122
120
|
log_file = ssh_forward_log_file(host_ip, host_port,
|
123
121
|
guest_ip, guest_port)
|
124
122
|
@logger.info "Logging to #{log_file}"
|
125
|
-
spawn(ssh_cmd,
|
123
|
+
spawn(ssh_cmd, [:out, :err] => [log_file, 'w'])
|
126
124
|
end
|
127
125
|
|
128
126
|
def ssh_forward_log_file(host_ip, host_port, guest_ip, guest_port)
|
@@ -131,7 +129,7 @@ module VagrantPlugins
|
|
131
129
|
File.join(
|
132
130
|
log_dir,
|
133
131
|
'ssh-forwarding-%s_%s-%s_%s.log' %
|
134
|
-
[
|
132
|
+
[host_ip, host_port, guest_ip, guest_port]
|
135
133
|
)
|
136
134
|
end
|
137
135
|
|
@@ -155,7 +153,7 @@ module VagrantPlugins
|
|
155
153
|
class ClearForwardedPorts
|
156
154
|
@@lock = Mutex.new
|
157
155
|
|
158
|
-
def initialize(app,
|
156
|
+
def initialize(app, _env)
|
159
157
|
@app = app
|
160
158
|
@logger = Log4r::Logger.new(
|
161
159
|
'vagrant_libvirt::action::clear_forward_ports'
|
@@ -175,7 +173,7 @@ module VagrantPlugins
|
|
175
173
|
kill_cmd = ''
|
176
174
|
|
177
175
|
if tag[:port] <= 1024
|
178
|
-
kill_cmd << 'sudo '
|
176
|
+
kill_cmd << 'sudo ' # add sudo prefix
|
179
177
|
end
|
180
178
|
|
181
179
|
kill_cmd << "kill #{tag[:pid]}"
|
@@ -199,8 +197,8 @@ module VagrantPlugins
|
|
199
197
|
glob = @env[:machine].data_dir.join('pids').to_s + '/ssh_*.pid'
|
200
198
|
@ssh_pids = Dir[glob].map do |file|
|
201
199
|
{
|
202
|
-
:
|
203
|
-
:
|
200
|
+
pid: File.read(file).strip.chomp,
|
201
|
+
port: File.basename(file)['ssh_'.length..-1 * ('.pid'.length + 1)].to_i
|
204
202
|
}
|
205
203
|
end
|
206
204
|
end
|
@@ -5,25 +5,25 @@ module VagrantPlugins
|
|
5
5
|
module Action
|
6
6
|
# Halt the domain.
|
7
7
|
class HaltDomain
|
8
|
-
def initialize(app,
|
9
|
-
@logger = Log4r::Logger.new(
|
8
|
+
def initialize(app, _env)
|
9
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::action::halt_domain')
|
10
10
|
@app = app
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
-
env[:ui].info(I18n.t(
|
14
|
+
env[:ui].info(I18n.t('vagrant_libvirt.halt_domain'))
|
15
15
|
|
16
16
|
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
17
|
-
raise Errors::NoDomainError if domain
|
17
|
+
raise Errors::NoDomainError if domain.nil?
|
18
18
|
|
19
|
-
@logger.info(
|
19
|
+
@logger.info('Trying gracefull shutdown.')
|
20
20
|
domain.shutdown
|
21
21
|
begin
|
22
|
-
domain.wait_for(30)
|
22
|
+
domain.wait_for(30) do
|
23
23
|
!ready?
|
24
|
-
|
24
|
+
end
|
25
25
|
rescue Fog::Errors::TimeoutError
|
26
|
-
@logger.info(
|
26
|
+
@logger.info('VM is still running. Calling force poweroff.')
|
27
27
|
domain.poweroff
|
28
28
|
end
|
29
29
|
|
@@ -33,4 +33,3 @@ module VagrantPlugins
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|