|
12 | 12 | APISelect, APISelectMultiple, StaticSelect2Multiple, TagFilterField
|
13 | 13 | )
|
14 | 14 |
|
15 |
| -from .models import ASN, ASNStatusChoices, Community, BGPSession, SessionStatusChoices |
| 15 | +from .models import ( |
| 16 | + ASN, ASNStatusChoices, Community, BGPSession, |
| 17 | + SessionStatusChoices, RoutingPolicy, BGPPeerGroup |
| 18 | +) |
16 | 19 |
|
17 | 20 |
|
18 | 21 | class ASNFilterForm(BootstrapMixin, forms.ModelForm):
|
@@ -208,14 +211,34 @@ class BGPSessionForm(BootstrapMixin, forms.ModelForm):
|
208 | 211 | 'device_id': '$device'
|
209 | 212 | }
|
210 | 213 | )
|
| 214 | + import_policies = DynamicModelMultipleChoiceField( |
| 215 | + queryset=RoutingPolicy.objects.all(), |
| 216 | + required=False, |
| 217 | + widget=APISelectMultiple( |
| 218 | + api_url='/api/plugins/bgp/routing_policy/' |
| 219 | + ) |
| 220 | + ) |
| 221 | + export_policies = DynamicModelMultipleChoiceField( |
| 222 | + queryset=RoutingPolicy.objects.all(), |
| 223 | + required=False, |
| 224 | + widget=APISelectMultiple( |
| 225 | + api_url='/api/plugins/bgp/routing_policy/' |
| 226 | + ) |
| 227 | + ) |
211 | 228 |
|
212 | 229 | class Meta:
|
213 | 230 | model = BGPSession
|
214 | 231 | fields = [
|
215 | 232 | 'name', 'site', 'device',
|
216 | 233 | 'local_as', 'remote_as', 'local_address', 'remote_address',
|
217 |
| - 'description', 'status', 'tenant', 'tags', |
| 234 | + 'description', 'status', 'tenant', 'tags', 'import_policies', 'export_policies' |
218 | 235 | ]
|
| 236 | + fieldsets = ( |
| 237 | + ('Session', ('name', 'site', 'device', 'description', 'status', 'tenant', 'tags')), |
| 238 | + ('Remote', ('remote_as', 'remote_address')), |
| 239 | + ('Local', ('local_as', 'local_address')), |
| 240 | + ('Policies', ('import_policies', 'export_policies')) |
| 241 | + ) |
219 | 242 |
|
220 | 243 |
|
221 | 244 | class BGPSessionAddForm(BGPSessionForm):
|
@@ -268,3 +291,27 @@ class BGPSessionFilterForm(BootstrapMixin, forms.ModelForm):
|
268 | 291 | class Meta:
|
269 | 292 | model = BGPSession
|
270 | 293 | fields = ['q', 'status', 'tenant', 'remote_as', 'local_as']
|
| 294 | + |
| 295 | + |
| 296 | +class RoutingPolicyFilterForm(BootstrapMixin, forms.ModelForm): |
| 297 | + q = forms.CharField( |
| 298 | + required=False, |
| 299 | + label='Search' |
| 300 | + ) |
| 301 | + |
| 302 | + tag = TagFilterField(RoutingPolicy) |
| 303 | + |
| 304 | + class Meta: |
| 305 | + model = RoutingPolicy |
| 306 | + fields = ['q'] |
| 307 | + |
| 308 | + |
| 309 | +class RoutingPolicyForm(BootstrapMixin, forms.ModelForm): |
| 310 | + tags = DynamicModelMultipleChoiceField( |
| 311 | + queryset=Tag.objects.all(), |
| 312 | + required=False |
| 313 | + ) |
| 314 | + |
| 315 | + class Meta: |
| 316 | + model = RoutingPolicy |
| 317 | + fields = ['name', 'description'] |
0 commit comments