Skip to content

Commit 6bc9302

Browse files
authored
Closes #17608: Adds L2VPN.status field (#18791)
1 parent 4e65117 commit 6bc9302

File tree

16 files changed

+169
-25
lines changed

16 files changed

+169
-25
lines changed

docs/models/vpn/l2vpn.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ The technology employed in forming and operating the L2VPN. Choices include:
3333
!!! note
3434
Designating the type as VPWS, EPL, EP-LAN, EP-TREE will limit the L2VPN instance to two terminations.
3535

36+
### Status
37+
38+
The operational status of the L2VPN. By default, the following statuses are available:
39+
40+
* Active (default)
41+
* Planned
42+
* Faulty
43+
44+
!!! tip "Custom L2VPN statuses"
45+
Additional L2VPN statuses may be defined by setting `L2VPN.status` under the [`FIELD_CHOICES`](../../configuration/data-validation.md#field_choices) configuration parameter.
46+
47+
!!! info "This field was introduced in NetBox v4.3."
48+
3649
### Identifier
3750

3851
An optional numeric identifier. This can be used to track a pseudowire ID, for example.

netbox/templates/vpn/l2vpn.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ <h2 class="card-header">{% trans "L2VPN Attributes" %}</h2>
2222
<th scope="row">{% trans "Type" %}</th>
2323
<td>{{ object.get_type_display }}</td>
2424
</tr>
25+
<tr>
26+
<th scope="row">{% trans "Status" %}</th>
27+
<td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
28+
</tr>
2529
<tr>
2630
<th scope="row">{% trans "Description" %}</th>
2731
<td>{{ object.description|placeholder }}</td>

netbox/vpn/api/serializers_/l2vpn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class L2VPNSerializer(NetBoxModelSerializer):
3838
class Meta:
3939
model = L2VPN
4040
fields = [
41-
'id', 'url', 'display_url', 'display', 'identifier', 'name', 'slug', 'type', 'import_targets',
41+
'id', 'url', 'display_url', 'display', 'identifier', 'name', 'slug', 'type', 'status', 'import_targets',
4242
'export_targets', 'description', 'comments', 'tenant', 'tags', 'custom_fields', 'created', 'last_updated'
4343
]
4444
brief_fields = ('id', 'url', 'display', 'identifier', 'name', 'slug', 'type', 'description')

netbox/vpn/choices.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,17 @@ class L2VPNTypeChoices(ChoiceSet):
267267
TYPE_EPLAN,
268268
TYPE_EPTREE
269269
)
270+
271+
272+
class L2VPNStatusChoices(ChoiceSet):
273+
key = 'L2VPN.status'
274+
275+
STATUS_ACTIVE = 'active'
276+
STATUS_PLANNED = 'planned'
277+
STATUS_DECOMMISSIONING = 'decommissioning'
278+
279+
CHOICES = [
280+
(STATUS_ACTIVE, _('Active'), 'green'),
281+
(STATUS_PLANNED, _('Planned'), 'cyan'),
282+
(STATUS_DECOMMISSIONING, _('Decommissioning'), 'red'),
283+
]

netbox/vpn/filtersets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ class L2VPNFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
298298
choices=L2VPNTypeChoices,
299299
null_value=None
300300
)
301+
status = django_filters.MultipleChoiceFilter(
302+
choices=L2VPNStatusChoices,
303+
)
301304
import_target_id = django_filters.ModelMultipleChoiceFilter(
302305
field_name='import_targets',
303306
queryset=RouteTarget.objects.all(),
@@ -323,7 +326,7 @@ class L2VPNFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
323326

324327
class Meta:
325328
model = L2VPN
326-
fields = ('id', 'identifier', 'name', 'slug', 'type', 'description')
329+
fields = ('id', 'identifier', 'name', 'slug', 'status', 'type', 'description')
327330

328331
def search(self, queryset, name, value):
329332
if not value.strip():

netbox/vpn/forms/bulk_edit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ class IPSecProfileBulkEditForm(NetBoxModelBulkEditForm):
260260

261261

262262
class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
263+
status = forms.ChoiceField(
264+
label=_('Status'),
265+
choices=L2VPNStatusChoices,
266+
)
263267
type = forms.ChoiceField(
264268
label=_('Type'),
265269
choices=add_blank_choice(L2VPNTypeChoices),
@@ -279,7 +283,7 @@ class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
279283

280284
model = L2VPN
281285
fieldsets = (
282-
FieldSet('type', 'tenant', 'description'),
286+
FieldSet('status', 'type', 'tenant', 'description'),
283287
)
284288
nullable_fields = ('tenant', 'description', 'comments')
285289

netbox/vpn/forms/bulk_import.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ class L2VPNImportForm(NetBoxModelImportForm):
260260
required=False,
261261
to_field_name='name',
262262
)
263+
status = CSVChoiceField(
264+
label=_('Status'),
265+
choices=L2VPNStatusChoices,
266+
help_text=_('Operational status')
267+
)
263268
type = CSVChoiceField(
264269
label=_('Type'),
265270
choices=L2VPNTypeChoices,

netbox/vpn/forms/filtersets.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,14 @@ class L2VPNFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
210210
model = L2VPN
211211
fieldsets = (
212212
FieldSet('q', 'filter_id', 'tag'),
213-
FieldSet('type', 'import_target_id', 'export_target_id', name=_('Attributes')),
213+
FieldSet('type', 'status', 'import_target_id', 'export_target_id', name=_('Attributes')),
214214
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
215215
)
216+
status = forms.MultipleChoiceField(
217+
label=_('Status'),
218+
choices=L2VPNStatusChoices,
219+
required=False
220+
)
216221
type = forms.ChoiceField(
217222
label=_('Type'),
218223
choices=add_blank_choice(L2VPNTypeChoices),

netbox/vpn/forms/model_forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ class L2VPNForm(TenancyForm, NetBoxModelForm):
409409
comments = CommentField()
410410

411411
fieldsets = (
412-
FieldSet('name', 'slug', 'type', 'identifier', 'description', 'tags', name=_('L2VPN')),
412+
FieldSet('name', 'slug', 'type', 'status', 'identifier', 'description', 'tags', name=_('L2VPN')),
413413
FieldSet('import_targets', 'export_targets', name=_('Route Targets')),
414414
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
415415
)
416416

417417
class Meta:
418418
model = L2VPN
419419
fields = (
420-
'name', 'slug', 'type', 'identifier', 'import_targets', 'export_targets', 'tenant', 'description',
421-
'comments', 'tags'
420+
'name', 'slug', 'type', 'status', 'identifier', 'import_targets', 'export_targets', 'tenant',
421+
'description', 'comments', 'tags'
422422
)
423423

424424

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
6+
dependencies = [
7+
('vpn', '0007_natural_ordering'),
8+
]
9+
10+
operations = [
11+
migrations.AddField(
12+
model_name='l2vpn',
13+
name='status',
14+
field=models.CharField(default='active', max_length=50),
15+
),
16+
]

0 commit comments

Comments
 (0)