143 |
143 |
144 COLOR_VLANS = { |
144 COLOR_VLANS = { |
145 1: 'grey', # pvl-lan |
145 1: 'grey', # pvl-lan |
146 2: 'blue', # pvl-lan2 |
146 2: 'blue', # pvl-lan2 |
147 3: 'red', # pvl-san |
147 3: 'red', # pvl-san |
148 4: 'yellow', # pvl-veturi |
148 4: 'green', # pvl-veturi |
149 7: 'orange', # pvl-ranssi |
149 7: 'orange', # pvl-ranssi |
150 8: 'green', # pvl-mgmt |
150 8: 'yellow', # pvl-mgmt |
151 10: 'brown', # pvl-public |
151 10: 'brown', # pvl-public |
152 |
152 100: 'navyblue', # pvl-test |
153 100: 'red', # test |
153 103: 'red4', # pvl-test-san |
154 102: 'red', # ganeti |
154 104: 'red2', # pvl-ganeti |
155 103: 'red', # test-san |
155 192: 'purple', # paivola-services |
156 104: 'red', # pvl-ganeti |
156 255: 'magenta', # pvl-sonera |
157 |
|
158 192: 'green', # paivola-services |
|
159 255: 'purple', # pvl-sonera |
|
160 } |
157 } |
161 |
158 |
162 def apply_graph (options, items, vlans={}) : |
159 def apply_graph (options, items, vlans={}) : |
163 import pydot |
160 import pydot |
164 |
161 |
224 |
222 |
225 colors = [] |
223 colors = [] |
226 for tag in sorted(tagged) : |
224 for tag in sorted(tagged) : |
227 if tag in COLOR_VLANS : |
225 if tag in COLOR_VLANS : |
228 colors.append(COLOR_VLANS[tag]) |
226 colors.append(COLOR_VLANS[tag]) |
|
227 elif tag in vlan_colors : |
|
228 colors.append(vlan_colors[tag]) |
229 else : |
229 else : |
230 log.warn("%s#%s: unknown vlan %s", host, local['port_id'], tag) |
230 color = '/paired12/{count}'.format(count=1+len(vlan_colors)) |
231 colors.append('black') |
231 |
232 |
232 log.info("%s#%s: chosing new vlan %s color %s", host, local['port_id'], tag, color) |
233 if untag and untag in COLOR_VLANS : |
233 |
|
234 vlan_colors[tag] = color |
|
235 colors.append(color) |
|
236 |
|
237 if not untag : |
|
238 pass |
|
239 elif untag in COLOR_VLANS : |
234 fillcolor = COLOR_VLANS[untag] |
240 fillcolor = COLOR_VLANS[untag] |
235 elif untag : |
241 elif untag in vlan_colors : |
236 log.warn("%s#%s: no color for vlan %s", host, local['port_id'], untag) |
242 fillcolor = vlan_colors[untag] |
|
243 else : |
|
244 color = '/paired12/{count}'.format(count=1+len(vlan_colors)) |
|
245 |
|
246 log.warn("%s#%s: chosing new vlan %s color %s", host, local['port_id'], untag, color) |
|
247 |
|
248 fillcolor = vlan_colors[tag] = color |
237 |
249 |
238 # first color overrides fillcolor for heads |
250 # first color overrides fillcolor for heads |
239 if colors and fillcolor : |
251 if colors and fillcolor : |
240 color = ':'.join([fillcolor] + colors) |
252 color = ':'.join([fillcolor] + colors) |
241 elif colors : |
253 elif colors : |
252 # XXX: this happens when LLDP gives us the LACP ports but the VLANS are on the TRK port |
264 # XXX: this happens when LLDP gives us the LACP ports but the VLANS are on the TRK port |
253 log.warn("%s#%s: unknown port for vlans: %s", host, local['port_id'], vlans.get(host)) |
265 log.warn("%s#%s: unknown port for vlans: %s", host, local['port_id'], vlans.get(host)) |
254 |
266 |
255 untag = tag = None |
267 untag = tag = None |
256 |
268 |
|
269 else : |
|
270 untag = tag = None |
|
271 |
257 # edge |
272 # edge |
258 if (src_name, local['port'], dst_name, remote['port']) in edges : |
273 if (src_name, local['port'], dst_name, remote['port']) in edges : |
259 log.warning("%s:%s <- %s:%s: duplicate", src_name, local['port'], dst_name, remote['port']) |
274 log.warning("%s:%s <- %s:%s: duplicate", src_name, local['port'], dst_name, remote['port']) |
260 |
275 |
261 elif (dst_name, remote['port'], src_name, local['port']) in edges : |
276 elif (dst_name, remote['port'], src_name, local['port']) in edges : |
269 log.warn("%s -> %s: remote port mismatch: %s vs %s", src_name, dst_name, remote['port'], edge.get('taillabel')) |
284 log.warn("%s -> %s: remote port mismatch: %s vs %s", src_name, dst_name, remote['port'], edge.get('taillabel')) |
270 |
285 |
271 if edge.get('fillcolor') != fillcolor : |
286 if edge.get('fillcolor') != fillcolor : |
272 log.warn("%s#%s -> %s#%s: remote untag mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], fillcolor, edge.get('fillcolor')) |
287 log.warn("%s#%s -> %s#%s: remote untag mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], fillcolor, edge.get('fillcolor')) |
273 |
288 |
274 if edge.get('color') != '"' + color + '"' : |
289 if edge.get('color') != '"' + (color or 'black') + '"' : |
275 log.warn("%s#%s -> %s#%s: remote tagged mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], color, edge.get('color')) |
290 log.warn("%s#%s -> %s#%s: remote tagged mismatch: %s vs %s", src_name, local['port'], dst_name, remote['port'], color, edge.get('color')) |
276 |
291 |
277 # mark as bidirectional |
292 # mark as bidirectional |
278 edges[(src_name, local['port'], dst_name, remote['port'])] = edge |
293 edges[(src_name, local['port'], dst_name, remote['port'])] = edge |
279 |
294 |