lib/ohai/plugins/network.rb in ohai-16.3.2 vs lib/ohai/plugins/network.rb in ohai-16.4.11

- old
+ new

@@ -15,11 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # Ohai.plugin(:NetworkAddresses) do - require "ipaddress" require_relative "../mixin/network_helper" include Ohai::Mixin::NetworkHelper provides "ipaddress", "ip6address", "macaddress" @@ -86,13 +85,13 @@ # link level default route logger.trace("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}") r = gw_if_ips.first else # checking network masks - r = gw_if_ips.select do |v| + r = gw_if_ips.find do |v| network_contains_address(network[gw_attr], v[:ipaddress], v[:iface]) - end.first + end if r.nil? r = gw_if_ips.first logger.trace("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}") else logger.trace("Plugin Network: [#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}") @@ -132,9 +131,11 @@ # ipaddress, ip6address and macaddress are set for each interface by the # #{os}::network plugin. atm it is expected macaddress is set at the same # time as ipaddress. if ipaddress is set and macaddress is nil, that means # the interface ipaddress is bound to has the NOARP flag collect_data do + require "ipaddress" unless defined?(IPAddress) + results = {} network Mash.new unless network network[:interfaces] ||= Mash.new counters Mash.new unless counters