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)