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