Initial commit of version 2
This commit is contained in:
commit
ff7105eedc
23 changed files with 782 additions and 0 deletions
28
generator/Filter.py
Normal file
28
generator/Filter.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
class Filter(object):
|
||||
def __init__(self, args):
|
||||
self.__args__ = args
|
||||
self.__filters__ = self.__getFilters()
|
||||
|
||||
def filterLocalGraphs(self, localGraphs):
|
||||
filteredGraphs = []
|
||||
for localGraph in localGraphs:
|
||||
if localGraph.isAutoupdaterEnabledOnAllNodes() == False:
|
||||
continue
|
||||
if self.__allowCloudsWithLanLinks__() == False and len(localGraph.getLanLinksInCloud()) > 0:
|
||||
continue
|
||||
filteredGraphs.append(localGraph)
|
||||
return filteredGraphs
|
||||
|
||||
def __allowCloudsWithLanLinks__(self):
|
||||
if 'exclude_clouds_with_lan_links' in self.__filters__ or 'no_lan' in self.__filters__:
|
||||
return False
|
||||
return True
|
||||
|
||||
def __getFilters(self):
|
||||
return [] if self.__args__.filters == None else self.__args__.filters
|
||||
|
||||
def filterNodes(self, nodes):
|
||||
filteredNodes = []
|
||||
for node in nodes:
|
||||
filteredNodes.append(node)
|
||||
return filteredNodes
|
44
generator/NginxConfGen.py
Normal file
44
generator/NginxConfGen.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from exceptions.HieraException import HieraException
|
||||
from generator.Filter import Filter
|
||||
class NginxConfGen(object):
|
||||
def __init__(self, domains, args):
|
||||
self.__domains__ = domains
|
||||
self.__args__ = args
|
||||
self.__filter__ = Filter(self.__args__)
|
||||
self.__generatedDomains__ = self.__genDomains__()
|
||||
|
||||
def __genDomains__(self):
|
||||
domains = {}
|
||||
for k,v in self.__domains__.items():
|
||||
domains[k] = self.__genDomain__(v)
|
||||
return domains
|
||||
|
||||
def __genDomain__(self, domain):
|
||||
nodes = {}
|
||||
for localGraph in self.__filter__.filterLocalGraphs(domain.localGraphs):
|
||||
try:
|
||||
for node in self.__filter__.filterNodes(localGraph.getNodesWithNoDependencies()):
|
||||
nodes[node.nodeID] = {
|
||||
'hostname' : node.hostname,
|
||||
'ipv6_addresses' : node.publicIPv6Addresses
|
||||
}
|
||||
except HieraException:
|
||||
print('Was not able to add local cloud, because no VPN link was found.')
|
||||
|
||||
return nodes
|
||||
|
||||
def writeNginxConfigFile(self):
|
||||
f = open(self.__args__.out_file,'w')
|
||||
f.write(self.__genNginxConfigFileContent__())
|
||||
f.close()
|
||||
|
||||
def __genNginxConfigFileContent__(self):
|
||||
content = ''
|
||||
for k, v in self.__generatedDomains__.items():
|
||||
content += 'geo $' + k + ' {\n default 0;'
|
||||
for ksub, vsub in v.items():
|
||||
for address in vsub['ipv6_addresses']:
|
||||
content += '\n ' + address + ' 1; #' + vsub['hostname']
|
||||
content += '\n}\n'
|
||||
return content
|
||||
|
0
generator/__init__.py
Normal file
0
generator/__init__.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue