diff options
author | Phil Dibowitz <phild@fb.com> | 2016-06-15 09:29:57 -0700 |
---|---|---|
committer | Phil Dibowitz <phild@fb.com> | 2016-06-15 10:32:11 -0700 |
commit | 0a666b19e6bc1b6912423c873c33fc4198bc03fa (patch) | |
tree | 75a75171c3e39bfcfa48600501c95a0b7d83f5a2 | |
parent | 17e5c748a70e5388a542a1cff5f86b630c5a629e (diff) | |
download | ohai-0a666b19e6bc1b6912423c873c33fc4198bc03fa.tar.gz |
Add additional info to networking interfaces/addresses
I'd like to know if addresses are dynamic or not, for example.
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 12 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 18f6dd31..65aa3d1a 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -310,10 +310,18 @@ Ohai.plugin(:Network) do end def parse_ip_addr_inet6_line(cint, iface, line) - if line =~ /inet6 ([a-f0-9\:]+)\/(\d+) scope (\w+)/ + if line =~ /inet6 ([a-f0-9\:]+)\/(\d+) scope (\w+)( .*)?/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] tmp_addr = $1 - iface[cint][:addresses][tmp_addr] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("host") ? "Node" : $3.capitalize) } + tags = $4 || "" + tags = tags.split(" ") + + iface[cint][:addresses][tmp_addr] = { + "family" => "inet6", + "prefixlen" => $2, + "scope" => ($3.eql?("host") ? "Node" : $3.capitalize), + "tags" => tags, + } end end diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index 40bbdc17..b91e8d0f 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -808,6 +808,10 @@ EOM expect(plugin["network"]["interfaces"]["eth3"]["state"]).to eq("up") end + it "detects tags on v6 addresses of the ethernet interface" do + expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["2001:44b8:4160:8f00:a00:27ff:fe13:eacd"]["tags"]).to eq(["dynamic"]) + end + describe "when IPv6 is disabled" do before :each do allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(false) |