# HG changeset patch # User Tero Marttila # Date 1395095396 -7200 # Node ID 8321a569d5c0a67906d9c8bb70127ef6f74bd4e7 # Parent e7a55db740720ba1496f594e8878077481c55454 pvl.hosts-lldp: --no-vlans, bump font size, tweak vlan color logics again diff -r e7a55db74072 -r 8321a569d5c0 bin/pvl.hosts-lldp --- a/bin/pvl.hosts-lldp Tue Mar 18 00:16:38 2014 +0200 +++ b/bin/pvl.hosts-lldp Tue Mar 18 00:29:56 2014 +0200 @@ -186,7 +186,10 @@ if src_name in nodes : src = nodes[src_name] else : - src = nodes[src_name] = pydot.Node(src_name, label=src_label) + src = nodes[src_name] = pydot.Node(src_name, + label = src_label, + fontsize = 18, + ) dot.add_node(src) # dst @@ -205,17 +208,21 @@ if dst_name in nodes : dst = nodes[dst_name] else : - dst = nodes[dst_name] = pydot.Node(dst_name, label=dst_label) + dst = nodes[dst_name] = pydot.Node(dst_name, + label = dst_label, + fontsize = 18, + ) dot.add_node(dst) # edges headlabel = '"{remote[port]}"'.format(remote=remote) taillabel = '"{local[port]}"'.format(local=local) - fillcolor = None - color = None + fillcolor = 'black' + color = 'black' + untag = tagged = None # vlans? - if host in vlans and local['port_id'] in vlans[host] : + if vlans and host in vlans and local['port_id'] in vlans[host] : untag, tagged = vlans[host][local['port_id']] log.debug("%s#%s: %s+%s", host, local['port_id'], untag, tagged) @@ -248,27 +255,17 @@ fillcolor = vlan_colors[tag] = color # first color overrides fillcolor for heads - if colors and fillcolor : + if colors and untag : color = ':'.join([fillcolor] + colors) elif colors : color = ':'.join(colors) elif fillcolor : color = fillcolor - else : - color = 'black' - - if not fillcolor : - fillcolor = 'black' elif vlans : # XXX: this happens when LLDP gives us the LACP ports but the VLANS are on the TRK port log.warn("%s#%s: unknown port for vlans: %s", host, local['port_id'], vlans.get(host)) - untag = tag = None - - else : - untag = tag = None - # edge if (src_name, local['port'], dst_name, remote['port']) in edges : log.warning("%s:%s <- %s:%s: duplicate", src_name, local['port'], dst_name, remote['port']) @@ -286,7 +283,7 @@ if edge.get('fillcolor') != fillcolor : log.warn("%s#%s -> %s#%s: remote untag mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], fillcolor, edge.get('fillcolor')) - if edge.get('color') != '"' + (color or 'black') + '"' : + if edge.get('color') != '"' + color + '"' : log.warn("%s#%s -> %s#%s: remote tagged mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], color, edge.get('color')) # mark as bidirectional @@ -307,8 +304,8 @@ dir = 'forward' if untag else 'none', headlabel = headlabel, taillabel = taillabel, - color = '"{color}"'.format(color=color) if color else 'black', - fillcolor = fillcolor or 'black', + color = '"{color}"'.format(color=color), + fillcolor = fillcolor, ) dot.add_edge(edge) @@ -329,6 +326,9 @@ parser.add_option('--graph-dot', help="Output .dot graph data") + parser.add_option('--no-vlans', action='store_const', dest='vlans', const=False, + help="Do not color VLANs") + # input options, args = parser.parse_args(argv[1:]) pvl.args.apply(options) @@ -336,7 +336,10 @@ hosts = pvl.hosts.apply(options, args) # lookup host-port-vlan mappings - vlans = dict(apply_hosts_vlan(options, hosts)) + if options.vlans is False : + vlans = None + else : + vlans = dict(apply_hosts_vlan(options, hosts)) # discover node/port graph items = apply_hosts_lldp(options, hosts)