PEP8
This commit is contained in:
parent
4766ad74ee
commit
ca0df7c33c
@ -1,5 +1,8 @@
|
|||||||
import dns.resolver
|
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):
|
def resolve(app, conf):
|
||||||
hosts = {}
|
hosts = {}
|
||||||
services = app['services']
|
services = app['services']
|
||||||
@ -7,12 +10,17 @@ def resolve(app, conf):
|
|||||||
for service in services:
|
for service in services:
|
||||||
hosts[service['name']] = []
|
hosts[service['name']] = []
|
||||||
try:
|
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()
|
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 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
|
return hosts
|
||||||
|
Loading…
Reference in New Issue
Block a user