X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bin%2Fplc-kml.py;h=417ef15ba44a0d38354edb2dd0f91d485ee0ff3a;hb=9767039754a9a61f1a720f172b0138573a72f817;hp=6cd460db6e8bffd2845fca85aeb8050a39fd1d5e;hpb=a455b90d009a6a43cf2c66e99aba9f639223c548;p=myplc.git diff --git a/bin/plc-kml.py b/bin/plc-kml.py index 6cd460d..417ef15 100755 --- a/bin/plc-kml.py +++ b/bin/plc-kml.py @@ -34,32 +34,18 @@ class KmlMap: 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() - 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): + if not self.options.nodegroup: + title="%s sites"%api.config.PLC_NAME + detailed="All the sites known to the %s testbed"%api.config.PLC_NAME + else: + title="Nodegroup %s"%self.options.nodegroup + detailed="All sites involved in nodegroup %s"%self.options.nodegroup self.write(""" - PlanetLab Sites + %(title)s 9.180821112577378 44.43275321178062 @@ -68,8 +54,8 @@ class KmlMap: 0 -7.767386340832667 - All the sites known to the PlanetLab testbed. -""") + %(detailed)s. +"""%locals()) def write_footer (self): self.write(""" @@ -83,7 +69,63 @@ class KmlMap: return (peer['peername'],peer['peer_url'].replace("PLCAPI/",""),) return "Unknown peer_name" - def write_site (self, site, peers): + # 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): + if self.options.nodegroup: + self.refresh_nodegroup() + else: + self.refresh_all_sites() + + def refresh_all_sites(self): + self.open() + self.write_header() + # cache peers + peers = GetPeers() + 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() + + def refresh_nodegroup(self): + try: + nodegroup=GetNodeGroups({'groupname':self.options.nodegroup})[0] + except: + print "No such nodegroup %s - ignored"%self.options.nodegroup + return + nodegroup_node_ids=nodegroup['node_ids'] + if len(nodegroup_node_ids)==0: + print "Empty nodegroup %s - ignored"%self.options.nodegroup + return + # let's go + self.open() + self.write_header() + # cache peers + peers = GetPeers() + nodes=GetNodes(nodegroup_node_ids) + global_node_hash = dict ( [ (n['node_id'],n) for n in nodes ] ) + site_ids = [ node['site_id'] for node in nodes] + # remove any duplicate + site_ids = list(set(site_ids)) + sites = GetSites (site_ids) + # patch sites so that 'node_ids' only contains the nodes in the nodegroup + for site in sites: + site['node_ids'] = [ node_id for node_id in site['node_ids'] if node_id in nodegroup_node_ids ] + node_hash = dict ( [ (node_id, global_node_hash[node_id]) for node_id in site['node_ids'] ] ) + self.write_site(site,peers,nodegroup_id=nodegroup['nodegroup_id'], node_hash=node_hash) + self.write_footer() + self.close() + + def write_site (self, site, peers, nodegroup_id=False, node_hash={}): # discard sites with missing lat or lon if not site['latitude'] or not site['longitude']: return @@ -101,67 +143,6 @@ class KmlMap: baseurl='http://%s'%api.config.PLC_WWW_HOST peer_id=site['peer_id'] - # open description - description = "
" - - # TESTBED - description += "" - description += "" - - # URL - if site['url']: - site_url=site['url'] - description += "" - - description += "" - description += "" - description += "" - - # NODES - description += "" - - #SLICES - description += "" - - description += "" - - # close description - description += "
 
" - description += "Testbed" - description += "" - (peername,peerurl) = self.peer_info (site,peers) - 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 += "
 
" - - if not self.options.labels: - name="" - description="" - # STYLE # the size for google icons if not self.options.use_custom_icons: @@ -185,6 +166,96 @@ class KmlMap: iconspec="%(iconurl)s%(xyspec)s"%locals() + # open description + # can't seem to get classes to get through to the google maps API + # so have to use hard-wired settings + description = "" + description += "" + description += "" + + # TESTBED + description += "" + description += "" + (peername,peerurl) = self.peer_info (site,peers) + description += "" + + # URL + if site['url']: + site_url=site['url'] + description += "" + description += "" + description += "" + description += "" + + # nodegroup direct link + if self.options.nodegroup: + nodegroup=self.options.nodegroup + description += "" + description += "" + description += "" + description += "" + + + # Usage area + description += "" + description += "" + + # encapsulate usage in a table of its own + description += "" + + # close description + description += "
Testbed" + description += "

"%locals() + description += " %(peername)s "%locals() + description += "

Website" + description += " %(site_url)s "%locals() + description += "
Nodegroup" + description += " %(nodegroup)s "%locals() + description += "
Usage" + description += "" + description += "" + + # NODES + # regular all-sites mode + if not nodegroup_id: + description += "" + # nodegroup mode : show all nodes + else: + for node_id in site['node_ids']: + node=node_hash[node_id] + hostname=node['hostname'] + description += "" + + #SLICES + if not nodegroup_id: + description += "" + + # close usage table + description += "
" + description += ""%locals() + description += "" + if nb_nodes: + description += "%(nb_nodes)d node(s)"%locals() + else: + description += "No node" + description += "
" + description += ""%locals() + description += "" + description += "%(hostname)s "%locals() + description += "
" + description += ""%locals() + description += "" + if nb_slices: + description += "%(nb_slices)d slice(s)"%locals() + else: + description += "No slice" + description += "
" + description += "
" + + if not self.options.labels: + name="" + description="" + # set the camera 50km high template=""" @@ -213,6 +284,10 @@ def main () : parser.add_option("-n","--no-label",action="store_false",dest="labels", default=True, help="outputs only geographic positions, no labels") + + parser.add_option("-g","--nodegroup",action='store',dest='nodegroup',default=None, + help="outputs a kml file for a given nodegroup only") + # default - for private depls. - is to use google-provided icons like palette-3 parser.add_option("-c","--custom",action="store_true",dest="use_custom_icons", default=False,