Skip to content

Commit

Permalink
V0.0.1 (#2)
Browse files Browse the repository at this point in the history
* Models update - validators on distance

* updated migrations files

* Included url in static route serializer fields

* updated serializer view name

* Verbose name change in init

* Testing linkify

* Updated link on prefix in table view

* Changed next hop to arrayfield

* Models update

* Added bulk edit and delete views and updated README
  • Loading branch information
jbparrish17 authored May 30, 2022
1 parent 43da1d3 commit 6e6b8cb
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 10 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,40 @@
[Netbox](https://github.com/netbox-community/netbox) plugin for static route documentation.

## Installation

This project is not currently packaged. Installation will require cloning the repository and running setup.py in the Netbox virtual environment.

## Configuration

### Netbox Configuration
After running setup.py, enable the plugin in `netbox/netbox/configuration.py` in the `PLUGINS` parameter (which is a list):

```python
# configuration.py
PLUGINS = [
'netbox_static_routes',
]
```

Save the file and restart the Netbox service.

### Apply Migrations
Like any Netbox plugin which implements database models, you must apply migration files included in the project using the `migrate` management command:

```bash
$ python netbox/manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, netbox_access_lists, sessions, social_django, taggit, tenancy, users, virtualization, wireless
Running migrations:
Applying netbox_static_routes.0001_initial... OK
```

You may or may not have to restart the Netbox service after applying migrations.

Netbox Static Routes should be usable upon page refresh.

## Roadmap
### Next-Hop Types
Currently Netbox Static Routes only supports next-hops as arrays of IP addresses. Some network vendors allow for next-hops other than an IP address. Examples include an interface or a route table. It would be helpful to allow for storage of other types beyond IP addresses.

## Contributing
Open for contribution. Email me at jbparrish17@gmail.com with any suggestions or if you would like to contribute.
14 changes: 12 additions & 2 deletions netbox_static_routes/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dcim.models import Site, Device
from ipam.models import Prefix, VRF
from django import forms
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelBulkEditForm
from .models import StaticRoute
from utilities.forms.fields import CommentField, DynamicModelChoiceField

Expand Down Expand Up @@ -56,4 +56,14 @@ class StaticRouteFilterForm(NetBoxModelFilterSetForm):
required=False
)

# consider adding a bulk edit form
class StaticRouteBulkEditForm(NetBoxModelBulkEditForm):
model = StaticRoute
pk = forms.ModelMultipleChoiceField(
queryset=StaticRoute.objects.all(),
widget=forms.MultipleHiddenInput
)
distance = forms.IntegerField(
max_value=255,
min_value=1,
required=False
)
44 changes: 44 additions & 0 deletions netbox_static_routes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.0.4 on 2022-05-30 17:44

import django.contrib.postgres.fields
import django.core.serializers.json
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import taggit.managers


class Migration(migrations.Migration):

initial = True

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

operations = [
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)),
('next_hop', django.contrib.postgres.fields.ArrayField(base_field=models.GenericIPAddressField(), null=True, size=None)),
('distance', models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(255)])),
('comments', models.TextField(blank=True)),
('destination_prefix', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='ipam.prefix')),
('device', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='dcim.device')),
('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='%(class)s_related', to='dcim.site')),
('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='+', to='ipam.vrf')),
],
options={
'verbose_name_plural': 'Static Routes',
'ordering': ('device', 'vrf', 'destination_prefix', 'next_hop'),
'unique_together': {('device', 'vrf', 'destination_prefix')},
},
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions netbox_static_routes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from django.db import models
from django.urls import reverse
from django.core.validators import MaxValueValidator, MinValueValidator
<<<<<<< HEAD
from django.contrib.postgres.fields import ArrayField
=======
>>>>>>> main
from netbox.models import NetBoxModel
from utilities.choices import ChoiceSet

Expand Down Expand Up @@ -46,8 +50,14 @@ class StaticRoute(NetBoxModel):
on_delete=models.PROTECT,
null=True
)
<<<<<<< HEAD
next_hop = ArrayField(
base_field=models.GenericIPAddressField(),
null=True
=======
next_hop = models.GenericIPAddressField(
null=True,
>>>>>>> main
)
distance = models.PositiveIntegerField(
default=1,
Expand Down
9 changes: 5 additions & 4 deletions netbox_static_routes/tables.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import django_tables2 as tables
from netbox.tables import NetBoxTable, ChoiceFieldColumn
from .models import StaticRoute
from django.urls import path


class StaticRouteTable(NetBoxTable):
pk = tables.Column(
linkify=True
)
destination_prefix = tables.Column(
linkify=True
linkify=(
('plugins:netbox_static_routes:staticroute', {'pk': tables.A('pk')})
)
)
site = tables.Column(
linkify=True
Expand Down
4 changes: 3 additions & 1 deletion netbox_static_routes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
urlpatterns = (
path('static-routes/', views.StaticRouteListView.as_view(), name='staticroute_list'),
path('static-routes/add/', views.StaticRouteEditView.as_view(), name='staticroute_add'),
path('static-routes/edit/', views.StaticRouteBulkEditView.as_view(), name='staticroute_bulk_edit'),
path('static-routes/delete/', views.StaticRouteBulkDeleteView.as_view(), name='staticroute_bulk_delete'),
path('static-routes/<int:pk>', views.StaticRouteView.as_view(), name='staticroute'),
path('static-routes/<int:pk>/edit/', views.StaticRouteEditView.as_view(), name='staticroute_edit'),
path('static-routes/<int:pk>/delete/', views.StaticRouteDeleteView.as_view(), name='staticroute_delete'),
path('static-routes/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='staticroute_changelog', kwargs={
'model': models.StaticRoute
}),
)
)
2 changes: 1 addition & 1 deletion netbox_static_routes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1'
__version__ = '0.0.1'
12 changes: 11 additions & 1 deletion netbox_static_routes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ class StaticRouteEditView(generic.ObjectEditView):
queryset = models.StaticRoute.objects.all()
form = forms.StaticRouteForm

class StaticRouteBulkEditView(generic.BulkEditView):
queryset = models.StaticRoute.objects.all()
table = tables.StaticRouteTable
form = forms.StaticRouteBulkEditForm
filterset = filtersets.StaticRouteFilterSet

class StaticRouteDeleteView(generic.ObjectDeleteView):
queryset = models.StaticRoute.objects.all()


class StaticRouteBulkDeleteView(generic.BulkDeleteView):
queryset = models.StaticRoute.objects.all()
table = tables.StaticRouteTable

0 comments on commit 6e6b8cb

Please sign in to comment.