my dict update

This commit is contained in:
Difrex 2016-08-03 09:54:09 +03:00
parent d62a424cf2
commit 0c3c2014cc
2 changed files with 11 additions and 6 deletions

View File

@ -36,7 +36,7 @@ while 1:
for app in confs: for app in confs:
app_conf = load_app_conf(app) app_conf = load_app_conf(app)
app_hosts = resolve(app_conf, conf) app_hosts = resolve(app_conf, conf)
my = { 'hosts': app_hosts } my = { 'services': app_hosts }
service_conf = gen(my, app_conf['template']) service_conf = gen(my, app_conf['template'])
print(reload_conf(service_conf, app_conf)) print(reload_conf(service_conf, app_conf))

View File

@ -1,13 +1,18 @@
import dns.resolver import dns.resolver
def resolve(app, conf): def resolve(app, conf):
hosts = [] hosts = {}
services = app['services'] services = app['services']
domain = conf['domain'] domain = conf['domain']
for service in services: for service in services:
for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'): hosts[service['name']] = []
info = str(rdata).split() try:
server = { service['name']: { 'name': info[3], 'port': info[2] } } for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'):
hosts.append(server) info = str(rdata).split()
server = { 'name': info[3], 'port': info[2] }
hosts[ service['name'] ].append(server)
except Exception as e:
print("Could not resolve " + service['name'] + '.' + service['group'] + '._tcp.' + domain)
return hosts return hosts