libs/tools: change resolve_identifier() to return ipv4 and ipv6 separately
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2020-11-09 18:46:37 +01:00
parent 67386d9efa
commit eaf268aea9
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 28 additions and 28 deletions

View file

@ -35,9 +35,8 @@ def get_ips_of_secondary_nameservers(metadata):
ips = set()
for rnode in repo.nodes_in_group('dns'):
if rnode.metadata.get('powerdns/is_secondary', False):
ips.update({
str(ip) for ip in repo.libs.tools.resolve_identifier(repo, rnode.name)
})
for identifier, found_ips in repo.libs.tools.resolve_identifier(repo, rnode.name).items():
ips.update({str(ip) for ip in found_ips})
return {
'powerdns': {
@ -53,9 +52,8 @@ def get_ips_of_primary_nameservers(metadata):
ips = set()
for rnode in repo.nodes_in_group('dns'):
if not rnode.metadata.get('powerdns/is_secondary', False):
ips.update({
str(ip) for ip in repo.libs.tools.resolve_identifier(repo, rnode.name)
})
for identifier, found_ips in repo.libs.tools.resolve_identifier(repo, rnode.name).items():
ips.update({str(ip) for ip in found_ips})
return {
'powerdns': {
@ -75,29 +73,19 @@ def generate_dns_entries_for_nodes(metadata):
ip4 = None
ip6 = None
ips = repo.libs.tools.resolve_identifier(repo, rnode.name)
for ip in ips:
if (
not ip4 and
not ip.is_private and
'.' in str(ip) # poor-mans 'is this ipv4' detection
):
found_ips = repo.libs.tools.resolve_identifier(repo, rnode.name)
for ip in sorted(found_ips['ipv4']):
if not ip4 and not ip.is_private:
ip4 = ip
if (
not ip6 and
not ip.is_private and
':' in str(ip)
):
for ip in sorted(found_ips['ipv6']):
if not ip6 and not ip.is_private:
ip6 = ip
# We're doing this once again to get the nodes which only have
# private ips.
if not ip4:
for ip in ips:
if '.' in str(ip):
ip4 = ip
break
if not ip4 and len(found_ips['ipv4']):
ip4 = sorted(found_ips['ipv4'])[0]
if ip4:
results.add('{} IN A {}'.format(dns_name, ip4))