diff --git a/netbox_routing/api/_serializers/ospf.py b/netbox_routing/api/_serializers/ospf.py index 97fed8e..9cfb2f8 100644 --- a/netbox_routing/api/_serializers/ospf.py +++ b/netbox_routing/api/_serializers/ospf.py @@ -19,8 +19,8 @@ class OSPFInstanceSerializer(NetBoxModelSerializer): class Meta: model = OSPFInstance - fields = ('url', 'id', 'display', 'name', 'router_id', 'process_id', 'device', 'description', 'comments',) - brief_fields = ('url', 'id', 'display', 'name', 'router_id', 'process_id', 'device') + fields = ('url', 'id', 'display', 'name', 'router_id', 'process_id', 'device', 'description', 'comments', ) + brief_fields = ('url', 'id', 'display', 'name', 'router_id', 'process_id', 'device', ) class OSPFAreaSerializer(NetBoxModelSerializer): @@ -29,7 +29,7 @@ class OSPFAreaSerializer(NetBoxModelSerializer): class Meta: model = OSPFArea fields = ('url', 'id', 'display', 'area_id', 'description', 'comments',) - brief_fields = ('url', 'id', 'display', 'area_id') + brief_fields = ('url', 'id', 'display', 'area_id',) class OSPFInterfaceSerializer(NetBoxModelSerializer): diff --git a/netbox_routing/filtersets/ospf.py b/netbox_routing/filtersets/ospf.py index 0ee40c2..3439112 100644 --- a/netbox_routing/filtersets/ospf.py +++ b/netbox_routing/filtersets/ospf.py @@ -3,7 +3,7 @@ from django.db.models import Q from django.utils.translation import gettext as _ -from dcim.models import Device +from dcim.models import Device, Interface from utilities.filters import MultiValueCharFilter from netbox.filtersets import NetBoxModelFilterSet @@ -83,6 +83,50 @@ def filter_aid(self, queryset, name, value): class OSPFInterfaceFilterSet(NetBoxModelFilterSet): + instance_id = django_filters.ModelMultipleChoiceFilter( + field_name='instance', + queryset=OSPFInstance.objects.all(), + label='Instance (ID)', + ) + instance = django_filters.ModelMultipleChoiceFilter( + field_name='instance__name', + queryset=OSPFInstance.objects.all(), + to_field_name='name', + label='Instance', + ) + area_id = django_filters.ModelMultipleChoiceFilter( + field_name='area', + queryset=OSPFArea.objects.all(), + label='Area (ID)', + ) + area = django_filters.ModelMultipleChoiceFilter( + field_name='area__area_id', + queryset=OSPFArea.objects.all(), + to_field_name='area_id', + label='Area', + ) + device_id = django_filters.ModelMultipleChoiceFilter( + field_name='interface__device', + queryset=Device.objects.all(), + label='Device (ID)', + ) + device = django_filters.ModelMultipleChoiceFilter( + field_name='interface__device__name', + queryset=Device.objects.all(), + to_field_name='name', + label='Device', + ) + interface_id = django_filters.ModelMultipleChoiceFilter( + field_name='interface', + queryset=Interface.objects.all(), + label='Area (ID)', + ) + interface = django_filters.ModelMultipleChoiceFilter( + field_name='interface__name', + queryset=Interface.objects.all(), + to_field_name='name', + label='Area', + ) class Meta: model = OSPFInterface diff --git a/netbox_routing/graphql/filters.py b/netbox_routing/graphql/filters.py index 95a57a2..62468f3 100644 --- a/netbox_routing/graphql/filters.py +++ b/netbox_routing/graphql/filters.py @@ -1,3 +1,6 @@ +from typing import Annotated + +import strawberry import strawberry_django from netbox_routing import filtersets, models @@ -6,6 +9,9 @@ __all__ = ( 'StaticRouteFilter', + 'OSPFInstanceFilter', + 'OSPFAreaFilter', + 'OSPFInterfaceFilter', ) @@ -14,3 +20,21 @@ class StaticRouteFilter(BaseFilterMixin): prefix: str next_hop: str + + +@strawberry_django.filter(models.OSPFInstance, lookups=True) +@autotype_decorator(filtersets.OSPFInstanceFilterSet) +class OSPFInstanceFilter(BaseFilterMixin): + router_id: str + + +@strawberry_django.filter(models.OSPFArea, lookups=True) +@autotype_decorator(filtersets.OSPFAreaFilterSet) +class OSPFAreaFilter(BaseFilterMixin): + pass + + +@strawberry_django.filter(models.OSPFInterface, lookups=True) +@autotype_decorator(filtersets.OSPFInterfaceFilterSet) +class OSPFInterfaceFilter(BaseFilterMixin): + pass diff --git a/netbox_routing/graphql/schema.py b/netbox_routing/graphql/schema.py index cb61742..07a73b2 100644 --- a/netbox_routing/graphql/schema.py +++ b/netbox_routing/graphql/schema.py @@ -12,6 +12,19 @@ class StaticRouteQuery: static_route_list: List[StaticRouteType] = strawberry_django.field() +@strawberry.type(name="Query") +class OSPFQuery: + ospf_instance: OSPFInstanceType = strawberry_django.field() + ospf_instance_list: List[OSPFInstanceType] = strawberry_django.field() + + ospf_area: OSPFAreaType = strawberry_django.field() + ospf_area_list: List[OSPFAreaType] = strawberry_django.field() + + ospf_interface: OSPFInterfaceType = strawberry_django.field() + ospf_interface_list: List[OSPFInterfaceType] = strawberry_django.field() + + schema = [ StaticRouteQuery, + OSPFQuery ] diff --git a/netbox_routing/graphql/types.py b/netbox_routing/graphql/types.py index dc2d432..b12ee81 100644 --- a/netbox_routing/graphql/types.py +++ b/netbox_routing/graphql/types.py @@ -10,6 +10,9 @@ __all__ = ( 'StaticRouteType', + 'OSPFInstanceType', + 'OSPFAreaType', + 'OSPFInterfaceType', ) @@ -28,3 +31,43 @@ class StaticRouteType(NetBoxObjectType): metric: int | None permanent: bool | None + +@strawberry_django.type( + models.OSPFInstance, + fields='__all__', + filters=OSPFInstanceFilter +) +class OSPFInstanceType(NetBoxObjectType): + + name: str + device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] + router_id: str + process_id: str + + +@strawberry_django.type( + models.OSPFArea, + fields='__all__', + filters=OSPFAreaFilter +) +class OSPFAreaType(NetBoxObjectType): + + area_id: str + + +@strawberry_django.type( + models.OSPFInterface, + fields='__all__', + filters=OSPFInterfaceFilter +) +class OSPFInterfaceType(NetBoxObjectType): + + device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] + instance: Annotated["OSPFInstanceType", strawberry.lazy('netbox_routing.graphql.types')] + area: Annotated["OSPFAreaType", strawberry.lazy('netbox_routing.graphql.types')] + interface: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')] + priority: str | None + bfd: bool | None + authentication: str | None + passphrase: str | None +