diff options
Diffstat (limited to 'retiolum/hosts/.scripts/parse.py')
-rwxr-xr-x | retiolum/hosts/.scripts/parse.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/retiolum/hosts/.scripts/parse.py b/retiolum/hosts/.scripts/parse.py index 951fce94..54f6c35d 100755 --- a/retiolum/hosts/.scripts/parse.py +++ b/retiolum/hosts/.scripts/parse.py @@ -1,24 +1,52 @@ #!/usr/bin/python2 import sys +""" TODO: Refactoring needed to pull the edges out of the node structures again, +it should be easier to handle both structures""" def write_digraph(nodes): - print ('digraph retiolum {') + """ + writes the complete digraph in dot format + """ + print ('graph retiolum {') print (' node[shape=box,style=filled,fillcolor=grey]') + generate_stats(nodes) + merge_edges(nodes) for k,v in nodes.iteritems(): write_node(k,v) print ('}') +def generate_stats(nodes): + """ Generates some statistics of the network and nodes + """ + for k,v in nodes.iteritems(): + v['num_conns'] = len(v.get('to',[])) + +def merge_edges(nodes): + """ merge back and forth edges into one + DESTRUCTS the current structure by deleting "connections" in the nodes + + """ + for k,v in nodes.iteritems(): + for con in v.get('to',[]): + for i,secon in enumerate(nodes[con['name']].get('to',[])): + if k == secon['name']: + del (nodes[con['name']]['to'][i]) + + def write_node(k,v): + """ writes a single node and its edges """ node = " "+k+"[label=\"" node += k+"\\l" node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" + if v.has_key('num_conns'): + node += "Num Connects:"+str(v['num_conns'])+"\\l" node += "internal:"+v['internal-ip']+"\\l\"" if v['external-ip'] == "MYSELF": node += ",fillcolor=steelblue1" node += "]" print (node) for con in v.get('to',[]): - print " "+k+ "->" +con['name'] + "[weight="+str(10/float(con['weight']))+"]" + print " "+k+ " -- " +con['name'] + "[weight="+str(10/float(con['weight']))+"]" def parse_input(): nodes={} |