- Timestamp:
- Apr 7, 2012, 11:55:17 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/make-network-kml.py
r10375 r10377 13 13 import yaml 14 14 15 OUTFILE = os.path.join(os.getcwd(),'network.kml')16 15 17 16 try: … … 51 50 </kml> 52 51 ''' 53 def make_graph( ):52 def make_graph(debug=False): 54 53 poel = {} 55 54 link_type = {} 56 55 link_data = {} 57 56 hosts = {} 57 58 58 try: 59 59 for host in gformat.get_hostlist(): 60 print "## Processing host", host60 if debug: print "## Processing host", host 61 61 datadump = gformat.get_yaml(host) 62 62 nodename = datadump['nodename'] … … 94 94 uptime = store['uptime'][nodename] 95 95 t_kb = float(b_in + b_out) / 1024 96 print "# INFO: Found %s kB in %s seconds" % (t_kb, INTERVAL)96 if debug: print "# INFO: Found %s kB in %s seconds" % (t_kb, INTERVAL) 97 97 retval = ((t_kb) / uptime) * INTERVAL 98 98 link_data[addr] = retval 99 99 100 print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr])100 if debug: print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr]) 101 101 except (KeyError, ValueError), e: 102 print "[FOUT] in '%s' interface '%s'" % (host,iface_key)103 print e102 if debug: print "[FOUT] in '%s' interface '%s'" % (host,iface_key) 103 if debug: print e 104 104 sys.exit(1) 105 105 106 f = open(OUTFILE,'w')107 sys.stderr.write("# Building KML file\n")108 print >> f,HEADER106 output = '' 107 if debug: print "# Building KML file" 108 output += HEADER 109 109 for nodename, datadump in hosts.iteritems(): 110 print >> f,POINT % datadump110 output += POINT % datadump 111 111 112 112 for addr,leden in poel.iteritems(): … … 129 129 for key, value in hosts[lid].iteritems(): 130 130 keys[key + 'B'] = value 131 print >> f, LINE % keys 132 print >> f, FOOTER 133 f.flush() 134 sys.stderr.write("# COMPLETED find your output in %s\n" % OUTFILE) 131 output += LINE % keys 132 output += FOOTER 133 return output 135 134 136 135 if __name__ == "__main__": 137 make_graph() 136 OUTFILE = os.path.join(os.getcwd(),'network.kml') 137 kml_data = make_graph(debug=True) 138 f = open(OUTFILE,'w') 139 f.write(kml_data) 140 f.close() 141 print "# COMPLETED find your output in %s\n" % OUTFILE 138 142
Note:
See TracChangeset
for help on using the changeset viewer.