2 from pathlib import Path
3 from texttable import Texttable
5 from nsconfig.core import Nsc
8 def do_test(nsc: Nsc) -> None:
9 test_dir = Path('test')
10 test_dir.mkdir(exist_ok=True)
11 for z in nsc.get_zones():
12 print(f'Zone: {z.name}')
13 print(f'Old serial: {z.prev_state.serial}')
14 print(f'Old hash: {z.prev_state.hash}')
15 print(f'New serial: {z.state.serial}')
16 print(f'New hash: {z.state.hash}')
17 out_file = test_dir / z.safe_name
18 print(f'Dumping to: {out_file}')
19 with open(out_file, 'w') as f:
24 def do_status(nsc: Nsc) -> None:
25 table = Texttable(max_width=0)
26 table.header(['Zone', 'Old serial', 'Old hash', 'New serial', 'New hash', 'S'])
27 table.set_cols_dtype(['t', 'i', 't', 'i', 't', 't'])
28 table.set_deco(Texttable.HEADER)
30 for z in nsc.get_zones():
31 if z.state.serial == z.prev_state.serial:
47 def do_update(nsc: Nsc) -> None:
48 for z in nsc.get_zones():
49 if z.state.serial != z.prev_state.serial:
50 print(f'Updating zone {z.name} (serial {z.state.serial})')
55 def main(nsc: Nsc) -> None:
56 parser = argparse.ArgumentParser(description='Configure name server')
57 subparsers = parser.add_subparsers(help='action to perform', dest='action', required=True, metavar='ACTION')
59 test_parser = subparsers.add_parser('test', help='test new configuration', description='Test new configuration')
61 status_parser = subparsers.add_parser('status', help='list status of zones', description='List status of zones')
63 update_parser = subparsers.add_parser('update', help='update configuration', description='Update zone files and daemon configuration as needed')
65 args = parser.parse_args()
69 if args.action == 'test':
71 elif args.action == 'status':
73 elif args.action == 'update':