]> mj.ucw.cz Git - pynsc.git/blobdiff - nsconfig/cli.py
Support for secondary zones
[pynsc.git] / nsconfig / cli.py
index 241ede47d051a92559b75cc36b1ca12fe750837c..9d342c071ab232256db4c2f2add91a252af4a992 100644 (file)
@@ -2,7 +2,7 @@ import argparse
 from pathlib import Path
 from texttable import Texttable
 
-from nsconfig.core import Nsc
+from nsconfig.core import Nsc, ZoneType
 
 
 def do_test(nsc: Nsc) -> None:
@@ -10,14 +10,18 @@ def do_test(nsc: Nsc) -> None:
     test_dir.mkdir(exist_ok=True)
     for z in nsc.get_zones():
         print(f'Zone:        {z.name}')
-        print(f'Old serial:  {z.prev_state.serial}')
-        print(f'Old hash:    {z.prev_state.hash}')
-        print(f'New serial:  {z.state.serial}')
-        print(f'New hash:    {z.state.hash}')
-        out_file = test_dir / z.safe_name
-        print(f'Dumping to:  {out_file}')
-        with open(out_file, 'w') as f:
-            z.dump(file=f)
+        print(f'Type:        {z.zone_type.name}')
+        if z.zone_type == ZoneType.primary:
+            print(f'Old serial:  {z.prev_state.serial}')
+            print(f'Old hash:    {z.prev_state.hash}')
+            print(f'New serial:  {z.state.serial}')
+            print(f'New hash:    {z.state.hash}')
+            out_file = test_dir / z.safe_name
+            print(f'Dumping to:  {out_file}')
+            with open(out_file, 'w') as f:
+                z.dump(file=f)
+        else:
+            print(f'Primary:     {z.primary_server}')
         print()
 
 
@@ -28,6 +32,9 @@ def do_status(nsc: Nsc) -> None:
     table.set_deco(Texttable.HEADER)
 
     for z in nsc.get_zones():
+        if z.zone_type != ZoneType.primary:
+            table.add_row([z.name, 'secondary', "", "", "", ""])
+            continue
         if z.state.serial == z.prev_state.serial:
             action = ""
         else:
@@ -46,7 +53,7 @@ def do_status(nsc: Nsc) -> None:
 
 def do_update(nsc: Nsc) -> None:
     for z in nsc.get_zones():
-        if z.state.serial != z.prev_state.serial:
+        if z.zone_type == ZoneType.primary and z.state.serial != z.prev_state.serial:
             print(f'Updating zone {z.name} (serial {z.state.serial})')
             z.write_zone()
             z.write_state()