#!/usr/bin/env plcsh
#
# this script generates a kml file, located under the default location below
# you should crontab this job from your myplc image
# you can then use the googlemap.js javascript for creating your applet
# more on this at http://svn.planet-lab.org/wiki/GooglemapSetup
#
# kml reference can be found at
# http://code.google.com/apis/kml/documentation/kmlreference.html
#
import sys
default_output = "/var/www/html/sites/sites.kml"
default_local_icon = "sites/google-local.png"
default_foreign_icon = "sites/google-foreign.png"
default_local_builtin = "palette-4.png"
default_foreign_builtin = "palette-3.png"
class KmlMap:
def __init__ (self,outputname,options):
self.outputname=outputname
self.options=options
def open (self):
self.output = open(self.outputname,"w")
def close (self):
if self.output:
self.output.close()
self.output = None
def write(self,string):
self.output.write(string.encode("UTF-8"))
# mention local last
@staticmethod
def site_compare (s1,s2):
p1 = p2 = 0
if s1['peer_id']: p1=s1['peer_id']
if s2['peer_id']: p2=s2['peer_id']
return p2-p1
def refresh (self):
self.open()
self.write_header()
# cache peers
peers = GetPeers({},['peer_id','peername'])
all_sites = GetSites({'enabled':True,'is_public':True})
all_sites.sort(KmlMap.site_compare)
for site in all_sites:
self.write_site(site,peers)
self.write_footer()
self.close()
# initial placement is for europe - dunno how to tune that yet
def write_header (self):
self.write("""
| " description += "Testbed" description += " | " if peer_id: peername = 'PlanetLab Central' peerurl = 'http://www.planet-lab.org' #self.peer_name(site,peers) else: peername = 'PlanetLab Europe' peerurl = 'http://www.planet-lab.eu' description += " %(peername)s "%locals() #description += "[description]"%locals() description += " | "
if peer_id:
description += " "%locals()
else:
description += " "%locals()
description += " |
| " description += "Website" description += " | " description += " %(site_url)s "%locals() description += " | |
| Usage details: | ||
"
description += " "%locals()
description += " | " if nb_nodes: description += "%(nb_nodes)d node(s)"%locals() #description += " (in Comon)"%locals() else: description += "No node" description += " | |
"
description += " "%locals()
description += " | " if nb_slices: description += "%(nb_slices)d slice(s)"%locals() else: description += "No slice" description += " | |