From 607da9d39bb897f7b30d37b4b6a4692cb4d61579 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 9 Nov 2020 15:37:48 +0100 Subject: [PATCH] bundles/powerdns: user resolve_identifier() for node-dns-entries --- bundles/powerdns/metadata.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/bundles/powerdns/metadata.py b/bundles/powerdns/metadata.py index 345a7a9..006b0cf 100644 --- a/bundles/powerdns/metadata.py +++ b/bundles/powerdns/metadata.py @@ -75,17 +75,29 @@ def generate_dns_entries_for_nodes(metadata): ip4 = None ip6 = None - # We only need this for GCE, because machines over there don't - # have a public ipv4 address. - if rnode.metadata.get('external_ipv4', None): - ip4 = rnode.metadata.get('external_ipv4') + 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 + ): + ip4 = ip - for iface, config in sorted(rnode.metadata.get('interfaces', {}).items()): - if not ip4 and 'ipv4' in config: - ip4 = sorted(config['ipv4'])[0] + if ( + not ip6 and + not ip.is_private and + ':' in str(ip) + ): + ip6 = ip - if not ip6 and 'ipv6' in config: - ip6 = sorted(config['ipv6'])[0] + # 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 ip4: results.add('{} IN A {}'.format(dns_name, ip4))