diff options
author | Matt Whiteley <mwhiteley@fastly.com> | 2016-01-07 11:47:31 -0800 |
---|---|---|
committer | Matt Whiteley <mwhiteley@fastly.com> | 2016-01-14 17:54:13 -0800 |
commit | abbcae0359cfc636d5c98c7c205b448adecd5087 (patch) | |
tree | 32ea898d08f18eaad5fa9eabae638f5290ece40a | |
parent | e93ecd56d52025657bd1628ddbe82b6feda7e0f5 (diff) | |
download | ohai-abbcae0359cfc636d5c98c7c205b448adecd5087.tar.gz |
Allow route table override
* read default route table name from ohai plugin configuration
* default to `main` table to maintain current behavior
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 14 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 4 |
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index c9dfe32d..e2a5c887 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -76,8 +76,8 @@ Ohai.plugin(:Network) do # the routing table source field. # 3) and since we're at it, let's populate some :routes attributes # (going to do that for both inet and inet6 addresses) - def check_routing_table(family, iface) - so = shell_out("ip -o -f #{family[:name]} route show") + def check_routing_table(family, iface, default_route_table) + so = shell_out("ip -o -f #{family[:name]} route show table #{default_route_table}") so.stdout.lines do |line| line.strip! Ohai::Log.debug("Parsing #{line}") @@ -384,6 +384,14 @@ Ohai.plugin(:Network) do counters Mash.new unless counters counters[:network] = Mash.new unless counters[:network] + # ohai.plugin[:network][:default_route_table] = 'default' + if configuration(:default_route_table).nil? || configuration(:default_route_table).empty? + default_route_table = 'main' + else + default_route_table = configuration(:default_route_table) + end + Ohai::Log.debug("default route table is '#{default_route_table}'") + # Match the lead line for an interface from iproute2 # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex @@ -415,7 +423,7 @@ Ohai.plugin(:Network) do iface = extract_neighbors(family, iface, neigh_attr) - iface = check_routing_table(family, iface) + iface = check_routing_table(family, iface, default_route_table) routes = parse_routes(family, iface) diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index cdc7ab1e..b6f6a615 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -330,8 +330,8 @@ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE allow(plugin).to receive(:shell_out).with("ip -d -s link").and_return(mock_shell_out(0, linux_ip_link_s_d, "")) allow(plugin).to receive(:shell_out).with("ip -f inet neigh show").and_return(mock_shell_out(0, linux_ip_neighbor_show, "")) allow(plugin).to receive(:shell_out).with("ip -f inet6 neigh show").and_return(mock_shell_out(0, linux_ip_inet6_neighbor_show, "")) - allow(plugin).to receive(:shell_out).with("ip -o -f inet route show").and_return(mock_shell_out(0, linux_ip_route, "")) - allow(plugin).to receive(:shell_out).with("ip -o -f inet6 route show").and_return(mock_shell_out(0, linux_ip_route_inet6, "")) + allow(plugin).to receive(:shell_out).with("ip -o -f inet route show table main").and_return(mock_shell_out(0, linux_ip_route, "")) + allow(plugin).to receive(:shell_out).with("ip -o -f inet6 route show table main").and_return(mock_shell_out(0, linux_ip_route_inet6, "")) allow(plugin).to receive(:shell_out).with("route -n").and_return(mock_shell_out(0, linux_route_n, "")) allow(plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, linux_ifconfig, "")) |