Commit 5dd14183 authored by godog's avatar godog

main: run a command when zones are added or removed

parent b1b40111
Pipeline #2007 passed with stage
in 23 seconds
import optparse
import os
import shlex
import subprocess
import sys
import yaml
from zonetool import zone
......@@ -22,6 +24,10 @@ def main():
parser.add_option(
'--delete', dest='delete', action='store_true',
help='Delete obsolete zone files in output_dir')
parser.add_option(
'--if-changed', dest='if_changed',
default='', metavar='COMMAND',
help='Run COMMAND if zones have been added or removed.')
parser.add_option(
'-n', '--dry-run', dest='dry_run', action='store_true',
help='Do not actually write zone files')
......@@ -74,6 +80,11 @@ def main():
dry_run=opts.dry_run,
update_policies=opts.update_policies)
changed, removed = zw.write(zp.render(), postproc=pproc)
if opts.if_changed and (len(changed) + len(removed) > 0):
if not opts.dry_run:
subprocess.check_call(shlex.split(opts.if_changed))
sys.exit(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment