Some refactoring

This commit is contained in:
Difrex 2016-08-10 12:07:03 +03:00
parent fe92921cac
commit 3fa821e2dc

View File

@ -25,18 +25,25 @@ def resolve(app, conf):
# /etc/surok/conf.d/service_conf.json # /etc/surok/conf.d/service_conf.json
group = service['group'] group = service['group']
try: fqdn = '_' + service['name'] + '.' + group + '._tcp.' + domain
fqdn = '_' + service['name'] + '.' + group + '._tcp.' + domain hosts[service['name']] = do_query(fqdn)
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 DNSException:
print("Could not resolve " +
service['name'] + '.' +
group + '._tcp.' + domain)
return hosts return hosts
# Do SRV queries
# Return array: [{"name": "f.q.d.n", "port": 8876}]
def do_query(fqdn):
servers = []
try:
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]}
servers.append(server)
except DNSException:
print("Could not resolve " + fqdn)
return servers