Module: VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
- Includes:
- Vagrant::Util::NetworkIP
- Included in:
- Action::CreateNetworkInterfaces, Action::CreateNetworks
- Defined in:
- lib/vagrant-libvirt/util/libvirt_util.rb
Instance Method Summary collapse
-
#libvirt_networks(libvirt_client) ⇒ Object
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).
Instance Method Details
#libvirt_networks(libvirt_client) ⇒ Object
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)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vagrant-libvirt/util/libvirt_util.rb', line 12 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 |