Changeset 11444 in genesis


Ignore:
Timestamp:
Sep 5, 2012, 9:06:53 PM (12 years ago)
Author:
rick
Message:

Quick om export te maken van nodeplanner applicatie.

Location:
tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r11427 r11444  
    11531153        content_type='application/vnd.google-earth.kml+xml'
    11541154        output = make_network_kml.make_graph()
     1155    elif base_uri.endswith('/api/get/nodeplanner.json'):
     1156        content_type='application/json'
     1157        output = make_network_kml.make_nodeplanner_json()
    11551158    elif not uri[0]:
    11561159      if is_text_request(environ):
     
    14601463  for header in response_headers:
    14611464     print "%s: %s" % header
    1462   print "\n"
     1465  print
    14631466  print output
    14641467
  • tools/make_network_kml.py

    r10890 r11444  
    66import gformat
    77import glob
     8import json
    89import os
    910import re
     
    7172'''
    7273
    73 def make_graph(debug=False):
     74def get_graph_data(debug=False):
    7475  poel = {}
    7576  link_type = {}
     
    140141    if debug: print e
    141142    sys.exit(1)
    142 
     143  return (poel, link_type, link_data, link_status, hosts)
     144
     145
     146def make_nodeplanner_json(debug=False):
     147  # Input data
     148  poel, link_type, link_data, link_status, hosts = get_graph_data(debug)
     149
     150  # Export data
     151  points = []
     152  for nodename, datadump in hosts.iteritems():
     153    points.append({'name':  datadump['nodename'], 'lat' : float(datadump['latitude']), 'lon' : float(datadump['longitude']), 'state' : datadump['status']})
     154  links = []
     155  for addr,leden in poel.iteritems():
     156    for index,lid in enumerate(leden[:-1]):
     157      for buur in leden[index + 1:]:
     158        links.append({'master' : hosts[buur]['nodename'], 'slave': hosts[lid]['nodename'], 'state' : link_status[addr][4:].lower()})
     159
     160  # Format data
     161  return json.dumps({'points' : points, 'links' : links})
     162   
     163 
     164
     165def make_graph(debug=False):
     166  poel, link_type, link_data, link_status, hosts = get_graph_data(debug)
    143167  output = ''
    144168  if debug: print "# Building KML file"
Note: See TracChangeset for help on using the changeset viewer.