Parcourir la source

ipam.VLAN: Added description field, extended name to 64 chars

Jeremy Stretch il y a 8 ans
Parent
commit
d241cce502

+ 1 - 1
netbox/ipam/api/serializers.py

@@ -102,7 +102,7 @@ class VLANSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = VLAN
-        fields = ['id', 'site', 'group', 'vid', 'name', 'status', 'role', 'display_name']
+        fields = ['id', 'site', 'group', 'vid', 'name', 'status', 'role', 'description', 'display_name']
 
 
 class VLANNestedSerializer(VLANSerializer):

+ 3 - 2
netbox/ipam/forms.py

@@ -474,7 +474,7 @@ class VLANForm(forms.ModelForm, BootstrapMixin):
 
     class Meta:
         model = VLAN
-        fields = ['site', 'group', 'vid', 'name', 'status', 'role']
+        fields = ['site', 'group', 'vid', 'name', 'description', 'status', 'role']
         help_texts = {
             'site': "The site at which this VLAN exists",
             'group': "VLAN group (optional)",
@@ -511,7 +511,7 @@ class VLANFromCSVForm(forms.ModelForm):
 
     class Meta:
         model = VLAN
-        fields = ['site', 'group', 'vid', 'name', 'status_name', 'role']
+        fields = ['site', 'group', 'vid', 'name', 'status_name', 'role', 'description']
 
     def save(self, *args, **kwargs):
         m = super(VLANFromCSVForm, self).save(commit=False)
@@ -532,6 +532,7 @@ class VLANBulkEditForm(forms.Form, BootstrapMixin):
     group = forms.ModelChoiceField(queryset=VLANGroup.objects.all(), required=False)
     status = forms.ChoiceField(choices=FORM_VLAN_STATUS_CHOICES, required=False)
     role = forms.ModelChoiceField(queryset=Role.objects.all(), required=False)
+    description = forms.CharField(max_length=100, required=False)
 
 
 class VLANBulkDeleteForm(ConfirmationForm):

+ 25 - 0
netbox/ipam/migrations/0005_auto_20160725_1842.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.8 on 2016-07-25 18:42
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ipam', '0004_ipam_vlangroup_uniqueness'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='vlan',
+            name='description',
+            field=models.CharField(blank=True, max_length=100),
+        ),
+        migrations.AlterField(
+            model_name='vlan',
+            name='name',
+            field=models.CharField(max_length=64),
+        ),
+    ]

+ 4 - 1
netbox/ipam/models.py

@@ -406,7 +406,8 @@ class VLAN(CreatedUpdatedModel):
         MinValueValidator(1),
         MaxValueValidator(4094)
     ])
-    name = models.CharField(max_length=30)
+    name = models.CharField(max_length=64)
+    description = models.CharField(max_length=100, blank=True)
     status = models.PositiveSmallIntegerField('Status', choices=VLAN_STATUS_CHOICES, default=1)
     role = models.ForeignKey('Role', related_name='vlans', on_delete=models.SET_NULL, blank=True, null=True)
 
@@ -434,10 +435,12 @@ class VLAN(CreatedUpdatedModel):
     def to_csv(self):
         return ','.join([
             self.site.name,
+            self.group.name if self.group else '',
             str(self.vid),
             self.name,
             self.get_status_display(),
             self.role.name if self.role else '',
+            self.description,
         ])
 
     @property

+ 1 - 1
netbox/ipam/views.py

@@ -565,7 +565,7 @@ class VLANBulkEditView(PermissionRequiredMixin, BulkEditView):
     def update_objects(self, pk_list, form):
 
         fields_to_update = {}
-        for field in ['site', 'group', 'status', 'role']:
+        for field in ['site', 'group', 'status', 'role', 'description']:
             if form.cleaned_data[field]:
                 fields_to_update[field] = form.cleaned_data[field]
 

+ 10 - 0
netbox/templates/ipam/vlan.html

@@ -70,6 +70,16 @@
                     <td>{{ vlan.name }}</td>
                 </tr>
                 <tr>
+                    <td>Description</td>
+                    <td>
+                        {% if vlan.description %}
+                            {{ vlan.description }}
+                        {% else %}
+                            <span class="text-muted">None</span>
+                        {% endif %}
+                    </td>
+                </tr>
+                <tr>
                     <td>Status</td>
                     <td>
                         <span class="label label-{{ vlan.get_status_class }}">{{ vlan.get_status_display }}</span>

+ 1 - 0
netbox/templates/ipam/vlan_bulk_edit.html

@@ -11,6 +11,7 @@
             <td>{{ vlan.site }}</td>
             <td>{{ vlan.status }}</td>
             <td>{{ vlan.role }}</td>
+            <td>{{ vlan.description }}</td>
         </tr>
     {% endfor %}
 {% endblock %}

+ 6 - 1
netbox/templates/ipam/vlan_import.html

@@ -58,10 +58,15 @@
 					<td>Functional role (optional)</td>
 					<td>Security</td>
 				</tr>
+				<tr>
+					<td>Description</td>
+					<td>Short description (optional)</td>
+					<td>Security team only</td>
+				</tr>
 			</tbody>
 		</table>
 		<h4>Example</h4>
-		<pre>LAS2,Backend Network,1400,Cameras,Active,Security</pre>
+		<pre>LAS2,Backend Network,1400,Cameras,Active,Security,Security team only</pre>
 	</div>
 </div>
 {% endblock %}