in functions/source/populate_NLB_TG_with_ALB/dns/resolver.py [0:0]
def __init__(self, qname, rdtype, rdclass, response,
raise_on_no_answer=True):
self.qname = qname
self.rdtype = rdtype
self.rdclass = rdclass
self.response = response
min_ttl = -1
rrset = None
for count in xrange(0, 15):
try:
rrset = response.find_rrset(response.answer, qname,
rdclass, rdtype)
if min_ttl == -1 or rrset.ttl < min_ttl:
min_ttl = rrset.ttl
break
except KeyError:
if rdtype != dns.rdatatype.CNAME:
try:
crrset = response.find_rrset(response.answer,
qname,
rdclass,
dns.rdatatype.CNAME)
if min_ttl == -1 or crrset.ttl < min_ttl:
min_ttl = crrset.ttl
for rd in crrset:
qname = rd.target
break
continue
except KeyError:
if raise_on_no_answer:
raise NoAnswer(response=response)
if raise_on_no_answer:
raise NoAnswer(response=response)
if rrset is None and raise_on_no_answer:
raise NoAnswer(response=response)
self.canonical_name = qname
self.rrset = rrset
if rrset is None:
while 1:
# Look for a SOA RR whose owner name is a superdomain
# of qname.
try:
srrset = response.find_rrset(response.authority, qname,
rdclass, dns.rdatatype.SOA)
if min_ttl == -1 or srrset.ttl < min_ttl:
min_ttl = srrset.ttl
if srrset[0].minimum < min_ttl:
min_ttl = srrset[0].minimum
break
except KeyError:
try:
qname = qname.parent()
except dns.name.NoParent:
break
self.expiration = time.time() + min_ttl