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:
@ -483,7 +483,6 @@ class L2VPNTerminationSerializer(NetBoxModelSerializer):
|
||||
fields = [
|
||||
'id', 'url', 'display', 'l2vpn', 'assigned_object_type', 'assigned_object_id',
|
||||
'assigned_object',
|
||||
# Extra Fields
|
||||
'tags', 'custom_fields', 'created', 'last_updated'
|
||||
]
|
||||
|
||||
|
@ -18,7 +18,7 @@ from netbox.config import get_config
|
||||
from utilities.constants import ADVISORY_LOCK_KEYS
|
||||
from utilities.utils import count_related
|
||||
from . import serializers
|
||||
from ..models.l2vpn import L2VPN, L2VPNTermination
|
||||
from ipam.models import L2VPN, L2VPNTermination
|
||||
|
||||
|
||||
class IPAMRootView(APIRootView):
|
||||
@ -159,7 +159,7 @@ class ServiceViewSet(NetBoxModelViewSet):
|
||||
|
||||
|
||||
class L2VPNViewSet(NetBoxModelViewSet):
|
||||
queryset = L2VPN.objects
|
||||
queryset = L2VPN.objects.prefetch_related('import_targets', 'export_targets', 'tenant', 'tags')
|
||||
serializer_class = serializers.L2VPNSerializer
|
||||
filterset_class = filtersets.L2VPNFilterSet
|
||||
|
||||
|
@ -893,6 +893,9 @@ class L2VPNForm(TenancyForm, NetBoxModelForm):
|
||||
fields = (
|
||||
'name', 'slug', 'type', 'identifier', 'description', 'import_targets', 'export_targets', 'tenant', 'tags'
|
||||
)
|
||||
widgets = {
|
||||
'type': StaticSelect(),
|
||||
}
|
||||
|
||||
|
||||
class L2VPNTerminationForm(NetBoxModelForm):
|
||||
|
@ -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.'
|
||||
)
|
||||
|
@ -263,7 +263,7 @@ IPAM_MENU = Menu(
|
||||
MenuGroup(
|
||||
label='L2VPNs',
|
||||
items=(
|
||||
get_model_item('ipam', 'l2vpn', 'L2VPN'),
|
||||
get_model_item('ipam', 'l2vpn', 'L2VPNs'),
|
||||
get_model_item('ipam', 'l2vpntermination', 'Terminations'),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user