--- a/bin/pvl.hosts-graph Sun Mar 30 14:21:57 2014 +0300
+++ b/bin/pvl.hosts-graph Mon Mar 31 14:27:39 2014 +0300
@@ -169,8 +169,10 @@
{ (remote, remote_port, local_port, local): (local_untag, tagged, remote_untag) }
"""
- nodes = { }
+ nodes = { } # host: label
links = { }
+
+ hosts_by_lldp = { }
# first scan: lldp hosts
for host, host_attrs in snmp.iteritems() :
@@ -178,8 +180,10 @@
if lldp :
lldp_local = lldp['local']
+ local = lldp_local['chassis']
- nodes[lldp_local['chassis']] = host.location
+ nodes[host] = host.location
+ hosts_by_lldp[local] = host
# second scan: lldp remotes
for host, host_attrs in snmp.iteritems() :
@@ -189,6 +193,7 @@
continue
local = lldp['local']['chassis']
+ local_node = host
if 'vlan' in host_attrs :
vlans = dict(host_vlans(host, host_attrs['vlan']))
@@ -199,8 +204,13 @@
local_port = port_attrs['local']['port']
for remote, remote_attrs in port_attrs['remote'].iteritems() :
- if remote not in nodes :
- nodes[remote] = remote_attrs['sys_name']
+ if remote in hosts_by_lldp :
+ remote_node = hosts_by_lldp[remote]
+ else :
+ remote_node = remote
+
+ # non-snmp lldp host
+ nodes[remote_node] = remote_attrs['sys_name']
remote_port = remote_attrs['port']
@@ -214,8 +224,8 @@
local_untag, local_tagged = port_vlans
# bidirectional mappings
- forward = (local, local_port, remote_port, remote)
- reverse = (remote, remote_port, local_port, local)
+ forward = (local_node, local_port, remote_port, remote_node)
+ reverse = (remote_node, remote_port, local_port, local_node)
if reverse not in links :
links[forward] = (local_untag, local_tagged, None)
@@ -225,14 +235,14 @@
# merge
if remote_untag != local_untag :
log.warning("%s:%s untag %s <=> %s untag %s:%s",
- nodes[local], local_port, local_untag,
- remote_untag, nodes[remote], remote_port
+ host, local_port, local_untag,
+ remote_untag, remote_node, remote_port
)
if remote_tagged != local_tagged :
log.warning("%s:%s tagged %s <-> %s tagged %s:%s",
- nodes[local], local_port, ':'.join(str(x) for x in sorted(local_tagged)),
- ':'.join(str(x) for x in sorted(remote_tagged)), nodes[remote], remote_port
+ host, local_port, ':'.join(str(x) for x in sorted(local_tagged)),
+ ':'.join(str(x) for x in sorted(remote_tagged)), remote_node, remote_port
)
links[reverse] = (remote_untag, remote_tagged, local_untag)