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,7 +3,7 @@ from netbox.api.viewsets import NetBoxModelViewSet
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from .. import disk_filtersets, hardware_filtersets
|
||||
from ..models import CPUModel, DeviceHardware, Disk, DiskBayLayout, DiskBayTemplate, RAIDGroup, SwitchStack
|
||||
from ..models import CableVLANAssignment, CPUModel, DeviceHardware, Disk, DiskBayLayout, DiskBayTemplate, RAIDGroup, SwitchStack
|
||||
from . import serializers
|
||||
|
||||
|
||||
@@ -58,3 +58,17 @@ class SwitchStackViewSet(ModelViewSet):
|
||||
if params.get("member_id"):
|
||||
queryset = queryset.filter(members__in=params.getlist("member_id")).distinct()
|
||||
return queryset
|
||||
|
||||
|
||||
class CableVLANAssignmentViewSet(ModelViewSet):
|
||||
"""VLANs of cable connections; filter with ``?cable_id=``."""
|
||||
|
||||
queryset = CableVLANAssignment.objects.prefetch_related("vlans").order_by("pk")
|
||||
serializer_class = serializers.CableVLANAssignmentSerializer
|
||||
permission_classes = [TokenPermissions]
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
if self.request.query_params.get("cable_id"):
|
||||
queryset = queryset.filter(cable_id__in=self.request.query_params.getlist("cable_id"))
|
||||
return queryset
|
||||
Reference in new issue
Block a user