Coverage for vpn/forms/bulk_edit.py: 100%
71 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from django import forms
2from django.utils.translation import gettext_lazy as _
4from netbox.forms import NetBoxModelBulkEditForm, OrganizationalModelBulkEditForm, PrimaryModelBulkEditForm
5from tenancy.models import Tenant
6from utilities.forms import add_blank_choice
7from utilities.forms.fields import ChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
8from utilities.forms.rendering import FieldSet
9from vpn.choices import *
10from vpn.models import *
12__all__ = (
13 'IKEPolicyBulkEditForm',
14 'IKEProposalBulkEditForm',
15 'IPSecPolicyBulkEditForm',
16 'IPSecProfileBulkEditForm',
17 'IPSecProposalBulkEditForm',
18 'L2VPNBulkEditForm',
19 'L2VPNTerminationBulkEditForm',
20 'TunnelBulkEditForm',
21 'TunnelGroupBulkEditForm',
22 'TunnelTerminationBulkEditForm',
23)
26class TunnelGroupBulkEditForm(OrganizationalModelBulkEditForm):
27 model = TunnelGroup
28 nullable_fields = ('description', 'comments')
31class TunnelBulkEditForm(PrimaryModelBulkEditForm):
32 status = ChoiceField(
33 label=_('Status'),
34 choices=add_blank_choice(TunnelStatusChoices),
35 required=False
36 )
37 group = DynamicModelChoiceField(
38 queryset=TunnelGroup.objects.all(),
39 label=_('Tunnel group'),
40 required=False
41 )
42 encapsulation = ChoiceField(
43 label=_('Encapsulation'),
44 choices=add_blank_choice(TunnelEncapsulationChoices),
45 required=False
46 )
47 ipsec_profile = DynamicModelMultipleChoiceField(
48 queryset=IPSecProfile.objects.all(),
49 label=_('IPSec profile'),
50 required=False
51 )
52 tenant = DynamicModelChoiceField(
53 label=_('Tenant'),
54 queryset=Tenant.objects.all(),
55 required=False
56 )
57 tunnel_id = forms.IntegerField(
58 label=_('Tunnel ID'),
59 required=False
60 )
62 model = Tunnel
63 fieldsets = (
64 FieldSet('status', 'group', 'encapsulation', 'tunnel_id', 'description', name=_('Tunnel')),
65 FieldSet('ipsec_profile', name=_('Security')),
66 FieldSet('tenant', name=_('Tenancy')),
67 )
68 nullable_fields = (
69 'group', 'ipsec_profile', 'tunnel_id', 'tenant', 'description', 'comments',
70 )
73class TunnelTerminationBulkEditForm(NetBoxModelBulkEditForm):
74 role = ChoiceField(
75 label=_('Role'),
76 choices=add_blank_choice(TunnelTerminationRoleChoices),
77 required=False
78 )
80 model = TunnelTermination
83class IKEProposalBulkEditForm(PrimaryModelBulkEditForm):
84 authentication_method = ChoiceField(
85 label=_('Authentication method'),
86 choices=add_blank_choice(AuthenticationMethodChoices),
87 required=False
88 )
89 encryption_algorithm = ChoiceField(
90 label=_('Encryption algorithm'),
91 choices=add_blank_choice(EncryptionAlgorithmChoices),
92 required=False
93 )
94 authentication_algorithm = ChoiceField(
95 label=_('Authentication algorithm'),
96 choices=add_blank_choice(AuthenticationAlgorithmChoices),
97 required=False
98 )
99 group = ChoiceField(
100 label=_('Group'),
101 choices=add_blank_choice(DHGroupChoices),
102 required=False
103 )
104 sa_lifetime = forms.IntegerField(
105 label=_('SA lifetime'),
106 required=False
107 )
109 model = IKEProposal
110 fieldsets = (
111 FieldSet(
112 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime',
113 'description',
114 ),
115 )
116 nullable_fields = (
117 'sa_lifetime', 'description', 'comments',
118 )
121class IKEPolicyBulkEditForm(PrimaryModelBulkEditForm):
122 version = ChoiceField(
123 label=_('Version'),
124 choices=add_blank_choice(IKEVersionChoices),
125 required=False
126 )
127 mode = ChoiceField(
128 label=_('Mode'),
129 choices=add_blank_choice(IKEModeChoices),
130 required=False
131 )
132 preshared_key = forms.CharField(
133 label=_('Pre-shared key'),
134 required=False
135 )
137 model = IKEPolicy
138 fieldsets = (
139 FieldSet('version', 'mode', 'preshared_key', 'description'),
140 )
141 nullable_fields = (
142 'mode', 'preshared_key', 'description', 'comments',
143 )
146class IPSecProposalBulkEditForm(PrimaryModelBulkEditForm):
147 encryption_algorithm = ChoiceField(
148 label=_('Encryption algorithm'),
149 choices=add_blank_choice(EncryptionAlgorithmChoices),
150 required=False
151 )
152 authentication_algorithm = ChoiceField(
153 label=_('Authentication algorithm'),
154 choices=add_blank_choice(AuthenticationAlgorithmChoices),
155 required=False
156 )
157 sa_lifetime_seconds = forms.IntegerField(
158 label=_('SA lifetime (seconds)'),
159 required=False
160 )
161 sa_lifetime_data = forms.IntegerField(
162 label=_('SA lifetime (KB)'),
163 required=False
164 )
166 model = IPSecProposal
167 fieldsets = (
168 FieldSet(
169 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data',
170 'description',
171 ),
172 )
173 nullable_fields = (
174 'sa_lifetime_seconds', 'sa_lifetime_data', 'description', 'comments',
175 )
178class IPSecPolicyBulkEditForm(PrimaryModelBulkEditForm):
179 pfs_group = ChoiceField(
180 label=_('PFS group'),
181 choices=add_blank_choice(DHGroupChoices),
182 required=False
183 )
185 model = IPSecPolicy
186 fieldsets = (
187 FieldSet('pfs_group', 'description'),
188 )
189 nullable_fields = (
190 'pfs_group', 'description', 'comments',
191 )
194class IPSecProfileBulkEditForm(PrimaryModelBulkEditForm):
195 mode = ChoiceField(
196 label=_('Mode'),
197 choices=add_blank_choice(IPSecModeChoices),
198 required=False
199 )
200 ike_policy = DynamicModelChoiceField(
201 label=_('IKE policy'),
202 queryset=IKEPolicy.objects.all(),
203 required=False
204 )
205 ipsec_policy = DynamicModelChoiceField(
206 label=_('IPSec policy'),
207 queryset=IPSecPolicy.objects.all(),
208 required=False
209 )
211 model = IPSecProfile
212 fieldsets = (
213 FieldSet('mode', 'ike_policy', 'ipsec_policy', 'description', name=_('Profile')),
214 )
215 nullable_fields = (
216 'description', 'comments',
217 )
220class L2VPNBulkEditForm(PrimaryModelBulkEditForm):
221 status = ChoiceField(
222 label=_('Status'),
223 choices=L2VPNStatusChoices,
224 )
225 type = ChoiceField(
226 label=_('Type'),
227 choices=add_blank_choice(L2VPNTypeChoices),
228 required=False
229 )
230 tenant = DynamicModelChoiceField(
231 label=_('Tenant'),
232 queryset=Tenant.objects.all(),
233 required=False
234 )
236 model = L2VPN
237 fieldsets = (
238 FieldSet('status', 'type', 'tenant', 'description'),
239 )
240 nullable_fields = ('tenant', 'description', 'comments')
243class L2VPNTerminationBulkEditForm(NetBoxModelBulkEditForm):
244 model = L2VPN