Commit ea37f512 authored by Simon Redman's avatar Simon Redman

Add check to ignore disabled interfaces

parent d5b91d53
......@@ -38,7 +38,7 @@ def parse_ipv4_networks(netgraph):
For each ssh session, query the remote for its interfaces, then parse that for its IPv4 address
:param netgraph: networkx topology graph, annotated with logged-in ssh sessions
:return: mapping of hosts to map of interfaces to that interface's IPv6 interface address
:return: mapping of hosts to map of interfaces to that interface's IPv4 address
"""
hosts = []
sessions = []
......@@ -65,9 +65,16 @@ def parse_ipv4_networks(netgraph):
if interface_name == 'lo':
# Don't mess with the loopback interface
continue
# Figure out whether the interface is alive. Look for "state" followed by "UP" or "DOWN"
# (This does not work on Ubuntu 12.04, but works on 16.04) -- One way to make it work on 12.04 would be to not pass `-6` to the ip command
state, *more_states = re.findall(r'\sstate\s+(UP|DOWN)\s+', remainder[0])
assert len(more_states) == 0, "Should have found only one state"
if state == "DOWN":
# Ignore disabled interfaces
continue
# Parse out the ipv4 address. There should be only one.
ipaddr = re.findall(r'\sinet\s+(.*?)\s+brd.*scope global', remainder[0])
assert len(ipaddr) == 1, "Should only have found one link-local address!"
assert len(ipaddr) == 1, "Should only have found one ipv4 address!"
ipaddr = ipaddress.ip_interface(ipaddr[0])
interface_map[hosts[host_idx]][interface_name] = ipaddr
return interface_map
......@@ -78,7 +85,7 @@ def parse_local_interface_addresses(netgraph):
For each ssh session, query the remote for its interfaces, then parse that for its IPv6 interface ID on each interface
:param netgraph: networkx topology graph, annotated with logged-in ssh sessions
:return: mapping of hosts to map of interfaces to that interface's IPv4 address
:return: mapping of hosts to map of interfaces to that interface's IPv6 interface address
"""
hosts = []
sessions = []
......@@ -105,6 +112,13 @@ def parse_local_interface_addresses(netgraph):
if interface_name == 'lo':
# Don't mess with the loopback interface
continue
# Figure out whether the interface is alive. Look for "state" followed by "UP" or "DOWN"
# (This does not work on Ubuntu 12.04, but works on 16.04) -- One way to make it work on 12.04 would be to not pass `-6` to the ip command
state, *more_states = re.findall(r'\sstate\s+(UP|DOWN)\s+', remainder[0])
assert len(more_states) == 0, "Should have found only one state"
if state == "DOWN":
# Ignore disabled interfaces
continue
# Parse out the link-local ipv6 address. There should be only one.
ipaddr = re.findall(r'\sinet6\s+(.*?)\s+scope link', remainder[0])
assert len(ipaddr) == 1, "Should only have found one link-local address!"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment