diff options
author | Kris Shannon <k.shannon@amaze.com.au> | 2019-11-22 21:39:12 +1100 |
---|---|---|
committer | Kris Shannon <k.shannon@amaze.com.au> | 2019-11-22 21:39:12 +1100 |
commit | 6c6de0511039f1c64e83802e98de4eae3550ebad (patch) | |
tree | 16348f00deac4a5e13ce345bb8f3b537f49a69d9 | |
parent | ae3930b699be1707d595743e77808548d98c0233 (diff) | |
download | ohai-6c6de0511039f1c64e83802e98de4eae3550ebad.tar.gz |
Use network helper to parse netmask instead of 'scanf'
The 'scanf' library is gone in Ruby 2.7
A helper for parsing hex netmasks was already written for aix so use it
instead.
Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
-rw-r--r-- | lib/ohai/plugins/darwin/network.rb | 10 | ||||
-rw-r--r-- | lib/ohai/plugins/solaris2/network.rb | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/ohai/plugins/darwin/network.rb b/lib/ohai/plugins/darwin/network.rb index 24c6f22d..9736987d 100644 --- a/lib/ohai/plugins/darwin/network.rb +++ b/lib/ohai/plugins/darwin/network.rb @@ -17,9 +17,13 @@ # Ohai.plugin(:Network) do + require_relative "../../mixin/network_helper" + provides "network", "network/interfaces" provides "counters/network", "counters/network/interfaces" + include Ohai::Mixin::NetworkHelper + def parse_media(media_string) media = {} line_array = media_string.split(" ") @@ -87,8 +91,6 @@ Ohai.plugin(:Network) do end collect_data(:darwin) do - require "scanf" - network Mash.new unless network network[:interfaces] ||= Mash.new counters Mash.new unless counters @@ -138,11 +140,11 @@ Ohai.plugin(:Network) do end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask 0x(([0-9a-f]){1,8})\s*$/ iface[cint][:addresses] ||= Mash.new - iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * "." } + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => hex_to_dec_netmask($2) } end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask 0x(([0-9a-f]){1,8}) broadcast (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses] ||= Mash.new - iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * ".", "broadcast" => $4 } + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => hex_to_dec_netmask($2) , "broadcast" => $4 } end if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*) prefixlen (\d+)\s*/ iface[cint][:addresses] ||= Mash.new diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb index 5e890f2b..aa60b21e 100644 --- a/lib/ohai/plugins/solaris2/network.rb +++ b/lib/ohai/plugins/solaris2/network.rb @@ -63,9 +63,13 @@ unless defined?(ETHERNET_ENCAPS) end Ohai.plugin(:Network) do + require_relative "../../mixin/network_helper" + provides "network", "network/interfaces" provides "counters/network", "counters/network/interfaces" + include Ohai::Mixin::NetworkHelper + def solaris_encaps_lookup(ifname) return "Ethernet" if ETHERNET_ENCAPS.include?(ifname) return "Ethernet" if ifname.eql?("net") @@ -92,8 +96,6 @@ Ohai.plugin(:Network) do end collect_data(:solaris2) do - require "scanf" - iface = Mash.new network Mash.new unless network network[:interfaces] ||= Mash.new @@ -124,11 +126,11 @@ Ohai.plugin(:Network) do end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8})\s*$/ iface[cint][:addresses] ||= Mash.new - iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * "." } + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => hex_to_dec_netmask($2) } end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8}) broadcast (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses] ||= Mash.new - iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * ".", "broadcast" => $4 } + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => hex_to_dec_netmask($2) , "broadcast" => $4 } end if line =~ %r{\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)/(\d+)\s*$} iface[cint][:addresses] ||= Mash.new |