mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ignore networks that cannot be used (#1628)
If the network does not have a bridge name, ignore it and move onto the next one. This allows for hostdev networks to exist without breaking. Includes some rudimentary testing to exercise the lookup code along with a small bit of refactoring based on the realisation that there is no need to lookup the network information twice as it is available if the list_all_networks API is used. Fixes: #599
This commit is contained in:
@@ -152,14 +152,16 @@ module VagrantPlugins
|
||||
def libvirt_networks(libvirt_client)
|
||||
libvirt_networks = []
|
||||
|
||||
active = libvirt_client.list_networks
|
||||
inactive = libvirt_client.list_defined_networks
|
||||
|
||||
# Iterate over all (active and inactive) networks.
|
||||
active.concat(inactive).each do |network_name|
|
||||
libvirt_network = libvirt_client.lookup_network_by_name(
|
||||
network_name
|
||||
)
|
||||
libvirt_client.list_all_networks.each do |libvirt_network|
|
||||
begin
|
||||
bridge_name = libvirt_network.bridge_name
|
||||
rescue Libvirt::Error
|
||||
# there does not appear to be a mechanism to determine the type of network, only by
|
||||
# querying the attribute and catching the error is it possible to ignore unsupported.
|
||||
@logger.debug "Ignoring #{libvirt_network.name} as it does not support retrieval of bridge_name attribute"
|
||||
next
|
||||
end
|
||||
|
||||
# Parse ip address and netmask from the network xml description.
|
||||
xml = Nokogiri::XML(libvirt_network.xml_desc)
|
||||
@@ -182,12 +184,12 @@ module VagrantPlugins
|
||||
network_address = (network_address(ip, netmask) if ip && netmask)
|
||||
|
||||
libvirt_networks << {
|
||||
name: network_name,
|
||||
name: libvirt_network.name,
|
||||
ip_address: ip,
|
||||
netmask: netmask,
|
||||
network_address: network_address,
|
||||
dhcp_enabled: dhcp_enabled,
|
||||
bridge_name: libvirt_network.bridge_name,
|
||||
bridge_name: bridge_name,
|
||||
domain_name: domain_name,
|
||||
created: true,
|
||||
active: libvirt_network.active?,
|
||||
|
||||
Reference in New Issue
Block a user