summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-01-19 18:50:20 +0000
committerThom May <thom@may.lt>2016-01-19 18:50:20 +0000
commit95f64ea3843309dd1e7d8f46c132d3fc3e8893ba (patch)
treedf0eafa7dfb5490bbd84dfdbfda434b601f698a9
parent4bf8cc50ab473d1258c6934c959b6ca62f792cf6 (diff)
parentabbcae0359cfc636d5c98c7c205b448adecd5087 (diff)
downloadohai-95f64ea3843309dd1e7d8f46c132d3fc3e8893ba.tar.gz
Merge pull request #700 from whiteley/default_route_table_hint
Allow route table override
-rw-r--r--lib/ohai/plugins/linux/network.rb14
-rw-r--r--spec/unit/plugins/linux/network_spec.rb4
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, ""))