From 0c3c2014cc52d819a7c82b8e26298daf9af2b606 Mon Sep 17 00:00:00 2001 From: Difrex Date: Wed, 3 Aug 2016 09:54:09 +0300 Subject: [PATCH] my dict update --- surok.py | 2 +- surok/discovery.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/surok.py b/surok.py index 1cf77e8..e74276c 100755 --- a/surok.py +++ b/surok.py @@ -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)) diff --git a/surok/discovery.py b/surok/discovery.py index 6d8297a..f4a6ff4 100644 --- a/surok/discovery.py +++ b/surok/discovery.py @@ -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