diff options
author | Bryan McLellan <btm@chef.io> | 2015-12-28 12:15:15 -0800 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-12-28 12:19:34 -0800 |
commit | 2dd13f97a7c19ea11b813f71a59272af24f6b334 (patch) | |
tree | c2157a1be4a00e0bb18a69d819332d5a9ce254b7 | |
parent | 230372117754675f52338bc2727e6beceb9a31f1 (diff) | |
download | ohai-2dd13f97a7c19ea11b813f71a59272af24f6b334.tar.gz |
Do not set macaddress if it is already set
Previously we almost always set macaddress to the value from the interface we
took ipaddress from, unless we didn't get any ipaddress, at which point we
would accept the macaddress from the interface we took ip6address from.
We're seeing ipv6 only hosts now, we need to be able to take macaddress from
an ip6address interface if that's the most logical choice so we can ignore
loopback or random/meaningless virtual interfaces that don't go anywhere.
-rw-r--r-- | lib/ohai/plugins/network.rb | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb index 42858d24..d7096986 100644 --- a/lib/ohai/plugins/network.rb +++ b/lib/ohai/plugins/network.rb @@ -71,10 +71,7 @@ Ohai.plugin(:NetworkAddresses) do int_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] +"_interface" gw_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] + "_gateway" - # If we have a default interface that has addresses, - # populate the short-cut attributes ipaddress, ip6address and macaddress if network[int_attr] - # working with the address(es) of the default network interface gw_if_ips = ips.select do |v| v[:iface] == network[int_attr] @@ -153,32 +150,30 @@ Ohai.plugin(:NetworkAddresses) do if (family == "inet") && ipaddress.nil? if r["ip"].nil? Ohai::Log.warn("unable to detect ipaddress") - # i don't issue this warning if r["ip"] exists and r["mac"].nil? - # as it could be a valid setup with a NOARP default_interface - Ohai::Log.warn("unable to detect macaddress") else ipaddress r["ip"] - macaddress r["mac"] end elsif (family == "inet6") && ip6address.nil? if r["ip"].nil? Ohai::Log.debug("unable to detect ip6address") else ip6address r["ip"] - # don't overwrite macaddress set by "#{os}::network" plugin - # and also overwrite mac address from ipv4 loopback interface - if r["mac"] && macaddress.nil? && (ipaddress.nil? || ipaddress == "127.0.0.1") - Ohai::Log.debug("macaddress set to #{r["mac"]} from the ipv6 setup") - macaddress r["mac"] - end end end + + # set the macaddress [only if we haven't already]. this allows the #{os}::network plugin to set macaddress + # otherwise we set macaddress on a first-found basis (and we started with ipv4) + if macaddress.nil? && r["mac"] + Ohai::Log.debug("setting macaddress from interface '#{r["iface"]}'") + macaddress r["mac"] + end + results[family] = r end if results["inet"]["iface"] && results["inet6"]["iface"] && (results["inet"]["iface"] != results["inet6"]["iface"]) - Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]}), macaddress has been set using the ipaddress interface") + Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})") end end end |