]> mj.ucw.cz Git - pynsc.git/blob - nsconfig/daemon/bind.py
First bits of daemon configuration
[pynsc.git] / nsconfig / daemon / bind.py
1 from pathlib import Path
2 import sys
3 from typing import TextIO
4
5 from nsconfig.core import NscZonePrimary, NscZoneSecondary
6 from nsconfig.daemon import NscDaemon
7
8
9 class NscDaemonBind(NscDaemon):
10     config_path: Path = Path('named.conf.nsc')
11
12     def dump_config(self, file: TextIO = sys.stdout) -> None:
13         file.write('# Domains managed by NSC\n')
14         file.write('# This file was automatically generated by NSC, please do not edit manually.\n\n')
15         for z in self.nsc.get_zones():
16             file.write(f'zone "{z.name}" in {{\n')  # broken editor: }}
17             if isinstance(z, NscZonePrimary):
18                 file.write('\ttype master;\n')
19                 file.write(f'\tfile "{z.zone_file}";\n')
20             elif isinstance(z, NscZoneSecondary):
21                 file.write('\ttype slave;\n')
22                 file.write(f'\tfile "zone/{z.secondary_file}";\n')
23                 file.write(f'\tmasters {{ {z.primary_server}; }};\n')
24             else:
25                 raise NotImplementedError()
26             file.write('}\n\n')