pvl.hosts-lldp: tweaked vlan colors
authorTero Marttila <terom@paivola.fi>
Tue, 18 Mar 2014 00:16:38 +0200
changeset 392 e7a55db74072
parent 391 e2c367b1556f
child 393 8321a569d5c0
pvl.hosts-lldp: tweaked vlan colors
bin/pvl.hosts-lldp
--- a/bin/pvl.hosts-lldp	Mon Mar 17 23:55:11 2014 +0200
+++ b/bin/pvl.hosts-lldp	Tue Mar 18 00:16:38 2014 +0200
@@ -145,18 +145,15 @@
     1:      'grey',         # pvl-lan
     2:      'blue',         # pvl-lan2
     3:      'red',          # pvl-san
-    4:      'yellow',       # pvl-veturi
+    4:      'green',        # pvl-veturi
     7:      'orange',       # pvl-ranssi
-    8:      'green',        # pvl-mgmt
+    8:      'yellow',       # pvl-mgmt
     10:     'brown',        # pvl-public
-
-    100:    'red',          # test
-    102:    'red',          # ganeti
-    103:    'red',          # test-san
-    104:    'red',          # pvl-ganeti
-
-    192:    'green',        # paivola-services
-    255:    'purple',       # pvl-sonera
+    100:    'navyblue',     # pvl-test
+    103:    'red4',         # pvl-test-san
+    104:    'red2',         # pvl-ganeti
+    192:    'purple',       # paivola-services
+    255:    'magenta',      # pvl-sonera
 }
 
 def apply_graph (options, items, vlans={}) :
@@ -179,6 +176,7 @@
 
     nodes = { }
     edges = { }
+    vlan_colors = { } # { vlan: color }
 
     for host, local, remote, remote_host in items :
         # src
@@ -226,14 +224,28 @@
             for tag in sorted(tagged) :
                 if tag in COLOR_VLANS :
                     colors.append(COLOR_VLANS[tag])
+                elif tag in vlan_colors :
+                    colors.append(vlan_colors[tag])
                 else :
-                    log.warn("%s#%s: unknown vlan %s", host, local['port_id'], tag)
-                    colors.append('black')
+                    color = '/paired12/{count}'.format(count=1+len(vlan_colors))
+                    
+                    log.info("%s#%s: chosing new vlan %s color %s", host, local['port_id'], tag, color)
 
-            if untag and untag in COLOR_VLANS :
+                    vlan_colors[tag] = color
+                    colors.append(color)
+
+            if not untag :
+                pass
+            elif untag in COLOR_VLANS :
                 fillcolor = COLOR_VLANS[untag]
-            elif untag :
-                log.warn("%s#%s: no color for vlan %s", host, local['port_id'], untag)
+            elif untag in vlan_colors :
+                fillcolor = vlan_colors[untag]
+            else :
+                color = '/paired12/{count}'.format(count=1+len(vlan_colors))
+
+                log.warn("%s#%s: chosing new vlan %s color %s", host, local['port_id'], untag, color)
+                    
+                fillcolor = vlan_colors[tag] = color
             
             # first color overrides fillcolor for heads
             if colors and fillcolor :
@@ -254,6 +266,9 @@
 
             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'])
@@ -271,7 +286,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 + '"' :
+            if edge.get('color') != '"' + (color or 'black') + '"' :
                 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