source: genesis/nodes/make-network-graph.py@ 8281

Last change on this file since 8281 was 8281, checked in by rick, 14 years ago

Exclude some ranges of machines actually not connected

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2# vim:ts=2:et:sw=2:ai
3#
4# Build topological network graph
5# Rick van der Zwet <info@rickvanderzwet.nl>
6import re
7import sys
8import glob
9import tempfile
10import subprocess
11import gformat
12
13OUTFILE = 'network.png'
14
15def make_graph():
16 poel = {}
17 link_type = {}
18 try:
19 for host in gformat.get_proxylist() + gformat.get_nodelist():
20 print "## Processing host", host
21 datadump = gformat.get_yaml(host)
22 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
23 for iface_key in iface_keys:
24 l = datadump[iface_key]['ip']
25 addr, mask = l.split('/')
26
27 # Not parsing of these folks please
28 if "192.168" in addr:
29 continue
30 if "0.0.0.0" in addr:
31 continue
32
33 addr = gformat.parseaddr(addr)
34 mask = int(mask)
35 addr = addr & ~((1 << (32 - mask)) - 1)
36 if poel.has_key(addr):
37 poel[addr] += [host]
38 else:
39 poel[addr] = [host]
40 # Assume all eth2wifibridge to be 11a for a moment
41 if datadump[iface_key].has_key('eth2wifibridge'):
42 link_type[addr] = '11a'
43 else:
44 link_type[addr] = datadump[iface_key]['type']
45 print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr])
46 except (KeyError, ValueError), e:
47 print "[FOUT] in '%s' interface '%s'" % (host,iface_key)
48 print e
49 sys.exit(1)
50
51 f = tempfile.NamedTemporaryFile(bufsize=0)
52 sys.stderr.write("# Building temponary graph file\n")
53 print >> f, "Graph WirelessLeidenNetwork {"
54 print >> f ,"""
55graph [ fontsize = 36,
56 overlap = scalexy,
57 splines = true,
58 ]
59"""
60 for addr,leden in poel.iteritems():
61 if link_type[addr] == '11a':
62 color = 'red'
63 weight = 4
64 elif link_type[addr] == 'eth':
65 color = 'blue'
66 weight = 8
67 else:
68 color = 'black'
69 weight = 1
70 leden = sorted(set(leden))
71 for index,lid in enumerate(leden[:-1]):
72 for buur in leden[index + 1:]:
73 print >> f,' %s -- %s [label="%s", color="%s", weight="%s"]' % (lid, buur, gformat.showaddr(addr), color, weight)
74 print >> f, "}"
75 sys.stderr.write("# Plotting temponary graph file using graphviz\n")
76 retval = subprocess.call(["neato","-Tpng",f.name, "-o", OUTFILE])
77 if retval != 0:
78 sys.stderr.write("# FAILED [%i]\n" % retval)
79 subprocess.call(["cat",f.name])
80 exit(1)
81 sys.stderr.write("# COMPLETED find your output in %s\n" % OUTFILE)
82
83
84if __name__ == "__main__":
85 make_graph()
86
Note: See TracBrowser for help on using the repository browser.