summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCooper Lees <me@cooperlees.com>2020-07-02 12:52:03 -0700
committerCooper Lees <me@cooperlees.com>2020-07-02 12:52:18 -0700
commite12ef5a5777160fdf7fdda2fbc5e7fc367cd2d8f (patch)
tree793bb97b2608837f6b83bb1d80d9e9872a333a2b
parent5f06da1d49d99f0d727ea07c7c24c2c376f83d26 (diff)
downloadohai-e12ef5a5777160fdf7fdda2fbc5e7fc367cd2d8f.tar.gz
Go back to a one liner using .respond_to? rather than family == inet
Signed-off-by: Cooper Lees <me@cooperlees.com>
-rw-r--r--lib/ohai/plugins/network.rb9
1 files changed, 1 insertions, 8 deletions
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 04e799b0..57ef0baa 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -25,13 +25,6 @@ Ohai.plugin(:NetworkAddresses) do
depends "network/interfaces"
- # Try to u32 an IPv4 and fallback to u128 if it fails before throwing
- def int_an_ip(ipaddress)
- ipaddress.to_u32
- rescue NoMethodError
- ipaddress.to_u128
- end
-
# 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")
@@ -61,7 +54,7 @@ Ohai.plugin(:NetworkAddresses) do
ipaddresses.sort_by do |v|
[ ( scope_prio.index(v[:scope]) || 999999 ),
128 - v[:ipaddress].prefix.to_i,
- int_an_ip(v[:ipaddress]),
+ ipaddress.respond_to?(:to_u32) ? ipaddress.to_u32 : ipaddress.to_u128,
]
end
end