From 5b0b366b828eaeb96a0646050bec1b059072a042 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 4 Dec 2023 09:19:56 -0500 Subject: [PATCH] #9816: Promote IKE & IPSec proposals and policies to primary models --- docs/development/models.md | 4 ++++ netbox/templates/vpn/ikepolicy.html | 1 + netbox/templates/vpn/ikeproposal.html | 1 + netbox/templates/vpn/ipsecpolicy.html | 1 + netbox/templates/vpn/ipsecproposal.html | 1 + netbox/vpn/api/serializers.py | 13 ++++++----- netbox/vpn/filtersets.py | 12 ++++++---- netbox/vpn/forms/bulk_import.py | 8 +++---- netbox/vpn/forms/model_forms.py | 8 +++---- netbox/vpn/migrations/0001_initial.py | 12 ++++++---- netbox/vpn/models/crypto.py | 30 +++++-------------------- netbox/vpn/search.py | 4 ++++ netbox/vpn/tables/crypto.py | 22 +++++++++++++----- 13 files changed, 65 insertions(+), 52 deletions(-) diff --git a/docs/development/models.md b/docs/development/models.md index f55c39cf86c..19b7be6dee7 100644 --- a/docs/development/models.md +++ b/docs/development/models.md @@ -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) diff --git a/netbox/templates/vpn/ikepolicy.html b/netbox/templates/vpn/ikepolicy.html index 559ba6d17bf..da116cfa2cf 100644 --- a/netbox/templates/vpn/ikepolicy.html +++ b/netbox/templates/vpn/ikepolicy.html @@ -48,6 +48,7 @@
{% trans "IKE Policy" %}
{% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/comments.html' %} {% include 'inc/panels/tags.html' %} {% plugin_right_page object %}
diff --git a/netbox/templates/vpn/ikeproposal.html b/netbox/templates/vpn/ikeproposal.html index 33cf60c812d..c8b25f623f4 100644 --- a/netbox/templates/vpn/ikeproposal.html +++ b/netbox/templates/vpn/ikeproposal.html @@ -51,6 +51,7 @@
{% trans "IKE Proposal" %}
{% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/comments.html' %} {% include 'inc/panels/tags.html' %} {% plugin_right_page object %}
diff --git a/netbox/templates/vpn/ipsecpolicy.html b/netbox/templates/vpn/ipsecpolicy.html index 4960d9dd33b..3e75a7db793 100644 --- a/netbox/templates/vpn/ipsecpolicy.html +++ b/netbox/templates/vpn/ipsecpolicy.html @@ -35,6 +35,7 @@
{% trans "IPSec Policy" %}
{% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/comments.html' %} {% include 'inc/panels/tags.html' %} {% plugin_right_page object %}
diff --git a/netbox/templates/vpn/ipsecproposal.html b/netbox/templates/vpn/ipsecproposal.html index 7425eef4345..d97775bf81a 100644 --- a/netbox/templates/vpn/ipsecproposal.html +++ b/netbox/templates/vpn/ipsecproposal.html @@ -47,6 +47,7 @@
{% trans "IPSec Proposal" %}
{% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/comments.html' %} {% include 'inc/panels/tags.html' %} {% plugin_right_page object %}
diff --git a/netbox/vpn/api/serializers.py b/netbox/vpn/api/serializers.py index cd464cf2284..176deba04c2 100644 --- a/netbox/vpn/api/serializers.py +++ b/netbox/vpn/api/serializers.py @@ -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', ) @@ -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', ) @@ -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', ) @@ -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', ) diff --git a/netbox/vpn/filtersets.py b/netbox/vpn/filtersets.py index 249de9ca2d0..2efd0189c84 100644 --- a/netbox/vpn/filtersets.py +++ b/netbox/vpn/filtersets.py @@ -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) ) @@ -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) ) @@ -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) ) @@ -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) ) diff --git a/netbox/vpn/forms/bulk_import.py b/netbox/vpn/forms/bulk_import.py index 33e93d28fb3..37da63da3a1 100644 --- a/netbox/vpn/forms/bulk_import.py +++ b/netbox/vpn/forms/bulk_import.py @@ -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', ) @@ -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', ) @@ -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', ) @@ -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', ) diff --git a/netbox/vpn/forms/model_forms.py b/netbox/vpn/forms/model_forms.py index 4c59fcadf44..5c3db1c997d 100644 --- a/netbox/vpn/forms/model_forms.py +++ b/netbox/vpn/forms/model_forms.py @@ -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', ] @@ -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', ] @@ -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', ] @@ -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', ] diff --git a/netbox/vpn/migrations/0001_initial.py b/netbox/vpn/migrations/0001_initial.py index f5d9ae0c18c..17e000e53e8 100644 --- a/netbox/vpn/migrations/0001_initial.py +++ b/netbox/vpn/migrations/0001_initial.py @@ -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)), @@ -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={ @@ -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)), @@ -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()), diff --git a/netbox/vpn/models/crypto.py b/netbox/vpn/models/crypto.py index 1954dc6a01d..260f779409f 100644 --- a/netbox/vpn/models/crypto.py +++ b/netbox/vpn/models/crypto.py @@ -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__ = ( @@ -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 @@ -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, @@ -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 @@ -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', diff --git a/netbox/vpn/search.py b/netbox/vpn/search.py index d0b2ad0c6c4..3036535115a 100644 --- a/netbox/vpn/search.py +++ b/netbox/vpn/search.py @@ -20,6 +20,7 @@ class IKEProposalIndex(SearchIndex): fields = ( ('name', 100), ('description', 500), + ('comments', 5000), ) display_attrs = ('description',) @@ -30,6 +31,7 @@ class IKEPolicyIndex(SearchIndex): fields = ( ('name', 100), ('description', 500), + ('comments', 5000), ) display_attrs = ('description',) @@ -40,6 +42,7 @@ class IPSecProposalIndex(SearchIndex): fields = ( ('name', 100), ('description', 500), + ('comments', 5000), ) display_attrs = ('description',) @@ -50,6 +53,7 @@ class IPSecPolicyIndex(SearchIndex): fields = ( ('name', 100), ('description', 500), + ('comments', 5000), ) display_attrs = ('description',) diff --git a/netbox/vpn/tables/crypto.py b/netbox/vpn/tables/crypto.py index cd6d3c24df6..5e102db24c6 100644 --- a/netbox/vpn/tables/crypto.py +++ b/netbox/vpn/tables/crypto.py @@ -33,6 +33,9 @@ class IKEProposalTable(NetBoxTable): sa_lifetime = tables.Column( verbose_name=_('SA Lifetime') ) + comments = columns.MarkdownColumn( + verbose_name=_('Comments'), + ) tags = columns.TagColumn( url_name='vpn:ikeproposal_list' ) @@ -41,7 +44,7 @@ class Meta(NetBoxTable.Meta): model = IKEProposal fields = ( 'pk', 'id', 'name', 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', - 'group', 'sa_lifetime', 'description', 'tags', 'created', 'last_updated', + 'group', 'sa_lifetime', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', @@ -67,6 +70,9 @@ class IKEPolicyTable(NetBoxTable): preshared_key = tables.Column( verbose_name=_('Pre-shared Key') ) + comments = columns.MarkdownColumn( + verbose_name=_('Comments'), + ) tags = columns.TagColumn( url_name='vpn:ikepolicy_list' ) @@ -74,8 +80,8 @@ class IKEPolicyTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = IKEPolicy fields = ( - 'pk', 'id', 'name', 'version', 'mode', 'proposals', 'preshared_key', 'description', 'tags', 'created', - 'last_updated', + 'pk', 'id', 'name', 'version', 'mode', 'proposals', 'preshared_key', 'description', 'comments', 'tags', + 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'version', 'mode', 'proposals', 'description', @@ -99,6 +105,9 @@ class IPSecProposalTable(NetBoxTable): sa_lifetime_data = tables.Column( verbose_name=_('SA Lifetime (KB)') ) + comments = columns.MarkdownColumn( + verbose_name=_('Comments'), + ) tags = columns.TagColumn( url_name='vpn:ipsecproposal_list' ) @@ -107,7 +116,7 @@ class Meta(NetBoxTable.Meta): model = IPSecProposal fields = ( 'pk', 'id', 'name', 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', - 'sa_lifetime_data', 'description', 'tags', 'created', 'last_updated', + 'sa_lifetime_data', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', @@ -127,6 +136,9 @@ class IPSecPolicyTable(NetBoxTable): pfs_group = tables.Column( verbose_name=_('PFS Group') ) + comments = columns.MarkdownColumn( + verbose_name=_('Comments'), + ) tags = columns.TagColumn( url_name='vpn:ipsecpolicy_list' ) @@ -134,7 +146,7 @@ class IPSecPolicyTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = IPSecPolicy fields = ( - 'pk', 'id', 'name', 'proposals', 'pfs_group', 'description', 'tags', 'created', 'last_updated', + 'pk', 'id', 'name', 'proposals', 'pfs_group', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'proposals', 'pfs_group', 'description',