vagrant-libvirt 0.12.0 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/stackprof-flamegraph.pl +29 -0
- data/bin/stackprof-gprof2dot.py +29 -0
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +3 -70
- data/lib/vagrant-libvirt/action/start_domain.rb +39 -6
- data/lib/vagrant-libvirt/config.rb +20 -15
- data/lib/vagrant-libvirt/util/hash_with_blank_filter.rb +22 -0
- data/lib/vagrant-libvirt/util/network_util.rb +71 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/spec/unit/action/create_network_interfaces.rb +50 -0
- data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +6 -0
- data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +6 -0
- data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +6 -0
- data/spec/unit/action/start_domain_spec/default.xml +6 -0
- data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +6 -0
- data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +6 -0
- data/spec/unit/action/start_domain_spec/default_with_different_formatting.xml +6 -0
- data/spec/unit/action/start_domain_spec/existing_with_iommu.xml +64 -0
- data/spec/unit/action/start_domain_spec/existing_with_two_interfaces_iommu.xml +71 -0
- data/spec/unit/action/start_domain_spec.rb +103 -0
- data/spec/unit/provider_spec.rb +11 -0
- data/spec/unit/util/network_util_spec.rb +135 -11
- metadata +14 -4
- data/lib/vagrant-libvirt/action/destroy_domain_confirm.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0825408b8026061a93791df6756ce840683b4ac6a314cfec9ac1254b5ebb35d7'
|
4
|
+
data.tar.gz: 6c933dfb97f1e8cf9c5ce3e14ecdef59abbdd6dac4d9822e712571634b0d3d3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b73ba987dd3e61e77062c36f995da22d4b934ccd78ba0cc6b3a083f6623bf99198c523bf38a9f6152c4fc958a36eb89afdd521c9b50af7dce819fdd1aa400a8
|
7
|
+
data.tar.gz: 174c59f4549f98b73987e5b308c3d52161ec54e2265838c143834ca7e90bfe4646c90e495520b660b201d094ef2634b082daeec2d4ed47c9948b8a4899d7102e
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'stackprof-flamegraph.pl' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../SynologyDrive/git/github.com/vagrant-libvirt/vagrant-libvirt/Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("vagrant-libvirt", "stackprof-flamegraph.pl")
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'stackprof-gprof2dot.py' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../SynologyDrive/git/github.com/vagrant-libvirt/vagrant-libvirt/Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("vagrant-libvirt", "stackprof-gprof2dot.py")
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'log4r'
|
4
|
-
require 'vagrant/util/network_ip'
|
5
|
-
require 'vagrant/util/scoped_hash_override'
|
6
4
|
|
7
5
|
require 'vagrant-libvirt/util/erb_template'
|
8
6
|
require 'vagrant-libvirt/util/network_util'
|
@@ -15,15 +13,12 @@ module VagrantPlugins
|
|
15
13
|
class CreateNetworkInterfaces
|
16
14
|
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
17
15
|
include VagrantPlugins::ProviderLibvirt::Util::NetworkUtil
|
18
|
-
include Vagrant::Util::NetworkIP
|
19
|
-
include Vagrant::Util::ScopedHashOverride
|
20
16
|
|
21
17
|
def initialize(app, env)
|
22
18
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::create_network_interfaces')
|
23
19
|
@management_network_name = env[:machine].provider_config.management_network_name
|
24
20
|
config = env[:machine].provider_config
|
25
|
-
@nic_model_type = config.nic_model_type
|
26
|
-
@nic_adapter_count = config.nic_adapter_count
|
21
|
+
@nic_model_type = config.nic_model_type
|
27
22
|
@app = app
|
28
23
|
end
|
29
24
|
|
@@ -39,34 +34,7 @@ module VagrantPlugins
|
|
39
34
|
end
|
40
35
|
|
41
36
|
# Setup list of interfaces before creating them.
|
42
|
-
adapters = []
|
43
|
-
|
44
|
-
# Vagrant gives you adapter 0 by default
|
45
|
-
# Assign interfaces to slots.
|
46
|
-
configured_networks(env[:machine], @logger).each do |options|
|
47
|
-
# don't need to create interface for this type
|
48
|
-
next if options[:iface_type] == :forwarded_port
|
49
|
-
|
50
|
-
# TODO: fill first ifaces with adapter option specified.
|
51
|
-
if options[:adapter]
|
52
|
-
if adapters[options[:adapter]]
|
53
|
-
raise Errors::InterfaceSlotNotAvailable
|
54
|
-
end
|
55
|
-
|
56
|
-
free_slot = options[:adapter].to_i
|
57
|
-
@logger.debug "Using specified adapter slot #{free_slot}"
|
58
|
-
else
|
59
|
-
free_slot = find_empty(adapters)
|
60
|
-
@logger.debug "Adapter not specified so found slot #{free_slot}"
|
61
|
-
raise Errors::InterfaceSlotExhausted if free_slot.nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
# We have slot for interface, fill it with interface configuration.
|
65
|
-
adapters[free_slot] = options
|
66
|
-
adapters[free_slot][:network_name] = interface_network(
|
67
|
-
env[:machine].provider.driver, adapters[free_slot]
|
68
|
-
)
|
69
|
-
end
|
37
|
+
adapters = network_interfaces(env[:machine], @logger)
|
70
38
|
|
71
39
|
# Create each interface as new domain device.
|
72
40
|
@macs_per_network = Hash.new(0)
|
@@ -81,7 +49,7 @@ module VagrantPlugins
|
|
81
49
|
@driver_name = iface_configuration.fetch(:driver_name, false)
|
82
50
|
@driver_iommu = iface_configuration.fetch(:driver_iommu, false )
|
83
51
|
@driver_queues = iface_configuration.fetch(:driver_queues, false)
|
84
|
-
@device_name = iface_configuration.fetch(:iface_name,
|
52
|
+
@device_name = iface_configuration.fetch(:iface_name, nil)
|
85
53
|
@mtu = iface_configuration.fetch(:mtu, nil)
|
86
54
|
@pci_bus = iface_configuration.fetch(:bus, nil)
|
87
55
|
@pci_slot = iface_configuration.fetch(:slot, nil)
|
@@ -286,41 +254,6 @@ module VagrantPlugins
|
|
286
254
|
Nokogiri::XML::Node::SaveOptions::FORMAT
|
287
255
|
)
|
288
256
|
end
|
289
|
-
|
290
|
-
def find_empty(array, start = 0, stop = @nic_adapter_count)
|
291
|
-
(start..stop).each do |i|
|
292
|
-
return i unless array[i]
|
293
|
-
end
|
294
|
-
nil
|
295
|
-
end
|
296
|
-
|
297
|
-
# Return network name according to interface options.
|
298
|
-
def interface_network(driver, options)
|
299
|
-
# no need to get interface network for tcp tunnel config
|
300
|
-
return 'tunnel_interface' if options.fetch(:tunnel_type, nil)
|
301
|
-
|
302
|
-
if options[:network_name]
|
303
|
-
@logger.debug 'Found network by name'
|
304
|
-
return options[:network_name]
|
305
|
-
end
|
306
|
-
|
307
|
-
# Get list of all (active and inactive) Libvirt networks.
|
308
|
-
available_networks = libvirt_networks(driver)
|
309
|
-
|
310
|
-
return 'public' if options[:iface_type] == :public_network
|
311
|
-
|
312
|
-
if options[:ip]
|
313
|
-
address = network_address(options[:ip], options[:netmask])
|
314
|
-
available_networks.each do |network|
|
315
|
-
if address == network[:network_address]
|
316
|
-
@logger.debug 'Found network by ip'
|
317
|
-
return network[:name]
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
raise Errors::NetworkNotAvailableError, network_name: options[:ip]
|
323
|
-
end
|
324
257
|
end
|
325
258
|
end
|
326
259
|
end
|
@@ -6,6 +6,7 @@ require 'rexml/document'
|
|
6
6
|
require 'rexml/formatters/pretty'
|
7
7
|
require 'rexml/xpath'
|
8
8
|
|
9
|
+
require 'vagrant-libvirt/util/network_util'
|
9
10
|
require 'vagrant-libvirt/util/xml'
|
10
11
|
|
11
12
|
module VagrantPlugins
|
@@ -13,9 +14,11 @@ module VagrantPlugins
|
|
13
14
|
module Action
|
14
15
|
# Just start the domain.
|
15
16
|
class StartDomain
|
17
|
+
include VagrantPlugins::ProviderLibvirt::Util::NetworkUtil
|
16
18
|
|
17
|
-
def initialize(app,
|
19
|
+
def initialize(app, env)
|
18
20
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::start_domain')
|
21
|
+
config = env[:machine].provider_config
|
19
22
|
@app = app
|
20
23
|
end
|
21
24
|
|
@@ -68,14 +71,44 @@ module VagrantPlugins
|
|
68
71
|
end
|
69
72
|
|
70
73
|
# Interface type
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
adapters = network_interfaces(env[:machine], @logger)
|
75
|
+
index = 0
|
76
|
+
REXML::XPath.each(xml_descr, '/domain/devices/interface') do |iface|
|
77
|
+
# initial config defaults
|
78
|
+
nic_model_type = index == 0 && config.mgmt_attach ? config.management_network_model_type : config.nic_model_type
|
79
|
+
driver_iommu = index == 0 && config.mgmt_attach ? config.management_network_driver_iommu : false
|
80
|
+
# resolve per adapter option
|
81
|
+
if index < adapters.length
|
82
|
+
nic_model_type = adapters[index].fetch(:model_type, nic_model_type)
|
83
|
+
driver_iommu = adapters[index].fetch(:driver_iommu, driver_iommu )
|
84
|
+
end
|
85
|
+
|
86
|
+
iface_model = iface.elements['model']
|
87
|
+
if iface_model.attributes['type'] != nic_model_type
|
88
|
+
@logger.debug "network type updated from '#{iface_model.attributes['type']}' to '#{nic_model_type}'"
|
89
|
+
descr_changed = true
|
90
|
+
iface_model.attributes['type'] = nic_model_type
|
91
|
+
end
|
92
|
+
|
93
|
+
iface_driver = iface.elements['driver'] || REXML::Element.new('driver', iface)
|
94
|
+
|
95
|
+
if nic_model_type == 'virtio'
|
96
|
+
iommu = driver_iommu ? 'on': 'off'
|
97
|
+
if !iface_driver.attributes['iommu'].nil? && !driver_iommu.nil? && iface_driver.attributes['iommu'] != iommu
|
75
98
|
descr_changed = true
|
76
|
-
|
99
|
+
iface_driver.attributes['iommu'] = iommu
|
100
|
+
end
|
101
|
+
else
|
102
|
+
if !iface_driver.nil?
|
103
|
+
descr_changed = true if iface_driver.attributes['iommu']
|
104
|
+
iface_driver.attributes.delete('iommu')
|
77
105
|
end
|
78
106
|
end
|
107
|
+
iface.delete_element(iface_driver) if iface_driver.attributes.empty?
|
108
|
+
index += 1
|
109
|
+
end
|
110
|
+
if adapters.length != index
|
111
|
+
env[:ui].warn("number of network adapters in current config (#{adapters.length}) is different to attached interfaces (#{index}), may have incorrectly updated")
|
79
112
|
end
|
80
113
|
|
81
114
|
# vCpu count
|
@@ -70,6 +70,7 @@ module VagrantPlugins
|
|
70
70
|
attr_accessor :management_network_mtu
|
71
71
|
attr_accessor :management_network_keep
|
72
72
|
attr_accessor :management_network_driver_iommu
|
73
|
+
attr_accessor :management_network_iface_name
|
73
74
|
attr_accessor :management_network_model_type
|
74
75
|
|
75
76
|
# System connection information
|
@@ -258,6 +259,7 @@ module VagrantPlugins
|
|
258
259
|
@management_network_mtu = UNSET_VALUE
|
259
260
|
@management_network_keep = UNSET_VALUE
|
260
261
|
@management_network_driver_iommu = UNSET_VALUE
|
262
|
+
@management_network_iface_name = UNSET_VALUE
|
261
263
|
@management_network_model_type = UNSET_VALUE
|
262
264
|
|
263
265
|
# System connection information
|
@@ -960,20 +962,6 @@ module VagrantPlugins
|
|
960
962
|
@snapshot_pool_name = @storage_pool_name if @snapshot_pool_name == UNSET_VALUE
|
961
963
|
@storage_pool_path = nil if @storage_pool_path == UNSET_VALUE
|
962
964
|
@random_hostname = false if @random_hostname == UNSET_VALUE
|
963
|
-
@management_network_device = 'virbr0' if @management_network_device == UNSET_VALUE
|
964
|
-
@management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
|
965
|
-
@management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE
|
966
|
-
@management_network_mode = 'nat' if @management_network_mode == UNSET_VALUE
|
967
|
-
@management_network_mac = nil if @management_network_mac == UNSET_VALUE
|
968
|
-
@management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE
|
969
|
-
@management_network_autostart = false if @management_network_autostart == UNSET_VALUE
|
970
|
-
@management_network_pci_bus = nil if @management_network_pci_bus == UNSET_VALUE
|
971
|
-
@management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE
|
972
|
-
@management_network_domain = nil if @management_network_domain == UNSET_VALUE
|
973
|
-
@management_network_mtu = nil if @management_network_mtu == UNSET_VALUE
|
974
|
-
@management_network_keep = false if @management_network_keep == UNSET_VALUE
|
975
|
-
@management_network_driver_iommu = false if @management_network_driver_iommu == UNSET_VALUE
|
976
|
-
@management_network_model_type = 'virtio' if @management_network_model_type == UNSET_VALUE
|
977
965
|
|
978
966
|
# Domain specific settings.
|
979
967
|
@title = '' if @title == UNSET_VALUE
|
@@ -1032,7 +1020,7 @@ module VagrantPlugins
|
|
1032
1020
|
end
|
1033
1021
|
@disk_address_type = nil if @disk_address_type == UNSET_VALUE
|
1034
1022
|
@disk_driver_opts = {} if @disk_driver_opts == UNSET_VALUE
|
1035
|
-
@nic_model_type =
|
1023
|
+
@nic_model_type = 'virtio' if @nic_model_type == UNSET_VALUE
|
1036
1024
|
@nested = false if @nested == UNSET_VALUE
|
1037
1025
|
@volume_cache = nil if @volume_cache == UNSET_VALUE
|
1038
1026
|
@kernel = nil if @kernel == UNSET_VALUE
|
@@ -1147,6 +1135,23 @@ module VagrantPlugins
|
|
1147
1135
|
|
1148
1136
|
@serials = [{:type => 'pty', :source => nil}] if @serials == UNSET_VALUE
|
1149
1137
|
|
1138
|
+
# management network options
|
1139
|
+
@management_network_device = 'virbr0' if @management_network_device == UNSET_VALUE
|
1140
|
+
@management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
|
1141
|
+
@management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE
|
1142
|
+
@management_network_mode = 'nat' if @management_network_mode == UNSET_VALUE
|
1143
|
+
@management_network_mac = nil if @management_network_mac == UNSET_VALUE
|
1144
|
+
@management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE
|
1145
|
+
@management_network_autostart = false if @management_network_autostart == UNSET_VALUE
|
1146
|
+
@management_network_pci_bus = nil if @management_network_pci_bus == UNSET_VALUE
|
1147
|
+
@management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE
|
1148
|
+
@management_network_domain = nil if @management_network_domain == UNSET_VALUE
|
1149
|
+
@management_network_mtu = nil if @management_network_mtu == UNSET_VALUE
|
1150
|
+
@management_network_keep = false if @management_network_keep == UNSET_VALUE
|
1151
|
+
@management_network_driver_iommu = false if @management_network_driver_iommu == UNSET_VALUE
|
1152
|
+
@management_network_iface_name = nil if @management_network_iface_name == UNSET_VALUE
|
1153
|
+
@management_network_model_type = @nic_model_type if @management_network_model_type == UNSET_VALUE
|
1154
|
+
|
1150
1155
|
@host_device_exclude_prefixes = ['docker', 'macvtap', 'virbr', 'vnet'] if @host_device_exclude_prefixes == UNSET_VALUE
|
1151
1156
|
end
|
1152
1157
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'vagrant/util/hash_with_indifferent_access'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module VagrantLibvirt
|
5
|
+
module Util
|
6
|
+
class HashWithCompactBlank < ::Vagrant::Util::HashWithIndifferentAccess
|
7
|
+
def compact_blank
|
8
|
+
copy = self.dup
|
9
|
+
copy.each do |k, _v|
|
10
|
+
if copy[k].respond_to(:compact_blank)
|
11
|
+
copy[k].compact_blank
|
12
|
+
elsif copy[k].respond_to(:each_pair)
|
13
|
+
copy[k].delete_if { |_k, v| v.to_s.empty? }
|
14
|
+
else
|
15
|
+
copy[k].reject! { |e| e.to_s.empty? }
|
16
|
+
end
|
17
|
+
end.delete_if { |_k, v| v.empty? }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'ipaddr'
|
4
4
|
require 'nokogiri'
|
5
5
|
require 'vagrant/util/network_ip'
|
6
|
+
require 'vagrant/util/scoped_hash_override'
|
6
7
|
|
7
8
|
class IPAddr
|
8
9
|
def get_mask
|
@@ -17,6 +18,39 @@ module VagrantPlugins
|
|
17
18
|
module Util
|
18
19
|
module NetworkUtil
|
19
20
|
include Vagrant::Util::NetworkIP
|
21
|
+
include Vagrant::Util::ScopedHashOverride
|
22
|
+
|
23
|
+
def network_interfaces(machine, logger)
|
24
|
+
# Setup list of interfaces before creating them.
|
25
|
+
adapters = []
|
26
|
+
|
27
|
+
# Vagrant gives you adapter 0 by default
|
28
|
+
# Assign interfaces to slots.
|
29
|
+
configured_networks(machine, logger).each do |options|
|
30
|
+
# don't need to create interface for this type
|
31
|
+
next if options[:iface_type] == :forwarded_port
|
32
|
+
|
33
|
+
# TODO: fill first ifaces with adapter option specified.
|
34
|
+
if options[:adapter]
|
35
|
+
if adapters[options[:adapter]]
|
36
|
+
raise Errors::InterfaceSlotNotAvailable
|
37
|
+
end
|
38
|
+
|
39
|
+
free_slot = options[:adapter].to_i
|
40
|
+
@logger.debug "Using specified adapter slot #{free_slot}"
|
41
|
+
else
|
42
|
+
free_slot = find_empty(adapters, 0, machine.provider_config.nic_adapter_count)
|
43
|
+
@logger.debug "Adapter not specified so found slot #{free_slot}"
|
44
|
+
raise Errors::InterfaceSlotExhausted if free_slot.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
# We have slot for interface, fill it with interface configuration.
|
48
|
+
adapters[free_slot] = options
|
49
|
+
adapters[free_slot][:network_name] = interface_network(machine.provider.driver, adapters[free_slot])
|
50
|
+
end
|
51
|
+
|
52
|
+
adapters
|
53
|
+
end
|
20
54
|
|
21
55
|
def configured_networks(machine, logger)
|
22
56
|
qemu_use_session = machine.provider_config.qemu_use_session
|
@@ -34,6 +68,7 @@ module VagrantPlugins
|
|
34
68
|
management_network_mtu = machine.provider_config.management_network_mtu
|
35
69
|
management_network_keep = machine.provider_config.management_network_keep
|
36
70
|
management_network_driver_iommu = machine.provider_config.management_network_driver_iommu
|
71
|
+
management_network_iface_name = machine.provider_config.management_network_iface_name
|
37
72
|
management_network_model_type = machine.provider_config.management_network_model_type
|
38
73
|
logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode"
|
39
74
|
|
@@ -79,6 +114,7 @@ module VagrantPlugins
|
|
79
114
|
end
|
80
115
|
|
81
116
|
management_network_options[:driver_iommu] = management_network_driver_iommu
|
117
|
+
management_network_options[:iface_name] = management_network_iface_name
|
82
118
|
|
83
119
|
unless management_network_mac.nil?
|
84
120
|
management_network_options[:mac] = management_network_mac
|
@@ -196,6 +232,41 @@ module VagrantPlugins
|
|
196
232
|
|
197
233
|
libvirt_networks
|
198
234
|
end
|
235
|
+
|
236
|
+
def find_empty(array, start, stop)
|
237
|
+
(start..stop).each do |i|
|
238
|
+
return i unless array[i]
|
239
|
+
end
|
240
|
+
nil
|
241
|
+
end
|
242
|
+
|
243
|
+
# Return network name according to interface options.
|
244
|
+
def interface_network(driver, options)
|
245
|
+
# no need to get interface network for tcp tunnel config
|
246
|
+
return 'tunnel_interface' if options.fetch(:tunnel_type, nil)
|
247
|
+
|
248
|
+
if options[:network_name]
|
249
|
+
@logger.debug 'Found network by name'
|
250
|
+
return options[:network_name]
|
251
|
+
end
|
252
|
+
|
253
|
+
# Get list of all (active and inactive) Libvirt networks.
|
254
|
+
available_networks = libvirt_networks(driver)
|
255
|
+
|
256
|
+
return 'public' if options[:iface_type] == :public_network
|
257
|
+
|
258
|
+
if options[:ip]
|
259
|
+
address = network_address(options[:ip], options[:netmask])
|
260
|
+
available_networks.each do |network|
|
261
|
+
if address == network[:network_address]
|
262
|
+
@logger.debug 'Found network by ip'
|
263
|
+
return network[:name]
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
raise Errors::NetworkNotAvailableError, network_name: options[:ip]
|
269
|
+
end
|
199
270
|
end
|
200
271
|
end
|
201
272
|
end
|
data/lib/vagrant-libvirt/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.12.
|
1
|
+
0.12.2
|
@@ -92,6 +92,56 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateNetworkInterfaces do
|
|
92
92
|
expect(subject.call(env)).to be_nil
|
93
93
|
end
|
94
94
|
|
95
|
+
context 'management network' do
|
96
|
+
let(:domain_xml) {
|
97
|
+
# don't need full domain here, just enough for the network element to work
|
98
|
+
<<-EOF.unindent
|
99
|
+
<domain type='qemu'>
|
100
|
+
<devices>
|
101
|
+
<interface type='network'>
|
102
|
+
<alias name='ua-net-0'/>
|
103
|
+
<mac address='52:54:00:7d:14:0e'/>
|
104
|
+
<source network='vagrant-libvirt'/>
|
105
|
+
<target dev="myvnet0"></target>
|
106
|
+
<model type='virtio'/>
|
107
|
+
<driver iommu='off'/>
|
108
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
109
|
+
</interface>
|
110
|
+
</devices>
|
111
|
+
</domain>
|
112
|
+
EOF
|
113
|
+
}
|
114
|
+
|
115
|
+
before do
|
116
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when iface name is set' do
|
120
|
+
let(:vagrantfile_providerconfig) {
|
121
|
+
<<-EOF
|
122
|
+
libvirt.management_network_iface_name = 'myvnet0'
|
123
|
+
EOF
|
124
|
+
}
|
125
|
+
let(:management_nic_xml) {
|
126
|
+
<<-EOF.unindent
|
127
|
+
<interface type="network">
|
128
|
+
<alias name="ua-net-0"></alias>
|
129
|
+
<source network="vagrant-libvirt"></source>
|
130
|
+
<target dev="myvnet0"></target>
|
131
|
+
<model type="virtio"></model>
|
132
|
+
<driver iommu="off"></driver>
|
133
|
+
</interface>
|
134
|
+
EOF
|
135
|
+
}
|
136
|
+
|
137
|
+
it 'should set target appropriately' do
|
138
|
+
expect(driver).to receive(:attach_device).with(management_nic_xml)
|
139
|
+
|
140
|
+
expect(subject.call(env)).to be_nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
95
145
|
context 'private network' do
|
96
146
|
let(:vagrantfile) do
|
97
147
|
<<-EOF
|
@@ -23,6 +23,12 @@
|
|
23
23
|
|
24
24
|
</clock>
|
25
25
|
<devices>
|
26
|
+
<interface type='network'>
|
27
|
+
<alias name='ua-net-0'/>
|
28
|
+
<source network='vagrant-libvirt'/>
|
29
|
+
<model type='virtio'/>
|
30
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
31
|
+
</interface>
|
26
32
|
<serial type='pty'>
|
27
33
|
<target port='0'/>
|
28
34
|
</serial>
|
@@ -23,6 +23,12 @@
|
|
23
23
|
<timer name='rtc'/>
|
24
24
|
</clock>
|
25
25
|
<devices>
|
26
|
+
<interface type='network'>
|
27
|
+
<alias name='ua-net-0'/>
|
28
|
+
<source network='vagrant-libvirt'/>
|
29
|
+
<model type='virtio'/>
|
30
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
31
|
+
</interface>
|
26
32
|
<serial type='pty'>
|
27
33
|
<target port='0'/>
|
28
34
|
</serial>
|
@@ -24,6 +24,12 @@
|
|
24
24
|
<timer name='tsc'/>
|
25
25
|
</clock>
|
26
26
|
<devices>
|
27
|
+
<interface type='network'>
|
28
|
+
<alias name='ua-net-0'/>
|
29
|
+
<source network='vagrant-libvirt'/>
|
30
|
+
<model type='virtio'/>
|
31
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
32
|
+
</interface>
|
27
33
|
<serial type='pty'>
|
28
34
|
<target port='0'/>
|
29
35
|
</serial>
|
@@ -21,6 +21,12 @@
|
|
21
21
|
</features>
|
22
22
|
<clock offset='utc'/>
|
23
23
|
<devices>
|
24
|
+
<interface type='network'>
|
25
|
+
<alias name='ua-net-0'/>
|
26
|
+
<source network='vagrant-libvirt'/>
|
27
|
+
<model type='virtio'/>
|
28
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
29
|
+
</interface>
|
24
30
|
<serial type='pty'>
|
25
31
|
<target port='0'/>
|
26
32
|
</serial>
|
@@ -21,6 +21,12 @@
|
|
21
21
|
</features>
|
22
22
|
<clock offset='utc'/>
|
23
23
|
<devices>
|
24
|
+
<interface type='network'>
|
25
|
+
<alias name='ua-net-0'/>
|
26
|
+
<source network='vagrant-libvirt'/>
|
27
|
+
<model type='virtio'/>
|
28
|
+
<address bus='0x00' domain='0x0000' function='0x0' slot='0x05' type='pci'/>
|
29
|
+
</interface>
|
24
30
|
<serial type='pty'>
|
25
31
|
<target port='0'/>
|
26
32
|
</serial>
|
@@ -21,6 +21,12 @@
|
|
21
21
|
</features>
|
22
22
|
<clock offset='utc'/>
|
23
23
|
<devices>
|
24
|
+
<interface type='network'>
|
25
|
+
<alias name='ua-net-0'/>
|
26
|
+
<source network='vagrant-libvirt'/>
|
27
|
+
<model type='virtio'/>
|
28
|
+
<address bus='0x00' domain='0x0000' function='0x0' slot='0x05' type='pci'/>
|
29
|
+
</interface>
|
24
30
|
<serial type='pty'>
|
25
31
|
<target port='0'/>
|
26
32
|
</serial>
|
@@ -22,6 +22,12 @@
|
|
22
22
|
</features>
|
23
23
|
<clock offset='utc'/>
|
24
24
|
<devices>
|
25
|
+
<interface type='network'>
|
26
|
+
<alias name='ua-net-0'/>
|
27
|
+
<source network='vagrant-libvirt'/>
|
28
|
+
<model type='virtio'/>
|
29
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
30
|
+
</interface>
|
25
31
|
<serial type='pty'>
|
26
32
|
<target port='0'/>
|
27
33
|
</serial>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<domain type='qemu'>
|
2
|
+
<name>vagrant-libvirt_default</name>
|
3
|
+
<uuid>881a931b-0110-4d10-81aa-47a1a19f5726</uuid>
|
4
|
+
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
5
|
+
<memory unit='KiB'>2097152</memory>
|
6
|
+
<currentMemory unit='KiB'>2097152</currentMemory>
|
7
|
+
<vcpu placement='static'>2</vcpu>
|
8
|
+
<os>
|
9
|
+
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
10
|
+
<bootmenu enable='no'/>
|
11
|
+
<boot dev='hd'/>
|
12
|
+
</os>
|
13
|
+
<features>
|
14
|
+
<acpi/>
|
15
|
+
<apic/>
|
16
|
+
<pae/>
|
17
|
+
</features>
|
18
|
+
<cpu mode='host-model' check='partial'/>
|
19
|
+
<clock offset='utc'/>
|
20
|
+
<on_poweroff>destroy</on_poweroff>
|
21
|
+
<on_reboot>restart</on_reboot>
|
22
|
+
<on_crash>destroy</on_crash>
|
23
|
+
<devices>
|
24
|
+
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<driver name='qemu' type='qcow2'/>
|
27
|
+
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
|
28
|
+
<target dev='vda' bus='virtio'/>
|
29
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
30
|
+
</disk>
|
31
|
+
<controller type='usb' index='0' model='piix3-uhci'>
|
32
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
33
|
+
</controller>
|
34
|
+
<controller type='pci' index='0' model='pci-root'/>
|
35
|
+
<interface type='network'>
|
36
|
+
<alias name='ua-net-0'/>
|
37
|
+
<source network='vagrant-libvirt'/>
|
38
|
+
<model type='virtio'/>
|
39
|
+
<driver iommu='on'/>
|
40
|
+
<address bus='0x00' domain='0x0000' function='0x0' slot='0x05' type='pci'/>
|
41
|
+
</interface>
|
42
|
+
<serial type='pty'>
|
43
|
+
<target type='isa-serial' port='0'>
|
44
|
+
<model name='isa-serial'/>
|
45
|
+
</target>
|
46
|
+
</serial>
|
47
|
+
<console type='pty'>
|
48
|
+
<target type='serial' port='0'/>
|
49
|
+
</console>
|
50
|
+
<input type='mouse' bus='ps2'/>
|
51
|
+
<input type='keyboard' bus='ps2'/>
|
52
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' websocket='-1'>
|
53
|
+
<listen type='address' address='127.0.0.1'/>
|
54
|
+
</graphics>
|
55
|
+
<audio id='1' type='none'/>
|
56
|
+
<video>
|
57
|
+
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
|
58
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
59
|
+
</video>
|
60
|
+
<memballoon model='virtio'>
|
61
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
62
|
+
</memballoon>
|
63
|
+
</devices>
|
64
|
+
</domain>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<domain type='qemu'>
|
2
|
+
<name>vagrant-libvirt_default</name>
|
3
|
+
<uuid>881a931b-0110-4d10-81aa-47a1a19f5726</uuid>
|
4
|
+
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
5
|
+
<memory unit='KiB'>2097152</memory>
|
6
|
+
<currentMemory unit='KiB'>2097152</currentMemory>
|
7
|
+
<vcpu placement='static'>2</vcpu>
|
8
|
+
<os>
|
9
|
+
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
10
|
+
<bootmenu enable='no'/>
|
11
|
+
<boot dev='hd'/>
|
12
|
+
</os>
|
13
|
+
<features>
|
14
|
+
<acpi/>
|
15
|
+
<apic/>
|
16
|
+
<pae/>
|
17
|
+
</features>
|
18
|
+
<cpu mode='host-model' check='partial'/>
|
19
|
+
<clock offset='utc'/>
|
20
|
+
<on_poweroff>destroy</on_poweroff>
|
21
|
+
<on_reboot>restart</on_reboot>
|
22
|
+
<on_crash>destroy</on_crash>
|
23
|
+
<devices>
|
24
|
+
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<driver name='qemu' type='qcow2'/>
|
27
|
+
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
|
28
|
+
<target dev='vda' bus='virtio'/>
|
29
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
30
|
+
</disk>
|
31
|
+
<controller type='usb' index='0' model='piix3-uhci'>
|
32
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
33
|
+
</controller>
|
34
|
+
<controller type='pci' index='0' model='pci-root'/>
|
35
|
+
<interface type='network'>
|
36
|
+
<alias name='ua-net-0'/>
|
37
|
+
<source network='vagrant-libvirt'/>
|
38
|
+
<model type='virtio'/>
|
39
|
+
<driver iommu='on'/>
|
40
|
+
<address bus='0x00' domain='0x0000' function='0x0' slot='0x05' type='pci'/>
|
41
|
+
</interface>
|
42
|
+
<interface type='network'>
|
43
|
+
<alias name='ua-net-1'/>
|
44
|
+
<source network='private'/>
|
45
|
+
<model type='virtio'/>
|
46
|
+
<driver iommu='on'/>
|
47
|
+
<address bus='0x00' domain='0x0000' function='0x0' slot='0x06' type='pci'/>
|
48
|
+
</interface>
|
49
|
+
<serial type='pty'>
|
50
|
+
<target type='isa-serial' port='0'>
|
51
|
+
<model name='isa-serial'/>
|
52
|
+
</target>
|
53
|
+
</serial>
|
54
|
+
<console type='pty'>
|
55
|
+
<target type='serial' port='0'/>
|
56
|
+
</console>
|
57
|
+
<input type='mouse' bus='ps2'/>
|
58
|
+
<input type='keyboard' bus='ps2'/>
|
59
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' websocket='-1'>
|
60
|
+
<listen type='address' address='127.0.0.1'/>
|
61
|
+
</graphics>
|
62
|
+
<audio id='1' type='none'/>
|
63
|
+
<video>
|
64
|
+
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
|
65
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
66
|
+
</video>
|
67
|
+
<memballoon model='virtio'>
|
68
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
69
|
+
</memballoon>
|
70
|
+
</devices>
|
71
|
+
</domain>
|
@@ -162,6 +162,109 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
context 'interface' do
|
166
|
+
let(:test_file) { 'existing_with_iommu.xml' }
|
167
|
+
let(:updated_domain_xml) {
|
168
|
+
new_xml = domain_xml.dup
|
169
|
+
new_xml.sub!(
|
170
|
+
/<model type='virtio'\/>\s+<driver iommu='on'\/>/m,
|
171
|
+
<<-EOF
|
172
|
+
<model type='e1000'/>
|
173
|
+
EOF
|
174
|
+
)
|
175
|
+
new_xml
|
176
|
+
}
|
177
|
+
let(:vagrantfile_providerconfig) {
|
178
|
+
<<-EOF
|
179
|
+
libvirt.management_network_model_type = 'e1000'
|
180
|
+
EOF
|
181
|
+
}
|
182
|
+
|
183
|
+
it 'should remove iommu if not interface model not virtio' do
|
184
|
+
expect(ui).to_not receive(:warn)
|
185
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
186
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
187
|
+
expect(libvirt_domain).to receive(:autostart=)
|
188
|
+
expect(domain).to receive(:start)
|
189
|
+
|
190
|
+
expect(subject.call(env)).to be_nil
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'iommu mismatch' do
|
194
|
+
let(:updated_domain_xml) {
|
195
|
+
new_xml = domain_xml.dup
|
196
|
+
new_xml.sub!(/(<model type='virtio'\/>\s+)<driver iommu='on'\/>/m) { |_|
|
197
|
+
match = Regexp.last_match
|
198
|
+
|
199
|
+
"#{match[1]}<driver iommu='off'/>"
|
200
|
+
}
|
201
|
+
new_xml
|
202
|
+
}
|
203
|
+
let(:vagrantfile_providerconfig) {
|
204
|
+
<<-EOF
|
205
|
+
libvirt.management_network_driver_iommu = false
|
206
|
+
EOF
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
it 'should update iommu to off' do
|
211
|
+
expect(ui).to_not receive(:warn)
|
212
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
213
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
214
|
+
expect(libvirt_domain).to receive(:autostart=)
|
215
|
+
expect(domain).to receive(:start)
|
216
|
+
|
217
|
+
expect(subject.call(env)).to be_nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'with additional interface' do
|
222
|
+
let(:test_file) { 'existing_with_two_interfaces_iommu.xml' }
|
223
|
+
let(:adapters) {
|
224
|
+
[
|
225
|
+
{:iface_type => :private_network, :model_type => "e1000", :network_name => "vagrant-libvirt", :driver_iommu => false},
|
226
|
+
{:iface_type => :private_network, :model_type => "virtio", :network_name => "vagrant-libvirt-1", :driver_iommu => true},
|
227
|
+
]
|
228
|
+
}
|
229
|
+
before do
|
230
|
+
allow(subject).to receive(:network_interfaces).and_return(adapters)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should only update the management interface' do
|
234
|
+
expect(updated_domain_xml).to match(/<source network='vagrant-libvirt'\/>\s+<model type='e1000'\/>/m)
|
235
|
+
expect(updated_domain_xml).to match(/<source network='private'\/>\s+<model type='virtio'\/>/m)
|
236
|
+
|
237
|
+
expect(ui).to_not receive(:warn)
|
238
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
239
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
240
|
+
expect(libvirt_domain).to receive(:autostart=)
|
241
|
+
expect(domain).to receive(:start)
|
242
|
+
|
243
|
+
expect(subject.call(env)).to be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'with more adapters configured than attached' do
|
247
|
+
let(:adapters) {
|
248
|
+
[
|
249
|
+
{:iface_type => :private_network, :model_type => "e1000", :network_name => "vagrant-libvirt", :driver_iommu => false},
|
250
|
+
{:iface_type => :private_network, :model_type => "virtio", :network_name => "vagrant-libvirt-1", :driver_iommu => true},
|
251
|
+
{:iface_type => :private_network, :model_type => "virtio", :network_name => "vagrant-libvirt-2", :driver_iommu => true},
|
252
|
+
]
|
253
|
+
}
|
254
|
+
|
255
|
+
it 'should update and trigger a warning about mismatched adapters' do
|
256
|
+
expect(ui).to receive(:warn).with(/number of network adapters in current config \(3\) is different to attached interfaces \(2\)/)
|
257
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
258
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
259
|
+
expect(libvirt_domain).to receive(:autostart=)
|
260
|
+
expect(domain).to receive(:start)
|
261
|
+
|
262
|
+
expect(subject.call(env)).to be_nil
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
165
268
|
context 'cpu' do
|
166
269
|
let(:test_file) { 'existing.xml' }
|
167
270
|
let(:updated_domain_xml) {
|
@@ -8,28 +8,29 @@ describe 'VagrantPlugins::ProviderLibvirt::Util::NetworkUtil' do
|
|
8
8
|
include_context 'libvirt'
|
9
9
|
|
10
10
|
subject do
|
11
|
-
Class.new
|
11
|
+
Class.new do
|
12
12
|
include VagrantPlugins::ProviderLibvirt::Util::NetworkUtil
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@logger = Log4r::Logger.new('test-logger')
|
16
16
|
end
|
17
|
-
|
17
|
+
end.new
|
18
18
|
end
|
19
19
|
|
20
|
-
def create_libvirt_network(name, attrs={})
|
20
|
+
def create_libvirt_network(name, attrs = {})
|
21
21
|
default_attrs = {
|
22
|
-
|
23
|
-
|
22
|
+
active?: true,
|
23
|
+
autostart?: true
|
24
24
|
}
|
25
|
-
network_xml = File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), name
|
25
|
+
network_xml = File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), "#{name}.xml"))
|
26
26
|
double = instance_double(::Libvirt::Network)
|
27
27
|
allow(double).to receive(:xml_desc).and_return(network_xml)
|
28
28
|
allow(double).to receive(:name).and_return(name)
|
29
29
|
|
30
30
|
xml = REXML::Document.new(network_xml)
|
31
31
|
bridge = REXML::XPath.first(xml, '/network/bridge')
|
32
|
-
default_attrs[:bridge_name] =
|
32
|
+
default_attrs[:bridge_name] =
|
33
|
+
!bridge.nil? ? bridge.attributes['name'] : Libvirt::Error.new("network #{name} does not have attribute bridge_name")
|
33
34
|
|
34
35
|
default_attrs.merge(attrs).each do |aname, avalue|
|
35
36
|
if avalue.is_a?(Exception)
|
@@ -50,10 +51,133 @@ describe 'VagrantPlugins::ProviderLibvirt::Util::NetworkUtil' do
|
|
50
51
|
expect(logger).to_not receive(:debug)
|
51
52
|
expect(driver).to receive(:list_all_networks).and_return([default_network, additional_network])
|
52
53
|
|
53
|
-
expect(subject.libvirt_networks(driver)).to match_array(
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
expect(subject.libvirt_networks(driver)).to match_array(
|
55
|
+
[
|
56
|
+
hash_including(name: 'default'),
|
57
|
+
hash_including(name: 'vagrant-libvirt')
|
58
|
+
]
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#network_interfaces' do
|
64
|
+
let(:configured_networks_all) do
|
65
|
+
[
|
66
|
+
{
|
67
|
+
iface_type: :private_network,
|
68
|
+
ip: '192.168.121.0',
|
69
|
+
netmask: '255.255.255.0',
|
70
|
+
network_name: 'vagrant-libvirt',
|
71
|
+
},
|
72
|
+
{
|
73
|
+
auto_correct: true,
|
74
|
+
iface_type: :forwarded_port,
|
75
|
+
},
|
76
|
+
{
|
77
|
+
iface_type: :private_network,
|
78
|
+
ip: '192.168.123.0',
|
79
|
+
netmask: '255.255.255.0',
|
80
|
+
network_name: 'vagrant-libvirt-1',
|
81
|
+
},
|
82
|
+
{
|
83
|
+
iface_type: :private_network,
|
84
|
+
ip: '192.168.124.0',
|
85
|
+
netmask: '255.255.255.0',
|
86
|
+
network_name: 'vagrant-libvirt-2',
|
87
|
+
},
|
88
|
+
]
|
89
|
+
end
|
90
|
+
let(:configured_networks) do
|
91
|
+
[
|
92
|
+
configured_networks_all[0]
|
93
|
+
]
|
94
|
+
end
|
95
|
+
|
96
|
+
before do
|
97
|
+
expect(subject).to receive(:configured_networks).with(machine, logger).and_return(configured_networks)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should return a list of default adapters configured' do
|
101
|
+
expect(logger).to receive(:debug).with('Adapter not specified so found slot 0')
|
102
|
+
expect(logger).to receive(:debug).with('Found network by name')
|
103
|
+
|
104
|
+
expect(subject.network_interfaces(machine, logger)).to match_array([configured_networks[0]])
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with forwarded ports' do
|
108
|
+
let(:configured_networks) do
|
109
|
+
[
|
110
|
+
configured_networks_all[0],
|
111
|
+
configured_networks_all[1]
|
112
|
+
]
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should skip the forwarded port' do
|
116
|
+
expect(logger).to receive(:debug).with('Adapter not specified so found slot 0')
|
117
|
+
expect(logger).to receive(:debug).with('Found network by name')
|
118
|
+
|
119
|
+
expect(subject.network_interfaces(machine, logger)).to match_array([configured_networks[0]])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with 2 additional private networks with adapter set' do
|
124
|
+
let(:configured_networks) do
|
125
|
+
[
|
126
|
+
configured_networks_all[0],
|
127
|
+
configured_networks_all[2].merge(:adapter => 2),
|
128
|
+
configured_networks_all[3],
|
129
|
+
]
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should return the first private network last' do
|
133
|
+
expect(logger).to receive(:debug).with('Adapter not specified so found slot 0')
|
134
|
+
expect(logger).to receive(:debug).with('Found network by name').exactly(3).times
|
135
|
+
expect(logger).to receive(:debug).with('Using specified adapter slot 2')
|
136
|
+
expect(logger).to receive(:debug).with('Adapter not specified so found slot 1')
|
137
|
+
|
138
|
+
expect(subject.network_interfaces(machine, logger)).to match_array(
|
139
|
+
[
|
140
|
+
configured_networks[0],
|
141
|
+
configured_networks[2],
|
142
|
+
configured_networks[1]
|
143
|
+
]
|
144
|
+
)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#configured_networks' do
|
150
|
+
it 'should return a list of default adapters configured' do
|
151
|
+
expect(logger).to receive(:info).with('Using vagrant-libvirt at 192.168.121.0/24 as the management network nat is the mode')
|
152
|
+
expect(logger).to receive(:debug).with(/In config found network type forwarded_port options/)
|
153
|
+
|
154
|
+
expect(subject.configured_networks(machine, logger)).to match_array(
|
155
|
+
[
|
156
|
+
hash_including(
|
157
|
+
{
|
158
|
+
forward_mode: 'nat',
|
159
|
+
iface_type: :private_network,
|
160
|
+
ip: '192.168.121.0',
|
161
|
+
model_type: 'virtio',
|
162
|
+
netmask: '255.255.255.0',
|
163
|
+
network_name: 'vagrant-libvirt',
|
164
|
+
}
|
165
|
+
),
|
166
|
+
hash_including(
|
167
|
+
{
|
168
|
+
auto_correct: true,
|
169
|
+
forward_mode: 'nat',
|
170
|
+
guest: 22,
|
171
|
+
host: 2222,
|
172
|
+
host_ip: '127.0.0.1',
|
173
|
+
id: 'ssh',
|
174
|
+
iface_type: :forwarded_port,
|
175
|
+
netmask: '255.255.255.0',
|
176
|
+
protocol: 'tcp',
|
177
|
+
}
|
178
|
+
)
|
179
|
+
]
|
180
|
+
)
|
57
181
|
end
|
58
182
|
end
|
59
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-libvirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Stanek
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-
|
14
|
+
date: 2023-06-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog-libvirt
|
@@ -159,12 +159,16 @@ email:
|
|
159
159
|
- pronix.service@gmail.com
|
160
160
|
- brian@polibyte.com
|
161
161
|
- daragh.bailey@gmail.com
|
162
|
-
executables:
|
162
|
+
executables:
|
163
|
+
- stackprof-flamegraph.pl
|
164
|
+
- stackprof-gprof2dot.py
|
163
165
|
extensions: []
|
164
166
|
extra_rdoc_files: []
|
165
167
|
files:
|
166
168
|
- LICENSE
|
167
169
|
- README.md
|
170
|
+
- bin/stackprof-flamegraph.pl
|
171
|
+
- bin/stackprof-gprof2dot.py
|
168
172
|
- lib/vagrant-libvirt.rb
|
169
173
|
- lib/vagrant-libvirt/action.rb
|
170
174
|
- lib/vagrant-libvirt/action/clean_machine_folder.rb
|
@@ -174,7 +178,6 @@ files:
|
|
174
178
|
- lib/vagrant-libvirt/action/create_network_interfaces.rb
|
175
179
|
- lib/vagrant-libvirt/action/create_networks.rb
|
176
180
|
- lib/vagrant-libvirt/action/destroy_domain.rb
|
177
|
-
- lib/vagrant-libvirt/action/destroy_domain_confirm.rb
|
178
181
|
- lib/vagrant-libvirt/action/destroy_networks.rb
|
179
182
|
- lib/vagrant-libvirt/action/forward_ports.rb
|
180
183
|
- lib/vagrant-libvirt/action/halt_domain.rb
|
@@ -230,6 +233,7 @@ files:
|
|
230
233
|
- lib/vagrant-libvirt/util/domain_flags.rb
|
231
234
|
- lib/vagrant-libvirt/util/erb_template.rb
|
232
235
|
- lib/vagrant-libvirt/util/error_codes.rb
|
236
|
+
- lib/vagrant-libvirt/util/hash_with_blank_filter.rb
|
233
237
|
- lib/vagrant-libvirt/util/network_util.rb
|
234
238
|
- lib/vagrant-libvirt/util/nfs.rb
|
235
239
|
- lib/vagrant-libvirt/util/resolvers.rb
|
@@ -316,6 +320,8 @@ files:
|
|
316
320
|
- spec/unit/action/start_domain_spec/existing.xml
|
317
321
|
- spec/unit/action/start_domain_spec/existing_added_nvram.xml
|
318
322
|
- spec/unit/action/start_domain_spec/existing_reordered.xml
|
323
|
+
- spec/unit/action/start_domain_spec/existing_with_iommu.xml
|
324
|
+
- spec/unit/action/start_domain_spec/existing_with_two_interfaces_iommu.xml
|
319
325
|
- spec/unit/action/start_domain_spec/nvram_domain.xml
|
320
326
|
- spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml
|
321
327
|
- spec/unit/action/start_domain_spec/nvram_domain_removed.xml
|
@@ -327,6 +333,7 @@ files:
|
|
327
333
|
- spec/unit/config_spec.rb
|
328
334
|
- spec/unit/driver_spec.rb
|
329
335
|
- spec/unit/plugin_spec.rb
|
336
|
+
- spec/unit/provider_spec.rb
|
330
337
|
- spec/unit/templates/domain_all_settings.xml
|
331
338
|
- spec/unit/templates/domain_cpu_mode_passthrough.xml
|
332
339
|
- spec/unit/templates/domain_custom_cpu_model.xml
|
@@ -442,6 +449,8 @@ test_files:
|
|
442
449
|
- spec/unit/action/start_domain_spec/existing.xml
|
443
450
|
- spec/unit/action/start_domain_spec/existing_added_nvram.xml
|
444
451
|
- spec/unit/action/start_domain_spec/existing_reordered.xml
|
452
|
+
- spec/unit/action/start_domain_spec/existing_with_iommu.xml
|
453
|
+
- spec/unit/action/start_domain_spec/existing_with_two_interfaces_iommu.xml
|
445
454
|
- spec/unit/action/start_domain_spec/nvram_domain.xml
|
446
455
|
- spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml
|
447
456
|
- spec/unit/action/start_domain_spec/nvram_domain_removed.xml
|
@@ -454,6 +463,7 @@ test_files:
|
|
454
463
|
- spec/unit/config_spec.rb
|
455
464
|
- spec/unit/driver_spec.rb
|
456
465
|
- spec/unit/plugin_spec.rb
|
466
|
+
- spec/unit/provider_spec.rb
|
457
467
|
- spec/unit/templates/domain_all_settings.xml
|
458
468
|
- spec/unit/templates/domain_cpu_mode_passthrough.xml
|
459
469
|
- spec/unit/templates/domain_custom_cpu_model.xml
|
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
require "vagrant/action/builtin/confirm"
|
3
|
-
|
4
|
-
module VagrantPlugins
|
5
|
-
module VagrantLibvirt
|
6
|
-
module Action
|
7
|
-
class DestroyDomainConfirm < Vagrant::Action::Builtin::Confirm
|
8
|
-
def initialize(app, env)
|
9
|
-
force_key = :force_confirm_destroy
|
10
|
-
message = I18n.t("vagrant_libvirt.destroy_domain.confirmation",
|
11
|
-
name: env[:machine].name)
|
12
|
-
|
13
|
-
super(app, env, message, force_key, allowed: ["y", "n", "Y", "N"])
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|