Secondary nameservers: Allow IPv6

This commit is contained in:
David Duque 2020-05-28 15:47:02 +01:00
parent 211d3ff8a8
commit 235ebe9a4a
No known key found for this signature in database
GPG Key ID: 2F327738A3C0AE3A
1 changed files with 7 additions and 3 deletions

View File

@ -905,6 +905,8 @@ def set_secondary_dns(hostnames, env):
# Resolve hostname.
try:
response = resolver.query(item, "A")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
response = resolver.query(item, "AAAA")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
raise ValueError("Could not resolve the IP address of %s." % item)
else:
@ -912,12 +914,14 @@ def set_secondary_dns(hostnames, env):
try:
if "/" in item[4:]:
v = ipaddress.ip_network(item[4:]) # raises a ValueError if there's a problem
if not isinstance(v, ipaddress.IPv4Network): raise ValueError("That's an IPv6 subnet.")
if not isinstance(v, ipaddress.IPv4Network) and not isinstance(v, ipaddress.IPv6Network):
raise ValueError("That's neither an IPv4 or IPv6 subnet.")
else:
v = ipaddress.ip_address(item[4:]) # raises a ValueError if there's a problem
if not isinstance(v, ipaddress.IPv4Address): raise ValueError("That's an IPv6 address.")
if not isinstance(v, ipaddress.IPv4Network) and not isinstance(v, ipaddress.IPv6Network):
raise ValueError("That's neither an IPv4 or IPv6 address.")
except ValueError:
raise ValueError("'%s' is not an IPv4 address or subnet." % item[4:])
raise ValueError("'%s' is not an IPv4 or IPv6 address or subnet." % item[4:])
# Set.
set_custom_dns_record("_secondary_nameserver", "A", " ".join(hostnames), "set", env)