Skip to content

Commit abe2668

Browse files
committed
add import for communities #21
1 parent 74e4a30 commit abe2668

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

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)