Closes #17608: Adds L2VPN.status field (#18791)

This commit is contained in:
Jason Novinger
2025-03-06 16:06:06 -06:00
committed by GitHub
parent 4e65117e7c
commit 6bc9302ce5
16 changed files with 169 additions and 25 deletions

View File

@@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
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__ = (
@@ -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,
@@ -56,7 +62,7 @@ class L2VPN(ContactsMixin, PrimaryModel):
null=True
)
clone_fields = ('type',)
clone_fields = ('type', 'status')
class Meta:
ordering = ('name', 'identifier')
@@ -68,6 +74,9 @@ class L2VPN(ContactsMixin, PrimaryModel):
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: