Netztyp VPN: standortübergreifende Tunnelnetze, Konzept v0.6
- Netz-Typ VPN; Standort optional nur für VPN, kein DHCP-Bereich - Eindeutigkeit von Netzen ohne Standort per bedingter UniqueConstraint - README: Netztyp, Regel, WireGuard-Netz 172.25.25.0/24 in Kapitel 10 - AUFBAUPLAN: Schritt 2 (Gegenstelle, Tunnel, Standort-Rahmen) in Phase 7 - 66 Tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab8e0d8ffd
commit
ae15a0aba8
5 files changed
+66
-4
No files matched your search
+17
-1
@@ -225,6 +225,7 @@ class Netz(GeprueftesModel):
|
||||
TRANSFER = "transfer", "Transfer"
|
||||
LAN = "lan", "LAN"
|
||||
VLAN = "vlan", "VLAN"
|
||||
VPN = "vpn", "VPN"
|
||||
|
||||
name = models.CharField(max_length=100)
|
||||
slug = models.SlugField("Logische ID", unique=True)
|
||||
@@ -234,7 +235,10 @@ class Netz(GeprueftesModel):
|
||||
gateway = models.GenericIPAddressField(null=True, blank=True)
|
||||
dhcp_von = models.GenericIPAddressField("DHCP von", null=True, blank=True)
|
||||
dhcp_bis = models.GenericIPAddressField("DHCP bis", null=True, blank=True)
|
||||
standort = models.ForeignKey(Standort, on_delete=models.PROTECT, related_name="netze")
|
||||
standort = models.ForeignKey(
|
||||
Standort, on_delete=models.PROTECT, null=True, blank=True, related_name="netze",
|
||||
help_text="Bei VPN-Netzen leer lassen – ein Tunnelnetz gehört beiden Seiten.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["cidr"]
|
||||
@@ -244,6 +248,11 @@ class Netz(GeprueftesModel):
|
||||
fields=["standort", "cidr"], name="cidr_je_standort_eindeutig",
|
||||
violation_error_message="Dieses Netz gibt es am Standort bereits.",
|
||||
),
|
||||
# NULL zählt in UniqueConstraints nicht als gleich – standortlose Netze extra prüfen
|
||||
models.UniqueConstraint(
|
||||
fields=["cidr"], condition=models.Q(standort__isnull=True), name="cidr_ohne_standort_eindeutig",
|
||||
violation_error_message="Dieses standortübergreifende Netz gibt es bereits.",
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
@@ -274,6 +283,13 @@ class Netz(GeprueftesModel):
|
||||
fehler["dhcp_bis"] = "Ende liegt vor dem Anfang."
|
||||
if self.typ == self.Typ.VLAN and not self.vlan_id:
|
||||
fehler["vlan_id"] = "Ein VLAN-Netz braucht eine VLAN-ID."
|
||||
if self.typ == self.Typ.VPN:
|
||||
if self.standort_id:
|
||||
fehler["standort"] = "VPN-Netze gehören keinem Standort (Tunnel zwischen Standorten)."
|
||||
if self.dhcp_von:
|
||||
fehler["dhcp_von"] = "VPN-Netze haben keinen DHCP-Bereich."
|
||||
elif not self.standort_id:
|
||||
fehler["standort"] = "Nur VPN-Netze sind ohne Standort."
|
||||
if fehler:
|
||||
raise ValidationError(fehler)
|
||||
|
||||
|
||||
Reference in new issue
Block a user