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:
app_conf = load_app_conf(app)
app_hosts = resolve(app_conf, conf)
my = { 'hosts': app_hosts }
my = { 'services': app_hosts }
service_conf = gen(my, app_conf['template'])
print(reload_conf(service_conf, app_conf))

View File

@ -1,13 +1,18 @@
import dns.resolver
def resolve(app, conf):
hosts = []
hosts = {}
services = app['services']
domain = conf['domain']
for service in services:
for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'):
info = str(rdata).split()
server = { service['name']: { 'name': info[3], 'port': info[2] } }
hosts.append(server)
hosts[service['name']] = []
try:
for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'):
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