]> mj.ucw.cz Git - pynsc.git/blobdiff - nsconfig/daemon/bind.py
More daemon configuration
[pynsc.git] / nsconfig / daemon / bind.py
index 13a9e0c1087f2153b936b8d0c4c03bc6869891cf..24a24fca8ae49200edf15467c96c190097fdd7fb 100644 (file)
@@ -2,12 +2,22 @@ from pathlib import Path
 import sys
 from typing import TextIO
 
-from nsconfig.core import NscZonePrimary, NscZoneSecondary
+from nsconfig.core import NscZone, NscZonePrimary, NscZoneSecondary
 from nsconfig.daemon import NscDaemon
 
 
 class NscDaemonBind(NscDaemon):
-    config_path: Path = Path('named.conf.nsc')
+    config_path: Path
+    control_command: str
+    need_full_reload: bool
+
+    def __init__(self,
+                 config_file: str = 'named.conf.nsc',
+                 control_command: str = 'rndc') -> None:
+        super().__init__()
+        self.config_path = Path(config_file)
+        self.control_command = control_command
+        self.need_full_reload = False
 
     def dump_config(self, file: TextIO = sys.stdout) -> None:
         file.write('# Domains managed by NSC\n')
@@ -24,3 +34,17 @@ class NscDaemonBind(NscDaemon):
             else:
                 raise NotImplementedError()
             file.write('}\n\n')
+
+    def write_config(self) -> None:
+        if self._write_config(self.config_path):
+            self.need_full_reload = True
+
+    def reload_zone(self, z: NscZone) -> None:
+        if isinstance(z, NscZonePrimary) and not self.need_full_reload:
+            print(f'Reloading zone {z.name}')
+            self._run_command([self.control_command, 'reload', z.name])
+
+    def reload_daemon(self) -> None:
+        if self.need_full_reload:
+            print('Reloading daemon')
+            self._run_command([self.control_command, 'reload'])