Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #17608: Adds L2VPN.status field #18791

Open
wants to merge 8 commits into
base: feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/models/vpn/l2vpn.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ The technology employed in forming and operating the L2VPN. Choices include:
!!! note
Designating the type as VPWS, EPL, EP-LAN, EP-TREE will limit the L2VPN instance to two terminations.

### Status

The operational status of the L2VPN. By default, the following statuses are available:

* Active (default)
* Planned
* Faulty

!!! tip "Custom L2VPN statuses"
Additional L2VPN statuses may be defined by setting `L2VPN.status` under the [`FIELD_CHOICES`](../../configuration/data-validation.md#field_choices) configuration parameter.

!!! info "This field was introduced in NetBox v4.3."

### Identifier

An optional numeric identifier. This can be used to track a pseudowire ID, for example.
Expand Down
4 changes: 4 additions & 0 deletions netbox/templates/vpn/l2vpn.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ <h2 class="card-header">{% trans "L2VPN Attributes" %}</h2>
<th scope="row">{% trans "Type" %}</th>
<td>{{ object.get_type_display }}</td>
</tr>
<tr>
<th scope="row">{% trans "Status" %}</th>
<td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
</tr>
<tr>
<th scope="row">{% trans "Description" %}</th>
<td>{{ object.description|placeholder }}</td>
Expand Down
2 changes: 1 addition & 1 deletion netbox/vpn/api/serializers_/l2vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class L2VPNSerializer(NetBoxModelSerializer):
class Meta:
model = L2VPN
fields = [
'id', 'url', 'display_url', 'display', 'identifier', 'name', 'slug', 'type', 'import_targets',
'id', 'url', 'display_url', 'display', 'identifier', 'name', 'slug', 'type', 'status', 'import_targets',
'export_targets', 'description', 'comments', 'tenant', 'tags', 'custom_fields', 'created', 'last_updated'
]
brief_fields = ('id', 'url', 'display', 'identifier', 'name', 'slug', 'type', 'description')
Expand Down
14 changes: 14 additions & 0 deletions netbox/vpn/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,17 @@ class L2VPNTypeChoices(ChoiceSet):
TYPE_EPLAN,
TYPE_EPTREE
)


class L2VPNStatusChoices(ChoiceSet):
key = 'L2VPN.status'

STATUS_ACTIVE = 'active'
STATUS_PLANNED = 'planned'
STATUS_DECOMMISSIONED = 'decommissioned'
Copy link
Contributor Author

@jnovinger jnovinger Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be STATUS_DECOMMISSIONING ... like other choice sets for the sake of consistency?


CHOICES = [
(STATUS_ACTIVE, _('Active'), 'green'),
(STATUS_PLANNED, _('Planned'), 'cyan'),
(STATUS_DECOMMISSIONED, _('Decommissioned'), 'red'),
]
3 changes: 3 additions & 0 deletions netbox/vpn/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ class L2VPNFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
choices=L2VPNTypeChoices,
null_value=None
)
status = django_filters.MultipleChoiceFilter(
choices=L2VPNStatusChoices,
)
import_target_id = django_filters.ModelMultipleChoiceFilter(
field_name='import_targets',
queryset=RouteTarget.objects.all(),
Expand Down
6 changes: 5 additions & 1 deletion netbox/vpn/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ class IPSecProfileBulkEditForm(NetBoxModelBulkEditForm):


class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
status = forms.ChoiceField(
label=_('Status'),
choices=L2VPNStatusChoices,
)
type = forms.ChoiceField(
label=_('Type'),
choices=add_blank_choice(L2VPNTypeChoices),
Expand All @@ -279,7 +283,7 @@ class L2VPNBulkEditForm(NetBoxModelBulkEditForm):

model = L2VPN
fieldsets = (
FieldSet('type', 'tenant', 'description'),
FieldSet('status', 'type', 'tenant', 'description'),
)
nullable_fields = ('tenant', 'description', 'comments')

Expand Down
5 changes: 5 additions & 0 deletions netbox/vpn/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ class L2VPNImportForm(NetBoxModelImportForm):
required=False,
to_field_name='name',
)
status = CSVChoiceField(
label=_('Status'),
choices=L2VPNStatusChoices,
help_text=_('Operational status')
)
type = CSVChoiceField(
label=_('Type'),
choices=L2VPNTypeChoices,
Expand Down
7 changes: 6 additions & 1 deletion netbox/vpn/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ class L2VPNFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
model = L2VPN
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('type', 'import_target_id', 'export_target_id', name=_('Attributes')),
FieldSet('type', 'status', 'import_target_id', 'export_target_id', name=_('Attributes')),
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
)
status = forms.MultipleChoiceField(
label=_('Status'),
choices=L2VPNStatusChoices,
required=False
)
type = forms.ChoiceField(
label=_('Type'),
choices=add_blank_choice(L2VPNTypeChoices),
Expand Down
6 changes: 3 additions & 3 deletions netbox/vpn/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,16 @@ class L2VPNForm(TenancyForm, NetBoxModelForm):
comments = CommentField()

fieldsets = (
FieldSet('name', 'slug', 'type', 'identifier', 'description', 'tags', name=_('L2VPN')),
FieldSet('name', 'slug', 'type', 'status', 'identifier', 'description', 'tags', name=_('L2VPN')),
FieldSet('import_targets', 'export_targets', name=_('Route Targets')),
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
)

class Meta:
model = L2VPN
fields = (
'name', 'slug', 'type', 'identifier', 'import_targets', 'export_targets', 'tenant', 'description',
'comments', 'tags'
'name', 'slug', 'type', 'status', 'identifier', 'import_targets', 'export_targets', 'tenant',
'description', 'comments', 'tags'
)


Expand Down
16 changes: 16 additions & 0 deletions netbox/vpn/migrations/0008_add_l2vpn_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vpn', '0007_natural_ordering'),
]

operations = [
migrations.AddField(
model_name='l2vpn',
name='status',
field=models.CharField(default='active', max_length=50),
),
]
11 changes: 10 additions & 1 deletion netbox/vpn/models/l2vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from core.models import ObjectType
from netbox.models import NetBoxModel, PrimaryModel
from netbox.models.features import ContactsMixin
from vpn.choices import L2VPNTypeChoices
from vpn.choices import L2VPNStatusChoices, L2VPNTypeChoices
from vpn.constants import L2VPN_ASSIGNMENT_MODELS

__all__ = (
Expand All @@ -33,6 +33,12 @@ class L2VPN(ContactsMixin, PrimaryModel):
max_length=50,
choices=L2VPNTypeChoices
)
status = models.CharField(
verbose_name=_('status'),
max_length=50,
choices=L2VPNStatusChoices,
default=L2VPNStatusChoices.STATUS_ACTIVE,
)
identifier = models.BigIntegerField(
verbose_name=_('identifier'),
null=True,
Expand Down Expand Up @@ -68,6 +74,9 @@ def __str__(self):
return f'{self.name} ({self.identifier})'
return f'{self.name}'

def get_status_color(self):
return L2VPNStatusChoices.colors.get(self.status)

@cached_property
def can_add_termination(self):
if self.type in L2VPNTypeChoices.P2P and self.terminations.count() >= 2:
Expand Down
2 changes: 1 addition & 1 deletion netbox/vpn/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ class L2VPNIndex(SearchIndex):
('description', 500),
('comments', 5000),
)
display_attrs = ('type', 'identifier', 'tenant', 'description')
display_attrs = ('type', 'status', 'identifier', 'tenant', 'description')
9 changes: 6 additions & 3 deletions netbox/vpn/tables/l2vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class L2VPNTable(TenancyColumnsMixin, NetBoxTable):
verbose_name=_('Name'),
linkify=True
)
status = columns.ChoiceFieldColumn(
verbose_name=_('Status')
)
import_targets = columns.TemplateColumn(
verbose_name=_('Import Targets'),
template_code=L2VPN_TARGETS,
Expand All @@ -43,10 +46,10 @@ class L2VPNTable(TenancyColumnsMixin, NetBoxTable):
class Meta(NetBoxTable.Meta):
model = L2VPN
fields = (
'pk', 'name', 'slug', 'identifier', 'type', 'import_targets', 'export_targets', 'tenant', 'tenant_group',
'description', 'comments', 'tags', 'created', 'last_updated',
'pk', 'name', 'slug', 'status', 'identifier', 'type', 'import_targets', 'export_targets', 'tenant',
'tenant_group', 'description', 'comments', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'identifier', 'type', 'description')
default_columns = ('pk', 'name', 'status', 'identifier', 'type', 'description')


class L2VPNTerminationTable(NetBoxTable):
Expand Down
23 changes: 17 additions & 6 deletions netbox/vpn/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,25 @@ def setUpTestData(cls):
RouteTarget.objects.bulk_create(rts)

l2vpns = (
L2VPN(name='L2VPN 1', slug='l2vpn-1', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650001'),
L2VPN(name='L2VPN 2', slug='l2vpn-2', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650002'),
L2VPN(name='L2VPN 3', slug='l2vpn-3', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650003')
L2VPN(
name='L2VPN 1', slug='l2vpn-1', status=L2VPNStatusChoices.STATUS_ACTIVE,
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650001'
),
L2VPN(
name='L2VPN 2', slug='l2vpn-2', status=L2VPNStatusChoices.STATUS_DECOMMISSIONED,
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650002'
),
L2VPN(
name='L2VPN 3', slug='l2vpn-3', status=L2VPNStatusChoices.STATUS_PLANNED,
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650003'
)
)
L2VPN.objects.bulk_create(l2vpns)

cls.csv_data = (
'name,slug,type,identifier',
'L2VPN 5,l2vpn-5,vxlan,456',
'L2VPN 6,l2vpn-6,vxlan,444',
'name,status,slug,type,identifier',
'L2VPN 5,active,l2vpn-5,vxlan,456',
'L2VPN 6,planned,l2vpn-6,vxlan,444',
)

cls.csv_update_data = (
Expand All @@ -594,12 +603,14 @@ def setUpTestData(cls):

cls.bulk_edit_data = {
'description': 'New Description',
'status': L2VPNStatusChoices.STATUS_DECOMMISSIONED,
}

cls.form_data = {
'name': 'L2VPN 8',
'slug': 'l2vpn-8',
'type': L2VPNTypeChoices.TYPE_VXLAN,
'status': L2VPNStatusChoices.STATUS_PLANNED,
'identifier': 123,
'description': 'Description',
'import_targets': [rts[0].pk],
Expand Down