Skip to content

Commit

Permalink
#9816: Promote IKE & IPSec proposals and policies to primary models
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 4, 2023
1 parent 3faf485 commit 5b0b366
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 52 deletions.
4 changes: 4 additions & 0 deletions docs/development/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ These are considered the "core" application models which are used to model netwo
* [tenancy.Tenant](../models/tenancy/tenant.md)
* [virtualization.Cluster](../models/virtualization/cluster.md)
* [virtualization.VirtualMachine](../models/virtualization/virtualmachine.md)
* [vpn.IKEPolicy](../models/vpn/ikepolicy.md)
* [vpn.IKEProposal](../models/vpn/ikeproposal.md)
* [vpn.IPSecPolicy](../models/vpn/ipsecpolicy.md)
* [vpn.IPSecProfile](../models/vpn/ipsecprofile.md)
* [vpn.IPSecProposal](../models/vpn/ipsecproposal.md)
* [vpn.L2VPN](../models/vpn/l2vpn.md)
* [vpn.Tunnel](../models/vpn/tunnel.md)
* [wireless.WirelessLAN](../models/wireless/wirelesslan.md)
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/vpn/ikepolicy.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h5 class="card-header">{% trans "IKE Policy" %}</h5>
</div>
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/vpn/ikeproposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h5 class="card-header">{% trans "IKE Proposal" %}</h5>
</div>
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/vpn/ipsecpolicy.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h5 class="card-header">{% trans "IPSec Policy" %}</h5>
</div>
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/vpn/ipsecproposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h5 class="card-header">{% trans "IPSec Proposal" %}</h5>
</div>
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
Expand Down
13 changes: 7 additions & 6 deletions netbox/vpn/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class Meta:
model = IKEProposal
fields = (
'id', 'url', 'display', 'name', 'description', 'authentication_method', 'encryption_algorithm',
'authentication_algorithm', 'group', 'sa_lifetime', 'tags', 'custom_fields', 'created', 'last_updated',
'authentication_algorithm', 'group', 'sa_lifetime', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
)


Expand All @@ -131,8 +132,8 @@ class IKEPolicySerializer(NetBoxModelSerializer):
class Meta:
model = IKEPolicy
fields = (
'id', 'url', 'display', 'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'tags',
'custom_fields', 'created', 'last_updated',
'id', 'url', 'display', 'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'comments',
'tags', 'custom_fields', 'created', 'last_updated',
)


Expand All @@ -151,7 +152,7 @@ class Meta:
model = IPSecProposal
fields = (
'id', 'url', 'display', 'name', 'description', 'encryption_algorithm', 'authentication_algorithm',
'sa_lifetime_seconds', 'sa_lifetime_data', 'tags', 'custom_fields', 'created', 'last_updated',
'sa_lifetime_seconds', 'sa_lifetime_data', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
)


Expand All @@ -173,8 +174,8 @@ class IPSecPolicySerializer(NetBoxModelSerializer):
class Meta:
model = IPSecPolicy
fields = (
'id', 'url', 'display', 'name', 'description', 'proposals', 'pfs_group', 'tags', 'custom_fields', 'created',
'last_updated',
'id', 'url', 'display', 'name', 'description', 'proposals', 'pfs_group', 'comments', 'tags',
'custom_fields', 'created', 'last_updated',
)


Expand Down
12 changes: 8 additions & 4 deletions netbox/vpn/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value)
Q(description__icontains=value) |
Q(comments__icontains=value)
)


Expand All @@ -155,7 +156,8 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value)
Q(description__icontains=value) |
Q(comments__icontains=value)
)


Expand All @@ -176,7 +178,8 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value)
Q(description__icontains=value) |
Q(comments__icontains=value)
)


Expand All @@ -200,7 +203,8 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value)
Q(description__icontains=value) |
Q(comments__icontains=value)
)


Expand Down
8 changes: 4 additions & 4 deletions netbox/vpn/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Meta:
model = IKEProposal
fields = (
'name', 'description', 'authentication_method', 'encryption_algorithm', 'authentication_algorithm',
'group', 'sa_lifetime', 'tags',
'group', 'sa_lifetime', 'comments', 'tags',
)


Expand All @@ -169,7 +169,7 @@ class IKEPolicyImportForm(NetBoxModelImportForm):
class Meta:
model = IKEPolicy
fields = (
'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'tags',
'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'comments', 'tags',
)


Expand All @@ -187,7 +187,7 @@ class Meta:
model = IPSecProposal
fields = (
'name', 'description', 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds',
'sa_lifetime_data', 'tags',
'sa_lifetime_data', 'comments', 'tags',
)


Expand All @@ -205,7 +205,7 @@ class IPSecPolicyImportForm(NetBoxModelImportForm):
class Meta:
model = IPSecPolicy
fields = (
'name', 'description', 'proposals', 'pfs_group', 'tags',
'name', 'description', 'proposals', 'pfs_group', 'comments', 'tags',
)


Expand Down
8 changes: 4 additions & 4 deletions netbox/vpn/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Meta:
model = IKEProposal
fields = [
'name', 'description', 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group',
'sa_lifetime', 'tags',
'sa_lifetime', 'comments', 'tags',
]


Expand All @@ -298,7 +298,7 @@ class IKEPolicyForm(NetBoxModelForm):
class Meta:
model = IKEPolicy
fields = [
'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'tags',
'name', 'description', 'version', 'mode', 'proposals', 'preshared_key', 'comments', 'tags',
]


Expand All @@ -315,7 +315,7 @@ class Meta:
model = IPSecProposal
fields = [
'name', 'description', 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds',
'sa_lifetime_data', 'tags',
'sa_lifetime_data', 'comments', 'tags',
]


Expand All @@ -333,7 +333,7 @@ class IPSecPolicyForm(NetBoxModelForm):
class Meta:
model = IPSecPolicy
fields = [
'name', 'description', 'proposals', 'pfs_group', 'tags',
'name', 'description', 'proposals', 'pfs_group', 'comments', 'tags',
]


Expand Down
12 changes: 8 additions & 4 deletions netbox/vpn/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class Migration(migrations.Migration):
('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=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(max_length=100, unique=True)),
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('version', models.PositiveSmallIntegerField(default=2)),
('mode', models.CharField()),
('preshared_key', models.TextField(blank=True)),
Expand All @@ -42,8 +43,9 @@ class Migration(migrations.Migration):
('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=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(max_length=100, unique=True)),
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('pfs_group', models.PositiveSmallIntegerField(blank=True, null=True)),
],
options={
Expand Down Expand Up @@ -123,8 +125,9 @@ class Migration(migrations.Migration):
('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=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(max_length=100, unique=True)),
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('encryption_algorithm', models.CharField()),
('authentication_algorithm', models.CharField()),
('sa_lifetime_seconds', models.PositiveIntegerField(blank=True, null=True)),
Expand Down Expand Up @@ -154,8 +157,9 @@ class Migration(migrations.Migration):
('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=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(max_length=100, unique=True)),
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('authentication_method', models.CharField()),
('encryption_algorithm', models.CharField()),
('authentication_algorithm', models.CharField()),
Expand Down
30 changes: 5 additions & 25 deletions netbox/vpn/models/crypto.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_lazy as _

from netbox.models import NetBoxModel, PrimaryModel
from netbox.models import PrimaryModel
from vpn.choices import *

__all__ = (
Expand All @@ -18,17 +18,12 @@
# IKE
#

class IKEProposal(NetBoxModel):
class IKEProposal(PrimaryModel):
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
authentication_method = models.CharField(
verbose_name=('authentication method'),
choices=AuthenticationMethodChoices
Expand Down Expand Up @@ -69,17 +64,12 @@ def get_absolute_url(self):
return reverse('vpn:ikeproposal', args=[self.pk])


class IKEPolicy(NetBoxModel):
class IKEPolicy(PrimaryModel):
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
version = models.PositiveSmallIntegerField(
verbose_name=_('version'),
choices=IKEVersionChoices,
Expand Down Expand Up @@ -122,17 +112,12 @@ def get_absolute_url(self):
# IPSec
#

class IPSecProposal(NetBoxModel):
class IPSecProposal(PrimaryModel):
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
encryption_algorithm = models.CharField(
verbose_name=_('encryption'),
choices=EncryptionAlgorithmChoices
Expand Down Expand Up @@ -170,17 +155,12 @@ def get_absolute_url(self):
return reverse('vpn:ipsecproposal', args=[self.pk])


class IPSecPolicy(NetBoxModel):
class IPSecPolicy(PrimaryModel):
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
proposals = models.ManyToManyField(
to='vpn.IPSecProposal',
related_name='ipsec_policies',
Expand Down
4 changes: 4 additions & 0 deletions netbox/vpn/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IKEProposalIndex(SearchIndex):
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('description',)

Expand All @@ -30,6 +31,7 @@ class IKEPolicyIndex(SearchIndex):
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('description',)

Expand All @@ -40,6 +42,7 @@ class IPSecProposalIndex(SearchIndex):
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('description',)

Expand All @@ -50,6 +53,7 @@ class IPSecPolicyIndex(SearchIndex):
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('description',)

Expand Down
Loading

0 comments on commit 5b0b366

Please sign in to comment.