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')
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'])