Skip to content

Commit 66e1b5c

Browse files
authored
Merge pull request #140 from k01ek/develop
Develop
2 parents d0d24f6 + abe2668 commit 66e1b5c

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

netbox_bgp/api/serializers.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ class BGPSessionSerializer(NetBoxModelSerializer):
103103

104104
class Meta:
105105
model = BGPSession
106-
fields = '__all__'
106+
#fields = '__all__'
107+
fields = [
108+
'id', 'tags', 'custom_fields',
109+
'display', 'status', 'site', 'tenant',
110+
'device', 'local_address', 'remote_address',
111+
'local_as', 'remote_as', 'peer_group', 'import_policies',
112+
'export_policies', 'created', 'last_updated',
113+
'name', 'description'
114+
]
107115
validators = []
108116

109117
def validate(self, attrs):
@@ -152,7 +160,13 @@ class CommunitySerializer(NetBoxModelSerializer):
152160
class Meta:
153161
model = Community
154162
# fields = ['id', 'value', 'status', 'description', 'tenant', 'tags']
155-
fields = '__all__'
163+
fields = [
164+
'id', 'tags', 'custom_fields', 'display',
165+
'status', 'tenant', 'created', 'last_updated',
166+
'description',
167+
'value', 'site', 'role'
168+
]
169+
# fields = '__all__'
156170

157171

158172
class RoutingPolicyRuleSerializer(NetBoxModelSerializer):
@@ -172,7 +186,7 @@ class NestedPrefixListSerializer(WritableNestedSerializer):
172186

173187
class Meta:
174188
model = PrefixList
175-
fields = ("id", "url", "display", "name")
189+
fields = ['id', 'url', 'display', 'name']
176190

177191

178192
class PrefixListRuleSerializer(NetBoxModelSerializer):
@@ -181,3 +195,9 @@ class PrefixListRuleSerializer(NetBoxModelSerializer):
181195
class Meta:
182196
model = PrefixListRule
183197
fields = '__all__'
198+
fields = [
199+
'id', 'tags', 'custom_fields', 'display',
200+
'prefix_list', 'created', 'last_updated',
201+
'index', 'action',
202+
'prefix_custom', 'ge', 'le', 'prefix'
203+
]

netbox_bgp/forms.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import re
2-
31
from django import forms
42
from django.conf import settings
53
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, ValidationError
@@ -11,12 +9,12 @@
119
from ipam.models import IPAddress, Prefix, ASN
1210
from ipam.formfields import IPNetworkFormField
1311
from utilities.forms.fields import (
14-
DynamicModelChoiceField,
12+
DynamicModelChoiceField, CSVModelChoiceField,
1513
DynamicModelMultipleChoiceField,
16-
TagFilterField
14+
TagFilterField, CSVChoiceField,
1715
)
1816
from utilities.forms.widgets import APISelect, APISelectMultiple
19-
from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
17+
from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm, NetBoxModelImportForm
2018

2119
from .models import (
2220
Community, BGPSession, RoutingPolicy, BGPPeerGroup,
@@ -93,6 +91,23 @@ class CommunityBulkEditForm(NetBoxModelBulkEditForm):
9391
'tenant', 'description',
9492
]
9593

94+
class CommunityImportForm(NetBoxModelImportForm):
95+
tenant = CSVModelChoiceField(
96+
queryset=Tenant.objects.all(),
97+
required=False,
98+
to_field_name='name',
99+
help_text=_('Assigned tenant')
100+
)
101+
102+
status = CSVChoiceField(
103+
choices=CommunityStatusChoices,
104+
help_text=_('Operational status')
105+
)
106+
107+
class Meta:
108+
model = Community
109+
fields = ('value', 'description', 'tags')
110+
96111

97112
class BGPSessionForm(NetBoxModelForm):
98113
name = forms.CharField(

netbox_bgp/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Community
99
path('community/', views.CommunityListView.as_view(), name='community_list'),
1010
path('community/add/', views.CommunityEditView.as_view(), name='community_add'),
11+
path('community/import/', views.CommunityBulkImportView.as_view(), name='community_import'),
1112
path('community/edit/', views.CommunityBulkEditView.as_view(), name='community_bulk_edit'),
1213
path('community/delete/', views.CommunityBulkDeleteView.as_view(), name='community_bulk_delete'),
1314
path('community/<int:pk>/', views.CommunityView.as_view(), name='community'),

netbox_bgp/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.10.0"
1+
__version__ = "0.10.1"

netbox_bgp/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class CommunityDeleteView(generic.ObjectDeleteView):
5151
default_return_url = 'plugins:netbox_bgp:community_list'
5252

5353

54+
class CommunityBulkImportView(generic.BulkImportView):
55+
queryset = Community.objects.all()
56+
model_form = forms.CommunityImportForm
57+
58+
5459
# Session
5560

5661

0 commit comments

Comments
 (0)