diff options
author | Tim Smith <tsmith@chef.io> | 2017-06-10 14:33:54 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-06-10 15:00:57 -0700 |
commit | 4af278603214300eb44e7929cff406bc7aace051 (patch) | |
tree | 095b2d148e92e672e5de3bbf8798889ad223976c /lib/ohai/plugins/linux/network.rb | |
parent | 72079a1ff60b9707850f7b178a2b1f9f026f4bb0 (diff) | |
download | ohai-network_which.tar.gz |
Avoid extra file stats and simplify things a bitnetwork_which
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/ohai/plugins/linux/network.rb')
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 87364499..32a89133 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -37,16 +37,12 @@ Ohai.plugin(:Network) do File.exist? "/proc/net/if_inet6" end - def iproute2_binary_path - which("ip") - end - def ethtool_binary_path - which("ethtool") + @ethtool ||= which("ethtool") end def is_openvz? - ::File.directory?("/proc/vz") + @openvz ||= ::File.directory?("/proc/vz") end def is_openvz_host? @@ -151,11 +147,11 @@ Ohai.plugin(:Network) do # determine layer 1 details for the interface using ethtool def ethernet_layer_one(iface) - return iface unless ethtool_binary = ethtool_binary_path + return iface unless ethtool_binary_path keys = %w{ Speed Duplex Port Transceiver Auto-negotiation MDI-X } iface.each_key do |tmp_int| next unless iface[tmp_int][:encapsulation] == "Ethernet" - so = shell_out("#{ethtool_binary} #{tmp_int}") + so = shell_out("#{ethtool_binary_path} #{tmp_int}") so.stdout.lines do |line| line.chomp! Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{line}") @@ -175,10 +171,10 @@ Ohai.plugin(:Network) do # determine ring parameters for the interface using ethtool def ethernet_ring_parameters(iface) - return iface unless ethtool_binary = ethtool_binary_path + return iface unless ethtool_binary_path iface.each_key do |tmp_int| next unless iface[tmp_int][:encapsulation] == "Ethernet" - so = shell_out("#{ethtool_binary} -g #{tmp_int}") + so = shell_out("#{ethtool_binary_path} -g #{tmp_int}") Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}") type = nil iface[tmp_int]["ring_params"] = {} @@ -471,7 +467,7 @@ Ohai.plugin(:Network) do # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex IPROUTE_INT_REGEX = /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/ unless defined? IPROUTE_INT_REGEX - if iproute2_binary_path + if which("ip") # families to get default routes from families = [{ :name => "inet", |