feat: REST API for cable VLAN assignments
- New endpoint /api/plugins/utilities/cable-vlans/ to read and write the connection VLANs of a cable (cable ID and VLAN IDs, filter with ?cable_id=) - Used by NetBox Synchronizer to keep the cable VLANs of switch ports in step with the port - Version 0.31.0 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
280c0e0315
commit
1d6b16c0e4
6 files changed
+36
-5
No files matched your search
@@ -3,9 +3,10 @@ from netbox.api.serializers import NetBoxModelSerializer
|
||||
from rest_framework import serializers
|
||||
from tenancy.api.serializers import TenantSerializer
|
||||
|
||||
from dcim.models import Device
|
||||
from dcim.models import Cable, Device
|
||||
from ipam.models import VLAN
|
||||
|
||||
from ..models import CPUModel, DeviceHardware, Disk, DiskBayLayout, DiskBayTemplate, RAIDGroup, SwitchStack
|
||||
from ..models import CableVLANAssignment, CPUModel, DeviceHardware, Disk, DiskBayLayout, DiskBayTemplate, RAIDGroup, SwitchStack
|
||||
|
||||
LAYOUT_FIELDS = ("name", "weight", "slot_count", "rows", "first_slot", "numbering", "form_factor")
|
||||
|
||||
@@ -215,3 +216,14 @@ class SwitchStackSerializer(serializers.ModelSerializer):
|
||||
if device is not None and any(member.pk == device.pk for member in data.get("members") or []):
|
||||
raise serializers.ValidationError({"members": "Der Switch kann nicht sein eigenes Mitglied sein."})
|
||||
return data
|
||||
|
||||
|
||||
class CableVLANAssignmentSerializer(serializers.ModelSerializer):
|
||||
"""VLANs of a cable connection as VLAN IDs (one assignment per cable)."""
|
||||
|
||||
cable = serializers.PrimaryKeyRelatedField(queryset=Cable.objects.all())
|
||||
vlans = serializers.PrimaryKeyRelatedField(queryset=VLAN.objects.all(), many=True, required=False)
|
||||
|
||||
class Meta:
|
||||
model = CableVLANAssignment
|
||||
fields = ("id", "cable", "vlans", "updated")
|
||||
Reference in new issue
Block a user