+ # 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={}):