Changeset 10377 in genesis for tools


Ignore:
Timestamp:
Apr 7, 2012, 11:55:17 AM (13 years ago)
Author:
rick
Message:

Allow the network kml to be more flexible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/make-network-kml.py

    r10375 r10377  
    1313import yaml
    1414
    15 OUTFILE = os.path.join(os.getcwd(),'network.kml')
    1615
    1716try:
     
    5150</kml>
    5251'''
    53 def make_graph():
     52def make_graph(debug=False):
    5453  poel = {}
    5554  link_type = {}
    5655  link_data = {}
    5756  hosts = {}
     57
    5858  try:
    5959    for host in gformat.get_hostlist():
    60       print "## Processing host", host
     60      if debug: print "## Processing host", host
    6161      datadump = gformat.get_yaml(host)
    6262      nodename = datadump['nodename']
     
    9494              uptime = store['uptime'][nodename]
    9595              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)
    9797              retval = ((t_kb) / uptime) * INTERVAL
    9898              link_data[addr] = retval
    9999
    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])
    101101  except (KeyError, ValueError), e:
    102     print "[FOUT] in '%s' interface '%s'" % (host,iface_key)
    103     print e
     102    if debug: print "[FOUT] in '%s' interface '%s'" % (host,iface_key)
     103    if debug: print e
    104104    sys.exit(1)
    105105
    106   f = open(OUTFILE,'w')
    107   sys.stderr.write("# Building KML file\n")
    108   print >> f, HEADER
     106  output = ''
     107  if debug: print "# Building KML file"
     108  output += HEADER
    109109  for nodename, datadump in hosts.iteritems():
    110     print >> f, POINT % datadump
     110    output += POINT % datadump
    111111
    112112  for addr,leden in poel.iteritems():
     
    129129        for key, value in hosts[lid].iteritems():
    130130           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
    135134
    136135if __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
    138142
Note: See TracChangeset for help on using the changeset viewer.