From e391240c54f64ed6528b4e838efd775637e0b149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AE=D0=B7=D0=B5=D1=84=D0=BE=D0=B2=D0=B8=D1=87=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=98=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 4 Nov 2021 11:00:39 +0500 Subject: [PATCH] fix for #61; --- README.md | 2 +- netbox_bgp/api/serializers.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bcf9448..62b0485 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You can use older Netbox version with 0.3.9 version of this plugin. The plugin is available as a Python package in pypi and can be installed with pip For NetBox 2.10 or 2.11: ``` -pip install netbox-bgp=0.3.9 +pip install netbox-bgp==0.3.9 ``` For NetBox 3.0: ``` diff --git a/netbox_bgp/api/serializers.py b/netbox_bgp/api/serializers.py index 80e133b..bf73616 100644 --- a/netbox_bgp/api/serializers.py +++ b/netbox_bgp/api/serializers.py @@ -161,6 +161,21 @@ class BGPSessionSerializer(TaggedObjectSerializer, CustomFieldModelSerializer): class Meta: model = BGPSession fields = '__all__' + validators = [] + + def validate(self, attrs): + qs = BGPSession.objects.filter( + device=attrs.get('device'), + local_as=attrs.get('local_as'), + local_address=attrs.get('local_address'), + remote_as=attrs.get('remote_as'), + remote_address=attrs.get('remote_address'), + ) + if qs.exists(): + raise ValidationError( + {'error': 'BGP Session with this Device, Local address, Local AS, Remote address and Remote AS already exists.'} + ) + return attrs def to_representation(self, instance): ret = super().to_representation(instance)