mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
working auto-arpa setup
This commit is contained in:
@@ -11,6 +11,7 @@ from sys import stdout
|
||||
|
||||
from . import __VERSION__
|
||||
from .idna import IdnaDict, idna_decode, idna_encode
|
||||
from .processor.arpa import AutoArpa
|
||||
from .provider.base import BaseProvider
|
||||
from .provider.plan import Plan
|
||||
from .provider.yaml import SplitYamlProvider, YamlProvider
|
||||
@@ -99,20 +100,12 @@ class Manager(object):
|
||||
return len(plan.changes[0].record.zone.name) if plan.changes else 0
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config_file,
|
||||
max_workers=None,
|
||||
include_meta=False,
|
||||
delay_arpa=False,
|
||||
self, config_file, max_workers=None, include_meta=False, auto_arpa=False
|
||||
):
|
||||
version = self._try_version('octodns', version=__VERSION__)
|
||||
self.log.info(
|
||||
'__init__: config_file=%s, delay_arpa=%s (octoDNS %s)',
|
||||
config_file,
|
||||
version,
|
||||
delay_arpa,
|
||||
'__init__: config_file=%s, (octoDNS %s)', config_file, version
|
||||
)
|
||||
self.delay_arpa = delay_arpa
|
||||
|
||||
self._configured_sub_zones = None
|
||||
|
||||
@@ -129,6 +122,8 @@ class Manager(object):
|
||||
manager_config, include_meta
|
||||
)
|
||||
|
||||
self.auto_arpa = self._config_auto_arpa(manager_config, auto_arpa)
|
||||
|
||||
self.global_processors = manager_config.get('processors', [])
|
||||
self.log.info('__init__: global_processors=%s', self.global_processors)
|
||||
|
||||
@@ -138,6 +133,16 @@ class Manager(object):
|
||||
processors_config = self.config.get('processors', {})
|
||||
self.processors = self._config_processors(processors_config)
|
||||
|
||||
if self.auto_arpa:
|
||||
self.log.info(
|
||||
'__init__: adding auto-arpa to processors and providers, appending it to global_processors list'
|
||||
)
|
||||
kwargs = self.auto_arpa if isinstance(auto_arpa, dict) else {}
|
||||
auto_arpa = AutoArpa('auto-arpa', **kwargs)
|
||||
self.providers[auto_arpa.name] = auto_arpa
|
||||
self.processors[auto_arpa.name] = auto_arpa
|
||||
self.global_processors.append(auto_arpa.name)
|
||||
|
||||
plan_outputs_config = manager_config.get(
|
||||
'plan_outputs',
|
||||
{
|
||||
@@ -183,6 +188,11 @@ class Manager(object):
|
||||
self.log.info('_config_include_meta: include_meta=%s', include_meta)
|
||||
return include_meta
|
||||
|
||||
def _config_auto_arpa(self, manager_config, auto_arpa=False):
|
||||
auto_arpa = auto_arpa or manager_config.get('auto_arpa', False)
|
||||
self.log.info('_config_auto_arpa: auto_arpa=%s', auto_arpa)
|
||||
return auto_arpa
|
||||
|
||||
def _config_providers(self, providers_config):
|
||||
self.log.debug('_config_providers: configuring providers')
|
||||
providers = {}
|
||||
@@ -480,12 +490,12 @@ class Manager(object):
|
||||
)
|
||||
|
||||
if (
|
||||
self.delay_arpa
|
||||
self.auto_arpa
|
||||
and eligible_zones
|
||||
and any(e.endswith('arpa.') for e in eligible_zones)
|
||||
):
|
||||
raise ManagerException(
|
||||
'ARPA zones cannot be synced during partial runs when delay_arpa is enabled'
|
||||
'ARPA zones cannot be synced during partial runs when auto_arpa is enabled'
|
||||
)
|
||||
|
||||
zones = self.config['zones']
|
||||
@@ -598,7 +608,7 @@ class Manager(object):
|
||||
'lenient': lenient,
|
||||
}
|
||||
|
||||
if self.delay_arpa and zone_name.endswith('arpa.'):
|
||||
if self.auto_arpa and zone_name.endswith('arpa.'):
|
||||
delayed_arpa.append(kwargs)
|
||||
else:
|
||||
futures.append(
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
4:
|
||||
type: PTR
|
||||
value: unit.tests.
|
||||
5:
|
||||
type: PTR
|
||||
value: unit.tests.
|
||||
@@ -1,6 +1,7 @@
|
||||
manager:
|
||||
max_workers: 2
|
||||
delayed_arpa: true
|
||||
auto_arpa:
|
||||
ttl: 1800
|
||||
|
||||
providers:
|
||||
in:
|
||||
@@ -22,6 +23,11 @@ zones:
|
||||
- dump
|
||||
3.2.2.in-addr.arpa.:
|
||||
sources:
|
||||
- in
|
||||
- auto-arpa
|
||||
targets:
|
||||
- dump
|
||||
b.e.f.f.f.d.1.8.f.2.6.0.1.2.e.0.0.5.0.4.4.6.0.1.0.6.2.ip6.arpa.:
|
||||
sources:
|
||||
- auto-arpa
|
||||
targets:
|
||||
- dump
|
||||
|
||||
@@ -909,9 +909,7 @@ class TestManager(TestCase):
|
||||
)
|
||||
|
||||
def test_delayed_arpa(self):
|
||||
manager = Manager(
|
||||
get_config_filename('simple-arpa.yaml'), delay_arpa=True
|
||||
)
|
||||
manager = Manager(get_config_filename('simple-arpa.yaml'))
|
||||
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
environ['YAML_TMP_DIR'] = tmpdir.dirname
|
||||
@@ -927,13 +925,13 @@ class TestManager(TestCase):
|
||||
eligible_zones=['unit.tests.', '3.2.2.in-addr.arpa.'],
|
||||
)
|
||||
self.assertEqual(
|
||||
'ARPA zones cannot be synced during partial runs when delay_arpa is enabled',
|
||||
'ARPA zones cannot be synced during partial runs when auto_arpa is enabled',
|
||||
str(ctx.exception),
|
||||
)
|
||||
|
||||
# full sync with arpa is fine, 2 extra records from it
|
||||
tc = manager.sync(dry_run=False)
|
||||
self.assertEqual(24, tc)
|
||||
self.assertEqual(26, tc)
|
||||
|
||||
|
||||
class TestMainThreadExecutor(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user