from bundlewrap.exceptions import NoSuchGroup defaults = { 'apt': { 'packages': { 'pdns-server': {}, 'pdns-tools': {}, 'pdns-backend-bind': {}, 'pdns-backend-pgsql': {}, }, }, 'powerdns': { 'api_key': repo.vault.password_for('{} powerdns api'.format(node.name)), }, 'postgresql': { 'users': { 'powerdns': { 'password': repo.vault.password_for('{} postgresql powerdns'.format(node.name)), }, }, 'databases': { 'powerdns': { 'owner': 'powerdns', }, }, }, } @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): ips.update({ str(ip) for ip in repo.libs.tools.resolve_identifier(repo, rnode.name) }) return { 'powerdns': { 'my_secondary_servers': ips, }, } @metadata_reactor def get_ips_of_primary_nameservers(metadata): if not metadata.get('powerdns/is_secondary', False): return {} 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) }) return { 'powerdns': { 'my_primary_servers': ips, }, } @metadata_reactor def generate_dns_entries_for_nodes(metadata): results = set() for rnode in repo.nodes: node_name_split = rnode.name.split('.') node_name_split.reverse() dns_name = '.'.join(node_name_split) 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 ): ip4 = ip if ( not ip6 and not ip.is_private and ':' in str(ip) ): 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 ip4: results.add('{} IN A {}'.format(dns_name, ip4)) if ip6: results.add('{} IN AAAA {}'.format(dns_name, ip6)) return { 'powerdns': { 'bind-zones': { 'kunbox.net': { 'records': results, }, }, }, } @metadata_reactor def hosts_entries_for_all_dns_servers(metadata): entries = {} for rnode in repo.nodes_in_group('dns'): 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')) return { 'hosts': { 'entries': entries, }, }