This commit is contained in:
Difrex 2016-08-09 15:23:32 +03:00
parent 4766ad74ee
commit ca0df7c33c

View File

@ -1,5 +1,8 @@
import dns.resolver
# Resolve service from mesos-dns SRV record
# return dict {"servicename": [{"name": "service.f.q.d.n", "port": 9999}]}
def resolve(app, conf):
hosts = {}
services = app['services']
@ -7,12 +10,17 @@ def resolve(app, conf):
for service in services:
hosts[service['name']] = []
try:
for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'):
for rdata in dns.resolver.query('_' +
service['name'] + '.' +
service['group'] + '._tcp.' +
domain, 'SRV'):
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:
print("Could not resolve " + service['name'] + '.' + service['group'] + '._tcp.' + domain)
print(str(e) + ": Could not resolve " +
service['name'] + '.' +
service['group'] + '._tcp.' + domain)
return hosts