From 1f288175e479bf475055c4cf3ccae9a69c67325a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 12:53:28 -0500 Subject: [PATCH 1/5] Add description field to RackRole and DeviceRole models (#3655) --- netbox/dcim/api/serializers.py | 6 +++-- netbox/dcim/forms.py | 4 ++-- .../dcim/migrations/0087_role_descriptions.py | 23 +++++++++++++++++++ netbox/dcim/models.py | 14 +++++++++-- netbox/dcim/tables.py | 15 ++++++------ 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 netbox/dcim/migrations/0087_role_descriptions.py diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index c6ca24905..defc6c8ca 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -108,7 +108,7 @@ class RackRoleSerializer(ValidatedModelSerializer): class Meta: model = RackRole - fields = ['id', 'name', 'slug', 'color', 'rack_count'] + fields = ['id', 'name', 'slug', 'color', 'description', 'rack_count'] class RackSerializer(TaggitSerializer, CustomFieldModelSerializer): @@ -301,7 +301,9 @@ class DeviceRoleSerializer(ValidatedModelSerializer): class Meta: model = DeviceRole - fields = ['id', 'name', 'slug', 'color', 'vm_role', 'device_count', 'virtualmachine_count'] + fields = [ + 'id', 'name', 'slug', 'color', 'vm_role', 'description', 'device_count', 'virtualmachine_count', + ] class PlatformSerializer(ValidatedModelSerializer): diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 831bb7c81..5f6a3e695 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -412,7 +412,7 @@ class RackRoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = RackRole fields = [ - 'name', 'slug', 'color', + 'name', 'slug', 'color', 'description', ] @@ -1387,7 +1387,7 @@ class DeviceRoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = DeviceRole fields = [ - 'name', 'slug', 'color', 'vm_role', + 'name', 'slug', 'color', 'vm_role', 'description', ] diff --git a/netbox/dcim/migrations/0087_role_descriptions.py b/netbox/dcim/migrations/0087_role_descriptions.py new file mode 100644 index 000000000..5f8fd9707 --- /dev/null +++ b/netbox/dcim/migrations/0087_role_descriptions.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.6 on 2019-12-10 17:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0086_device_name_nonunique'), + ] + + operations = [ + migrations.AddField( + model_name='devicerole', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AddField( + model_name='rackrole', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 7e16bad95..d29a1e729 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -433,8 +433,12 @@ class RackRole(ChangeLoggedModel): unique=True ) color = ColorField() + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug', 'color'] + csv_headers = ['name', 'slug', 'color', 'description'] class Meta: ordering = ['name'] @@ -450,6 +454,7 @@ class RackRole(ChangeLoggedModel): self.name, self.slug, self.color, + self.description, ) @@ -1412,8 +1417,12 @@ class DeviceRole(ChangeLoggedModel): verbose_name='VM Role', help_text='Virtual machines may be assigned to this role' ) + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug', 'color', 'vm_role'] + csv_headers = ['name', 'slug', 'color', 'vm_role', 'description'] class Meta: ordering = ['name'] @@ -1427,6 +1436,7 @@ class DeviceRole(ChangeLoggedModel): self.slug, self.color, self.vm_role, + self.description, ) diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py index 1b747ff75..7e1da41d4 100644 --- a/netbox/dcim/tables.py +++ b/netbox/dcim/tables.py @@ -272,16 +272,17 @@ class RackGroupTable(BaseTable): class RackRoleTable(BaseTable): pk = ToggleColumn() - name = tables.LinkColumn(verbose_name='Name') rack_count = tables.Column(verbose_name='Racks') - color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color') - slug = tables.Column(verbose_name='Slug') - actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, - verbose_name='') + color = tables.TemplateColumn(COLOR_LABEL) + actions = tables.TemplateColumn( + template_code=RACKROLE_ACTIONS, + attrs={'td': {'class': 'text-right noprint'}}, + verbose_name='' + ) class Meta(BaseTable.Meta): model = RackRole - fields = ('pk', 'name', 'rack_count', 'color', 'slug', 'actions') + fields = ('pk', 'name', 'rack_count', 'color', 'description', 'slug', 'actions') # @@ -614,7 +615,7 @@ class DeviceRoleTable(BaseTable): class Meta(BaseTable.Meta): model = DeviceRole - fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'slug', 'actions') + fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'actions') # From 7845d9b25f2d60889a3241005b945fa09160b3d9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 12:59:10 -0500 Subject: [PATCH 2/5] Add description field to Role model (#3655) --- netbox/ipam/api/serializers.py | 2 +- netbox/ipam/forms.py | 2 +- .../ipam/migrations/0032_role_description.py | 18 ++++++++++++++++++ netbox/ipam/models.py | 7 ++++++- netbox/ipam/tables.py | 8 ++++++-- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 netbox/ipam/migrations/0032_role_description.py diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py index 5ebc52390..1e1759408 100644 --- a/netbox/ipam/api/serializers.py +++ b/netbox/ipam/api/serializers.py @@ -71,7 +71,7 @@ class RoleSerializer(ValidatedModelSerializer): class Meta: model = Role - fields = ['id', 'name', 'slug', 'weight', 'prefix_count', 'vlan_count'] + fields = ['id', 'name', 'slug', 'weight', 'description', 'prefix_count', 'vlan_count'] class VLANGroupSerializer(ValidatedModelSerializer): diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 0df5c2a5b..e2f45ac52 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -240,7 +240,7 @@ class RoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = Role fields = [ - 'name', 'slug', 'weight', + 'name', 'slug', 'weight', 'description', ] diff --git a/netbox/ipam/migrations/0032_role_description.py b/netbox/ipam/migrations/0032_role_description.py new file mode 100644 index 000000000..5a6206bbc --- /dev/null +++ b/netbox/ipam/migrations/0032_role_description.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-12-10 17:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ipam', '0031_3569_service_fields'), + ] + + operations = [ + migrations.AddField( + model_name='role', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 68cefe77f..759215e0b 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -260,8 +260,12 @@ class Role(ChangeLoggedModel): weight = models.PositiveSmallIntegerField( default=1000 ) + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug', 'weight'] + csv_headers = ['name', 'slug', 'weight', 'description'] class Meta: ordering = ['weight', 'name'] @@ -274,6 +278,7 @@ class Role(ChangeLoggedModel): self.name, self.slug, self.weight, + self.description, ) diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 91f195ba0..c66d2d820 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -288,11 +288,15 @@ class RoleTable(BaseTable): orderable=False, verbose_name='VLANs' ) - actions = tables.TemplateColumn(template_code=ROLE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, verbose_name='') + actions = tables.TemplateColumn( + template_code=ROLE_ACTIONS, + attrs={'td': {'class': 'text-right noprint'}}, + verbose_name='' + ) class Meta(BaseTable.Meta): model = Role - fields = ('pk', 'name', 'prefix_count', 'vlan_count', 'slug', 'weight', 'actions') + fields = ('pk', 'name', 'prefix_count', 'vlan_count', 'description', 'slug', 'weight', 'actions') # From 24bdd10b4f8b4485d66ed071fc45fc67d0830d54 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 13:03:09 -0500 Subject: [PATCH 3/5] Add description field to SecretRole model (#3655) --- netbox/secrets/api/serializers.py | 2 +- netbox/secrets/forms.py | 2 +- .../migrations/0007_secretrole_description.py | 18 ++++++++++++++++++ netbox/secrets/models.py | 7 ++++++- netbox/secrets/tables.py | 5 ++--- 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 netbox/secrets/migrations/0007_secretrole_description.py diff --git a/netbox/secrets/api/serializers.py b/netbox/secrets/api/serializers.py index 7a0447a39..e278f3c40 100644 --- a/netbox/secrets/api/serializers.py +++ b/netbox/secrets/api/serializers.py @@ -18,7 +18,7 @@ class SecretRoleSerializer(ValidatedModelSerializer): class Meta: model = SecretRole - fields = ['id', 'name', 'slug', 'secret_count'] + fields = ['id', 'name', 'slug', 'description', 'secret_count'] class SecretSerializer(TaggitSerializer, CustomFieldModelSerializer): diff --git a/netbox/secrets/forms.py b/netbox/secrets/forms.py index ed0f455c1..064e7dbf8 100644 --- a/netbox/secrets/forms.py +++ b/netbox/secrets/forms.py @@ -42,7 +42,7 @@ class SecretRoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = SecretRole fields = [ - 'name', 'slug', 'users', 'groups', + 'name', 'slug', 'description', 'users', 'groups', ] widgets = { 'users': StaticSelect2Multiple(), diff --git a/netbox/secrets/migrations/0007_secretrole_description.py b/netbox/secrets/migrations/0007_secretrole_description.py new file mode 100644 index 000000000..abe13e09c --- /dev/null +++ b/netbox/secrets/migrations/0007_secretrole_description.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-12-10 18:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('secrets', '0006_custom_tag_models'), + ] + + operations = [ + migrations.AddField( + model_name='secretrole', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/secrets/models.py b/netbox/secrets/models.py index 6dcb5abee..f14d2d982 100644 --- a/netbox/secrets/models.py +++ b/netbox/secrets/models.py @@ -270,6 +270,10 @@ class SecretRole(ChangeLoggedModel): slug = models.SlugField( unique=True ) + description = models.CharField( + max_length=100, + blank=True, + ) users = models.ManyToManyField( to=User, related_name='secretroles', @@ -281,7 +285,7 @@ class SecretRole(ChangeLoggedModel): blank=True ) - csv_headers = ['name', 'slug'] + csv_headers = ['name', 'slug', 'description'] class Meta: ordering = ['name'] @@ -296,6 +300,7 @@ class SecretRole(ChangeLoggedModel): return ( self.name, self.slug, + self.description, ) def has_member(self, user): diff --git a/netbox/secrets/tables.py b/netbox/secrets/tables.py index 1f937f54b..cc1760b93 100644 --- a/netbox/secrets/tables.py +++ b/netbox/secrets/tables.py @@ -19,16 +19,15 @@ SECRETROLE_ACTIONS = """ class SecretRoleTable(BaseTable): pk = ToggleColumn() - name = tables.LinkColumn(verbose_name='Name') + name = tables.LinkColumn() secret_count = tables.Column(verbose_name='Secrets') - slug = tables.Column(verbose_name='Slug') actions = tables.TemplateColumn( template_code=SECRETROLE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, verbose_name='' ) class Meta(BaseTable.Meta): model = SecretRole - fields = ('pk', 'name', 'secret_count', 'slug', 'actions') + fields = ('pk', 'name', 'secret_count', 'description', 'slug', 'actions') # From 3d5fb2491ab1513531cde1ac8f493fe1399f9b9d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 13:09:41 -0500 Subject: [PATCH 4/5] Chnagelog for #3655 --- docs/release-notes/version-2.7.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 0a62a272d..280c13c3d 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -136,6 +136,7 @@ PATCH) to maintain backward compatibility. This behavior will be discontinued be * [#3455](https://github.com/digitalocean/netbox/issues/3455) - Add tenant assignment to cluster * [#3564](https://github.com/digitalocean/netbox/issues/3564) - Add list views for device components * [#3538](https://github.com/digitalocean/netbox/issues/3538) - Introduce a REST API endpoint for executing custom scripts +* [#3655](https://github.com/digitalocean/netbox/issues/3655) - Add `description` field to rack, device, VLAN/prefix, secret roles * [#3731](https://github.com/digitalocean/netbox/issues/3731) - Change Graph.type to a ContentType foreign key field ## API Changes @@ -146,9 +147,13 @@ PATCH) to maintain backward compatibility. This behavior will be discontinued be * dcim.ConsolePortTemplate: Added field `type` * dcim.ConsoleServerPort: Added field `type` * dcim.ConsoleServerPortTemplate: Added field `type` +* dcim.DeviceRole: Added field `description` * dcim.PowerPort: Added field `type` * dcim.PowerPortTemplate: Added field `type` * dcim.PowerOutlet: Added field `type` * dcim.PowerOutletTemplate: Added field `type` +* dcim.RackRole: Added field `description` * extras.Graph: The `type` field has been changed to a content type foreign key. Models are specified as `.`; e.g. `dcim.site`. +* ipam.Role: Added field `description` +* secrets.SecretRole: Added field `description` * virtualization.Cluster: Added field `tenant` From a6904dc5d59865398c66f17ba27d434c9c501308 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 13:24:02 -0500 Subject: [PATCH 5/5] Add description field to CircuitType (#3655) --- docs/release-notes/version-2.7.md | 3 ++- netbox/circuits/api/serializers.py | 2 +- netbox/circuits/forms.py | 2 +- .../migrations/0017_circuittype_description.py | 18 ++++++++++++++++++ netbox/circuits/models.py | 7 ++++++- netbox/circuits/tables.py | 6 ++++-- 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 netbox/circuits/migrations/0017_circuittype_description.py diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 280c13c3d..abcaf36c5 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -136,13 +136,14 @@ PATCH) to maintain backward compatibility. This behavior will be discontinued be * [#3455](https://github.com/digitalocean/netbox/issues/3455) - Add tenant assignment to cluster * [#3564](https://github.com/digitalocean/netbox/issues/3564) - Add list views for device components * [#3538](https://github.com/digitalocean/netbox/issues/3538) - Introduce a REST API endpoint for executing custom scripts -* [#3655](https://github.com/digitalocean/netbox/issues/3655) - Add `description` field to rack, device, VLAN/prefix, secret roles +* [#3655](https://github.com/digitalocean/netbox/issues/3655) - Add `description` field to organizational models * [#3731](https://github.com/digitalocean/netbox/issues/3731) - Change Graph.type to a ContentType foreign key field ## API Changes * Choice fields now use human-friendly strings for their values instead of integers (see [#3569](https://github.com/netbox-community/netbox/issues/3569)). * Introduced `/api/extras/scripts/` endpoint for retrieving and executing custom scripts +* circuits.CircuitType: Added field `description` * dcim.ConsolePort: Added field `type` * dcim.ConsolePortTemplate: Added field `type` * dcim.ConsoleServerPort: Added field `type` diff --git a/netbox/circuits/api/serializers.py b/netbox/circuits/api/serializers.py index fb63654b1..b22135b3f 100644 --- a/netbox/circuits/api/serializers.py +++ b/netbox/circuits/api/serializers.py @@ -36,7 +36,7 @@ class CircuitTypeSerializer(ValidatedModelSerializer): class Meta: model = CircuitType - fields = ['id', 'name', 'slug', 'circuit_count'] + fields = ['id', 'name', 'slug', 'description', 'circuit_count'] class CircuitSerializer(TaggitSerializer, CustomFieldModelSerializer): diff --git a/netbox/circuits/forms.py b/netbox/circuits/forms.py index ad99dd40d..a0458aa42 100644 --- a/netbox/circuits/forms.py +++ b/netbox/circuits/forms.py @@ -128,7 +128,7 @@ class CircuitTypeForm(BootstrapMixin, forms.ModelForm): class Meta: model = CircuitType fields = [ - 'name', 'slug', + 'name', 'slug', 'description', ] diff --git a/netbox/circuits/migrations/0017_circuittype_description.py b/netbox/circuits/migrations/0017_circuittype_description.py new file mode 100644 index 000000000..4cb5591dd --- /dev/null +++ b/netbox/circuits/migrations/0017_circuittype_description.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-12-10 18:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('circuits', '0016_3569_circuit_fields'), + ] + + operations = [ + migrations.AddField( + model_name='circuittype', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/circuits/models.py b/netbox/circuits/models.py index 672e18b62..aabb51ca5 100644 --- a/netbox/circuits/models.py +++ b/netbox/circuits/models.py @@ -98,8 +98,12 @@ class CircuitType(ChangeLoggedModel): slug = models.SlugField( unique=True ) + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug'] + csv_headers = ['name', 'slug', 'description'] class Meta: ordering = ['name'] @@ -114,6 +118,7 @@ class CircuitType(ChangeLoggedModel): return ( self.name, self.slug, + self.description, ) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index d67abdd1a..dbd9e6ba1 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -50,12 +50,14 @@ class CircuitTypeTable(BaseTable): name = tables.LinkColumn() circuit_count = tables.Column(verbose_name='Circuits') actions = tables.TemplateColumn( - template_code=CIRCUITTYPE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, verbose_name='' + template_code=CIRCUITTYPE_ACTIONS, + attrs={'td': {'class': 'text-right noprint'}}, + verbose_name='' ) class Meta(BaseTable.Meta): model = CircuitType - fields = ('pk', 'name', 'circuit_count', 'slug', 'actions') + fields = ('pk', 'name', 'circuit_count', 'description', 'slug', 'actions') #