class ZoneType(Enum):
primary = auto()
secondary = auto()
+ alias = auto()
class NscZone:
def process(self) -> None:
pass
+ def is_changed(self) -> bool:
+ return False
+
class NscZonePrimary(NscZone):
zone: Zone
state_file: Path
state: NscZoneState
prev_state: NscZoneState
+ aliases: List['NscZoneAlias']
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.prev_state = NscZoneState()
self.prev_state.load(self.state_file)
+ self.aliases = []
+
self.zone = dns.zone.Zone(origin=self.name, rdclass=RdataClass.IN)
self.update_soa()
self.secondary_file = self.nsc.secondary_dir / self.safe_name
+class NscZoneAlias(NscZone):
+ alias_for: NscZonePrimary
+
+ def __init__(self, *args, alias_for=NscZonePrimary, **kwargs) -> None:
+ assert isinstance(alias_for, NscZonePrimary)
+ super().__init__(*args, **kwargs)
+ self.zone_type = ZoneType.alias
+ self.alias_for = alias_for
+ self.zone_file = alias_for.zone_file
+ alias_for.aliases.append(self)
+
+ def is_changed(self) -> bool:
+ return self.alias_for.is_changed()
+
+
class Nsc:
start_time: datetime
zones: Dict[str, NscZone]
def add_zone(self,
name: Optional[str] = None,
reverse_for: str | IPNetwork | None = None,
+ alias_for: Optional[NscZonePrimary] = None,
follow_primary: str | IPAddress | None = None,
inherit_config: Optional[NscZoneConfig] = None,
**kwargs) -> Zone:
assert name not in self.zones
z: NscZone
- if follow_primary is None:
+ if alias_for is not None:
+ assert follow_primary is None
+ z = NscZoneAlias(self, name, reverse_for=reverse_for, alias_for=alias_for, inherit_config=inherit_config, **kwargs)
+ elif follow_primary is None:
z = NscZonePrimary(self, name, reverse_for=reverse_for, inherit_config=inherit_config, **kwargs)
else:
if isinstance(follow_primary, str):