This commit is contained in:
mwiegand 2021-11-07 18:07:28 +01:00
parent 6c64dbfdde
commit f333ad963e
3 changed files with 29 additions and 22 deletions

View file

@ -9,7 +9,7 @@ key "${key_name}" {
% endfor % endfor
% endfor % endfor
# ACL # ACLS
% for acl_name, acl_content in acls.items(): % for acl_name, acl_content in acls.items():
acl "${acl_name}" { acl "${acl_name}" {

View file

@ -1,6 +1,11 @@
from ipaddress import ip_address, ip_interface from ipaddress import ip_address, ip_interface
from datetime import datetime from datetime import datetime
if node.metadata.get('bind/type') == 'master':
master_node = node
else:
master_node = repo.get_node(node.metadata.get('bind/master_node'))
directories[f'/var/lib/bind'] = { directories[f'/var/lib/bind'] = {
'owner': 'bind', 'owner': 'bind',
'group': 'bind', 'group': 'bind',
@ -37,24 +42,12 @@ files['/etc/bind/named.conf'] = {
], ],
} }
if node.metadata.get('bind/type') == 'master':
master_node = node
master_ip = None
slave_ips = [
ip_interface(repo.get_node(slave).metadata.get('network/external/ipv4')).ip
for slave in node.metadata.get('bind/slaves')
]
else:
master_node = repo.get_node(node.metadata.get('bind/master_node'))
master_ip = ip_interface(repo.get_node(node.metadata.get('bind/master_node')).metadata.get('network/external/ipv4')).ip
slave_ips = []
files['/etc/bind/named.conf.options'] = { files['/etc/bind/named.conf.options'] = {
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
'type': node.metadata.get('bind/type'), 'type': node.metadata.get('bind/type'),
'slave_ips': sorted(slave_ips), 'slave_ips': node.metadata.get('bind/slave_ips', []),
'master_ip': master_ip, 'master_ip': node.metadata.get('bind/master_ip', None),
}, },
'owner': 'root', 'owner': 'root',
'group': 'bind', 'group': 'bind',
@ -73,7 +66,7 @@ files['/etc/bind/named.conf.local'] = {
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
'type': node.metadata.get('bind/type'), 'type': node.metadata.get('bind/type'),
'master_ip': master_ip, 'master_ip': node.metadata.get('bind/master_ip', None),
'acls': { 'acls': {
**master_node.metadata.get('bind/acls'), **master_node.metadata.get('bind/acls'),
**{ **{
@ -99,7 +92,7 @@ files['/etc/bind/named.conf.local'] = {
], ],
} }
for view_name, view_conf in node.metadata.get('bind/views').items(): for view_name, view_conf in master_node.metadata.get('bind/views').items():
directories[f"/var/lib/bind/{view_name}"] = { directories[f"/var/lib/bind/{view_name}"] = {
'owner': 'bind', 'owner': 'bind',
'group': 'bind', 'group': 'bind',

View file

@ -57,13 +57,27 @@ defaults = {
@metadata_reactor.provides( @metadata_reactor.provides(
'bind/type', 'bind/type',
'bind/master_ip',
'bind/slave_ips',
) )
def type(metadata): def master_slave(metadata):
return { if metadata.get('bind/master_node', None):
'bind': { return {
'type': 'slave' if metadata.get('bind/master_node', None) else 'master', 'bind': {
'type': 'slave',
'master_ip': str(ip_interface(repo.get_node(metadata.get('bind/master_node')).metadata.get('network/external/ipv4')).ip),
}
}
else:
return {
'bind': {
'type': 'master',
'slave_ips': {
str(ip_interface(repo.get_node(slave).metadata.get('network/external/ipv4')).ip)
for slave in metadata.get('bind/slaves')
}
}
} }
}
@metadata_reactor.provides( @metadata_reactor.provides(