Skip to content

Commit

Permalink
Fix issues identified by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps committed Sep 22, 2024
1 parent f196dd7 commit 094cdf1
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 4 deletions.
6 changes: 3 additions & 3 deletions netbox_routing/api/_serializers/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
46 changes: 45 additions & 1 deletion netbox_routing/filtersets/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions netbox_routing/graphql/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Annotated

import strawberry
import strawberry_django

from netbox_routing import filtersets, models
Expand All @@ -6,6 +9,9 @@

__all__ = (
'StaticRouteFilter',
'OSPFInstanceFilter',
'OSPFAreaFilter',
'OSPFInterfaceFilter',
)


Expand All @@ -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
13 changes: 13 additions & 0 deletions netbox_routing/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
43 changes: 43 additions & 0 deletions netbox_routing/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

__all__ = (
'StaticRouteType',
'OSPFInstanceType',
'OSPFAreaType',
'OSPFInterfaceType',
)


Expand All @@ -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

0 comments on commit 094cdf1

Please sign in to comment.