Phase 1 abgeschlossen: Art DSL, Host-IP an Bridge, Port 8001
- Schnittstellen-Art DSL: nur an Routern, ohne Bridge, Verbindung und IP - IP-Adresse kann an einer Bridge liegen (Host-IP), alternativ zur Schnittstelle - Admin: IP-Inline an Bridge und Schnittstelle inkl. Netz-Feld - Lokaler Port 8001 (8000 durch Portainer belegt) - README v0.4: offene Punkte 5 (teilweise) und 6 geklärt, Kapitel 10 aktualisiert - 49 Tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c22a717479
commit
c1766cd8ca
9 files changed
+151
-25
No files matched your search
+8
-3
@@ -41,10 +41,14 @@ class IPAdresseInline(admin.TabularInline):
|
||||
form = GeprueftesModelForm
|
||||
model = IPAdresse
|
||||
extra = 0
|
||||
fields = ["adresse", "schnittstelle", "art", "notiz"]
|
||||
fields = ["adresse", "netz", "schnittstelle", "bridge", "art", "notiz"]
|
||||
autocomplete_fields = ["schnittstelle"]
|
||||
|
||||
|
||||
class IPAdresseImNetzInline(IPAdresseInline):
|
||||
fields = ["adresse", "schnittstelle", "bridge", "art", "notiz"]
|
||||
|
||||
|
||||
@admin.register(Standort)
|
||||
class StandortAdmin(admin.ModelAdmin):
|
||||
form = GeprueftesModelForm
|
||||
@@ -73,6 +77,7 @@ class BridgeAdmin(admin.ModelAdmin):
|
||||
form = GeprueftesModelForm
|
||||
list_display = ["__str__", "host", "vlan_aware"]
|
||||
list_filter = ["host", "vlan_aware"]
|
||||
inlines = [IPAdresseInline]
|
||||
|
||||
|
||||
@admin.register(Schnittstelle)
|
||||
@@ -104,13 +109,13 @@ class NetzAdmin(admin.ModelAdmin):
|
||||
list_display = ["name", "slug", "cidr", "typ", "vlan_id", "gateway", "dhcp_von", "dhcp_bis", "standort"]
|
||||
list_filter = ["typ", "standort"]
|
||||
prepopulated_fields = {"slug": ["name"]}
|
||||
inlines = [IPAdresseInline]
|
||||
inlines = [IPAdresseImNetzInline]
|
||||
|
||||
|
||||
@admin.register(IPAdresse)
|
||||
class IPAdresseAdmin(admin.ModelAdmin):
|
||||
form = GeprueftesModelForm
|
||||
list_display = ["adresse", "netz", "schnittstelle", "art", "notiz"]
|
||||
list_display = ["adresse", "netz", "zugeordnet_an", "art", "notiz"]
|
||||
list_filter = ["netz", "art"]
|
||||
search_fields = ["adresse", "notiz", "schnittstelle__name", "schnittstelle__geraet__name"]
|
||||
autocomplete_fields = ["schnittstelle"]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-24 12:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventar', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='schnittstelle',
|
||||
name='art',
|
||||
field=models.CharField(choices=[('physisch', 'physisch'), ('virtuell', 'virtuell'), ('wlan', 'WLAN'), ('dsl', 'DSL')], max_length=10),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-24 12:23
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventar', '0002_schnittstelle_art_dsl'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ipadresse',
|
||||
name='bridge',
|
||||
field=models.ForeignKey(blank=True, help_text='Host-IP, die direkt auf der Bridge liegt (z. B. pve1 auf vmbr0).', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='ip_adressen', to='inventar.bridge'),
|
||||
),
|
||||
]
|
||||
+34
-2
@@ -305,6 +305,7 @@ class Schnittstelle(GeprueftesModel):
|
||||
PHYSISCH = "physisch", "physisch"
|
||||
VIRTUELL = "virtuell", "virtuell"
|
||||
WLAN = "wlan", "WLAN"
|
||||
DSL = "dsl", "DSL" # Anschluss nach außen, Gegenstelle wird nicht dokumentiert
|
||||
|
||||
class Modus(models.TextChoices):
|
||||
ACCESS = "access", "Access"
|
||||
@@ -368,8 +369,8 @@ class Schnittstelle(GeprueftesModel):
|
||||
fehler["durchgereicht_an"] = "Ein Port ist entweder Bridge-Port oder Passthrough, nie beides."
|
||||
|
||||
if self.bridge_id and geraet:
|
||||
if self.art == self.Art.WLAN:
|
||||
fehler["bridge"] = "WLAN-Schnittstellen hängen nicht an einer Bridge."
|
||||
if self.art in (self.Art.WLAN, self.Art.DSL):
|
||||
fehler["bridge"] = f"{self.get_art_display()}-Schnittstellen hängen nicht an einer Bridge."
|
||||
elif geraet.ist_gast:
|
||||
# Regel 2
|
||||
if self.bridge.host_id != geraet.host_id:
|
||||
@@ -390,6 +391,9 @@ class Schnittstelle(GeprueftesModel):
|
||||
elif self.durchgereicht_an.host_id != geraet.pk:
|
||||
fehler["durchgereicht_an"] = "Passthrough nur an einen Gast dieses Hosts."
|
||||
|
||||
if self.art == self.Art.DSL and geraet and geraet.typ != Geraet.Typ.ROUTER:
|
||||
fehler["art"] = "DSL-Anschlüsse gibt es nur an Routern/Modems."
|
||||
|
||||
if self.ssid_id and self.art != self.Art.WLAN:
|
||||
fehler["ssid"] = "SSID nur an WLAN-Schnittstellen."
|
||||
|
||||
@@ -448,6 +452,10 @@ class Verbindung(GeprueftesModel):
|
||||
if andere.filter(paar, typ=self.typ).exists():
|
||||
raise ValidationError("Diese Verbindung gibt es bereits.")
|
||||
|
||||
dsl = [f for f in ("a", "b") if getattr(self, f).art == Schnittstelle.Art.DSL]
|
||||
if dsl:
|
||||
raise ValidationError({f: "Am DSL-Anschluss wird keine Verbindung dokumentiert." for f in dsl})
|
||||
|
||||
if self.typ == self.Typ.KABEL:
|
||||
fehler = {}
|
||||
for feld in ("a", "b"):
|
||||
@@ -474,6 +482,10 @@ class IPAdresse(GeprueftesModel):
|
||||
schnittstelle = models.ForeignKey(
|
||||
Schnittstelle, on_delete=models.SET_NULL, null=True, blank=True, related_name="ip_adressen",
|
||||
)
|
||||
bridge = models.ForeignKey(
|
||||
Bridge, on_delete=models.SET_NULL, null=True, blank=True, related_name="ip_adressen",
|
||||
help_text="Host-IP, die direkt auf der Bridge liegt (z. B. pve1 auf vmbr0).",
|
||||
)
|
||||
art = models.CharField(max_length=12, choices=Art.choices, default=Art.STATISCH)
|
||||
notiz = models.CharField(max_length=200, blank=True)
|
||||
|
||||
@@ -486,3 +498,23 @@ class IPAdresse(GeprueftesModel):
|
||||
|
||||
def __str__(self):
|
||||
return self.adresse
|
||||
|
||||
@property
|
||||
def zugeordnet_an(self):
|
||||
"""Schnittstelle oder Bridge, an der die IP liegt (oder None)."""
|
||||
return self.schnittstelle or self.bridge
|
||||
|
||||
@property
|
||||
def geraet(self):
|
||||
if self.schnittstelle_id:
|
||||
return self.schnittstelle.geraet
|
||||
if self.bridge_id:
|
||||
return self.bridge.host
|
||||
return None
|
||||
|
||||
def clean(self):
|
||||
if self.schnittstelle_id and self.bridge_id:
|
||||
raise ValidationError({"bridge": "Eine IP liegt entweder an einer Schnittstelle oder an einer Bridge, nicht an beiden."})
|
||||
if self.schnittstelle_id and self.schnittstelle.art == Schnittstelle.Art.DSL:
|
||||
# Öffentliche Provider-IPs gehören nicht in die Doku (CLAUDE.md).
|
||||
raise ValidationError({"schnittstelle": "Am DSL-Anschluss wird keine IP dokumentiert."})
|
||||
+50
-1
@@ -3,7 +3,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import SSID, Bridge, Geraet, Netz, Schnittstelle, Standort, Verbindung
|
||||
from .models import SSID, Bridge, Geraet, IPAdresse, Netz, Schnittstelle, Standort, Verbindung
|
||||
|
||||
|
||||
class StartseiteTests(TestCase):
|
||||
@@ -172,6 +172,55 @@ class SchnittstelleTests(Homelab):
|
||||
SSID.objects.create(name="x", slug="x", band=SSID.Band.GHZ_5, ap=self.switch)
|
||||
|
||||
|
||||
class DSLTests(Homelab):
|
||||
def setUp(self):
|
||||
self.fritzbox = Geraet.objects.create(name="FritzBox", typ=Geraet.Typ.ROUTER, standort=self.homelab)
|
||||
self.dsl = Schnittstelle.objects.create(geraet=self.fritzbox, name="DSL", art=Schnittstelle.Art.DSL)
|
||||
|
||||
def test_dsl_nur_an_router(self):
|
||||
with self.assertRaises(ValidationError) as f:
|
||||
Schnittstelle.objects.create(geraet=self.pve1, name="DSL", art=Schnittstelle.Art.DSL)
|
||||
self.assertIn("art", f.exception.message_dict)
|
||||
|
||||
def test_dsl_ohne_bridge(self):
|
||||
with self.assertRaises(ValidationError) as f:
|
||||
Schnittstelle.objects.create(geraet=self.pve1, name="x", art=Schnittstelle.Art.DSL, bridge=self.vmbr1)
|
||||
self.assertIn("bridge", f.exception.message_dict)
|
||||
|
||||
def test_dsl_ohne_verbindung(self):
|
||||
for typ in (Verbindung.Typ.KABEL, Verbindung.Typ.VPN):
|
||||
with self.subTest(typ=typ), self.assertRaises(ValidationError):
|
||||
Verbindung.objects.create(a=self.dsl, b=self.nic1, typ=typ)
|
||||
|
||||
def test_dsl_ohne_ip(self):
|
||||
netz = Netz.objects.create(name="T", slug="t", cidr="192.168.5.0/24", typ=Netz.Typ.TRANSFER, standort=self.homelab)
|
||||
with self.assertRaises(ValidationError):
|
||||
IPAdresse.objects.create(adresse="192.168.5.9", netz=netz, schnittstelle=self.dsl)
|
||||
|
||||
|
||||
class IPAdresseTests(Homelab):
|
||||
def setUp(self):
|
||||
self.lan = Netz.objects.create(name="LAN", slug="lan", cidr="192.168.178.0/24", typ=Netz.Typ.LAN, standort=self.homelab)
|
||||
|
||||
def test_host_ip_auf_bridge(self):
|
||||
ip = IPAdresse.objects.create(adresse="192.168.178.254", netz=self.lan, bridge=self.vmbr1)
|
||||
self.assertEqual(ip.geraet, self.pve1)
|
||||
self.assertEqual(ip.zugeordnet_an, self.vmbr1)
|
||||
|
||||
def test_ip_an_schnittstelle(self):
|
||||
ip = IPAdresse.objects.create(adresse="192.168.178.9", netz=self.lan, schnittstelle=self.nic1)
|
||||
self.assertEqual(ip.geraet, self.pve1)
|
||||
|
||||
def test_nicht_schnittstelle_und_bridge(self):
|
||||
with self.assertRaises(ValidationError) as f:
|
||||
IPAdresse.objects.create(adresse="192.168.178.9", netz=self.lan, schnittstelle=self.nic1, bridge=self.vmbr1)
|
||||
self.assertIn("bridge", f.exception.message_dict)
|
||||
|
||||
def test_ohne_zuordnung_erlaubt(self):
|
||||
ip = IPAdresse.objects.create(adresse="192.168.178.9", netz=self.lan)
|
||||
self.assertIsNone(ip.geraet)
|
||||
|
||||
|
||||
class VerbindungTests(Homelab):
|
||||
def setUp(self):
|
||||
self.port3 = Schnittstelle.objects.create(geraet=self.switch, name="port-3", art=Schnittstelle.Art.PHYSISCH)
|
||||
|
||||
Reference in new issue
Block a user