dns query lifetime
This commit is contained in:
parent
60b1a798bf
commit
fe92921cac
@ -1,8 +1,10 @@
|
|||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
import dns.query
|
||||||
|
from dns.exception import DNSException
|
||||||
|
|
||||||
|
|
||||||
# Resolve service from mesos-dns SRV record
|
# 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):
|
def resolve(app, conf):
|
||||||
hosts = {}
|
hosts = {}
|
||||||
services = app['services']
|
services = app['services']
|
||||||
@ -24,16 +26,16 @@ def resolve(app, conf):
|
|||||||
group = service['group']
|
group = service['group']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for rdata in dns.resolver.query('_' +
|
fqdn = '_' + service['name'] + '.' + group + '._tcp.' + domain
|
||||||
service['name'] + '.' +
|
query = dns.resolver.query(fqdn, 'SRV')
|
||||||
group + '._tcp.' +
|
query.lifetime = 1.0
|
||||||
domain, 'SRV'):
|
|
||||||
|
for rdata in query:
|
||||||
info = str(rdata).split()
|
info = str(rdata).split()
|
||||||
server = {'name': info[3], 'port': info[2]}
|
server = {'name': info[3], 'port': info[2]}
|
||||||
|
|
||||||
hosts[service['name']].append(server)
|
hosts[service['name']].append(server)
|
||||||
except Exception as e:
|
except DNSException:
|
||||||
print(str(e) + ": Could not resolve " +
|
print("Could not resolve " +
|
||||||
service['name'] + '.' +
|
service['name'] + '.' +
|
||||||
group + '._tcp.' + domain)
|
group + '._tcp.' + domain)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user