1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Commit fixes Jeremy suggested

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>
This commit is contained in:
Daniel Sheppard
2022-07-06 08:17:50 -05:00
committed by GitHub
parent dbb1773e15
commit 0004b834fb
5 changed files with 14 additions and 8 deletions

View File

@@ -34,7 +34,7 @@ class L2VPN(NetBoxModel):
description = models.TextField(null=True, blank=True)
tenant = models.ForeignKey(
to='tenancy.Tenant',
on_delete=models.SET_NULL,
on_delete=models.PROTECT,
related_name='l2vpns',
blank=True,
null=True
@@ -85,7 +85,6 @@ class L2VPNTermination(NetBoxModel):
class Meta:
ordering = ('l2vpn',)
verbose_name = 'L2VPN Termination'
constraints = (
models.UniqueConstraint(
fields=('assigned_object_type', 'assigned_object_id'),
@@ -112,5 +111,10 @@ class L2VPNTermination(NetBoxModel):
# Only check if L2VPN is set and is of type P2P
if self.l2vpn and self.l2vpn.type in L2VPNTypeChoices.P2P:
if L2VPNTermination.objects.filter(l2vpn=self.l2vpn).exclude(pk=self.pk).count() >= 2:
raise ValidationError(f'P2P Type L2VPNs can only have 2 terminations; first delete a termination')
terminations_count = L2VPNTermination.objects.filter(l2vpn=self.l2vpn).exclude(pk=self.pk).count()
if terminations_count >= 2:
l2vpn_type = self.l2vpn.get_type_display()
raise ValidationError(
f'{l2vpn_type} L2VPNs cannot have more than two terminations; found {terminations_count} already '
f'defined.'
)