Changeset 8320 in genesis


Ignore:
Timestamp:
Aug 12, 2010, 3:07:45 PM (14 years ago)
Author:
rick
Message:

Dynamically generated map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/make-map.py

    r8306 r8320  
    100100
    101101def make_graph():
     102  status = None
     103  try:
     104    stream = file('/tmp/nodemap_status.yaml','r')
     105    status = yaml.load(stream)
     106  except IOError,e:
     107    print "# Error loading status '%s'" % e
     108
    102109  f = open('kmlfile.kml', 'w')
    103110  f.write("""<?xml version="1.0" encoding="UTF-8"?>
     
    120127    </Style>
    121128    <Style id="node_status_planned">
     129      <IconStyle>
     130        <scale>0.5</scale>
     131        <Icon><href>http://www.google.com/mapfiles/kml/paddle/wht-stars-lv.png</href></Icon> 
     132      </IconStyle>
     133    </Style>
     134    <Style id="node_status_unknown">
    122135      <IconStyle>
    123136        <scale>0.5</scale>
     
    162175      lam, phi = rd2etrs(datadump['rdnap_x'], datadump['rdnap_y'])
    163176      node[host] = (lam, phi)
     177      if not status:
     178        # By default assume up
     179        node_status = "up"
     180      elif status['node'][host] == gformat.OK:
     181        node_status = "up"
     182      elif status['node'][host] == gformat.DOWN:
     183        node_status = "down"
     184      elif status['node'][host] == gformat.UNKNOWN:
     185        node_status = "unknown"
     186      else:
     187        assert False, "Status cannot be generated"
    164188      f.write("""
    165189      <description>All active nodes</description>
     
    167191        <name>Node %(name)s</name>
    168192        <description>%(desc)s</description>
    169         <styleUrl>#node_status_up</styleUrl>
     193        <styleUrl>%(style)s</styleUrl>
    170194        <Point><coordinates>%(lam)s,%(phi)s,0</coordinates></Point>
    171195      </Placemark>
    172    """ % {'name' : host, 'desc' : cgi.escape(datadump['location']), 'lam' : lam, 'phi' : phi})
     196   """ % {'name' : host, 'desc' : cgi.escape(datadump['location']), 'style' : '#node_status_' + node_status, 'lam' : lam, 'phi' : phi})
    173197      nodes += [("POINT(%s, %s)" % (lam, phi))]
    174198  except (KeyError, ValueError), e:
     
    186210  for addr,leden in poel.iteritems():
    187211    if link_type[addr] == '11a':
    188       color = '#ff0000ff'
    189212      weight = 2
    190213    elif link_type[addr] == 'eth':
    191       color = '#ffff0000'
    192214      weight = 4
    193215    else:
    194       color = '#ff000000'
    195216      weight = 1
    196217
     
    198219    for index,lid in enumerate(leden[:-1]):
    199220      for buur in leden[index + 1:]:
     221        key = (lid + ".wLeiden.NET", buur + ".wLeiden.NET")
     222        rev_key = (key[1],key[0])
     223        link_status = None
     224        if not status:
     225          # Default assume OK
     226          link_status = gformat.OK
     227        elif status['link'].has_key(key):
     228          link_status = status['link'][key]
     229        elif status['link'].has_key(rev_key):
     230          link_status = status['link'][rev_key]
     231        else:
     232          # If link is not known assume nothing
     233          link_status = gformat.UNKNOWN
     234
     235
     236        if link_status == gformat.OK:
     237          color = '#ffff0000' # green
     238        elif link_status == gformat.DOWN:
     239          color = '#ff0000ff' # red
     240        elif link_status == gformat.UNKNOWN:
     241          color = '#55000000' # black
     242        else:
     243          assert False, "Link status not mapped properly"
     244
     245           
    200246        f.write("""
    201247      <Placemark>
Note: See TracChangeset for help on using the changeset viewer.