Просмотр исходного кода

Closes #7681: Add service_id field for provider networks

jeremystretch 4 лет назад
Родитель
Сommit
bffd22038b

+ 1 - 1
docs/models/circuits/providernetwork.md

@@ -2,4 +2,4 @@
 
 This model can be used to represent the boundary of a provider network, the details of which are unknown or unimportant to the NetBox user. For example, it might represent a provider's regional MPLS network to which multiple circuits provide connectivity.
 
-Each provider network must be assigned to a provider. A circuit may terminate to either a provider network or to a site.
+Each provider network must be assigned to a provider, and may optionally be assigned an arbitrary service ID. A circuit may terminate to either a provider network or to a site.

+ 3 - 0
docs/release-notes/version-3.2.md

@@ -41,6 +41,7 @@ FIELD_CHOICES = {
 ### Enhancements
 
 * [#7650](https://github.com/netbox-community/netbox/issues/7650) - Add support for local account password validation
+* [#7681](https://github.com/netbox-community/netbox/issues/7681) - Add `service_id` field for provider networks
 * [#7759](https://github.com/netbox-community/netbox/issues/7759) - Improved the user preferences form
 * [#8168](https://github.com/netbox-community/netbox/issues/8168) - Add `min_vid` and `max_vid` fields to VLAN group
 
@@ -58,6 +59,8 @@ FIELD_CHOICES = {
     * `/api/dcim/module-bays/`
     * `/api/dcim/module-bay-templates/`
     * `/api/dcim/module-types/`
+* circuits.ProviderNetwork
+    * Added `service_id` field
 * dcim.ConsolePort
     * Added `module` field
 * dcim.ConsoleServerPort

+ 2 - 2
netbox/circuits/api/serializers.py

@@ -37,8 +37,8 @@ class ProviderNetworkSerializer(PrimaryModelSerializer):
     class Meta:
         model = ProviderNetwork
         fields = [
-            'id', 'url', 'display', 'provider', 'name', 'description', 'comments', 'tags', 'custom_fields', 'created',
-            'last_updated',
+            'id', 'url', 'display', 'provider', 'name', 'service_id', 'description', 'comments', 'tags',
+            'custom_fields', 'created', 'last_updated',
         ]
 
 

+ 2 - 1
netbox/circuits/filtersets.py

@@ -98,13 +98,14 @@ class ProviderNetworkFilterSet(PrimaryModelFilterSet):
 
     class Meta:
         model = ProviderNetwork
-        fields = ['id', 'name']
+        fields = ['id', 'name', 'service_id']
 
     def search(self, queryset, name, value):
         if not value.strip():
             return queryset
         return queryset.filter(
             Q(name__icontains=value) |
+            Q(service_id__icontains=value) |
             Q(description__icontains=value) |
             Q(comments__icontains=value)
         ).distinct()

+ 6 - 2
netbox/circuits/forms/bulk_edit.py

@@ -62,10 +62,14 @@ class ProviderNetworkBulkEditForm(AddRemoveTagsForm, CustomFieldModelBulkEditFor
         queryset=Provider.objects.all(),
         required=False
     )
-    description = forms.CharField(
+    service_id = forms.CharField(
         max_length=100,
         required=False
     )
+    description = forms.CharField(
+        max_length=200,
+        required=False
+    )
     comments = CommentField(
         widget=SmallTextarea,
         label='Comments'
@@ -73,7 +77,7 @@ class ProviderNetworkBulkEditForm(AddRemoveTagsForm, CustomFieldModelBulkEditFor
 
     class Meta:
         nullable_fields = [
-            'description', 'comments',
+            'service_id', 'description', 'comments',
         ]
 
 

+ 1 - 1
netbox/circuits/forms/bulk_import.py

@@ -32,7 +32,7 @@ class ProviderNetworkCSVForm(CustomFieldModelCSVForm):
     class Meta:
         model = ProviderNetwork
         fields = [
-            'provider', 'name', 'description', 'comments',
+            'provider', 'name', 'service_id', 'description', 'comments',
         ]
 
 

+ 4 - 0
netbox/circuits/forms/filtersets.py

@@ -64,6 +64,10 @@ class ProviderNetworkFilterForm(CustomFieldModelFilterForm):
         label=_('Provider'),
         fetch_trigger='open'
     )
+    service_id = forms.CharField(
+        max_length=100,
+        required=False
+    )
     tag = TagFilterField(model)
 
 

+ 2 - 2
netbox/circuits/forms/models.py

@@ -66,10 +66,10 @@ class ProviderNetworkForm(CustomFieldModelForm):
     class Meta:
         model = ProviderNetwork
         fields = [
-            'provider', 'name', 'description', 'comments', 'tags',
+            'provider', 'name', 'service_id', 'description', 'comments', 'tags',
         ]
         fieldsets = (
-            ('Provider Network', ('provider', 'name', 'description', 'tags')),
+            ('Provider Network', ('provider', 'name', 'service_id', 'description', 'tags')),
         )
 
 

+ 16 - 0
netbox/circuits/migrations/0032_provider_service_id.py

@@ -0,0 +1,16 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('circuits', '0004_rename_cable_peer'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='providernetwork',
+            name='service_id',
+            field=models.CharField(blank=True, max_length=100),
+        ),
+    ]

+ 5 - 1
netbox/circuits/models/providers.py

@@ -5,7 +5,6 @@ from django.urls import reverse
 from dcim.fields import ASNField
 from extras.utils import extras_features
 from netbox.models import PrimaryModel
-from utilities.querysets import RestrictedQuerySet
 
 __all__ = (
     'ProviderNetwork',
@@ -87,6 +86,11 @@ class ProviderNetwork(PrimaryModel):
         on_delete=models.PROTECT,
         related_name='networks'
     )
+    service_id = models.CharField(
+        max_length=100,
+        blank=True,
+        verbose_name='Service ID'
+    )
     description = models.CharField(
         max_length=200,
         blank=True

+ 2 - 2
netbox/circuits/tables.py

@@ -69,8 +69,8 @@ class ProviderNetworkTable(BaseTable):
 
     class Meta(BaseTable.Meta):
         model = ProviderNetwork
-        fields = ('pk', 'id', 'name', 'provider', 'description', 'comments', 'tags')
-        default_columns = ('pk', 'name', 'provider', 'description')
+        fields = ('pk', 'id', 'name', 'provider', 'service_id', 'description', 'comments', 'tags')
+        default_columns = ('pk', 'name', 'provider', 'service_id', 'description')
 
 
 #

+ 4 - 0
netbox/templates/circuits/providernetwork.html

@@ -28,6 +28,10 @@
                         <th scope="row">Name</th>
                         <td>{{ object.name }}</td>
                     </tr>
+                    <tr>
+                        <th scope="row">Service ID</th>
+                        <td>{{ object.service_id|placeholder }}</td>
+                    </tr>
                     <tr>
                         <th scope="row">Description</th>
                         <td>{{ object.description|placeholder }}</td>