Skip to content

Commit 6e6b8cb

Browse files
authored
V0.0.1 (#2)
* 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
1 parent 43da1d3 commit 6e6b8cb

12 files changed

+120
-10
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,40 @@
22
[Netbox](https://github.com/netbox-community/netbox) plugin for static route documentation.
33

44
## Installation
5-
5+
This project is not currently packaged. Installation will require cloning the repository and running setup.py in the Netbox virtual environment.
66

77
## Configuration
88

9+
### Netbox Configuration
10+
After running setup.py, enable the plugin in `netbox/netbox/configuration.py` in the `PLUGINS` parameter (which is a list):
11+
12+
```python
13+
# configuration.py
14+
PLUGINS = [
15+
'netbox_static_routes',
16+
]
17+
```
18+
19+
Save the file and restart the Netbox service.
20+
21+
### Apply Migrations
22+
Like any Netbox plugin which implements database models, you must apply migration files included in the project using the `migrate` management command:
23+
24+
```bash
25+
$ python netbox/manage.py migrate
26+
Operations to perform:
27+
Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, netbox_access_lists, sessions, social_django, taggit, tenancy, users, virtualization, wireless
28+
Running migrations:
29+
Applying netbox_static_routes.0001_initial... OK
30+
```
31+
32+
You may or may not have to restart the Netbox service after applying migrations.
33+
34+
Netbox Static Routes should be usable upon page refresh.
35+
36+
## Roadmap
37+
### Next-Hop Types
38+
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.
39+
40+
## Contributing
41+
Open for contribution. Email me at [email protected] with any suggestions or if you would like to contribute.

netbox_static_routes/forms.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dcim.models import Site, Device
22
from ipam.models import Prefix, VRF
33
from django import forms
4-
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
4+
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelBulkEditForm
55
from .models import StaticRoute
66
from utilities.forms.fields import CommentField, DynamicModelChoiceField
77

@@ -56,4 +56,14 @@ class StaticRouteFilterForm(NetBoxModelFilterSetForm):
5656
required=False
5757
)
5858

59-
# consider adding a bulk edit form
59+
class StaticRouteBulkEditForm(NetBoxModelBulkEditForm):
60+
model = StaticRoute
61+
pk = forms.ModelMultipleChoiceField(
62+
queryset=StaticRoute.objects.all(),
63+
widget=forms.MultipleHiddenInput
64+
)
65+
distance = forms.IntegerField(
66+
max_value=255,
67+
min_value=1,
68+
required=False
69+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 4.0.4 on 2022-05-30 17:44
2+
3+
import django.contrib.postgres.fields
4+
import django.core.serializers.json
5+
import django.core.validators
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
import taggit.managers
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
initial = True
14+
15+
dependencies = [
16+
('dcim', '0153_created_datetimefield'),
17+
('extras', '0073_journalentry_tags_custom_fields'),
18+
('ipam', '0057_created_datetimefield'),
19+
]
20+
21+
operations = [
22+
migrations.CreateModel(
23+
name='StaticRoute',
24+
fields=[
25+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
26+
('created', models.DateTimeField(auto_now_add=True, null=True)),
27+
('last_updated', models.DateTimeField(auto_now=True, null=True)),
28+
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
29+
('next_hop', django.contrib.postgres.fields.ArrayField(base_field=models.GenericIPAddressField(), null=True, size=None)),
30+
('distance', models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(255)])),
31+
('comments', models.TextField(blank=True)),
32+
('destination_prefix', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='ipam.prefix')),
33+
('device', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='dcim.device')),
34+
('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='%(class)s_related', to='dcim.site')),
35+
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
36+
('vrf', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='ipam.vrf')),
37+
],
38+
options={
39+
'verbose_name_plural': 'Static Routes',
40+
'ordering': ('device', 'vrf', 'destination_prefix', 'next_hop'),
41+
'unique_together': {('device', 'vrf', 'destination_prefix')},
42+
},
43+
),
44+
]
Binary file not shown.
Binary file not shown.
Binary file not shown.

netbox_static_routes/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from django.db import models
33
from django.urls import reverse
44
from django.core.validators import MaxValueValidator, MinValueValidator
5+
<<<<<<< HEAD
6+
from django.contrib.postgres.fields import ArrayField
7+
=======
8+
>>>>>>> main
59
from netbox.models import NetBoxModel
610
from utilities.choices import ChoiceSet
711

@@ -46,8 +50,14 @@ class StaticRoute(NetBoxModel):
4650
on_delete=models.PROTECT,
4751
null=True
4852
)
53+
<<<<<<< HEAD
54+
next_hop = ArrayField(
55+
base_field=models.GenericIPAddressField(),
56+
null=True
57+
=======
4958
next_hop = models.GenericIPAddressField(
5059
null=True,
60+
>>>>>>> main
5161
)
5262
distance = models.PositiveIntegerField(
5363
default=1,

netbox_static_routes/tables.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import django_tables2 as tables
22
from netbox.tables import NetBoxTable, ChoiceFieldColumn
33
from .models import StaticRoute
4+
from django.urls import path
5+
46

57
class StaticRouteTable(NetBoxTable):
6-
pk = tables.Column(
7-
linkify=True
8-
)
98
destination_prefix = tables.Column(
10-
linkify=True
9+
linkify=(
10+
('plugins:netbox_static_routes:staticroute', {'pk': tables.A('pk')})
11+
)
1112
)
1213
site = tables.Column(
1314
linkify=True

netbox_static_routes/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
urlpatterns = (
66
path('static-routes/', views.StaticRouteListView.as_view(), name='staticroute_list'),
77
path('static-routes/add/', views.StaticRouteEditView.as_view(), name='staticroute_add'),
8+
path('static-routes/edit/', views.StaticRouteBulkEditView.as_view(), name='staticroute_bulk_edit'),
9+
path('static-routes/delete/', views.StaticRouteBulkDeleteView.as_view(), name='staticroute_bulk_delete'),
810
path('static-routes/<int:pk>', views.StaticRouteView.as_view(), name='staticroute'),
911
path('static-routes/<int:pk>/edit/', views.StaticRouteEditView.as_view(), name='staticroute_edit'),
1012
path('static-routes/<int:pk>/delete/', views.StaticRouteDeleteView.as_view(), name='staticroute_delete'),
1113
path('static-routes/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='staticroute_changelog', kwargs={
1214
'model': models.StaticRoute
1315
}),
14-
)
16+
)

0 commit comments

Comments
 (0)