mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Allow bridges referenced by libvirt networks (#1554)
Permit reference to bridge devices referenced by existing libvirt networks. Fixes: #1553
This commit is contained in:
@@ -512,6 +512,14 @@ virtual network.
|
|||||||
are listed [here](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
|
are listed [here](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
|
||||||
Default is 'false'.
|
Default is 'false'.
|
||||||
|
|
||||||
|
Additionally for public networks, to facilitate validating if the device provided
|
||||||
|
can be used, vagrant-libvirt will check both the host interfaces visible to libvirt
|
||||||
|
and the existing networks for any existing bridge names. While some name patterns are
|
||||||
|
automatically excluded as presumed incorrect, if this pattern list is incorrect
|
||||||
|
it may be overridden by setting the option:
|
||||||
|
* `host_device_exclude_prefixes` - ignore any device starting with any of these
|
||||||
|
string patterns as a valid bridge device for a public network definition.
|
||||||
|
|
||||||
### Management Network
|
### Management Network
|
||||||
|
|
||||||
vagrant-libvirt uses a private network to perform some management operations on
|
vagrant-libvirt uses a private network to perform some management operations on
|
||||||
|
|||||||
@@ -1213,7 +1213,11 @@ module VagrantPlugins
|
|||||||
|
|
||||||
def host_devices(machine)
|
def host_devices(machine)
|
||||||
@host_devices ||= begin
|
@host_devices ||= begin
|
||||||
machine.provider.driver.connection.client.list_all_interfaces().map { |iface| iface.name }.uniq.select do |dev|
|
(
|
||||||
|
machine.provider.driver.list_host_devices.map { |iface| iface.name } +
|
||||||
|
machine.provider.driver.list_networks.map { |net| net.bridge_name }
|
||||||
|
).uniq.select do |dev|
|
||||||
|
next if dev.empty?
|
||||||
dev != "lo" && !@host_device_exclude_prefixes.any? { |exclude| dev.start_with?(exclude) }
|
dev != "lo" && !@host_device_exclude_prefixes.any? { |exclude| dev.start_with?(exclude) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -201,6 +201,14 @@ module VagrantPlugins
|
|||||||
state
|
state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_host_devices
|
||||||
|
@connection.client.list_all_interfaces
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_networks
|
||||||
|
@connection.client.list_all_networks
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_ipaddress_from_system(mac)
|
def get_ipaddress_from_system(mac)
|
||||||
|
|||||||
@@ -640,12 +640,20 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
instance_double(Libvirt::Interface),
|
instance_double(Libvirt::Interface),
|
||||||
instance_double(Libvirt::Interface),
|
instance_double(Libvirt::Interface),
|
||||||
] }
|
] }
|
||||||
|
let(:libvirt_networks) { [
|
||||||
|
instance_double(Libvirt::Network),
|
||||||
|
instance_double(Libvirt::Network),
|
||||||
|
] }
|
||||||
|
let(:driver) { instance_double(::VagrantPlugins::ProviderLibvirt::Driver) }
|
||||||
before do
|
before do
|
||||||
machine.config.vm.network :public_network, dev: 'eth0', ip: "192.168.2.157"
|
machine.config.vm.network :public_network, dev: 'eth0', ip: "192.168.2.157"
|
||||||
expect(machine).to receive_message_chain('provider.driver.connection.client').and_return(libvirt_client)
|
allow(machine.provider).to receive(:driver).and_return(driver)
|
||||||
expect(libvirt_client).to receive(:list_all_interfaces).and_return(host_devices)
|
expect(driver).to receive(:list_host_devices).and_return(host_devices)
|
||||||
|
expect(driver).to receive(:list_networks).and_return(libvirt_networks)
|
||||||
expect(host_devices[0]).to receive(:name).and_return('eth0')
|
expect(host_devices[0]).to receive(:name).and_return('eth0')
|
||||||
expect(host_devices[1]).to receive(:name).and_return('virbr0')
|
expect(host_devices[1]).to receive(:name).and_return('virbr0')
|
||||||
|
expect(libvirt_networks[0]).to receive(:bridge_name).and_return('')
|
||||||
|
expect(libvirt_networks[1]).to receive(:bridge_name).and_return('virbr0')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should validate use of existing device' do
|
it 'should validate use of existing device' do
|
||||||
|
|||||||
Reference in New Issue
Block a user