Skip to content

Commit 665465b

Browse files
committed
Merge branch 'main' of github.com:jbparrish17/netbox-static-routes
2 parents 61a0426 + ca013d1 commit 665465b

8 files changed

+78
-4
lines changed

netbox_static_routes/api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Meta:
1515

1616
class StaticRouteSerializer(NetBoxModelSerializer):
1717
url = serializers.HyperlinkedIdentityField(
18-
view_name='plugins-api:netbox_access_lists-api:staticroute-detail'
18+
view_name='plugins-api:netbox_static_routes-api:staticroute-detail'
1919
)
2020

2121
class Meta:
2222
model = StaticRoute
2323
fields = (
24-
'id', 'display', 'destination_prefix', 'next_hop', 'site', 'device', 'vrf', 'comments', 'tags', 'custom_fields', 'created', 'last_updated'
24+
'id', 'url', 'display', 'destination_prefix', 'next_hop', 'site', 'device', 'vrf', 'comments', 'tags', 'custom_fields', 'created', 'last_updated'
2525
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 4.0.4 on 2022-05-28 14:51
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('netbox_static_routes', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='staticroute',
15+
options={'ordering': ('device', 'vrf', 'destination_prefix', 'next_hop'), 'verbose_name_plural': 'Static Routes'},
16+
),
17+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 4.0.4 on 2022-05-29 23:44
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('dcim', '0153_created_datetimefield'),
12+
('netbox_static_routes', '0002_alter_staticroute_options'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='staticroute',
18+
name='device',
19+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='dcim.device'),
20+
),
21+
migrations.AlterField(
22+
model_name='staticroute',
23+
name='distance',
24+
field=models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(255)]),
25+
),
26+
migrations.AlterField(
27+
model_name='staticroute',
28+
name='next_hop',
29+
field=models.GenericIPAddressField(null=True),
30+
),
31+
]
Binary file not shown.
Binary file not shown.
Binary file not shown.

netbox_static_routes/models.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
#from django.contrib.postgres.fields import ArrayField
22
from django.db import models
33
from django.urls import reverse
4+
from django.core.validators import MaxValueValidator, MinValueValidator
45
from netbox.models import NetBoxModel
6+
from utilities.choices import ChoiceSet
7+
8+
# future use
9+
class NextHopTypeChoices(ChoiceSet):
10+
key = 'StaticRoute.next_hop_type'
11+
12+
NH_TYPE_IP_ADDRESS = ('ip_address', 'IP Address')
13+
NH_TYPE_INTERFACE = ('interface', 'Interface')
14+
NH_TYPE_VRF = ('vrf', 'VRF')
15+
16+
CHOICES = [
17+
NH_TYPE_IP_ADDRESS,
18+
NH_TYPE_INTERFACE,
19+
NH_TYPE_VRF
20+
]
521

622
class StaticRoute(NetBoxModel):
723
site = models.ForeignKey(
@@ -14,6 +30,7 @@ class StaticRoute(NetBoxModel):
1430
device = models.ForeignKey(
1531
to='dcim.Device',
1632
on_delete=models.PROTECT,
33+
related_name='+',
1734
null=True,
1835
)
1936
vrf = models.ForeignKey(
@@ -29,8 +46,17 @@ class StaticRoute(NetBoxModel):
2946
on_delete=models.PROTECT,
3047
null=True
3148
)
32-
next_hop = models.GenericIPAddressField() # will want to add validators here to ensure v4 next-hop for v4 prefix and v6 next-hop for v6 prefix
33-
distance = models.PositiveIntegerField() # will want to add validators to limit integer
49+
next_hop = models.GenericIPAddressField(
50+
null=True,
51+
)
52+
distance = models.PositiveIntegerField(
53+
default=1,
54+
validators=[
55+
MinValueValidator(1),
56+
MaxValueValidator(255)
57+
],
58+
verbose_name='Administrative distance'
59+
)
3460
comments = models.TextField(
3561
blank=True
3662
)

0 commit comments

Comments
 (0)