Sha256: 9683cc2ec5d42848feafbafac273ccc8543ea130caf2071f01ca775c1876725b
Contents?: true
Size: 1.86 KB
Versions: 6
Compression:
Stored size: 1.86 KB
Contents
require 'nokogiri' require 'vagrant/util/network_ip' module VagrantPlugins module ProviderLibvirt module Util module LibvirtUtil include Vagrant::Util::NetworkIP # Return a list of all (active and inactive) libvirt networks as a list # of hashes with their name, network address and status (active or not) 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) # Parse ip address and netmask from the network xml description. xml = Nokogiri::XML(libvirt_network.xml_desc) ip = xml.xpath('/network/ip/@address').first ip = ip.value if ip netmask = xml.xpath('/network/ip/@netmask').first netmask = netmask.value if netmask # Calculate network address of network from ip address and # netmask. if ip && netmask network_address = network_address(ip, netmask) else network_address = nil end libvirt_networks << { name: network_name, ip_address: ip, netmask: netmask, network_address: network_address, bridge_name: libvirt_network.bridge_name, created: true, active: libvirt_network.active?, autostart: libvirt_network.autostart?, libvirt_network: libvirt_network } end libvirt_networks end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems