diff --git a/octodns/manager.py b/octodns/manager.py index 027df54..6497ff2 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -65,6 +65,13 @@ class MainThreadExecutor(object): class Manager(object): log = logging.getLogger('Manager') + @classmethod + def _plan_keyer(cls, p): + try: + return len(p[1].changes[0].record.zone.name) + except (AttributeError, IndexError): + return 0 + def __init__(self, config_file, max_workers=None, include_meta=False): self.log.info('__init__: config_file=%s', config_file) @@ -288,6 +295,13 @@ class Manager(object): # plan pairs. plans = [p for f in futures for p in f.result()] + # Best effort sort plans children first so that we create/update + # children zones before parents which should allow us to more safely + # extract things into sub-zones. Combining a child back into a parent + # can't really be done all that safely in general so we'll optimize for + # this direction. + plans.sort(key=self._plan_keyer, reverse=True) + for output in self.plan_outputs.values(): output.run(plans=plans, log=self.log)