From 235ebe9a4abe79ea659b28841e3bc1f4d35b212e Mon Sep 17 00:00:00 2001 From: David Duque Date: Thu, 28 May 2020 15:47:02 +0100 Subject: [PATCH] Secondary nameservers: Allow IPv6 --- management/dns_update.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index 7d053d5e..9f664172 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -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)