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 = [
|
fields = [
|
||||||
'id', 'url', 'display', 'l2vpn', 'assigned_object_type', 'assigned_object_id',
|
'id', 'url', 'display', 'l2vpn', 'assigned_object_type', 'assigned_object_id',
|
||||||
'assigned_object',
|
'assigned_object',
|
||||||
# Extra Fields
|
|
||||||
'tags', 'custom_fields', 'created', 'last_updated'
|
'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.constants import ADVISORY_LOCK_KEYS
|
||||||
from utilities.utils import count_related
|
from utilities.utils import count_related
|
||||||
from . import serializers
|
from . import serializers
|
||||||
from ..models.l2vpn import L2VPN, L2VPNTermination
|
from ipam.models import L2VPN, L2VPNTermination
|
||||||
|
|
||||||
|
|
||||||
class IPAMRootView(APIRootView):
|
class IPAMRootView(APIRootView):
|
||||||
@ -159,7 +159,7 @@ class ServiceViewSet(NetBoxModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class L2VPNViewSet(NetBoxModelViewSet):
|
class L2VPNViewSet(NetBoxModelViewSet):
|
||||||
queryset = L2VPN.objects
|
queryset = L2VPN.objects.prefetch_related('import_targets', 'export_targets', 'tenant', 'tags')
|
||||||
serializer_class = serializers.L2VPNSerializer
|
serializer_class = serializers.L2VPNSerializer
|
||||||
filterset_class = filtersets.L2VPNFilterSet
|
filterset_class = filtersets.L2VPNFilterSet
|
||||||
|
|
||||||
|
@ -893,6 +893,9 @@ class L2VPNForm(TenancyForm, NetBoxModelForm):
|
|||||||
fields = (
|
fields = (
|
||||||
'name', 'slug', 'type', 'identifier', 'description', 'import_targets', 'export_targets', 'tenant', 'tags'
|
'name', 'slug', 'type', 'identifier', 'description', 'import_targets', 'export_targets', 'tenant', 'tags'
|
||||||
)
|
)
|
||||||
|
widgets = {
|
||||||
|
'type': StaticSelect(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class L2VPNTerminationForm(NetBoxModelForm):
|
class L2VPNTerminationForm(NetBoxModelForm):
|
||||||
|
@ -34,7 +34,7 @@ class L2VPN(NetBoxModel):
|
|||||||
description = models.TextField(null=True, blank=True)
|
description = models.TextField(null=True, blank=True)
|
||||||
tenant = models.ForeignKey(
|
tenant = models.ForeignKey(
|
||||||
to='tenancy.Tenant',
|
to='tenancy.Tenant',
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.PROTECT,
|
||||||
related_name='l2vpns',
|
related_name='l2vpns',
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
@ -85,7 +85,6 @@ class L2VPNTermination(NetBoxModel):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('l2vpn',)
|
ordering = ('l2vpn',)
|
||||||
verbose_name = 'L2VPN Termination'
|
verbose_name = 'L2VPN Termination'
|
||||||
|
|
||||||
constraints = (
|
constraints = (
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(
|
||||||
fields=('assigned_object_type', 'assigned_object_id'),
|
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
|
# Only check if L2VPN is set and is of type P2P
|
||||||
if self.l2vpn and self.l2vpn.type in L2VPNTypeChoices.P2P:
|
if self.l2vpn and self.l2vpn.type in L2VPNTypeChoices.P2P:
|
||||||
if L2VPNTermination.objects.filter(l2vpn=self.l2vpn).exclude(pk=self.pk).count() >= 2:
|
terminations_count = L2VPNTermination.objects.filter(l2vpn=self.l2vpn).exclude(pk=self.pk).count()
|
||||||
raise ValidationError(f'P2P Type L2VPNs can only have 2 terminations; first delete a termination')
|
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(
|
MenuGroup(
|
||||||
label='L2VPNs',
|
label='L2VPNs',
|
||||||
items=(
|
items=(
|
||||||
get_model_item('ipam', 'l2vpn', 'L2VPN'),
|
get_model_item('ipam', 'l2vpn', 'L2VPNs'),
|
||||||
get_model_item('ipam', 'l2vpntermination', 'Terminations'),
|
get_model_item('ipam', 'l2vpntermination', 'Terminations'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user