lib/ohai/plugins/network.rb in ohai-0.6.12 vs lib/ohai/plugins/network.rb in ohai-0.6.14.rc.1

- old
+ new

@@ -24,32 +24,34 @@ network[:interfaces] = Mash.new unless network[:interfaces] counters Mash.new unless counters counters[:network] = Mash.new unless counters[:network] ipaddress nil +ip6address macaddress nil require_plugin "hostname" require_plugin "#{os}::network" # ipaddress and macaddress can be set from the #{os}::network plugin -# both ipaddress and macaddress have to be set in that case -return unless ipaddress.nil? or macaddress.nil? +return unless ipaddress.nil? def find_ip_and_mac(addresses, match = nil) - ip = nil; mac = nil + ip = nil; mac = nil; ip6 = nil addresses.keys.each do |addr| if match.nil? ip = addr if addresses[addr]["family"].eql?("inet") else ip = addr if addresses[addr]["family"].eql?("inet") && network_contains_address(match, addr, addresses[addr]) end + ip6 = addr if addresses[addr]["family"].eql?("inet6") && addresses[addr]["scope"].eql?("Global") mac = addr if addresses[addr]["family"].eql?("lladdr") break if (ip and mac) end Ohai::Log.debug("Found IPv4 address #{ip} with MAC #{mac} #{match.nil? ? '' : 'matching address ' + match}") - [ip, mac] + Ohai::Log.debug("Found IPv6 address #{ip6}") if ip6 + [ip, mac, ip6] end def network_contains_address(address_to_match, network_ip, network_opts) if network_opts[:peer] network_opts[:peer] == address_to_match @@ -59,16 +61,20 @@ network.include?(host) end end # If we have a default interface that has addresses, populate the short-cut attributes +# 0.0.0.0 is not a valid gateway address in this case if network[:default_interface] and + network[:default_gateway] and + network[:default_gateway] != "0.0.0.0" and network["interfaces"][network[:default_interface]] and network["interfaces"][network[:default_interface]]["addresses"] Ohai::Log.debug("Using default interface for default ip and mac address") im = find_ip_and_mac(network["interfaces"][network[:default_interface]]["addresses"], network[:default_gateway]) ipaddress im.shift macaddress im.shift + ip6address im.shift else network["interfaces"].keys.sort.each do |iface| if network["interfaces"][iface]["encapsulation"].eql?("Ethernet") Ohai::Log.debug("Picking ip and mac address from first Ethernet interface") im = find_ip_and_mac(network["interfaces"][iface]["addresses"])