Skip to content

Commit

Permalink
Update views.py for Interface View
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrichbaum authored Aug 11, 2024
1 parent ba9ea5b commit 339d527
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions netbox_prometheus_sd/api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ipam.models import IPAddress, Service
from virtualization.models import VirtualMachine
from dcim.models.devices import Device
from dcim.models.devices import Device, Interface

# pylint: disable=ungrouped-imports
try: # Netbox >= 3.5
Expand All @@ -23,7 +23,7 @@ class NetboxPrometheusSDModelViewSet( # pylint: disable=too-many-ancestors
# https://github.com/netbox-community/netbox/commit/1024782b9e0abb48f6da65f8248741227d53dbed#diff-d9224204dab475bbe888868c02235b8ef10f07c9201c45c90804d395dc161c40
try:
from ipam.filtersets import IPAddressFilterSet
from dcim.filtersets import DeviceFilterSet
from dcim.filtersets import DeviceFilterSet, InterfaceFtilterSet
from virtualization.filtersets import VirtualMachineFilterSet
except ImportError:
from ipam.filters import IPAddressFilterSet
Expand All @@ -37,7 +37,8 @@ class NetboxPrometheusSDModelViewSet( # pylint: disable=too-many-ancestors
PrometheusIPAddressSerializer,
PrometheusDeviceSerializer,
PrometheusVirtualMachineSerializer,
PrometheusServiceSerializer
PrometheusServiceSerializer,
PrometheusInterfaceSerializer
)


Expand Down Expand Up @@ -98,3 +99,17 @@ class IPAddressViewSet(NetboxPrometheusSDModelViewSet): # pylint: disable=too-m
serializer_class = PrometheusIPAddressSerializer
filterset_class = IPAddressFilterSet
pagination_class = None

class InterfaceViewSet(NetboxPrometheusSDModelViewSet): # pylint: disable=too-many-ancestors
queryset = Interface.objects.prefetch_related(
'_path', 'cable__terminations',
'l2vpn_terminations', # Referenced by InterfaceSerializer.l2vpn_termination
'ip_addresses', # Referenced by Interface.count_ipaddresses()
'fhrp_group_assignments', # Referenced by Interface.count_fhrp_groups()
"device",
"ip_addresses",
"tags",
)
filterset_class = InterfaceFilterSet
serializer_class = PrometheusInterfaceSerializer
pagination_class = None

0 comments on commit 339d527

Please sign in to comment.