Skip to content

Commit

Permalink
Merge pull request #43 from DanSheps/develop
Browse files Browse the repository at this point in the history
EIGRP Support
  • Loading branch information
DanSheps authored Sep 28, 2024
2 parents d0f408d + 27f0c12 commit 9c1a2a9
Show file tree
Hide file tree
Showing 36 changed files with 2,360 additions and 12 deletions.
71 changes: 71 additions & 0 deletions netbox_routing/api/_serializers/eigrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from rest_framework import serializers

from dcim.api.serializers_.device_components import InterfaceSerializer
from dcim.api.serializers_.devices import DeviceSerializer
from ipam.api.serializers_.ip import PrefixSerializer
from netbox.api.serializers import NetBoxModelSerializer
from netbox_routing.models import (
EIGRPRouter, EIGRPAddressFamily, EIGRPNetwork, EIGRPInterface
)


__all__ = (
'EIGRPRouterSerializer',
'EIGRPAddressFamilySerializer',
'EIGRPNetworkSerializer',
'EIGRPInterfaceSerializer',
)


class EIGRPRouterSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:eigrprouter-detail')
device = DeviceSerializer(nested=True)

class Meta:
model = EIGRPRouter
fields = ('url', 'id', 'display', 'name', 'pid', 'rid', 'device', 'description', 'comments', )
brief_fields = ('url', 'id', 'display', 'name', 'pid', 'rid', 'device', )


class EIGRPAddressFamilySerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:eigrpaddressfamily-detail')
router = EIGRPRouterSerializer(nested=True)


class Meta:
model = EIGRPAddressFamily
fields = (
'url', 'id', 'display', 'router', 'family', 'description', 'comments',
)
brief_fields = ('url', 'id', 'display', 'router', 'family',)


class EIGRPNetworkSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:eigrpnetwork-detail')
router = EIGRPRouterSerializer(nested=True)
address_family = EIGRPAddressFamilySerializer(nested=True)
network = PrefixSerializer(nested=True)

class Meta:
model = EIGRPNetwork
fields = (
'url', 'id', 'display', 'router', 'address_family', 'network', 'description', 'comments',
)
brief_fields = ('url', 'id', 'display', 'router', 'address_family', 'network',)


class EIGRPInterfaceSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:eigrpinterface-detail')
router = EIGRPRouterSerializer(nested=True)
address_family = EIGRPAddressFamilySerializer(nested=True)
interface = InterfaceSerializer(nested=True)

class Meta:
model = EIGRPInterface
fields = (
'url', 'id', 'display', 'router', 'address_family', 'interface', 'passive', 'bfd',
'authentication', 'passphrase', 'description', 'comments',
)
brief_fields = (
'url', 'id', 'display', 'router', 'address_family', 'interface',
)
6 changes: 6 additions & 0 deletions netbox_routing/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
BGPRouterSerializer, BGPScopeSerializer, BGPAddressFamilySerializer, BGPSettingSerializer
)
from netbox_routing.api._serializers.ospf import *
from netbox_routing.api._serializers.eigrp import *

__all__ = (
'StaticRouteSerializer',
Expand All @@ -14,6 +15,11 @@
'OSPFAreaSerializer',
'OSPFInterfaceSerializer',

'EIGRPRouterSerializer',
'EIGRPAddressFamilySerializer',
'EIGRPNetworkSerializer',
'EIGRPInterfaceSerializer',

'PrefixListSerializer',
'PrefixListEntrySerializer',
'RouteMapSerializer',
Expand Down
7 changes: 6 additions & 1 deletion netbox_routing/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from netbox.api.routers import NetBoxRouter
from .views import StaticRouteViewSet, PrefixListViewSet, RouteMapViewSet, PrefixListEntryViewSet, \
RouteMapEntryViewSet, OSPFInstanceViewSet, OSPFAreaViewSet, OSPFInterfaceViewSet, BGPRouterViewSet, \
BGPScopeViewSet, BGPAddressFamilyViewSet, BGPSettingViewSet
BGPScopeViewSet, BGPAddressFamilyViewSet, BGPSettingViewSet, EIGRPRouterViewSet, EIGRPAddressFamilyViewSet, \
EIGRPNetworkViewSet, EIGRPInterfaceViewSet

router = NetBoxRouter()
router.register('staticroute', StaticRouteViewSet)
Expand All @@ -12,6 +13,10 @@
router.register('ospf-instance', OSPFInstanceViewSet)
router.register('ospf-area', OSPFAreaViewSet)
router.register('ospf-interface', OSPFInterfaceViewSet)
router.register('eigrp-router', EIGRPRouterViewSet)
router.register('eigrp-address-family', EIGRPAddressFamilyViewSet)
router.register('eigrp-network', EIGRPNetworkViewSet)
router.register('eigrp-interface', EIGRPInterfaceViewSet)
router.register('prefix-list', PrefixListViewSet)
router.register('prefix-list-entry', PrefixListEntryViewSet)
router.register('route-map', RouteMapViewSet)
Expand Down
9 changes: 9 additions & 0 deletions netbox_routing/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from .ospf import OSPFInstanceViewSet, OSPFAreaViewSet, OSPFInterfaceViewSet
from .bgp import BGPRouterViewSet, BGPScopeViewSet, BGPAddressFamilyViewSet, BGPSettingViewSet
from .objects import PrefixListViewSet, PrefixListEntryViewSet, RouteMapViewSet, RouteMapEntryViewSet
from .eigrp import (
EIGRPRouterViewSet, EIGRPAddressFamilyViewSet,
EIGRPNetworkViewSet, EIGRPInterfaceViewSet
)

__all__ = (
'StaticRouteViewSet',
Expand All @@ -11,6 +15,11 @@
'BGPAddressFamilyViewSet',
'BGPSettingViewSet',

'EIGRPRouterViewSet',
'EIGRPAddressFamilyViewSet',
'EIGRPNetworkViewSet',
'EIGRPInterfaceViewSet',

'OSPFInstanceViewSet',
'OSPFAreaViewSet',
'OSPFInterfaceViewSet',
Expand Down
41 changes: 41 additions & 0 deletions netbox_routing/api/views/eigrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from netbox.api.viewsets import NetBoxModelViewSet
from netbox_routing import filtersets
from netbox_routing.api.serializers import (
EIGRPRouterSerializer, EIGRPRouterSerializer, EIGRPAddressFamilySerializer,
EIGRPInterfaceSerializer, EIGRPNetworkSerializer
)
from netbox_routing.models import (
EIGRPRouter, EIGRPAddressFamily, EIGRPNetwork, EIGRPInterface
)


__all__ = (
'EIGRPRouterViewSet',
'EIGRPAddressFamilyViewSet',
'EIGRPNetworkViewSet',
'EIGRPInterfaceViewSet',
)


class EIGRPRouterViewSet(NetBoxModelViewSet):
queryset = EIGRPRouter.objects.all()
serializer_class = EIGRPRouterSerializer
filterset_class = filtersets.EIGRPRouterFilterSet


class EIGRPAddressFamilyViewSet(NetBoxModelViewSet):
queryset = EIGRPAddressFamily.objects.all()
serializer_class = EIGRPAddressFamilySerializer
filterset_class = filtersets.EIGRPAddressFamilyFilterSet


class EIGRPNetworkViewSet(NetBoxModelViewSet):
queryset = EIGRPNetwork.objects.all()
serializer_class = EIGRPNetworkSerializer
filterset_class = filtersets.EIGRPNetworkFilterSet


class EIGRPInterfaceViewSet(NetBoxModelViewSet):
queryset = EIGRPInterface.objects.all()
serializer_class = EIGRPInterfaceSerializer
filterset_class = filtersets.EIGRPInterfaceFilterSet
11 changes: 11 additions & 0 deletions netbox_routing/choices/eigrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from utilities.choices import ChoiceSet


class EIGRPRouterChoices(ChoiceSet):
CLASSIC = 'classic'
NAMED = 'named'

CHOICES = [
(CLASSIC, 'Classic Router'),
(NAMED, 'Named Router')
]
11 changes: 11 additions & 0 deletions netbox_routing/constants/eigrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db.models import Q

EIGRP_ROUTER_MODELS = Q(
app_label='netbox_routing',
model__in=('eigrpnamedrouter', 'eigrpclassicrouter', )
)

EIGRP_ASSIGNABLE_MODELS = Q(
app_label='netbox_routing',
model__in=('eigrpnamedrouter', 'eigrpclassicrouter', 'eigrpaddressfamily', )
)
21 changes: 19 additions & 2 deletions netbox_routing/fields/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db import models
from netaddr import AddrFormatError, IPAddress

from ipam import lookups
from ipam.formfields import IPAddressFormField


Expand All @@ -14,7 +15,9 @@ def from_db_value(self, value, expression, connection):
return self.to_python(value)

def to_python(self, value):
if not value:
if value is None:
return None
elif not value:
return value
try:
# Always return a netaddr.IPNetwork object. (netaddr.IPAddress does not provide a mask.)
Expand All @@ -25,6 +28,8 @@ def to_python(self, value):
raise ValidationError(e)

def get_prep_value(self, value):
if value is None:
return None
if isinstance(value, list):
return [str(self.to_python(v)) for v in value]
return str(self.to_python(value))
Expand All @@ -35,4 +40,16 @@ def form_class(self):
def formfield(self, **kwargs):
defaults = {'form_class': self.form_class()}
defaults.update(kwargs)
return super().formfield(**defaults)
return super().formfield(**defaults)


IPAddressField.register_lookup(lookups.IExact)
IPAddressField.register_lookup(lookups.EndsWith)
IPAddressField.register_lookup(lookups.IEndsWith)
IPAddressField.register_lookup(lookups.StartsWith)
IPAddressField.register_lookup(lookups.IStartsWith)
IPAddressField.register_lookup(lookups.Regex)
IPAddressField.register_lookup(lookups.IRegex)
IPAddressField.register_lookup(lookups.NetContained)
IPAddressField.register_lookup(lookups.NetContainedOrEqual)
IPAddressField.register_lookup(lookups.NetFamily)
6 changes: 6 additions & 0 deletions netbox_routing/filtersets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .objects import PrefixListFilterSet, PrefixListEntryFilterSet, RouteMapFilterSet, RouteMapEntryFilterSet
from .ospf import *
from .bgp import *
from .eigrp import *


__all__ = (
Expand All @@ -14,6 +15,11 @@
'OSPFAreaFilterSet',
'OSPFInterfaceFilterSet',

'EIGRPRouterFilterSet',
'EIGRPAddressFamilyFilterSet',
'EIGRPNetworkFilterSet',
'EIGRPInterfaceFilterSet',

'PrefixListFilterSet',
'PrefixListEntryFilterSet',
'RouteMapFilterSet',
Expand Down
Loading

0 comments on commit 9c1a2a9

Please sign in to comment.