]> mj.ucw.cz Git - pynsc.git/blobdiff - nsconfig/core.py
More daemon configuration
[pynsc.git] / nsconfig / core.py
index b61a02d36f181d2826740df6f257f25fa12c0faf..8a3bb74f694453655887758f39063fa20182779e 100644 (file)
@@ -21,7 +21,11 @@ import json
 from pathlib import Path
 import socket
 import sys
-from typing import Optional, Dict, List, Self, Tuple, DefaultDict, TextIO
+from typing import Optional, Dict, List, Self, Tuple, DefaultDict, TextIO, TYPE_CHECKING
+
+
+if TYPE_CHECKING:
+    from nsconfig.daemon import NscDaemon
 
 
 IPAddress = IPv4Address | IPv6Address
@@ -327,6 +331,9 @@ class NscZonePrimary(NscZone):
     def write_state(self) -> None:
         self.state.save(self.state_file)
 
+    def is_changed(self) -> bool:
+        return self.state.serial != self.prev_state.serial
+
 
 class NscZoneSecondary(NscZone):
     primary_server: IPAddress
@@ -349,8 +356,12 @@ class Nsc:
     state_dir: Path
     zone_dir: Path
     secondary_dir: Path
+    daemon: 'NscDaemon'  # Set by DaemonConfig class
 
-    def __init__(self, directory: str = '.', **kwargs) -> None:
+    def __init__(self,
+                 directory: str = '.',
+                 daemon: Optional['NscDaemon'] = None,
+                 **kwargs) -> None:
         self.start_time = datetime.now()
         self.zones = {}
         self.default_zone_config = NscZoneConfig(**kwargs)
@@ -365,6 +376,12 @@ class Nsc:
         self.secondary_dir = self.root_dir / 'secondary'
         self.secondary_dir.mkdir(parents=True, exist_ok=True)
 
+        if daemon is None:
+            from nsconfig.daemon import NscDaemonNull
+            daemon = NscDaemonNull()
+        self.daemon = daemon
+        daemon.setup(self)
+
     def add_zone(self,
                  name: Optional[str] = None,
                  reverse_for: str | IPNetwork | None = None,