1
1
from rest_framework .serializers import HyperlinkedIdentityField , ValidationError
2
2
from rest_framework .relations import PrimaryKeyRelatedField
3
3
4
- # for netbox 3.3
5
- try :
6
- from netbox .api import ChoiceField , WritableNestedSerializer
7
- except ImportError :
8
- from netbox .api .fields import ChoiceField
9
- from netbox .api .serializers .nested import WritableNestedSerializer
4
+ from netbox .api .fields import ChoiceField
5
+ from netbox .api .serializers .nested import WritableNestedSerializer
10
6
11
7
from netbox .api .serializers import NetBoxModelSerializer
12
8
from dcim .api .nested_serializers import NestedSiteSerializer , NestedDeviceSerializer
@@ -103,7 +99,6 @@ class BGPSessionSerializer(NetBoxModelSerializer):
103
99
104
100
class Meta :
105
101
model = BGPSession
106
- #fields = '__all__'
107
102
fields = [
108
103
'id' , 'tags' , 'custom_fields' ,
109
104
'display' , 'status' , 'site' , 'tenant' ,
@@ -112,21 +107,7 @@ class Meta:
112
107
'export_policies' , 'created' , 'last_updated' ,
113
108
'name' , 'description'
114
109
]
115
- validators = []
116
110
117
- def validate (self , attrs ):
118
- qs = BGPSession .objects .filter (
119
- device = attrs .get ('device' ),
120
- local_as = attrs .get ('local_as' ),
121
- local_address = attrs .get ('local_address' ),
122
- remote_as = attrs .get ('remote_as' ),
123
- remote_address = attrs .get ('remote_address' ),
124
- )
125
- if qs .exists ():
126
- raise ValidationError (
127
- {'error' : 'BGP Session with this Device, Local address, Local AS, Remote address and Remote AS already exists.' }
128
- )
129
- return attrs
130
111
131
112
def to_representation (self , instance ):
132
113
ret = super ().to_representation (instance )
@@ -159,14 +140,12 @@ class CommunitySerializer(NetBoxModelSerializer):
159
140
160
141
class Meta :
161
142
model = Community
162
- # fields = ['id', 'value', 'status', 'description', 'tenant', 'tags']
163
143
fields = [
164
144
'id' , 'tags' , 'custom_fields' , 'display' ,
165
145
'status' , 'tenant' , 'created' , 'last_updated' ,
166
146
'description' ,
167
147
'value' , 'site' , 'role'
168
148
]
169
- # fields = '__all__'
170
149
171
150
172
151
class RoutingPolicyRuleSerializer (NetBoxModelSerializer ):
@@ -194,7 +173,6 @@ class PrefixListRuleSerializer(NetBoxModelSerializer):
194
173
195
174
class Meta :
196
175
model = PrefixListRule
197
- fields = '__all__'
198
176
fields = [
199
177
'id' , 'tags' , 'custom_fields' , 'display' ,
200
178
'prefix_list' , 'created' , 'last_updated' ,
0 commit comments