2020-10-16 21:02:47 +00:00
|
|
|
from bundlewrap.exceptions import NoSuchGroup
|
|
|
|
|
2020-10-13 17:06:22 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
|
|
|
'pdns-server': {},
|
|
|
|
'pdns-tools': {},
|
|
|
|
'pdns-backend-bind': {},
|
|
|
|
'pdns-backend-pgsql': {},
|
|
|
|
},
|
|
|
|
},
|
2020-10-16 15:44:31 +00:00
|
|
|
'powerdns': {
|
|
|
|
'api_key': repo.vault.password_for('{} powerdns api'.format(node.name)),
|
|
|
|
},
|
2020-10-13 17:06:22 +00:00
|
|
|
'postgresql': {
|
|
|
|
'users': {
|
|
|
|
'powerdns': {
|
|
|
|
'password': repo.vault.password_for('{} postgresql powerdns'.format(node.name)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'databases': {
|
|
|
|
'powerdns': {
|
|
|
|
'owner': 'powerdns',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-16 21:02:47 +00:00
|
|
|
|
|
|
|
|
2020-10-25 09:53:55 +00:00
|
|
|
@metadata_reactor
|
|
|
|
def get_ips_of_secondary_nameservers(metadata):
|
|
|
|
if metadata.get('powerdns/is_secondary', False):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
ips = set()
|
|
|
|
for rnode in repo.nodes_in_group('dns'):
|
|
|
|
if rnode.metadata.get('powerdns/is_secondary', False):
|
2020-11-09 17:46:37 +00:00
|
|
|
for identifier, found_ips in repo.libs.tools.resolve_identifier(repo, rnode.name).items():
|
|
|
|
ips.update({str(ip) for ip in found_ips})
|
2020-10-25 09:53:55 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'powerdns': {
|
|
|
|
'my_secondary_servers': ips,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-16 21:02:47 +00:00
|
|
|
@metadata_reactor
|
2020-10-17 10:56:17 +00:00
|
|
|
def get_ips_of_primary_nameservers(metadata):
|
|
|
|
if not metadata.get('powerdns/is_secondary', False):
|
2020-10-16 21:02:47 +00:00
|
|
|
return {}
|
|
|
|
|
2020-10-17 10:56:17 +00:00
|
|
|
ips = set()
|
|
|
|
for rnode in repo.nodes_in_group('dns'):
|
|
|
|
if not rnode.metadata.get('powerdns/is_secondary', False):
|
2020-11-09 17:46:37 +00:00
|
|
|
for identifier, found_ips in repo.libs.tools.resolve_identifier(repo, rnode.name).items():
|
|
|
|
ips.update({str(ip) for ip in found_ips})
|
2020-10-16 21:02:47 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'powerdns': {
|
2020-10-25 09:53:55 +00:00
|
|
|
'my_primary_servers': ips,
|
2020-10-16 21:02:47 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor
|
2020-10-17 10:57:35 +00:00
|
|
|
def generate_dns_entries_for_nodes(metadata):
|
|
|
|
results = set()
|
2020-10-16 21:02:47 +00:00
|
|
|
|
|
|
|
for rnode in repo.nodes:
|
2020-10-17 10:57:35 +00:00
|
|
|
node_name_split = rnode.name.split('.')
|
|
|
|
node_name_split.reverse()
|
|
|
|
dns_name = '.'.join(node_name_split)
|
|
|
|
ip4 = None
|
|
|
|
ip6 = None
|
2020-10-16 21:02:47 +00:00
|
|
|
|
2020-11-09 17:46:37 +00:00
|
|
|
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:
|
2020-11-09 14:37:48 +00:00
|
|
|
ip4 = ip
|
|
|
|
|
2020-11-09 17:46:37 +00:00
|
|
|
for ip in sorted(found_ips['ipv6']):
|
|
|
|
if not ip6 and not ip.is_private:
|
2020-11-09 14:37:48 +00:00
|
|
|
ip6 = ip
|
|
|
|
|
|
|
|
# We're doing this once again to get the nodes which only have
|
|
|
|
# private ips.
|
2020-11-09 17:46:37 +00:00
|
|
|
if not ip4 and len(found_ips['ipv4']):
|
|
|
|
ip4 = sorted(found_ips['ipv4'])[0]
|
2020-10-17 10:57:35 +00:00
|
|
|
|
|
|
|
if ip4:
|
|
|
|
results.add('{} IN A {}'.format(dns_name, ip4))
|
2020-10-16 21:02:47 +00:00
|
|
|
|
2020-10-17 10:57:35 +00:00
|
|
|
if ip6:
|
|
|
|
results.add('{} IN AAAA {}'.format(dns_name, ip6))
|
|
|
|
|
|
|
|
return {
|
|
|
|
'powerdns': {
|
|
|
|
'bind-zones': {
|
|
|
|
'kunbox.net': {
|
|
|
|
'records': results,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-25 09:58:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor
|
|
|
|
def hosts_entries_for_all_dns_servers(metadata):
|
|
|
|
entries = {}
|
|
|
|
|
|
|
|
for rnode in repo.nodes_in_group('dns'):
|
2020-10-25 10:07:23 +00:00
|
|
|
if rnode.name == node.name:
|
|
|
|
continue
|
|
|
|
|
|
|
|
ip = rnode.metadata.get('external_ipv4')
|
|
|
|
|
|
|
|
if ip:
|
|
|
|
entries[ip] = {
|
|
|
|
rnode.metadata.get('hostname'),
|
|
|
|
rnode.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
if rnode.metadata.get('powerdns/my_hostname', None):
|
|
|
|
entries[ip].add(rnode.metadata.get('powerdns/my_hostname'))
|
2020-10-25 09:58:11 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'hosts': {
|
|
|
|
'entries': entries,
|
|
|
|
},
|
|
|
|
}
|