Skip to content

Commit

Permalink
Convert NetBox models to PrimaryModels (#26)
Browse files Browse the repository at this point in the history
* Update readme

* Version bump

* Fix fieldsets

* Convert models to PrimaryModel
  • Loading branch information
DanSheps authored Sep 16, 2024
1 parent 6d6b72b commit 3851c98
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 21 deletions.
186 changes: 186 additions & 0 deletions netbox_routing/migrations/0008_convert_to_primarymodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Generated by Django 5.0.8 on 2024-09-14 01:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
'netbox_routing',
'0007_bgpsessiontemplate_asn_bgpsessiontemplate_bfd_and_more',
),
]

operations = [
migrations.AddField(
model_name='bgpaddressfamily',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgpaddressfamily',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgppeer',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgppeer',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgppeeraddressfamily',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgppeeraddressfamily',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgppeertemplate',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgppeertemplate',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgppoliytemplate',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgppoliytemplate',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgprouter',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgprouter',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgpscope',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgpscope',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgpsessiontemplate',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgpsessiontemplate',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='bgpsetting',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='bgpsetting',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='ospfarea',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='ospfarea',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='ospfinstance',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='ospfinstance',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='ospfinterface',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='ospfinterface',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='prefixlist',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='prefixlist',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='prefixlistentry',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='prefixlistentry',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='routemap',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='routemap',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='routemapentry',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='routemapentry',
name='description',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='staticroute',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='staticroute',
name='description',
field=models.CharField(blank=True, max_length=200),
),
]
20 changes: 10 additions & 10 deletions netbox_routing/models/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from django.db import models
from django.utils.translation import gettext as _

from netbox.models import NetBoxModel, NestedGroupModel
from netbox.models import PrimaryModel
from netbox_routing import choices
from netbox_routing.choices.bgp import BGPSettingChoices, BGPAddressFamilyChoices, BFDChoices
from netbox_routing.constants.bgp import BGPSETTING_ASSIGNMENT_MODELS, BGPAF_ASSIGNMENT_MODELS, \
BGPPEER_ASSIGNMENT_MODELS, BGPPEERAF_ASSIGNMENT_MODELS
from netbox_routing.fields.ip import IPAddressField


class BGPSetting(NetBoxModel):
class BGPSetting(PrimaryModel):
assigned_object_type = models.ForeignKey(
to=ContentType,
limit_choices_to=BGPSETTING_ASSIGNMENT_MODELS,
Expand Down Expand Up @@ -44,7 +44,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:bgpsetting', args=[self.pk])


class BGPRouter(NetBoxModel):
class BGPRouter(PrimaryModel):
device = models.ForeignKey(
to='dcim.Device',
on_delete=models.PROTECT,
Expand Down Expand Up @@ -76,7 +76,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:bgprouter', args=[self.pk])


class BGPScope(NetBoxModel):
class BGPScope(PrimaryModel):
router = models.ForeignKey(
to=BGPRouter,
on_delete=models.PROTECT,
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:bgpscope', args=[self.pk])


class BGPAddressFamily(NetBoxModel):
class BGPAddressFamily(PrimaryModel):
scope = models.ForeignKey(
to=BGPScope,
on_delete=models.PROTECT,
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:bgpaddressfamily', args=[self.pk])


class BGPSessionTemplate(NetBoxModel):
class BGPSessionTemplate(PrimaryModel):
name = models.CharField(
verbose_name='Name',
max_length=255
Expand Down Expand Up @@ -183,7 +183,7 @@ class BGPSessionTemplate(NetBoxModel):
)


class BGPPoliyTemplate(NetBoxModel):
class BGPPoliyTemplate(PrimaryModel):
name = models.CharField(
verbose_name='Name',
max_length=255
Expand Down Expand Up @@ -229,7 +229,7 @@ class BGPPoliyTemplate(NetBoxModel):
)


class BGPPeerTemplate(NetBoxModel):
class BGPPeerTemplate(PrimaryModel):
name = models.CharField(
verbose_name='Name',
max_length=255
Expand All @@ -247,7 +247,7 @@ class BGPPeerTemplate(NetBoxModel):
)


class BGPPeer(NetBoxModel):
class BGPPeer(PrimaryModel):
assigned_object_type = models.ForeignKey(
to=ContentType,
limit_choices_to=BGPPEER_ASSIGNMENT_MODELS,
Expand Down Expand Up @@ -292,7 +292,7 @@ class BGPPeer(NetBoxModel):
)


class BGPPeerAddressFamily(NetBoxModel):
class BGPPeerAddressFamily(PrimaryModel):
assigned_object_type = models.ForeignKey(
to=ContentType,
limit_choices_to=BGPPEERAF_ASSIGNMENT_MODELS,
Expand Down
10 changes: 5 additions & 5 deletions netbox_routing/models/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.core.exceptions import ValidationError

from ipam.fields import IPNetworkField
from netbox.models import NetBoxModel
from netbox.models import PrimaryModel
from netbox_routing.choices.objects import PermitDenyChoices


Expand All @@ -24,7 +24,7 @@ def get_type_color(self):
return PermitDenyChoices.colors.get(self.type)


class RouteMap(NetBoxModel):
class RouteMap(PrimaryModel):
name = models.CharField(
max_length=255
)
Expand All @@ -48,7 +48,7 @@ def __str__(self):
def get_absolute_url(self):
return reverse('plugins:netbox_routing:routemap', args=[self.pk])

class RouteMapEntry(PermitDenyChoiceMixin, NetBoxModel):
class RouteMapEntry(PermitDenyChoiceMixin, PrimaryModel):
route_map = models.ForeignKey(
to="netbox_routing.RouteMap",
on_delete=models.PROTECT,
Expand Down Expand Up @@ -94,7 +94,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:routemapentry', args=[self.pk])


class PrefixList(NetBoxModel):
class PrefixList(PrimaryModel):
name = models.CharField(
max_length=255
)
Expand All @@ -119,7 +119,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:prefixlist', args=[self.pk])


class PrefixListEntry(PermitDenyChoiceMixin, NetBoxModel):
class PrefixListEntry(PermitDenyChoiceMixin, PrimaryModel):
prefix_list = models.ForeignKey(
to="netbox_routing.PrefixList",
on_delete=models.PROTECT,
Expand Down
8 changes: 4 additions & 4 deletions netbox_routing/models/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.urls import reverse
from django.utils.translation import gettext as _

from netbox.models import NetBoxModel
from netbox.models import PrimaryModel

from netbox_routing import choices
from netbox_routing.fields.ip import IPAddressField
Expand All @@ -15,7 +15,7 @@
)


class OSPFInstance(NetBoxModel):
class OSPFInstance(PrimaryModel):
name = models.CharField(max_length=100)
router_id = IPAddressField(verbose_name=_('Router ID'))
process_id = models.IntegerField(verbose_name=_('Process ID'))
Expand All @@ -42,7 +42,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:ospfinstance', args=[self.pk])


class OSPFArea(NetBoxModel):
class OSPFArea(PrimaryModel):
area_id = models.CharField(max_length=100, verbose_name='Area ID')

prerequisite_models = ()
Expand All @@ -57,7 +57,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_routing:ospfarea', args=[self.pk])


class OSPFInterface(NetBoxModel):
class OSPFInterface(PrimaryModel):
instance = models.ForeignKey(
to='netbox_routing.OSPFInstance',
related_name='interfaces',
Expand Down
4 changes: 2 additions & 2 deletions netbox_routing/models/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse

from ipam.fields import IPNetworkField
from netbox.models import NetBoxModel
from netbox.models import PrimaryModel
from netbox_routing.fields.ip import IPAddressField


Expand All @@ -12,7 +12,7 @@
)


class StaticRoute(NetBoxModel):
class StaticRoute(PrimaryModel):
devices = models.ManyToManyField(
to='dcim.Device',
related_name='static_routes'
Expand Down

0 comments on commit 3851c98

Please sign in to comment.