Skip to content

Commit

Permalink
Merge pull request #5 from DanSheps/develop
Browse files Browse the repository at this point in the history
v0.0.2 Release
  • Loading branch information
DanSheps authored May 18, 2023
2 parents d3c1e60 + c6d02e4 commit 02daba0
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 43 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ A plugin for tracking all kinds of routing information
### Current features

* Static routing

### Under development

* Dynamic routing
* BGP
* Templates/Group inheritance
Expand Down
5 changes: 1 addition & 4 deletions netbox_routing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from extras.plugins import PluginConfig
from importlib.metadata import metadata

try:
from importlib.metadata import metadata
except ModuleNotFoundError:
from importlib_metadata import metadata

plugin = metadata('netbox_routing')

Expand Down
2 changes: 1 addition & 1 deletion netbox_routing/api/nested_serializers/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from netbox.api import WritableNestedSerializer
from netbox.api.serializers import WritableNestedSerializer
from netbox_routing.models import PrefixList, PrefixListEntry, RouteMap, RouteMapEntry


Expand Down
2 changes: 1 addition & 1 deletion netbox_routing/api/nested_serializers/static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from netbox.api import WritableNestedSerializer
from netbox.api.serializers import WritableNestedSerializer
from netbox_routing.models import StaticRoute


Expand Down
10 changes: 5 additions & 5 deletions netbox_routing/api/views/objects.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from netbox.api.viewsets import ModelViewSet
from netbox.api.viewsets import NetBoxModelViewSet
from netbox_routing.api.serializers import PrefixListSerializer, PrefixListEntrySerializer, RouteMapSerializer, \
RouteMapEntrySerializer
from netbox_routing.models import PrefixList, PrefixListEntry, RouteMap, RouteMapEntry


class PrefixListViewSet(ModelViewSet):
class PrefixListViewSet(NetBoxModelViewSet):
queryset = PrefixList.objects.all()
serializer_class = PrefixListSerializer


class PrefixListEntryViewSet(ModelViewSet):
class PrefixListEntryViewSet(NetBoxModelViewSet):
queryset = PrefixListEntry.objects.all()
serializer_class = PrefixListEntrySerializer


class RouteMapViewSet(ModelViewSet):
class RouteMapViewSet(NetBoxModelViewSet):
queryset = RouteMap.objects.all()
serializer_class = RouteMapSerializer


class RouteMapEntryViewSet(ModelViewSet):
class RouteMapEntryViewSet(NetBoxModelViewSet):
queryset = RouteMapEntry.objects.all()
serializer_class = RouteMapEntrySerializer
4 changes: 2 additions & 2 deletions netbox_routing/api/views/static.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from netbox.api.viewsets import ModelViewSet
from netbox.api.viewsets import NetBoxModelViewSet
from netbox_routing.api.serializers import StaticRouteSerializer
from netbox_routing.models import StaticRoute


class StaticRouteViewSet(ModelViewSet):
class StaticRouteViewSet(NetBoxModelViewSet):
queryset = StaticRoute.objects.all()
serializer_class = StaticRouteSerializer
106 changes: 106 additions & 0 deletions netbox_routing/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Generated by Django 4.0.3 on 2022-04-01 18:02

import django.core.serializers.json
from django.db import migrations, models
import django.db.models.deletion
import ipam.fields
import netbox_routing.fields.ip
import taggit.managers


class Migration(migrations.Migration):

initial = True

dependencies = [
('ipam', '0057_created_datetimefield'),
('extras', '0072_created_datetimefield'),
('dcim', '0153_created_datetimefield'),
]

operations = [
migrations.CreateModel(
name='PrefixList',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('name', models.CharField(max_length=255)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='RouteMap',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('name', models.CharField(max_length=255)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='StaticRoute',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('prefix', ipam.fields.IPNetworkField()),
('next_hop', netbox_routing.fields.ip.IPAddressField()),
('name', models.CharField(blank=True, max_length=50, null=True)),
('metric', models.PositiveSmallIntegerField()),
('permanent', models.BooleanField()),
('devices', models.ManyToManyField(related_name='static_routes', to='dcim.device')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
('vrf', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='staticroutes', to='ipam.vrf')),
],
),
migrations.CreateModel(
name='RouteMapEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('type', models.CharField(max_length=6)),
('sequence', models.PositiveSmallIntegerField()),
('route_map', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entries', to='netbox_routing.routemap')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='PrefixListEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('sequence', models.PositiveSmallIntegerField()),
('type', models.CharField(max_length=6)),
('prefix', ipam.fields.IPNetworkField()),
('ge', models.PositiveSmallIntegerField()),
('le', models.PositiveSmallIntegerField()),
('prefix_list', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entries', to='netbox_routing.prefixlist')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'abstract': False,
},
),
migrations.AddConstraint(
model_name='staticroute',
constraint=models.CheckConstraint(check=models.Q(models.Q(('metric__lte', 255), ('metric__gte', 0))), name='metric_gte_lte'),
),
]
Empty file.
30 changes: 30 additions & 0 deletions netbox_routing/models/ospf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.db import models

from netbox.models import NetBoxModel, WebhooksMixin, ChangeLoggedModel

from netbox_routing.fields.ip import IPAddressField


__all__ = (
'OSPFInstance',
'OSPFArea',
)


class OSPFInstance(NetBoxModel):
router_id = IPAddressField()
process_id = models.IntegerField()


class OSPFArea(NetBoxModel):
instance = models.ForeignKey(
to='netbox_routing.OSPFInstance'
)
area_id = models.IntegerField()
interfaces = models.ManyToManyField(
to='netbox_routing.OSPFArea',
on_delete=models.PROTECT,
related_name='ospf',
blank=False,
null=False
)
59 changes: 33 additions & 26 deletions netbox_routing/navigation.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
from extras.plugins import PluginMenuButton, PluginMenuItem
from extras.plugins import PluginMenuButton, PluginMenuItem, PluginMenu
from utilities.choices import ButtonColorChoices

menu_items = (
PluginMenuItem(
link='plugins:netbox_routing:staticroute_list',
link_text='Static Route',
buttons=(
PluginMenuButton('plugins:netbox_routing:staticroute_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:staticroute_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
),
PluginMenuItem(
link='plugins:netbox_routing:prefixlist_list',
link_text='Prefix Lists',
buttons=(
PluginMenuButton('plugins:netbox_routing:prefixlist_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:prefixlist_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
),
PluginMenuItem(
link='plugins:netbox_routing:routemap_list',
link_text='Route Maps',
buttons=(
PluginMenuButton('plugins:netbox_routing:routemap_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:routemap_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
static = PluginMenuItem(
link='plugins:netbox_routing:staticroute_list',
link_text='Static Route',
buttons=(
PluginMenuButton('plugins:netbox_routing:staticroute_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:staticroute_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
)
prefixlist = PluginMenuItem(
link='plugins:netbox_routing:prefixlist_list',
link_text='Prefix Lists',
buttons=(
PluginMenuButton('plugins:netbox_routing:prefixlist_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:prefixlist_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
)
routemap = PluginMenuItem(
link='plugins:netbox_routing:routemap_list',
link_text='Route Maps',
buttons=(
PluginMenuButton('plugins:netbox_routing:routemap_add', 'Add', 'mdi mdi-plus', ButtonColorChoices.GREEN),
PluginMenuButton('plugins:netbox_routing:routemap_import', 'Import', 'mdi mdi-upload', ButtonColorChoices.CYAN),
)
)

menu = PluginMenu(
label='Netbox Routing',
groups=(
('Routing Objects', (prefixlist, routemap )),
('Support Contracts', (static, )),
),
)
icon_class='mdi mdi-router'
)
1 change: 1 addition & 0 deletions netbox_routing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
path('routes/static/import/', views.StaticRouteListView.as_view(), name='staticroute_import'),
path('routes/static/<int:pk>/', views.StaticRouteView.as_view(), name='staticroute'),
path('routes/static/<int:pk>/edit/', views.StaticRouteEditView.as_view(), name='staticroute_edit'),
path('routes/static/<int:pk>/devices/', views.StaticRouteDevicesView.as_view(), name='staticroute_devices'),
path('routes/static/<int:pk>/delete/', views.StaticRouteDeleteView.as_view(), name='staticroute_delete'),
path('routes/static/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='staticroute_changelog', kwargs={'model': StaticRoute}),

Expand Down
4 changes: 3 additions & 1 deletion netbox_routing/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .static import StaticRouteListView, StaticRouteEditView, StaticRouteView, StaticRouteDeleteView
from .static import StaticRouteListView, StaticRouteDevicesView, StaticRouteEditView, StaticRouteView, \
StaticRouteDeleteView

from .objects import PrefixListView, PrefixListEditView, PrefixListListView, PrefixListDeleteView, RouteMapListView, \
RouteMapView, RouteMapEditView, RouteMapDeleteView, PrefixListEntryListView, PrefixListEntryEditView, \
Expand All @@ -8,6 +9,7 @@
__all__ = (
'StaticRouteListView',
'StaticRouteView',
'StaticRouteDevicesView',
'StaticRouteEditView',
'StaticRouteDeleteView',

Expand Down
27 changes: 26 additions & 1 deletion netbox_routing/views/static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dcim.filtersets import DeviceFilterSet
from dcim.models import Device
from dcim.tables import DeviceTable
from netbox.views.generic import ObjectListView, ObjectEditView, ObjectView, ObjectDeleteView
from netbox.views.generic import ObjectListView, ObjectEditView, ObjectView, ObjectDeleteView, ObjectChildrenView
from netbox_routing.filtersets.static import StaticRouteFilterSet
from netbox_routing.forms import StaticRouteForm
from netbox_routing.forms.filtersets.static import StaticRouteFilterSetForm
Expand All @@ -11,18 +12,23 @@
__all__ = (
'StaticRouteListView',
'StaticRouteView',
'StaticRouteDevicesView',
'StaticRouteEditView',
'StaticRouteDeleteView',
)

from utilities.views import register_model_view, ViewTab


@register_model_view(StaticRoute, name='list')
class StaticRouteListView(ObjectListView):
queryset = StaticRoute.objects.all()
table = StaticRouteTable
filterset = StaticRouteFilterSet
filterset_form = StaticRouteFilterSetForm


@register_model_view(StaticRoute)
class StaticRouteView(ObjectView):
queryset = StaticRoute.objects.all()
template_name = 'netbox_routing/staticroute.html'
Expand All @@ -43,10 +49,29 @@ def get_extra_context(self, request, instance):
}


@register_model_view(StaticRoute, name='assignments')
class StaticRouteDevicesView(ObjectChildrenView):
# template_name = 'dcim//.html'
queryset = StaticRoute.objects.all()
child_model = Device
table = DeviceTable
filterset = DeviceFilterSet
actions = []
tab = ViewTab(
label='Assigned Devices',
badge=lambda obj: Device.objects.filter(static_routes=obj).count(),
)

def get_children(self, request, parent):
return self.child_model.objects.filter(static_routes=parent)


@register_model_view(StaticRoute, name='edit')
class StaticRouteEditView(ObjectEditView):
queryset = StaticRoute.objects.all()
form = StaticRouteForm


@register_model_view(StaticRoute, name='delete')
class StaticRouteDeleteView(ObjectDeleteView):
pass
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='netbox-routing',
version='0.0.1',
version='0.0.2',
description='NetBox Routing',
long_description='Plugin for documentation of routing configuration and objects',
url='https://github.com/dansheps/netbox-routing/',
Expand All @@ -19,7 +19,7 @@
'Programming Language :: Python :: 3',
],
install_requires=[
'importlib',
'django-polymorphic',
],
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit 02daba0

Please sign in to comment.