bundles/powerdns: user resolve_identifier() for node-dns-entries

This commit is contained in:
Franzi 2020-11-09 15:37:48 +01:00
parent 5ffaa9b1c8
commit 607da9d39b
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -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))