Skip to content

Commit

Permalink
fix for #61;
Browse files Browse the repository at this point in the history
  • Loading branch information
k01ek committed Nov 4, 2021
1 parent 9ab3c0e commit e391240
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
15 changes: 15 additions & 0 deletions netbox_bgp/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e391240

Please sign in to comment.