From fe92921cac9e6a7d4c5e0d86024614138aeefedf Mon Sep 17 00:00:00 2001 From: Difrex Date: Wed, 10 Aug 2016 11:55:18 +0300 Subject: [PATCH] dns query lifetime --- surok/discovery.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/surok/discovery.py b/surok/discovery.py index a3d070e..cbde725 100644 --- a/surok/discovery.py +++ b/surok/discovery.py @@ -1,8 +1,10 @@ import dns.resolver +import dns.query +from dns.exception import DNSException # Resolve service from mesos-dns SRV record -# return dict {"servicename": [{"name": "service.f.q.d.n", "port": 9999}]} +# return dict {"servicename": [{"name": "service.f.q.d.n.", "port": 9999}]} def resolve(app, conf): hosts = {} services = app['services'] @@ -24,16 +26,16 @@ def resolve(app, conf): group = service['group'] try: - for rdata in dns.resolver.query('_' + - service['name'] + '.' + - group + '._tcp.' + - domain, 'SRV'): + fqdn = '_' + service['name'] + '.' + group + '._tcp.' + domain + query = dns.resolver.query(fqdn, 'SRV') + query.lifetime = 1.0 + + for rdata in query: info = str(rdata).split() server = {'name': info[3], 'port': info[2]} - hosts[service['name']].append(server) - except Exception as e: - print(str(e) + ": Could not resolve " + + except DNSException: + print("Could not resolve " + service['name'] + '.' + group + '._tcp.' + domain)