diff --git a/bundles/bind/metadata.py b/bundles/bind/metadata.py index fbf0e78..194c602 100644 --- a/bundles/bind/metadata.py +++ b/bundles/bind/metadata.py @@ -1,6 +1,7 @@ from ipaddress import ip_interface from json import dumps h = repo.libs.hashable.hashable +repo.libs.bind.repo = repo defaults = { 'apt': { @@ -103,7 +104,7 @@ def collect_records(metadata): for type, values in records.items(): for value in values: - if repo.libs.bind.record_matches_view(value, type, name, zone, view_name, metadata, repo): + if repo.libs.bind.record_matches_view(value, type, name, zone, view_name, metadata): views\ .setdefault(view_name, {})\ .setdefault('zones', {})\ diff --git a/libs/bind.py b/libs/bind.py index 6deee0a..e9feac5 100644 --- a/libs/bind.py +++ b/libs/bind.py @@ -1,6 +1,13 @@ from ipaddress import ip_address -def record_matches_view(value, type, name, zone, view, metadata, repo): +def _values_from_all_nodes(type, name, zone): + return { + value + for node in repo.nodes + for value in node.metadata.get(f'dns/{name}.{zone}/{type}', []) + } + +def record_matches_view(value, type, name, zone, view, metadata): if type not in ['A', 'AAAA']: return True @@ -9,12 +16,7 @@ def record_matches_view(value, type, name, zone, view, metadata, repo): return True elif not list(filter( lambda other_value: ip_address(other_value).is_private, - { - other_value - for other_node in repo.nodes - if other_node.metadata.get(f'dns/{name}.{zone}/{type}', []) - for other_value in other_node.metadata.get(f'dns/{name}.{zone}/{type}') - } + _values_from_all_nodes(type, name, zone), )): return True else: @@ -22,11 +24,6 @@ def record_matches_view(value, type, name, zone, view, metadata, repo): return True elif not list(filter( lambda other_value: ip_address(other_value).is_global, - { - other_value - for other_node in repo.nodes - if other_node.metadata.get(f'dns/{name}.{zone}/{type}', []) - for other_value in other_node.metadata.get(f'dns/{name}.{zone}/{type}') - } + _values_from_all_nodes(type, name, zone), )): return True