Skip to content

Commit

Permalink
add the option to prefer the primary nameserver in query_ns, use it f…
Browse files Browse the repository at this point in the history
…or domain checker,
  • Loading branch information
ThomasWaldmann committed Jan 26, 2015
1 parent a0dee62 commit b562c0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions nsupdate/main/dnstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ def update(fqdn, ipaddr, ttl=60):
raise SameIpError


def query_ns(fqdn, rdtype):
def query_ns(fqdn, rdtype, prefer_primary=False):
"""
query a dns name from our master server
query a dns name from our DNS server(s)
:param fqdn: fqdn to query the name server for
:type fqdn: dnstools.FQDN
:param rdtype: the query type
:type rdtype: int or str
:param prefer_primary: whether we rather want to query the primary first
:return: IP (as str)
:raises: see dns.resolver.Resolver.query
"""
Expand All @@ -213,8 +214,8 @@ def query_ns(fqdn, rdtype):
# want into the documented attributes:
resolver.nameservers = [nameserver, ]
if nameserver2:
# if we have a secondary ns, prefer it for queries
resolver.nameservers.insert(0, nameserver2)
pos = 1 if prefer_primary else 0
resolver.nameservers.insert(pos, nameserver2)
# we must put the root zone into the search list, so that if a fqdn without "."
# at the end comes in, it will append "." (and not the service server's domain).
resolver.search = [dns.name.root, ]
Expand Down
2 changes: 1 addition & 1 deletion nsupdate/management/commands/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def check_dns(domain):
"""
fqdn = FQDN(host=None, domain=domain)
try:
query_ns(fqdn, 'SOA')
query_ns(fqdn, 'SOA', prefer_primary=True)
queries_ok = True
except (dns.resolver.Timeout, dns.resolver.NoNameservers,
dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, NameServerNotAvailable):
Expand Down

0 comments on commit b562c0f

Please sign in to comment.