lib/ohai/plugins/network.rb in ohai-8.10.0 vs lib/ohai/plugins/network.rb in ohai-8.11.1

- old
+ new

@@ -14,12 +14,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -require 'ipaddress' -require 'ohai/mixin/network_constants' +require "ipaddress" +require "ohai/mixin/network_constants" Ohai.plugin(:NetworkAddresses) do include Ohai::Mixin::NetworkConstants provides "ipaddress", "ip6address", "macaddress" @@ -27,35 +27,35 @@ depends "network/interfaces" # from interface data create array of hashes with ipaddress, scope, and iface # sorted by scope, prefixlen and then ipaddress where longest prefixes first def sorted_ips(family = "inet") - fail "bad family #{family}" unless %w(inet inet6).include? family + raise "bad family #{family}" unless %w{inet inet6}.include? family # priority of ipv6 link scopes to sort by later scope_prio = [ "global", "site", "link", "host", "node", nil ] # grab ipaddress, scope, and iface for sorting later ipaddresses = [] - Mash[network['interfaces']].each do |iface, iface_v| - next if iface_v.nil? || !iface_v.has_key?('addresses') - iface_v['addresses'].each do |addr, addr_v| - next if addr_v.nil? or not addr_v.has_key? "family" or addr_v['family'] != family + Mash[network["interfaces"]].each do |iface, iface_v| + next if iface_v.nil? || !iface_v.has_key?("addresses") + iface_v["addresses"].each do |addr, addr_v| + next if addr_v.nil? or not addr_v.has_key? "family" or addr_v["family"] != family ipaddresses << { :ipaddress => addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"), :scope => addr_v["scope"].nil? ? nil : addr_v["scope"].downcase, - :iface => iface + :iface => iface, } end end # sort ip addresses by scope, by prefixlen and then by ip address # 128 - prefixlen: longest prefixes first ipaddresses.sort_by do |v| [ ( scope_prio.index(v[:scope]) || 999999 ), 128 - v[:ipaddress].prefix.to_i, - ( family == "inet" ? v[:ipaddress].to_u32 : v[:ipaddress].to_u128 ) + ( family == "inet" ? v[:ipaddress].to_u32 : v[:ipaddress].to_u128 ), ] end end # finds ip address / interface for interface with default route based on @@ -66,11 +66,11 @@ # return if there aren't any #{family} addresses! return [ nil, nil ] if ips.empty? # shortcuts to access default #{family} interface and gateway - int_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] +"_interface" + int_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] + "_interface" gw_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] + "_gateway" if network[int_attr] # working with the address(es) of the default network interface gw_if_ips = ips.select do |v| @@ -111,10 +111,10 @@ [ r[:ipaddress].to_s, r[:iface] ] end # select mac address of first interface with family of lladdr def find_mac_from_iface(iface) - r = network["interfaces"][iface]["addresses"].select{|k,v| v["family"] == "lladdr"} + r = network["interfaces"][iface]["addresses"].select { |k, v| v["family"] == "lladdr" } r.nil? || r.first.nil? ? nil : r.first.first end # address_to_match: String # ipaddress: IPAddress