Updated mechanism for generating output for nodes with disabled autoupdater or no geoinformations
This commit is contained in:
parent
c6a167dde5
commit
fac219a7ac
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -
|
||||
#Imports:
|
||||
import json, urllib, os
|
||||
import json, urllib, os, glob
|
||||
from graph import Graph
|
||||
from hieraException import HieraException
|
||||
|
||||
|
@ -13,9 +13,11 @@ class DomainSelector:
|
|||
|
||||
self.printStatus = printStatus
|
||||
self.targets = targets
|
||||
self.dataPath = dataPath.rstrip('/')
|
||||
self.nodesData = self.__getFile__(nodesFile)
|
||||
self.graphData = self.__getFile__(graphFile)
|
||||
self.dataPath = dataPath
|
||||
|
||||
self.__prepareOutDir__()
|
||||
|
||||
self.graph = Graph(self.nodesData, self.graphData)
|
||||
if self.targets == None:
|
||||
|
@ -28,8 +30,14 @@ class DomainSelector:
|
|||
self.writeConfigFiles(nodes,k)
|
||||
self.writeDumpFile(nodes,k)
|
||||
nodes = {}
|
||||
self.writeConfigFiles(self.graph.nodes_no_autoupdater,"no_autoupdater")
|
||||
self.writeConfigFiles(self.graph.nodes_no_geo,"no_geo")
|
||||
self.writeConfigFiles(self.graph.getProblemNodes(noAutoupdater = True),"no_autoupdater")
|
||||
self.writeConfigFiles(self.graph.getProblemNodes(noGeodata = True),"no_geo")
|
||||
self.writeConfigFiles(self.graph.getProblemNodes(noGeodata = True, noAutoupdater = True),"no_nothing")
|
||||
|
||||
def __prepareOutDir__(self):
|
||||
files = glob.glob(self.dataPath+'/*')
|
||||
for f in files:
|
||||
os.remove(f)
|
||||
|
||||
def __getFile__(self, nodesFile):
|
||||
if nodesFile.startswith('https://') or nodesFile.startswith('http://'):
|
||||
|
@ -52,16 +60,17 @@ class DomainSelector:
|
|||
|
||||
def writeConfigFiles(self, nodes, name):
|
||||
maxDepth = self.maxDepth(nodes)
|
||||
for i in range(0,maxDepth):
|
||||
content = 'geo $switch {\n default 0;'
|
||||
f = open(self.dataPath.rstrip('/')+'/'+name+'_node_level'+str(i),'w')
|
||||
for node in nodes.itervalues():
|
||||
if node.stepsToVpn == i:
|
||||
if node.ipv6 and node.hostname:
|
||||
content += '\n '+node.ipv6+' 1; #'+node.hostname
|
||||
content += '\n}'
|
||||
f.write(content.encode('utf8'))
|
||||
f.close()
|
||||
if len(nodes) > 0:
|
||||
for i in range(0,maxDepth):
|
||||
content = 'geo $switch {\n default 0;'
|
||||
f = open(self.dataPath.rstrip('/')+'/'+name+'_node_level'+str(i),'w')
|
||||
for node in nodes.itervalues():
|
||||
if node.stepsToVpn == i:
|
||||
if node.ipv6 and node.hostname:
|
||||
content += '\n '+node.ipv6+' 1; #'+node.hostname
|
||||
content += '\n}'
|
||||
f.write(content.encode('utf8'))
|
||||
f.close()
|
||||
|
||||
def writeDumpFile(self, nodes, name):
|
||||
content = {}
|
||||
|
|
38
graph.py
38
graph.py
|
@ -113,25 +113,45 @@ class Graph:
|
|||
def getOnlineState(self,node_id):
|
||||
return self.nodes['nodes'][node_id]['flags']['online']
|
||||
|
||||
def getProblemNodes(self, noAutoupdater = False, noGeodata = False, online = True):
|
||||
results = {}
|
||||
for k,v in self.nodes_list.iteritems():
|
||||
if v.isOnline or online == False:
|
||||
if noAutoupdater and noGeodata:
|
||||
if not v.autoupdater and not v.geodata:
|
||||
results[k] = v
|
||||
elif noAutoupdater:
|
||||
if v.autoupdater and v.geodata:
|
||||
results[k] = v
|
||||
elif noGeodata:
|
||||
if not v.geodata and v.autoupdater:
|
||||
results[k] = v
|
||||
return results
|
||||
|
||||
|
||||
def getNodeCloudsIn(self, region, branch = 'stable'):
|
||||
results = {}
|
||||
noAuto = False
|
||||
# noAuto = False
|
||||
for k,v in self.getAllLevelXNodes(0).iteritems():
|
||||
if v.isOnline == True:
|
||||
if v.geodata != None:
|
||||
if v.isInRegion(region):
|
||||
noAuto = False
|
||||
for ksub,vsub in v.getNodeCloud({}).iteritems():
|
||||
if not vsub.autoupdater or (branch and vsub.branch != branch):
|
||||
#break
|
||||
noAuto = True
|
||||
self.nodes_no_autoupdater[ksub] = vsub
|
||||
#else:
|
||||
if not noAuto:
|
||||
break
|
||||
else:
|
||||
results.update(v.getNodeCloud({}))
|
||||
else:
|
||||
self.nodes_no_geo.update(v.getNodeCloud({}))
|
||||
# noAuto = False
|
||||
# for ksub,vsub in v.getNodeCloud({}).iteritems():
|
||||
# if not vsub.autoupdater or (branch and vsub.branch != branch):
|
||||
# #break
|
||||
# noAuto = True
|
||||
# self.nodes_no_autoupdater[ksub] = vsub
|
||||
# #else:
|
||||
# if not noAuto:
|
||||
# results.update(v.getNodeCloud({}))
|
||||
# else:
|
||||
# self.nodes_no_geo.update(v.getNodeCloud({}))
|
||||
print "Result:",len(results), region
|
||||
return results
|
||||
|
||||
|
|
|
@ -36,16 +36,8 @@ def prepareTargets(args):
|
|||
specific_targets[k] = v
|
||||
return specific_targets
|
||||
|
||||
|
||||
|
||||
print args
|
||||
|
||||
targets = prepareTargets(args)
|
||||
|
||||
|
||||
|
||||
#ds = DomainSelector(nodesFile = 'nodes.json', graphFile = 'graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets)
|
||||
#ds = DomainSelector(nodesFile = 'https://service.freifunk-muensterland.de/maps/data_legacy/nodes.json', graphFile = 'https://service.freifunk-muensterland.de/maps/data_legacy/graph.json', printStatus = True, dataPath = '../domaenensplit_webserver_config/', targets = targets, branch = None)
|
||||
try:
|
||||
ds = DomainSelector(nodesFile = args.json_path.rstrip('/')+'/nodes.json', graphFile = args.json_path.rstrip('/')+'/graph.json', printStatus = args.print_status, dataPath = args.out_path, targets = targets, branch = args.only_specific_branch)
|
||||
except HieraException:
|
||||
|
|
Loading…
Reference in a new issue