From 330e78c85f636fd7f08b2d1e13ca01e525eba9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BCllhorst?= Date: Fri, 8 Jan 2016 17:24:41 +0100 Subject: [PATCH] Added check for disabled autoupdater and branch --- domain_selector.py | 4 ++-- graph.py | 26 +++++++++++++++++++++++--- node.py | 4 +++- node_hierarchy.py | 11 ++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/domain_selector.py b/domain_selector.py index c89fca3..1891e39 100644 --- a/domain_selector.py +++ b/domain_selector.py @@ -4,7 +4,7 @@ import json, urllib from graph import Graph class DomainSelector: - def __init__(self, nodesFile, graphFile, dataPath = './', printStatus = False, targets = None): + def __init__(self, nodesFile, graphFile, dataPath = './', printStatus = False, targets = None, branch = 'stable'): self.printStatus = printStatus self.targets = targets self.nodesData = self.__getFile__(nodesFile) @@ -18,7 +18,7 @@ class DomainSelector: else: nodes = {} for k,v in self.targets.iteritems(): - nodes = self.graph.getNodeCloudsIn(v) + nodes = self.graph.getNodeCloudsIn(v,branch) self.writeConfigFiles(nodes,k) self.writeDumpFile(nodes,k) nodes = {} diff --git a/graph.py b/graph.py index 00fcb56..99fcffc 100644 --- a/graph.py +++ b/graph.py @@ -21,7 +21,7 @@ class Graph: def parseNodes(self): for k,v in self.nodes['nodes'].iteritems(): lat, lon = self.getGeo(k) - node = Node(k, ipv6 = self.getPublicAddress(k), hostname = self.getHostname(k), isOnline = self.getOnlineState(k), lat=lat, lon=lon, coder = self.coder) + node = Node(k, ipv6 = self.getPublicAddress(k), hostname = self.getHostname(k), isOnline = self.getOnlineState(k), lat=lat, lon=lon, coder = self.coder, autoupdater = self.getAutoupdaterStatus(k), branch = self.getBranch(k)) self.nodes_list[k] = node def parseLinks(self): @@ -73,6 +73,22 @@ class Graph: def getHostname(self,node_id): return self.nodes['nodes'][node_id]['nodeinfo']['hostname'] + def getAutoupdaterStatus(self, node_id): + #return True + if 'autoupdater' in self.nodes['nodes'][node_id]['nodeinfo']['software']: + return self.nodes['nodes'][node_id]['nodeinfo']['software']['autoupdater']['enabled'] + else: + #if node is offline for a long time sometimes no autoupdater status can be found + return False + + def getBranch(self, node_id): + #return True + if 'autoupdater' in self.nodes['nodes'][node_id]['nodeinfo']['software']: + return self.nodes['nodes'][node_id]['nodeinfo']['software']['autoupdater']['branch'] + else: + #if node is offline for a long time sometimes no autoupdater status can be found + return None + def getGeo(self, node_id): if 'location' in self.nodes['nodes'][node_id]['nodeinfo'] and 'latitude' in self.nodes['nodes'][node_id]['nodeinfo']['location'] and 'longitude' in self.nodes['nodes'][node_id]['nodeinfo']['location']: return self.nodes['nodes'][node_id]['nodeinfo']['location']['latitude'], self.nodes['nodes'][node_id]['nodeinfo']['location']['longitude'] @@ -90,12 +106,16 @@ class Graph: return self.nodes['nodes'][node_id]['flags']['online'] - def getNodeCloudsIn(self, region): + def getNodeCloudsIn(self, region, branch = 'stable'): results = {} for k,v in self.getAllLevelXNodes(0).iteritems(): if v.geodata != None and v.isOnline == True: if v.isInRegion(region): - results.update(v.getNodeCloud({})) + for ksub,vsub in v.getNodeCloud({}).iteritems(): + if not vsub.autoupdater or vsub.branch != branch: + break + else: + results.update(v.getNodeCloud({})) print "Result:",len(results), region return results diff --git a/node.py b/node.py index 486b937..a67718b 100644 --- a/node.py +++ b/node.py @@ -4,7 +4,7 @@ from geocode import Geocode import time class Node(object): - def __init__(self, nodeid, ipv6 = None, hostname = None, isOnline = False, lastSeen = None, lat = None, lon = None, coder = None): + def __init__(self, nodeid, ipv6 = None, hostname = None, isOnline = False, lastSeen = None, lat = None, lon = None, coder = None, autoupdater = False, branch = None): self.coder = coder if self.coder == None: self.coder = Geocode(geocoderCache = True, printStatus = True) @@ -15,6 +15,8 @@ class Node(object): self.stepsToVpn = -1 self.isOnline = isOnline self.lastSeen = lastSeen + self.autoupdater = autoupdater + self.branch = branch self._geo = None self.geodata = None if lat != None and lon != None: diff --git a/node_hierarchy.py b/node_hierarchy.py index ac23bf9..abe1170 100755 --- a/node_hierarchy.py +++ b/node_hierarchy.py @@ -68,8 +68,17 @@ targets = { {'village' : u'Südlohn'}, {'town' : u'Velen'}, {'town' : u'Vreden'}, + ], + 'sassenberg' : [ + {'town' : u'Sassenberg'}, + ], + 'telgte' : [ + {'town' : u'Telgte'}, + ], + 'warendorf_stadt' : [ + {'town' : u'Warendorf'}, ] } #ds = DomainSelector(nodesFile = 'nodes.json', graphFile = 'graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets) -ds = DomainSelector(nodesFile = 'https://freifunk-muensterland.de/map/data/nodes.json', graphFile = 'https://freifunk-muensterland.de/map/data/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets) \ No newline at end of file +ds = DomainSelector(nodesFile = 'https://freifunk-muensterland.de/map/data/nodes.json', graphFile = 'https://freifunk-muensterland.de/map/data/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets, branch = 'stable') \ No newline at end of file