Przeglądaj źródła

Merge branch 'develop-2.8' into 3351-plugins

John Anderson 6 lat temu
rodzic
commit
a955f90a7e
96 zmienionych plików z 1082 dodań i 820 usunięć
  1. 1 1
      docs/additional-features/custom-scripts.md
  2. 2 2
      docs/administration/netbox-shell.md
  3. 25 51
      docs/api/overview.md
  4. 1 1
      docs/index.md
  5. 15 0
      docs/release-notes/version-2.7.md
  6. 13 1
      docs/release-notes/version-2.8.md
  7. 0 3
      netbox/circuits/api/urls.py
  8. 1 12
      netbox/circuits/api/views.py
  9. 28 0
      netbox/circuits/migrations/0008_standardize_description.py
  10. 6 3
      netbox/circuits/models.py
  11. 1 14
      netbox/circuits/tests/test_api.py
  12. 6 4
      netbox/dcim/api/serializers.py
  13. 0 3
      netbox/dcim/api/urls.py
  14. 1 30
      netbox/dcim/api/views.py
  15. 4 4
      netbox/dcim/filters.py
  16. 14 6
      netbox/dcim/forms.py
  17. 98 0
      netbox/dcim/migrations/0103_standardize_description.py
  18. 43 8
      netbox/dcim/models/__init__.py
  19. 11 1
      netbox/dcim/models/device_components.py
  20. 30 9
      netbox/dcim/tables.py
  21. 15 74
      netbox/dcim/tests/test_api.py
  22. 34 17
      netbox/dcim/tests/test_filters.py
  23. 20 20
      netbox/dcim/tests/test_views.py
  24. 2 3
      netbox/dcim/urls.py
  25. 17 7
      netbox/dcim/views.py
  26. 4 3
      netbox/extras/api/serializers.py
  27. 0 3
      netbox/extras/api/urls.py
  28. 1 13
      netbox/extras/api/views.py
  29. 9 172
      netbox/extras/constants.py
  30. 6 3
      netbox/extras/forms.py
  31. 23 0
      netbox/extras/migrations/0039_standardize_description.py
  32. 40 0
      netbox/extras/migrations/0039_update_features_content_types.py
  33. 23 0
      netbox/extras/migrations/0040_tag_description.py
  34. 10 11
      netbox/extras/models.py
  35. 1 1
      netbox/extras/tables.py
  36. 2 24
      netbox/extras/tests/test_api.py
  37. 3 4
      netbox/extras/tests/test_filters.py
  38. 68 0
      netbox/extras/utils.py
  39. 2 1
      netbox/extras/webhooks.py
  40. 2 2
      netbox/ipam/api/serializers.py
  41. 0 3
      netbox/ipam/api/urls.py
  42. 1 15
      netbox/ipam/api/views.py
  43. 2 2
      netbox/ipam/filters.py
  44. 2 2
      netbox/ipam/forms.py
  45. 58 0
      netbox/ipam/migrations/0036_standardize_description.py
  46. 26 9
      netbox/ipam/models.py
  47. 2 2
      netbox/ipam/tables.py
  48. 1 26
      netbox/ipam/tests/test_api.py
  49. 17 9
      netbox/ipam/tests/test_filters.py
  50. 10 8
      netbox/ipam/tests/test_views.py
  51. 2 8
      netbox/netbox/settings.py
  52. 0 3
      netbox/secrets/api/urls.py
  53. 1 9
      netbox/secrets/api/views.py
  54. 7 1
      netbox/secrets/forms.py
  55. 18 0
      netbox/secrets/migrations/0008_standardize_description.py
  56. 3 1
      netbox/secrets/models.py
  57. 0 7
      netbox/secrets/tests/test_api.py
  58. 1 0
      netbox/secrets/urls.py
  59. 9 10
      netbox/secrets/views.py
  60. 1 1
      netbox/templates/dcim/device.html
  61. 6 4
      netbox/templates/dcim/rack.html
  62. 146 0
      netbox/templates/dcim/rackreservation.html
  63. 21 0
      netbox/templates/dcim/rackreservation_edit.html
  64. 5 12
      netbox/templates/extras/tag.html
  65. 1 6
      netbox/templates/extras/tag_edit.html
  66. 1 1
      netbox/templates/inc/custom_fields_panel.html
  67. 1 0
      netbox/templates/inc/nav_menu.html
  68. 1 6
      netbox/templates/secrets/secret_edit.html
  69. 1 1
      netbox/templates/utilities/obj_edit.html
  70. 1 1
      netbox/tenancy/api/serializers.py
  71. 0 3
      netbox/tenancy/api/urls.py
  72. 1 9
      netbox/tenancy/api/views.py
  73. 1 1
      netbox/tenancy/filters.py
  74. 1 1
      netbox/tenancy/forms.py
  75. 23 0
      netbox/tenancy/migrations/0009_standardize_description.py
  76. 10 4
      netbox/tenancy/models.py
  77. 1 1
      netbox/tenancy/tables.py
  78. 0 7
      netbox/tenancy/tests/test_api.py
  79. 7 3
      netbox/tenancy/tests/test_filters.py
  80. 5 4
      netbox/tenancy/tests/test_views.py
  81. 18 0
      netbox/users/migrations/0002_standardize_description.py
  82. 1 1
      netbox/users/models.py
  83. 1 46
      netbox/utilities/api.py
  84. 2 2
      netbox/utilities/templatetags/helpers.py
  85. 0 27
      netbox/utilities/testing/utils.py
  86. 2 2
      netbox/virtualization/api/serializers.py
  87. 0 3
      netbox/virtualization/api/urls.py
  88. 1 12
      netbox/virtualization/api/views.py
  89. 2 2
      netbox/virtualization/filters.py
  90. 2 2
      netbox/virtualization/forms.py
  91. 23 0
      netbox/virtualization/migrations/0014_standardize_description.py
  92. 15 2
      netbox/virtualization/models.py
  93. 2 2
      netbox/virtualization/tables.py
  94. 13 14
      netbox/virtualization/tests/test_api.py
  95. 14 6
      netbox/virtualization/tests/test_filters.py
  96. 10 8
      netbox/virtualization/tests/test_views.py

+ 1 - 1
docs/additional-features/custom-scripts.md

@@ -63,7 +63,7 @@ A human-friendly description of what your script does.
 
 
 ### `field_order`
 ### `field_order`
 
 
-A list of field names indicating the order in which the form fields should appear. This is optional, however on Python 3.5 and earlier the fields will appear in random order. (Declarative ordering is preserved on Python 3.6 and above.) For example:
+A list of field names indicating the order in which the form fields should appear. This is optional, and should not be required on Python 3.6 and above. For example:
 
 
 ```
 ```
 field_order = ['var1', 'var2', 'var3']
 field_order = ['var1', 'var2', 'var3']

+ 2 - 2
docs/administration/netbox-shell.md

@@ -10,8 +10,8 @@ This will launch a customized version of [the built-in Django shell](https://doc
 
 
 ```
 ```
 $ ./manage.py nbshell
 $ ./manage.py nbshell
-### NetBox interactive shell (jstretch-laptop)
-### Python 3.5.2 | Django 2.0.8 | NetBox 2.4.3
+### NetBox interactive shell (localhost)
+### Python 3.6.9 | Django 2.2.11 | NetBox 2.7.10
 ### lsmodels() will show available models. Use help(<model>) for more info.
 ### lsmodels() will show available models. Use help(<model>) for more info.
 ```
 ```
 
 

+ 25 - 51
docs/api/overview.md

@@ -187,37 +187,6 @@ GET /api/ipam/prefixes/13980/?brief=1
 
 
 The brief format is supported for both lists and individual objects.
 The brief format is supported for both lists and individual objects.
 
 
-### Static Choice Fields
-
-Some model fields, such as the `status` field in the above example, utilize static integers corresponding to static choices. The available choices can be retrieved from the read-only `_choices` endpoint within each app. A specific `model:field` tuple may optionally be specified in the URL.
-
-Each choice includes a human-friendly label and its corresponding numeric value. For example, `GET /api/ipam/_choices/prefix:status/` will return:
-
-```
-[
-    {
-        "value": 0,
-        "label": "Container"
-    },
-    {
-        "value": 1,
-        "label": "Active"
-    },
-    {
-        "value": 2,
-        "label": "Reserved"
-    },
-    {
-        "value": 3,
-        "label": "Deprecated"
-    }
-]
-```
-
-Thus, to set a prefix's status to "Reserved," it would be assigned the integer `2`.
-
-A request for `GET /api/ipam/_choices/` will return choices for _all_ fields belonging to models within the IPAM app.
-
 ## Pagination
 ## Pagination
 
 
 API responses which contain a list of objects (for example, a request to `/api/dcim/devices/`) will be paginated to avoid unnecessary overhead. The root JSON object will contain the following attributes:
 API responses which contain a list of objects (for example, a request to `/api/dcim/devices/`) will be paginated to avoid unnecessary overhead. The root JSON object will contain the following attributes:
@@ -280,27 +249,32 @@ A list of objects retrieved via the API can be filtered by passing one or more q
 GET /api/ipam/prefixes/?status=1
 GET /api/ipam/prefixes/?status=1
 ```
 ```
 
 
-The choices available for fixed choice fields such as `status` are exposed in the API under a special `_choices` endpoint for each NetBox app. For example, the available choices for `Prefix.status` are listed at `/api/ipam/_choices/` under the key `prefix:status`:
+The choices available for fixed choice fields such as `status` can be retrieved by sending an `OPTIONS` API request for the desired endpoint:
+
+```no-highlight
+$ curl -s -X OPTIONS \
+-H "Content-Type: application/json" \
+-H "Accept: application/json; indent=4" \
+http://localhost:8000/api/ipam/prefixes/ | jq ".actions.POST.status.choices"
+[
+  {
+    "value": "container",
+    "display_name": "Container"
+  },
+  {
+    "value": "active",
+    "display_name": "Active"
+  },
+  {
+    "value": "reserved",
+    "display_name": "Reserved"
+  },
+  {
+    "value": "deprecated",
+    "display_name": "Deprecated"
+  }
+]
 
 
-```
-"prefix:status": [
-    {
-        "label": "Container",
-        "value": 0
-    },
-    {
-        "label": "Active",
-        "value": 1
-    },
-    {
-        "label": "Reserved",
-        "value": 2
-    },
-    {
-        "label": "Deprecated",
-        "value": 3
-    }
-],
 ```
 ```
 
 
 For most fields, when a filter is passed multiple times, objects matching _any_ of the provided values will be returned. For example, `GET /api/dcim/sites/?name=Foo&name=Bar` will return all sites named "Foo" _or_ "Bar". The exception to this rule is ManyToManyFields which may have multiple values assigned. Tags are the most common example of a ManyToManyField. For example, `GET /api/dcim/sites/?tag=foo&tag=bar` will return only sites tagged with both "foo" _and_ "bar".
 For most fields, when a filter is passed multiple times, objects matching _any_ of the provided values will be returned. For example, `GET /api/dcim/sites/?name=Foo&name=Bar` will return all sites named "Foo" _or_ "Bar". The exception to this rule is ManyToManyFields which may have multiple values assigned. Tags are the most common example of a ManyToManyField. For example, `GET /api/dcim/sites/?tag=foo&tag=bar` will return only sites tagged with both "foo" _and_ "bar".

+ 1 - 1
docs/index.md

@@ -55,7 +55,7 @@ NetBox is built on the [Django](https://djangoproject.com/) Python framework and
 
 
 ## Supported Python Versions
 ## Supported Python Versions
 
 
-NetBox supports Python 3.5, 3.6, and 3.7 environments currently. Python 3.5 is scheduled to be unsupported in NetBox v2.8.
+NetBox supports Python 3.6 and 3.7 environments currently. (Support for Python 3.5 was removed in NetBox v2.8.)
 
 
 ## Getting Started
 ## Getting Started
 
 

+ 15 - 0
docs/release-notes/version-2.7.md

@@ -1,5 +1,20 @@
 # NetBox v2.7 Release Notes
 # NetBox v2.7 Release Notes
 
 
+## v2.7.11 (FUTURE)
+
+### Enhancements
+
+* [#4309](https://github.com/netbox-community/netbox/issues/4309) - Add descriptive tooltip to custom fields on object views
+* [#4369](https://github.com/netbox-community/netbox/issues/4369) - Add a dedicated view for rack reservations
+
+### Bug Fixes
+
+* [#4340](https://github.com/netbox-community/netbox/issues/4340) - Enforce unique constraints for device and virtual machine names in the API
+* [#4343](https://github.com/netbox-community/netbox/issues/4343) - Fix Markdown support for tables
+* [#4365](https://github.com/netbox-community/netbox/issues/4365) - Fix exception raised on IP address bulk add view
+
+---
+
 ## v2.7.10 (2020-03-10)
 ## v2.7.10 (2020-03-10)
 
 
 **Note:** If your deployment requires any non-core Python packages (such as `napalm`, `django-storages`, or `django-auth-ldap`), list them in a file named `local_requirements.txt` in the NetBox root directory (alongside `requirements.txt`). This will ensure they are detected and re-installed by the upgrade script when the Python virtual environment is rebuilt.
 **Note:** If your deployment requires any non-core Python packages (such as `napalm`, `django-storages`, or `django-auth-ldap`), list them in a file named `local_requirements.txt` in the NetBox root directory (alongside `requirements.txt`). This will ensure they are detected and re-installed by the upgrade script when the Python virtual environment is rebuilt.

+ 13 - 1
docs/release-notes/version-2.8.md

@@ -20,12 +20,24 @@ If further customization of remote authentication is desired (for instance, if y
 
 
 * [#1754](https://github.com/netbox-community/netbox/issues/1754) - Added support for nested rack groups
 * [#1754](https://github.com/netbox-community/netbox/issues/1754) - Added support for nested rack groups
 * [#3939](https://github.com/netbox-community/netbox/issues/3939) - Added support for nested tenant groups
 * [#3939](https://github.com/netbox-community/netbox/issues/3939) - Added support for nested tenant groups
+* [#4078](https://github.com/netbox-community/netbox/issues/4078) - Standardized description fields across all models
 * [#4195](https://github.com/netbox-community/netbox/issues/4195) - Enabled application logging (see [logging configuration](../configuration/optional-settings.md#logging))
 * [#4195](https://github.com/netbox-community/netbox/issues/4195) - Enabled application logging (see [logging configuration](../configuration/optional-settings.md#logging))
 
 
 ### API Changes
 ### API Changes
 
 
-* dcim.Rack: The `/api/dcim/racks/<pk>/units/` endpoint has been replaced with `/api/dcim/racks/<pk>/elevation/`.
+* The `_choices` API endpoints have been removed. Instead, use an `OPTIONS` request to a model's endpoint to view the available values for all fields. ([#3416](https://github.com/netbox-community/netbox/issues/3416))
 * The `id__in` filter has been removed. Use the format `?id=1&id=2` instead. ([#4313](https://github.com/netbox-community/netbox/issues/4313))
 * The `id__in` filter has been removed. Use the format `?id=1&id=2` instead. ([#4313](https://github.com/netbox-community/netbox/issues/4313))
+* dcim.Manufacturer: Added a `description` field
+* dcim.Platform: Added a `description` field
+* dcim.Rack: The `/api/dcim/racks/<pk>/units/` endpoint has been replaced with `/api/dcim/racks/<pk>/elevation/`.
+* dcim.RackGroup: Added a `description` field
+* dcim.Region: Added a `description` field
+* extras.Tag: Renamed `comments` to `description`; truncated length to 200 characters; removed Markdown rendering
+* ipam.RIR: Added a `description` field
+* ipam.VLANGroup: Added a `description` field
+* tenancy.TenantGroup: Added a `description` field
+* virtualization.ClusterGroup: Added a `description` field
+* virtualization.ClusterType: Added a `description` field
 
 
 ### Other Changes
 ### Other Changes
 
 

+ 0 - 3
netbox/circuits/api/urls.py

@@ -14,9 +14,6 @@ class CircuitsRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = CircuitsRootView
 router.APIRootView = CircuitsRootView
 
 
-# Field choices
-router.register('_choices', views.CircuitsFieldChoicesViewSet, basename='field-choice')
-
 # Providers
 # Providers
 router.register('providers', views.ProviderViewSet)
 router.register('providers', views.ProviderViewSet)
 
 

+ 1 - 12
netbox/circuits/api/views.py

@@ -8,21 +8,10 @@ from circuits.models import Provider, CircuitTermination, CircuitType, Circuit
 from extras.api.serializers import RenderedGraphSerializer
 from extras.api.serializers import RenderedGraphSerializer
 from extras.api.views import CustomFieldModelViewSet
 from extras.api.views import CustomFieldModelViewSet
 from extras.models import Graph
 from extras.models import Graph
-from utilities.api import FieldChoicesViewSet, ModelViewSet
+from utilities.api import ModelViewSet
 from . import serializers
 from . import serializers
 
 
 
 
-#
-# Field choices
-#
-
-class CircuitsFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = (
-        (serializers.CircuitSerializer, ['status']),
-        (serializers.CircuitTerminationSerializer, ['term_side']),
-    )
-
-
 #
 #
 # Providers
 # Providers
 #
 #

+ 28 - 0
netbox/circuits/migrations/0008_standardize_description.py

@@ -0,0 +1,28 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('circuits', '0007_circuit_add_description_squashed_0017_circuittype_description'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='circuit',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='circuittermination',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='circuittype',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 6 - 3
netbox/circuits/models.py

@@ -7,6 +7,7 @@ from dcim.constants import CONNECTION_STATUS_CHOICES
 from dcim.fields import ASNField
 from dcim.fields import ASNField
 from dcim.models import CableTermination
 from dcim.models import CableTermination
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
+from extras.utils import extras_features
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from utilities.utils import serialize_object
 from utilities.utils import serialize_object
 from .choices import *
 from .choices import *
@@ -21,6 +22,7 @@ __all__ = (
 )
 )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'graphs', 'export_templates', 'webhooks')
 class Provider(ChangeLoggedModel, CustomFieldModel):
 class Provider(ChangeLoggedModel, CustomFieldModel):
     """
     """
     Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
     Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
@@ -108,7 +110,7 @@ class CircuitType(ChangeLoggedModel):
         unique=True
         unique=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True,
         blank=True,
     )
     )
 
 
@@ -131,6 +133,7 @@ class CircuitType(ChangeLoggedModel):
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Circuit(ChangeLoggedModel, CustomFieldModel):
 class Circuit(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A communications circuit connects two points. Each Circuit belongs to a Provider; Providers may have multiple
     A communications circuit connects two points. Each Circuit belongs to a Provider; Providers may have multiple
@@ -173,7 +176,7 @@ class Circuit(ChangeLoggedModel, CustomFieldModel):
         null=True,
         null=True,
         verbose_name='Commit rate (Kbps)')
         verbose_name='Commit rate (Kbps)')
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     comments = models.TextField(
     comments = models.TextField(
@@ -292,7 +295,7 @@ class CircuitTermination(CableTermination):
         verbose_name='Patch panel/port(s)'
         verbose_name='Patch panel/port(s)'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
 
 

+ 1 - 14
netbox/circuits/tests/test_api.py

@@ -6,7 +6,7 @@ from circuits.choices import *
 from circuits.models import Circuit, CircuitTermination, CircuitType, Provider
 from circuits.models import Circuit, CircuitTermination, CircuitType, Provider
 from dcim.models import Site
 from dcim.models import Site
 from extras.models import Graph
 from extras.models import Graph
-from utilities.testing import APITestCase, choices_to_dict
+from utilities.testing import APITestCase
 
 
 
 
 class AppTest(APITestCase):
 class AppTest(APITestCase):
@@ -18,19 +18,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('circuits-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
-        # Circuit
-        self.assertEqual(choices_to_dict(response.data.get('circuit:status')), CircuitStatusChoices.as_dict())
-
-        # CircuitTermination
-        self.assertEqual(choices_to_dict(response.data.get('circuit-termination:term_side')), CircuitTerminationSideChoices.as_dict())
-
 
 
 class ProviderTest(APITestCase):
 class ProviderTest(APITestCase):
 
 

+ 6 - 4
netbox/dcim/api/serializers.py

@@ -64,7 +64,7 @@ class RegionSerializer(serializers.ModelSerializer):
 
 
     class Meta:
     class Meta:
         model = Region
         model = Region
-        fields = ['id', 'name', 'slug', 'parent', 'site_count']
+        fields = ['id', 'name', 'slug', 'parent', 'description', 'site_count']
 
 
 
 
 class SiteSerializer(TaggitSerializer, CustomFieldModelSerializer):
 class SiteSerializer(TaggitSerializer, CustomFieldModelSerializer):
@@ -101,7 +101,7 @@ class RackGroupSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = RackGroup
         model = RackGroup
-        fields = ['id', 'name', 'slug', 'site', 'parent', 'rack_count']
+        fields = ['id', 'name', 'slug', 'site', 'parent', 'description', 'rack_count']
 
 
 
 
 class RackRoleSerializer(ValidatedModelSerializer):
 class RackRoleSerializer(ValidatedModelSerializer):
@@ -219,7 +219,9 @@ class ManufacturerSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = Manufacturer
         model = Manufacturer
-        fields = ['id', 'name', 'slug', 'devicetype_count', 'inventoryitem_count', 'platform_count']
+        fields = [
+            'id', 'name', 'slug', 'description', 'devicetype_count', 'inventoryitem_count', 'platform_count',
+        ]
 
 
 
 
 class DeviceTypeSerializer(TaggitSerializer, CustomFieldModelSerializer):
 class DeviceTypeSerializer(TaggitSerializer, CustomFieldModelSerializer):
@@ -356,7 +358,7 @@ class PlatformSerializer(ValidatedModelSerializer):
     class Meta:
     class Meta:
         model = Platform
         model = Platform
         fields = [
         fields = [
-            'id', 'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'device_count',
+            'id', 'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description', 'device_count',
             'virtualmachine_count',
             'virtualmachine_count',
         ]
         ]
 
 

+ 0 - 3
netbox/dcim/api/urls.py

@@ -14,9 +14,6 @@ class DCIMRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = DCIMRootView
 router.APIRootView = DCIMRootView
 
 
-# Field choices
-router.register('_choices', views.DCIMFieldChoicesViewSet, basename='field-choice')
-
 # Sites
 # Sites
 router.register('regions', views.RegionViewSet)
 router.register('regions', views.RegionViewSet)
 router.register('sites', views.SiteViewSet)
 router.register('sites', views.SiteViewSet)

+ 1 - 30
netbox/dcim/api/views.py

@@ -26,7 +26,7 @@ from extras.api.views import CustomFieldModelViewSet
 from extras.models import Graph
 from extras.models import Graph
 from ipam.models import Prefix, VLAN
 from ipam.models import Prefix, VLAN
 from utilities.api import (
 from utilities.api import (
-    get_serializer_for_model, IsAuthenticatedOrLoginNotRequired, FieldChoicesViewSet, ModelViewSet, ServiceUnavailable,
+    get_serializer_for_model, IsAuthenticatedOrLoginNotRequired, ModelViewSet, ServiceUnavailable,
 )
 )
 from utilities.utils import get_subquery
 from utilities.utils import get_subquery
 from virtualization.models import VirtualMachine
 from virtualization.models import VirtualMachine
@@ -34,35 +34,6 @@ from . import serializers
 from .exceptions import MissingFilterException
 from .exceptions import MissingFilterException
 
 
 
 
-#
-# Field choices
-#
-
-class DCIMFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = (
-        (serializers.CableSerializer, ['length_unit', 'status', 'termination_a_type', 'termination_b_type', 'type']),
-        (serializers.ConsolePortSerializer, ['type', 'connection_status']),
-        (serializers.ConsolePortTemplateSerializer, ['type']),
-        (serializers.ConsoleServerPortSerializer, ['type']),
-        (serializers.ConsoleServerPortTemplateSerializer, ['type']),
-        (serializers.DeviceSerializer, ['face', 'status']),
-        (serializers.DeviceTypeSerializer, ['subdevice_role']),
-        (serializers.FrontPortSerializer, ['type']),
-        (serializers.FrontPortTemplateSerializer, ['type']),
-        (serializers.InterfaceSerializer, ['type', 'mode']),
-        (serializers.InterfaceTemplateSerializer, ['type']),
-        (serializers.PowerFeedSerializer, ['phase', 'status', 'supply', 'type']),
-        (serializers.PowerOutletSerializer, ['type', 'feed_leg']),
-        (serializers.PowerOutletTemplateSerializer, ['type', 'feed_leg']),
-        (serializers.PowerPortSerializer, ['type', 'connection_status']),
-        (serializers.PowerPortTemplateSerializer, ['type']),
-        (serializers.RackSerializer, ['outer_unit', 'status', 'type', 'width']),
-        (serializers.RearPortSerializer, ['type']),
-        (serializers.RearPortTemplateSerializer, ['type']),
-        (serializers.SiteSerializer, ['status']),
-    )
-
-
 # Mixins
 # Mixins
 
 
 class CableTraceMixin(object):
 class CableTraceMixin(object):

+ 4 - 4
netbox/dcim/filters.py

@@ -74,7 +74,7 @@ class RegionFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = Region
         model = Region
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class SiteFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class SiteFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
@@ -166,7 +166,7 @@ class RackGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = RackGroup
         model = RackGroup
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class RackRoleFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 class RackRoleFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
@@ -318,7 +318,7 @@ class ManufacturerFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = Manufacturer
         model = Manufacturer
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class DeviceTypeFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class DeviceTypeFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
@@ -493,7 +493,7 @@ class PlatformFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = Platform
         model = Platform
-        fields = ['id', 'name', 'slug', 'napalm_driver']
+        fields = ['id', 'name', 'slug', 'napalm_driver', 'description']
 
 
 
 
 class DeviceFilterSet(
 class DeviceFilterSet(

+ 14 - 6
netbox/dcim/forms.py

@@ -192,7 +192,7 @@ class RegionForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = Region
         model = Region
         fields = (
         fields = (
-            'parent', 'name', 'slug',
+            'parent', 'name', 'slug', 'description',
         )
         )
 
 
 
 
@@ -404,7 +404,7 @@ class RackGroupForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = RackGroup
         model = RackGroup
         fields = (
         fields = (
-            'site', 'parent', 'name', 'slug',
+            'site', 'parent', 'name', 'slug', 'description',
         )
         )
 
 
 
 
@@ -823,6 +823,13 @@ class RackElevationFilterForm(RackFilterForm):
 #
 #
 
 
 class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
 class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
+    rack = forms.ModelChoiceField(
+        queryset=Rack.objects.all(),
+        required=False,
+        widget=forms.HiddenInput()
+    )
+    # TODO: Change this to an API-backed form field. We can't do this currently because we want to retain
+    # the multi-line <select> widget for easy selection of multiple rack units.
     units = SimpleArrayField(
     units = SimpleArrayField(
         base_field=forms.IntegerField(),
         base_field=forms.IntegerField(),
         widget=ArrayFieldSelectMultiple(
         widget=ArrayFieldSelectMultiple(
@@ -841,7 +848,7 @@ class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
     class Meta:
     class Meta:
         model = RackReservation
         model = RackReservation
         fields = [
         fields = [
-            'units', 'user', 'tenant_group', 'tenant', 'description',
+            'rack', 'units', 'user', 'tenant_group', 'tenant', 'description',
         ]
         ]
 
 
     def __init__(self, *args, **kwargs):
     def __init__(self, *args, **kwargs):
@@ -849,7 +856,8 @@ class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
         super().__init__(*args, **kwargs)
         super().__init__(*args, **kwargs)
 
 
         # Populate rack unit choices
         # Populate rack unit choices
-        self.fields['units'].widget.choices = self._get_unit_choices()
+        if hasattr(self.instance, 'rack'):
+            self.fields['units'].widget.choices = self._get_unit_choices()
 
 
     def _get_unit_choices(self):
     def _get_unit_choices(self):
         rack = self.instance.rack
         rack = self.instance.rack
@@ -983,7 +991,7 @@ class ManufacturerForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = Manufacturer
         model = Manufacturer
         fields = [
         fields = [
-            'name', 'slug',
+            'name', 'slug', 'description',
         ]
         ]
 
 
 
 
@@ -1768,7 +1776,7 @@ class PlatformForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = Platform
         model = Platform
         fields = [
         fields = [
-            'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args',
+            'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description',
         ]
         ]
         widgets = {
         widgets = {
             'napalm_args': SmallTextarea(),
             'napalm_args': SmallTextarea(),

+ 98 - 0
netbox/dcim/migrations/0103_standardize_description.py

@@ -0,0 +1,98 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('dcim', '0102_nested_rackgroups_rebuild'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='manufacturer',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AddField(
+            model_name='platform',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AddField(
+            model_name='rackgroup',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AddField(
+            model_name='region',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='consoleport',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='consoleserverport',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='devicebay',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='devicerole',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='frontport',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='interface',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='inventoryitem',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='poweroutlet',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='powerport',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='rackreservation',
+            name='description',
+            field=models.CharField(max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='rackrole',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='rearport',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='site',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 43 - 8
netbox/dcim/models/__init__.py

@@ -21,6 +21,7 @@ from dcim.constants import *
 from dcim.fields import ASNField
 from dcim.fields import ASNField
 from dcim.elevations import RackElevationSVG
 from dcim.elevations import RackElevationSVG
 from extras.models import ConfigContextModel, CustomFieldModel, ObjectChange, TaggedItem
 from extras.models import ConfigContextModel, CustomFieldModel, ObjectChange, TaggedItem
+from extras.utils import extras_features
 from utilities.fields import ColorField, NaturalOrderingField
 from utilities.fields import ColorField, NaturalOrderingField
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from utilities.utils import serialize_object, to_meters
 from utilities.utils import serialize_object, to_meters
@@ -75,6 +76,7 @@ __all__ = (
 # Regions
 # Regions
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class Region(MPTTModel, ChangeLoggedModel):
 class Region(MPTTModel, ChangeLoggedModel):
     """
     """
     Sites can be grouped within geographic Regions.
     Sites can be grouped within geographic Regions.
@@ -94,8 +96,12 @@ class Region(MPTTModel, ChangeLoggedModel):
     slug = models.SlugField(
     slug = models.SlugField(
         unique=True
         unique=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug', 'parent']
+    csv_headers = ['name', 'slug', 'parent', 'description']
 
 
     class MPTTMeta:
     class MPTTMeta:
         order_insertion_by = ['name']
         order_insertion_by = ['name']
@@ -111,6 +117,7 @@ class Region(MPTTModel, ChangeLoggedModel):
             self.name,
             self.name,
             self.slug,
             self.slug,
             self.parent.name if self.parent else None,
             self.parent.name if self.parent else None,
+            self.description,
         )
         )
 
 
     def get_site_count(self):
     def get_site_count(self):
@@ -133,6 +140,7 @@ class Region(MPTTModel, ChangeLoggedModel):
 # Sites
 # Sites
 #
 #
 
 
+@extras_features('custom_fields', 'custom_links', 'graphs', 'export_templates', 'webhooks')
 class Site(ChangeLoggedModel, CustomFieldModel):
 class Site(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A Site represents a geographic location within a network; typically a building or campus. The optional facility
     A Site represents a geographic location within a network; typically a building or campus. The optional facility
@@ -182,7 +190,7 @@ class Site(ChangeLoggedModel, CustomFieldModel):
         blank=True
         blank=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     physical_address = models.CharField(
     physical_address = models.CharField(
@@ -283,6 +291,7 @@ class Site(ChangeLoggedModel, CustomFieldModel):
 # Racks
 # Racks
 #
 #
 
 
+@extras_features('export_templates')
 class RackGroup(MPTTModel, ChangeLoggedModel):
 class RackGroup(MPTTModel, ChangeLoggedModel):
     """
     """
     Racks can be grouped as subsets within a Site. The scope of a group will depend on how Sites are defined. For
     Racks can be grouped as subsets within a Site. The scope of a group will depend on how Sites are defined. For
@@ -306,8 +315,12 @@ class RackGroup(MPTTModel, ChangeLoggedModel):
         null=True,
         null=True,
         db_index=True
         db_index=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['site', 'parent', 'name', 'slug']
+    csv_headers = ['site', 'parent', 'name', 'slug', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['site', 'name']
         ordering = ['site', 'name']
@@ -331,6 +344,7 @@ class RackGroup(MPTTModel, ChangeLoggedModel):
             self.parent.name if self.parent else '',
             self.parent.name if self.parent else '',
             self.name,
             self.name,
             self.slug,
             self.slug,
+            self.description,
         )
         )
 
 
     def to_objectchange(self, action):
     def to_objectchange(self, action):
@@ -362,7 +376,7 @@ class RackRole(ChangeLoggedModel):
     )
     )
     color = ColorField()
     color = ColorField()
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True,
         blank=True,
     )
     )
 
 
@@ -386,6 +400,7 @@ class RackRole(ChangeLoggedModel):
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Rack(ChangeLoggedModel, CustomFieldModel):
 class Rack(ChangeLoggedModel, CustomFieldModel):
     """
     """
     Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
     Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
@@ -785,7 +800,7 @@ class RackReservation(ChangeLoggedModel):
         on_delete=models.PROTECT
         on_delete=models.PROTECT
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100
+        max_length=200
     )
     )
 
 
     csv_headers = ['site', 'rack_group', 'rack', 'units', 'tenant', 'user', 'description']
     csv_headers = ['site', 'rack_group', 'rack', 'units', 'tenant', 'user', 'description']
@@ -796,6 +811,9 @@ class RackReservation(ChangeLoggedModel):
     def __str__(self):
     def __str__(self):
         return "Reservation for rack {}".format(self.rack)
         return "Reservation for rack {}".format(self.rack)
 
 
+    def get_absolute_url(self):
+        return reverse('dcim:rackreservation', args=[self.pk])
+
     def clean(self):
     def clean(self):
 
 
         if self.units:
         if self.units:
@@ -847,6 +865,7 @@ class RackReservation(ChangeLoggedModel):
 # Device Types
 # Device Types
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class Manufacturer(ChangeLoggedModel):
 class Manufacturer(ChangeLoggedModel):
     """
     """
     A Manufacturer represents a company which produces hardware devices; for example, Juniper or Dell.
     A Manufacturer represents a company which produces hardware devices; for example, Juniper or Dell.
@@ -858,8 +877,12 @@ class Manufacturer(ChangeLoggedModel):
     slug = models.SlugField(
     slug = models.SlugField(
         unique=True
         unique=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug']
+    csv_headers = ['name', 'slug', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -874,9 +897,11 @@ class Manufacturer(ChangeLoggedModel):
         return (
         return (
             self.name,
             self.name,
             self.slug,
             self.slug,
+            self.description
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class DeviceType(ChangeLoggedModel, CustomFieldModel):
 class DeviceType(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A DeviceType represents a particular make (Manufacturer) and model of device. It specifies rack height and depth, as
     A DeviceType represents a particular make (Manufacturer) and model of device. It specifies rack height and depth, as
@@ -1142,7 +1167,7 @@ class DeviceRole(ChangeLoggedModel):
         help_text='Virtual machines may be assigned to this role'
         help_text='Virtual machines may be assigned to this role'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True,
         blank=True,
     )
     )
 
 
@@ -1198,8 +1223,12 @@ class Platform(ChangeLoggedModel):
         verbose_name='NAPALM arguments',
         verbose_name='NAPALM arguments',
         help_text='Additional arguments to pass when initiating the NAPALM driver (JSON format)'
         help_text='Additional arguments to pass when initiating the NAPALM driver (JSON format)'
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args']
+    csv_headers = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -1217,9 +1246,11 @@ class Platform(ChangeLoggedModel):
             self.manufacturer.name if self.manufacturer else None,
             self.manufacturer.name if self.manufacturer else None,
             self.napalm_driver,
             self.napalm_driver,
             self.napalm_args,
             self.napalm_args,
+            self.description,
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'graphs', 'export_templates', 'webhooks')
 class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
 class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
     """
     """
     A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
     A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
@@ -1655,6 +1686,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
 # Virtual chassis
 # Virtual chassis
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class VirtualChassis(ChangeLoggedModel):
 class VirtualChassis(ChangeLoggedModel):
     """
     """
     A collection of Devices which operate with a shared control plane (e.g. a switch stack).
     A collection of Devices which operate with a shared control plane (e.g. a switch stack).
@@ -1721,6 +1753,7 @@ class VirtualChassis(ChangeLoggedModel):
 # Power
 # Power
 #
 #
 
 
+@extras_features('custom_links', 'export_templates', 'webhooks')
 class PowerPanel(ChangeLoggedModel):
 class PowerPanel(ChangeLoggedModel):
     """
     """
     A distribution point for electrical power; e.g. a data center RPP.
     A distribution point for electrical power; e.g. a data center RPP.
@@ -1767,6 +1800,7 @@ class PowerPanel(ChangeLoggedModel):
             ))
             ))
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
 class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
     """
     """
     An electrical circuit delivered from a PowerPanel.
     An electrical circuit delivered from a PowerPanel.
@@ -1928,6 +1962,7 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
 # Cables
 # Cables
 #
 #
 
 
+@extras_features('custom_links', 'export_templates', 'webhooks')
 class Cable(ChangeLoggedModel):
 class Cable(ChangeLoggedModel):
     """
     """
     A physical connection between two endpoints.
     A physical connection between two endpoints.

+ 11 - 1
netbox/dcim/models/device_components.py

@@ -11,6 +11,7 @@ from dcim.constants import *
 from dcim.exceptions import LoopDetected
 from dcim.exceptions import LoopDetected
 from dcim.fields import MACAddressField
 from dcim.fields import MACAddressField
 from extras.models import ObjectChange, TaggedItem
 from extras.models import ObjectChange, TaggedItem
+from extras.utils import extras_features
 from utilities.fields import NaturalOrderingField
 from utilities.fields import NaturalOrderingField
 from utilities.ordering import naturalize_interface
 from utilities.ordering import naturalize_interface
 from utilities.utils import serialize_object
 from utilities.utils import serialize_object
@@ -33,7 +34,7 @@ __all__ = (
 
 
 class ComponentModel(models.Model):
 class ComponentModel(models.Model):
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
 
 
@@ -169,6 +170,7 @@ class CableTermination(models.Model):
 # Console ports
 # Console ports
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class ConsolePort(CableTermination, ComponentModel):
 class ConsolePort(CableTermination, ComponentModel):
     """
     """
     A physical console port within a Device. ConsolePorts connect to ConsoleServerPorts.
     A physical console port within a Device. ConsolePorts connect to ConsoleServerPorts.
@@ -229,6 +231,7 @@ class ConsolePort(CableTermination, ComponentModel):
 # Console server ports
 # Console server ports
 #
 #
 
 
+@extras_features('webhooks')
 class ConsoleServerPort(CableTermination, ComponentModel):
 class ConsoleServerPort(CableTermination, ComponentModel):
     """
     """
     A physical port within a Device (typically a designated console server) which provides access to ConsolePorts.
     A physical port within a Device (typically a designated console server) which provides access to ConsolePorts.
@@ -282,6 +285,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
 # Power ports
 # Power ports
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class PowerPort(CableTermination, ComponentModel):
 class PowerPort(CableTermination, ComponentModel):
     """
     """
     A physical power supply (intake) port within a Device. PowerPorts connect to PowerOutlets.
     A physical power supply (intake) port within a Device. PowerPorts connect to PowerOutlets.
@@ -443,6 +447,7 @@ class PowerPort(CableTermination, ComponentModel):
 # Power outlets
 # Power outlets
 #
 #
 
 
+@extras_features('webhooks')
 class PowerOutlet(CableTermination, ComponentModel):
 class PowerOutlet(CableTermination, ComponentModel):
     """
     """
     A physical power outlet (output) within a Device which provides power to a PowerPort.
     A physical power outlet (output) within a Device which provides power to a PowerPort.
@@ -519,6 +524,7 @@ class PowerOutlet(CableTermination, ComponentModel):
 # Interfaces
 # Interfaces
 #
 #
 
 
+@extras_features('graphs', 'export_templates', 'webhooks')
 class Interface(CableTermination, ComponentModel):
 class Interface(CableTermination, ComponentModel):
     """
     """
     A network interface within a Device or VirtualMachine. A physical Interface can connect to exactly one other
     A network interface within a Device or VirtualMachine. A physical Interface can connect to exactly one other
@@ -792,6 +798,7 @@ class Interface(CableTermination, ComponentModel):
 # Pass-through ports
 # Pass-through ports
 #
 #
 
 
+@extras_features('webhooks')
 class FrontPort(CableTermination, ComponentModel):
 class FrontPort(CableTermination, ComponentModel):
     """
     """
     A pass-through port on the front of a Device.
     A pass-through port on the front of a Device.
@@ -864,6 +871,7 @@ class FrontPort(CableTermination, ComponentModel):
             )
             )
 
 
 
 
+@extras_features('webhooks')
 class RearPort(CableTermination, ComponentModel):
 class RearPort(CableTermination, ComponentModel):
     """
     """
     A pass-through port on the rear of a Device.
     A pass-through port on the rear of a Device.
@@ -915,6 +923,7 @@ class RearPort(CableTermination, ComponentModel):
 # Device bays
 # Device bays
 #
 #
 
 
+@extras_features('webhooks')
 class DeviceBay(ComponentModel):
 class DeviceBay(ComponentModel):
     """
     """
     An empty space within a Device which can house a child device
     An empty space within a Device which can house a child device
@@ -989,6 +998,7 @@ class DeviceBay(ComponentModel):
 # Inventory items
 # Inventory items
 #
 #
 
 
+@extras_features('export_templates', 'webhooks')
 class InventoryItem(ComponentModel):
 class InventoryItem(ComponentModel):
     """
     """
     An InventoryItem represents a serialized piece of hardware within a Device, such as a line card or power supply.
     An InventoryItem represents a serialized piece of hardware within a Device, such as a line card or power supply.

+ 30 - 9
netbox/dcim/tables.py

@@ -225,7 +225,7 @@ class RegionTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = Region
         model = Region
-        fields = ('pk', 'name', 'site_count', 'slug', 'actions')
+        fields = ('pk', 'name', 'site_count', 'description', 'slug', 'actions')
 
 
 
 
 #
 #
@@ -271,7 +271,7 @@ class RackGroupTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = RackGroup
         model = RackGroup
-        fields = ('pk', 'name', 'site', 'rack_count', 'slug', 'actions')
+        fields = ('pk', 'name', 'site', 'rack_count', 'description', 'slug', 'actions')
 
 
 
 
 #
 #
@@ -341,21 +341,38 @@ class RackDetailTable(RackTable):
 
 
 class RackReservationTable(BaseTable):
 class RackReservationTable(BaseTable):
     pk = ToggleColumn()
     pk = ToggleColumn()
+    reservation = tables.LinkColumn(
+        viewname='dcim:rackreservation',
+        args=[Accessor('pk')],
+        accessor='pk'
+    )
     site = tables.LinkColumn(
     site = tables.LinkColumn(
         viewname='dcim:site',
         viewname='dcim:site',
         accessor=Accessor('rack.site'),
         accessor=Accessor('rack.site'),
         args=[Accessor('rack.site.slug')],
         args=[Accessor('rack.site.slug')],
     )
     )
-    tenant = tables.TemplateColumn(template_code=COL_TENANT)
-    rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')])
-    unit_list = tables.Column(orderable=False, verbose_name='Units')
+    tenant = tables.TemplateColumn(
+        template_code=COL_TENANT
+    )
+    rack = tables.LinkColumn(
+        viewname='dcim:rack',
+        args=[Accessor('rack.pk')]
+    )
+    unit_list = tables.Column(
+        orderable=False,
+        verbose_name='Units'
+    )
     actions = tables.TemplateColumn(
     actions = tables.TemplateColumn(
-        template_code=RACKRESERVATION_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, verbose_name=''
+        template_code=RACKRESERVATION_ACTIONS,
+        attrs={'td': {'class': 'text-right noprint'}},
+        verbose_name=''
     )
     )
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = RackReservation
         model = RackReservation
-        fields = ('pk', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'actions')
+        fields = (
+            'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'actions',
+        )
 
 
 
 
 #
 #
@@ -383,7 +400,9 @@ class ManufacturerTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = Manufacturer
         model = Manufacturer
-        fields = ('pk', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'slug', 'actions')
+        fields = (
+            'pk', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'description', 'slug', 'actions',
+        )
 
 
 
 
 #
 #
@@ -659,7 +678,9 @@ class PlatformTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = Platform
         model = Platform
-        fields = ('pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'actions')
+        fields = (
+            'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'description', 'actions',
+        )
 
 
 
 
 #
 #

+ 15 - 74
netbox/dcim/tests/test_api.py

@@ -14,7 +14,7 @@ from dcim.models import (
 )
 )
 from ipam.models import IPAddress, VLAN
 from ipam.models import IPAddress, VLAN
 from extras.models import Graph
 from extras.models import Graph
-from utilities.testing import APITestCase, choices_to_dict
+from utilities.testing import APITestCase
 from virtualization.models import Cluster, ClusterType
 from virtualization.models import Cluster, ClusterType
 
 
 
 
@@ -27,79 +27,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('dcim-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
-        # Cable
-        self.assertEqual(choices_to_dict(response.data.get('cable:length_unit')), CableLengthUnitChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('cable:status')), CableStatusChoices.as_dict())
-        content_types = ContentType.objects.filter(CABLE_TERMINATION_MODELS)
-        cable_termination_choices = {
-            "{}.{}".format(ct.app_label, ct.model): str(ct) for ct in content_types
-        }
-        self.assertEqual(choices_to_dict(response.data.get('cable:termination_a_type')), cable_termination_choices)
-        self.assertEqual(choices_to_dict(response.data.get('cable:termination_b_type')), cable_termination_choices)
-        self.assertEqual(choices_to_dict(response.data.get('cable:type')), CableTypeChoices.as_dict())
-
-        # Console ports
-        self.assertEqual(choices_to_dict(response.data.get('console-port:type')), ConsolePortTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('console-port:connection_status')), dict(CONNECTION_STATUS_CHOICES))
-        self.assertEqual(choices_to_dict(response.data.get('console-port-template:type')), ConsolePortTypeChoices.as_dict())
-
-        # Console server ports
-        self.assertEqual(choices_to_dict(response.data.get('console-server-port:type')), ConsolePortTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('console-server-port-template:type')), ConsolePortTypeChoices.as_dict())
-
-        # Device
-        self.assertEqual(choices_to_dict(response.data.get('device:face')), DeviceFaceChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('device:status')), DeviceStatusChoices.as_dict())
-
-        # Device type
-        self.assertEqual(choices_to_dict(response.data.get('device-type:subdevice_role')), SubdeviceRoleChoices.as_dict())
-
-        # Front ports
-        self.assertEqual(choices_to_dict(response.data.get('front-port:type')), PortTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('front-port-template:type')), PortTypeChoices.as_dict())
-
-        # Interfaces
-        self.assertEqual(choices_to_dict(response.data.get('interface:type')), InterfaceTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('interface:mode')), InterfaceModeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('interface-template:type')), InterfaceTypeChoices.as_dict())
-
-        # Power feed
-        self.assertEqual(choices_to_dict(response.data.get('power-feed:phase')), PowerFeedPhaseChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-feed:status')), PowerFeedStatusChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-feed:supply')), PowerFeedSupplyChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-feed:type')), PowerFeedTypeChoices.as_dict())
-
-        # Power outlets
-        self.assertEqual(choices_to_dict(response.data.get('power-outlet:type')), PowerOutletTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-outlet:feed_leg')), PowerOutletFeedLegChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-outlet-template:type')), PowerOutletTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-outlet-template:feed_leg')), PowerOutletFeedLegChoices.as_dict())
-
-        # Power ports
-        self.assertEqual(choices_to_dict(response.data.get('power-port:type')), PowerPortTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('power-port:connection_status')), dict(CONNECTION_STATUS_CHOICES))
-        self.assertEqual(choices_to_dict(response.data.get('power-port-template:type')), PowerPortTypeChoices.as_dict())
-
-        # Rack
-        self.assertEqual(choices_to_dict(response.data.get('rack:type')), RackTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('rack:width')), RackWidthChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('rack:status')), RackStatusChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('rack:outer_unit')), RackDimensionUnitChoices.as_dict())
-
-        # Rear ports
-        self.assertEqual(choices_to_dict(response.data.get('rear-port:type')), PortTypeChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('rear-port-template:type')), PortTypeChoices.as_dict())
-
-        # Site
-        self.assertEqual(choices_to_dict(response.data.get('site:status')), SiteStatusChoices.as_dict())
-
 
 
 class RegionTest(APITestCase):
 class RegionTest(APITestCase):
 
 
@@ -2090,6 +2017,20 @@ class DeviceTest(APITestCase):
 
 
         self.assertFalse('config_context' in response.data['results'][0])
         self.assertFalse('config_context' in response.data['results'][0])
 
 
+    def test_unique_name_per_site_constraint(self):
+
+        data = {
+            'device_type': self.devicetype1.pk,
+            'device_role': self.devicerole1.pk,
+            'name': 'Test Device 1',
+            'site': self.site1.pk,
+        }
+
+        url = reverse('dcim-api:device-list')
+        response = self.client.post(url, data, format='json', **self.header)
+
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+
 
 
 class ConsolePortTest(APITestCase):
 class ConsolePortTest(APITestCase):
 
 

+ 34 - 17
netbox/dcim/tests/test_filters.py

@@ -17,14 +17,15 @@ from virtualization.models import Cluster, ClusterType
 
 
 class RegionTestCase(TestCase):
 class RegionTestCase(TestCase):
     queryset = Region.objects.all()
     queryset = Region.objects.all()
+    filterset = RegionFilterSet
 
 
     @classmethod
     @classmethod
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         regions = (
         regions = (
-            Region(name='Region 1', slug='region-1'),
-            Region(name='Region 2', slug='region-2'),
-            Region(name='Region 3', slug='region-3'),
+            Region(name='Region 1', slug='region-1', description='A'),
+            Region(name='Region 2', slug='region-2', description='B'),
+            Region(name='Region 3', slug='region-3', description='C'),
         )
         )
         for region in regions:
         for region in regions:
             region.save()
             region.save()
@@ -43,22 +44,26 @@ class RegionTestCase(TestCase):
     def test_id(self):
     def test_id(self):
         id_list = self.queryset.values_list('id', flat=True)[:2]
         id_list = self.queryset.values_list('id', flat=True)[:2]
         params = {'id': [str(id) for id in id_list]}
         params = {'id': [str(id) for id in id_list]}
-        self.assertEqual(RegionFilterSet(params, self.queryset).qs.count(), 2)
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
     def test_name(self):
     def test_name(self):
         params = {'name': ['Region 1', 'Region 2']}
         params = {'name': ['Region 1', 'Region 2']}
-        self.assertEqual(RegionFilterSet(params, self.queryset).qs.count(), 2)
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
     def test_slug(self):
     def test_slug(self):
         params = {'slug': ['region-1', 'region-2']}
         params = {'slug': ['region-1', 'region-2']}
-        self.assertEqual(RegionFilterSet(params, self.queryset).qs.count(), 2)
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
     def test_parent(self):
     def test_parent(self):
         parent_regions = Region.objects.filter(parent__isnull=True)[:2]
         parent_regions = Region.objects.filter(parent__isnull=True)[:2]
         params = {'parent_id': [parent_regions[0].pk, parent_regions[1].pk]}
         params = {'parent_id': [parent_regions[0].pk, parent_regions[1].pk]}
-        self.assertEqual(RegionFilterSet(params, self.queryset).qs.count(), 4)
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
         params = {'parent': [parent_regions[0].slug, parent_regions[1].slug]}
         params = {'parent': [parent_regions[0].slug, parent_regions[1].slug]}
-        self.assertEqual(RegionFilterSet(params, self.queryset).qs.count(), 4)
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
 
 
 
 
 class SiteTestCase(TestCase):
 class SiteTestCase(TestCase):
@@ -196,9 +201,9 @@ class RackGroupTestCase(TestCase):
             rackgroup.save()
             rackgroup.save()
 
 
         rack_groups = (
         rack_groups = (
-            RackGroup(name='Rack Group 1', slug='rack-group-1', site=sites[0], parent=parent_rack_groups[0]),
-            RackGroup(name='Rack Group 2', slug='rack-group-2', site=sites[1], parent=parent_rack_groups[1]),
-            RackGroup(name='Rack Group 3', slug='rack-group-3', site=sites[2], parent=parent_rack_groups[2]),
+            RackGroup(name='Rack Group 1', slug='rack-group-1', site=sites[0], parent=parent_rack_groups[0], description='A'),
+            RackGroup(name='Rack Group 2', slug='rack-group-2', site=sites[1], parent=parent_rack_groups[1], description='B'),
+            RackGroup(name='Rack Group 3', slug='rack-group-3', site=sites[2], parent=parent_rack_groups[2], description='C'),
         )
         )
         for rackgroup in rack_groups:
         for rackgroup in rack_groups:
             rackgroup.save()
             rackgroup.save()
@@ -216,6 +221,10 @@ class RackGroupTestCase(TestCase):
         params = {'slug': ['rack-group-1', 'rack-group-2']}
         params = {'slug': ['rack-group-1', 'rack-group-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_region(self):
     def test_region(self):
         regions = Region.objects.all()[:2]
         regions = Region.objects.all()[:2]
         params = {'region_id': [regions[0].pk, regions[1].pk]}
         params = {'region_id': [regions[0].pk, regions[1].pk]}
@@ -535,9 +544,9 @@ class ManufacturerTestCase(TestCase):
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         manufacturers = (
         manufacturers = (
-            Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
-            Manufacturer(name='Manufacturer 2', slug='manufacturer-2'),
-            Manufacturer(name='Manufacturer 3', slug='manufacturer-3'),
+            Manufacturer(name='Manufacturer 1', slug='manufacturer-1', description='A'),
+            Manufacturer(name='Manufacturer 2', slug='manufacturer-2', description='B'),
+            Manufacturer(name='Manufacturer 3', slug='manufacturer-3', description='C'),
         )
         )
         Manufacturer.objects.bulk_create(manufacturers)
         Manufacturer.objects.bulk_create(manufacturers)
 
 
@@ -554,6 +563,10 @@ class ManufacturerTestCase(TestCase):
         params = {'slug': ['manufacturer-1', 'manufacturer-2']}
         params = {'slug': ['manufacturer-1', 'manufacturer-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
 
 
 class DeviceTypeTestCase(TestCase):
 class DeviceTypeTestCase(TestCase):
     queryset = DeviceType.objects.all()
     queryset = DeviceType.objects.all()
@@ -1081,9 +1094,9 @@ class PlatformTestCase(TestCase):
         Manufacturer.objects.bulk_create(manufacturers)
         Manufacturer.objects.bulk_create(manufacturers)
 
 
         platforms = (
         platforms = (
-            Platform(name='Platform 1', slug='platform-1', manufacturer=manufacturers[0], napalm_driver='driver-1'),
-            Platform(name='Platform 2', slug='platform-2', manufacturer=manufacturers[1], napalm_driver='driver-2'),
-            Platform(name='Platform 3', slug='platform-3', manufacturer=manufacturers[2], napalm_driver='driver-3'),
+            Platform(name='Platform 1', slug='platform-1', manufacturer=manufacturers[0], napalm_driver='driver-1', description='A'),
+            Platform(name='Platform 2', slug='platform-2', manufacturer=manufacturers[1], napalm_driver='driver-2', description='B'),
+            Platform(name='Platform 3', slug='platform-3', manufacturer=manufacturers[2], napalm_driver='driver-3', description='C'),
         )
         )
         Platform.objects.bulk_create(platforms)
         Platform.objects.bulk_create(platforms)
 
 
@@ -1100,6 +1113,10 @@ class PlatformTestCase(TestCase):
         params = {'slug': ['platform-1', 'platform-2']}
         params = {'slug': ['platform-1', 'platform-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_napalm_driver(self):
     def test_napalm_driver(self):
         params = {'napalm_driver': ['driver-1', 'driver-2']}
         params = {'napalm_driver': ['driver-1', 'driver-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

+ 20 - 20
netbox/dcim/tests/test_views.py

@@ -46,13 +46,14 @@ class RegionTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
             'name': 'Region X',
             'name': 'Region X',
             'slug': 'region-x',
             'slug': 'region-x',
             'parent': regions[2].pk,
             'parent': regions[2].pk,
+            'description': 'A new region',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Region 4,region-4",
-            "Region 5,region-5",
-            "Region 6,region-6",
+            "name,slug,description",
+            "Region 4,region-4,Fourth region",
+            "Region 5,region-5,Fifth region",
+            "Region 6,region-6,Sixth region",
         )
         )
 
 
 
 
@@ -134,13 +135,14 @@ class RackGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
             'name': 'Rack Group X',
             'name': 'Rack Group X',
             'slug': 'rack-group-x',
             'slug': 'rack-group-x',
             'site': site.pk,
             'site': site.pk,
+            'description': 'A new rack group',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "site,name,slug",
-            "Site 1,Rack Group 4,rack-group-4",
-            "Site 1,Rack Group 5,rack-group-5",
-            "Site 1,Rack Group 6,rack-group-6",
+            "site,name,slug,description",
+            "Site 1,Rack Group 4,rack-group-4,Fourth rack group",
+            "Site 1,Rack Group 5,rack-group-5,Fifth rack group",
+            "Site 1,Rack Group 6,rack-group-6,Sixth rack group",
         )
         )
 
 
 
 
@@ -174,10 +176,6 @@ class RackRoleTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
 class RackReservationTestCase(ViewTestCases.PrimaryObjectViewTestCase):
 class RackReservationTestCase(ViewTestCases.PrimaryObjectViewTestCase):
     model = RackReservation
     model = RackReservation
 
 
-    # Disable inapplicable tests
-    test_get_object = None
-    test_create_object = None
-
     @classmethod
     @classmethod
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
@@ -309,13 +307,14 @@ class ManufacturerTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
         cls.form_data = {
         cls.form_data = {
             'name': 'Manufacturer X',
             'name': 'Manufacturer X',
             'slug': 'manufacturer-x',
             'slug': 'manufacturer-x',
+            'description': 'A new manufacturer',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Manufacturer 4,manufacturer-4",
-            "Manufacturer 5,manufacturer-5",
-            "Manufacturer 6,manufacturer-6",
+            "name,slug,description",
+            "Manufacturer 4,manufacturer-4,Fourth manufacturer",
+            "Manufacturer 5,manufacturer-5,Fifth manufacturer",
+            "Manufacturer 6,manufacturer-6,Sixth manufacturer",
         )
         )
 
 
 
 
@@ -868,13 +867,14 @@ class PlatformTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
             'manufacturer': manufacturer.pk,
             'manufacturer': manufacturer.pk,
             'napalm_driver': 'junos',
             'napalm_driver': 'junos',
             'napalm_args': None,
             'napalm_args': None,
+            'description': 'A new platform',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Platform 4,platform-4",
-            "Platform 5,platform-5",
-            "Platform 6,platform-6",
+            "name,slug,description",
+            "Platform 4,platform-4,Fourth platform",
+            "Platform 5,platform-5,Fifth platform",
+            "Platform 6,platform-6,Sixth platform",
         )
         )
 
 
 
 

+ 2 - 3
netbox/dcim/urls.py

@@ -2,7 +2,6 @@ from django.urls import path
 
 
 from extras.views import ObjectChangeLogView, ImageAttachmentEditView
 from extras.views import ObjectChangeLogView, ImageAttachmentEditView
 from ipam.views import ServiceCreateView
 from ipam.views import ServiceCreateView
-from secrets.views import secret_add
 from . import views
 from . import views
 from .models import (
 from .models import (
     Cable, ConsolePort, ConsoleServerPort, Device, DeviceRole, DeviceType, FrontPort, Interface, Manufacturer, Platform,
     Cable, ConsolePort, ConsoleServerPort, Device, DeviceRole, DeviceType, FrontPort, Interface, Manufacturer, Platform,
@@ -51,9 +50,11 @@ urlpatterns = [
 
 
     # Rack reservations
     # Rack reservations
     path('rack-reservations/', views.RackReservationListView.as_view(), name='rackreservation_list'),
     path('rack-reservations/', views.RackReservationListView.as_view(), name='rackreservation_list'),
+    path('rack-reservations/add/', views.RackReservationCreateView.as_view(), name='rackreservation_add'),
     path('rack-reservations/import/', views.RackReservationImportView.as_view(), name='rackreservation_import'),
     path('rack-reservations/import/', views.RackReservationImportView.as_view(), name='rackreservation_import'),
     path('rack-reservations/edit/', views.RackReservationBulkEditView.as_view(), name='rackreservation_bulk_edit'),
     path('rack-reservations/edit/', views.RackReservationBulkEditView.as_view(), name='rackreservation_bulk_edit'),
     path('rack-reservations/delete/', views.RackReservationBulkDeleteView.as_view(), name='rackreservation_bulk_delete'),
     path('rack-reservations/delete/', views.RackReservationBulkDeleteView.as_view(), name='rackreservation_bulk_delete'),
+    path('rack-reservations/<int:pk>/', views.RackReservationView.as_view(), name='rackreservation'),
     path('rack-reservations/<int:pk>/edit/', views.RackReservationEditView.as_view(), name='rackreservation_edit'),
     path('rack-reservations/<int:pk>/edit/', views.RackReservationEditView.as_view(), name='rackreservation_edit'),
     path('rack-reservations/<int:pk>/delete/', views.RackReservationDeleteView.as_view(), name='rackreservation_delete'),
     path('rack-reservations/<int:pk>/delete/', views.RackReservationDeleteView.as_view(), name='rackreservation_delete'),
     path('rack-reservations/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='rackreservation_changelog', kwargs={'model': RackReservation}),
     path('rack-reservations/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='rackreservation_changelog', kwargs={'model': RackReservation}),
@@ -69,7 +70,6 @@ urlpatterns = [
     path('racks/<int:pk>/edit/', views.RackEditView.as_view(), name='rack_edit'),
     path('racks/<int:pk>/edit/', views.RackEditView.as_view(), name='rack_edit'),
     path('racks/<int:pk>/delete/', views.RackDeleteView.as_view(), name='rack_delete'),
     path('racks/<int:pk>/delete/', views.RackDeleteView.as_view(), name='rack_delete'),
     path('racks/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='rack_changelog', kwargs={'model': Rack}),
     path('racks/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='rack_changelog', kwargs={'model': Rack}),
-    path('racks/<int:rack>/reservations/add/', views.RackReservationCreateView.as_view(), name='rack_add_reservation'),
     path('racks/<int:object_id>/images/add/', ImageAttachmentEditView.as_view(), name='rack_add_image', kwargs={'model': Rack}),
     path('racks/<int:object_id>/images/add/', ImageAttachmentEditView.as_view(), name='rack_add_image', kwargs={'model': Rack}),
 
 
     # Manufacturers
     # Manufacturers
@@ -179,7 +179,6 @@ urlpatterns = [
     path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
     path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
     path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
     path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
     path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),
     path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),
-    path('devices/<int:pk>/add-secret/', secret_add, name='device_addsecret'),
     path('devices/<int:device>/services/assign/', ServiceCreateView.as_view(), name='device_service_assign'),
     path('devices/<int:device>/services/assign/', ServiceCreateView.as_view(), name='device_service_assign'),
     path('devices/<int:object_id>/images/add/', ImageAttachmentEditView.as_view(), name='device_add_image', kwargs={'model': Device}),
     path('devices/<int:object_id>/images/add/', ImageAttachmentEditView.as_view(), name='device_add_image', kwargs={'model': Device}),
 
 

+ 17 - 7
netbox/dcim/views.py

@@ -479,20 +479,32 @@ class RackReservationListView(PermissionRequiredMixin, ObjectListView):
     action_buttons = ('export',)
     action_buttons = ('export',)
 
 
 
 
+class RackReservationView(PermissionRequiredMixin, View):
+    permission_required = 'dcim.view_rackreservation'
+
+    def get(self, request, pk):
+
+        rackreservation = get_object_or_404(RackReservation.objects.prefetch_related('rack'), pk=pk)
+
+        return render(request, 'dcim/rackreservation.html', {
+            'rackreservation': rackreservation,
+        })
+
+
 class RackReservationCreateView(PermissionRequiredMixin, ObjectEditView):
 class RackReservationCreateView(PermissionRequiredMixin, ObjectEditView):
     permission_required = 'dcim.add_rackreservation'
     permission_required = 'dcim.add_rackreservation'
     model = RackReservation
     model = RackReservation
     model_form = forms.RackReservationForm
     model_form = forms.RackReservationForm
+    template_name = 'dcim/rackreservation_edit.html'
+    default_return_url = 'dcim:rackreservation_list'
 
 
     def alter_obj(self, obj, request, args, kwargs):
     def alter_obj(self, obj, request, args, kwargs):
         if not obj.pk:
         if not obj.pk:
-            obj.rack = get_object_or_404(Rack, pk=kwargs['rack'])
+            if 'rack' in request.GET:
+                obj.rack = get_object_or_404(Rack, pk=request.GET.get('rack'))
             obj.user = request.user
             obj.user = request.user
         return obj
         return obj
 
 
-    def get_return_url(self, request, obj):
-        return obj.rack.get_absolute_url()
-
 
 
 class RackReservationEditView(RackReservationCreateView):
 class RackReservationEditView(RackReservationCreateView):
     permission_required = 'dcim.change_rackreservation'
     permission_required = 'dcim.change_rackreservation'
@@ -501,9 +513,7 @@ class RackReservationEditView(RackReservationCreateView):
 class RackReservationDeleteView(PermissionRequiredMixin, ObjectDeleteView):
 class RackReservationDeleteView(PermissionRequiredMixin, ObjectDeleteView):
     permission_required = 'dcim.delete_rackreservation'
     permission_required = 'dcim.delete_rackreservation'
     model = RackReservation
     model = RackReservation
-
-    def get_return_url(self, request, obj):
-        return obj.rack.get_absolute_url()
+    default_return_url = 'dcim:rackreservation_list'
 
 
 
 
 class RackReservationImportView(PermissionRequiredMixin, BulkImportView):
 class RackReservationImportView(PermissionRequiredMixin, BulkImportView):

+ 4 - 3
netbox/extras/api/serializers.py

@@ -13,6 +13,7 @@ from extras.constants import *
 from extras.models import (
 from extras.models import (
     ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, Tag,
     ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, Tag,
 )
 )
+from extras.utils import FeatureQuerySet
 from tenancy.api.nested_serializers import NestedTenantSerializer, NestedTenantGroupSerializer
 from tenancy.api.nested_serializers import NestedTenantSerializer, NestedTenantGroupSerializer
 from tenancy.models import Tenant, TenantGroup
 from tenancy.models import Tenant, TenantGroup
 from users.api.nested_serializers import NestedUserSerializer
 from users.api.nested_serializers import NestedUserSerializer
@@ -31,7 +32,7 @@ from .nested_serializers import *
 
 
 class GraphSerializer(ValidatedModelSerializer):
 class GraphSerializer(ValidatedModelSerializer):
     type = ContentTypeField(
     type = ContentTypeField(
-        queryset=ContentType.objects.filter(GRAPH_MODELS),
+        queryset=ContentType.objects.filter(FeatureQuerySet('graphs').get_queryset()),
     )
     )
 
 
     class Meta:
     class Meta:
@@ -67,7 +68,7 @@ class RenderedGraphSerializer(serializers.ModelSerializer):
 
 
 class ExportTemplateSerializer(ValidatedModelSerializer):
 class ExportTemplateSerializer(ValidatedModelSerializer):
     content_type = ContentTypeField(
     content_type = ContentTypeField(
-        queryset=ContentType.objects.filter(EXPORTTEMPLATE_MODELS),
+        queryset=ContentType.objects.filter(FeatureQuerySet('export_templates').get_queryset()),
     )
     )
     template_language = ChoiceField(
     template_language = ChoiceField(
         choices=TemplateLanguageChoices,
         choices=TemplateLanguageChoices,
@@ -91,7 +92,7 @@ class TagSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = Tag
         model = Tag
-        fields = ['id', 'name', 'slug', 'color', 'comments', 'tagged_items']
+        fields = ['id', 'name', 'slug', 'color', 'description', 'tagged_items']
 
 
 
 
 #
 #

+ 0 - 3
netbox/extras/api/urls.py

@@ -14,9 +14,6 @@ class ExtrasRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = ExtrasRootView
 router.APIRootView = ExtrasRootView
 
 
-# Field choices
-router.register('_choices', views.ExtrasFieldChoicesViewSet, basename='field-choice')
-
 # Custom field choices
 # Custom field choices
 router.register('_custom_field_choices', views.CustomFieldChoicesViewSet, basename='custom-field-choice')
 router.register('_custom_field_choices', views.CustomFieldChoicesViewSet, basename='custom-field-choice')
 
 

+ 1 - 13
netbox/extras/api/views.py

@@ -15,22 +15,10 @@ from extras.models import (
 )
 )
 from extras.reports import get_report, get_reports
 from extras.reports import get_report, get_reports
 from extras.scripts import get_script, get_scripts, run_script
 from extras.scripts import get_script, get_scripts, run_script
-from utilities.api import FieldChoicesViewSet, IsAuthenticatedOrLoginNotRequired, ModelViewSet
+from utilities.api import IsAuthenticatedOrLoginNotRequired, ModelViewSet
 from . import serializers
 from . import serializers
 
 
 
 
-#
-# Field choices
-#
-
-class ExtrasFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = (
-        (serializers.ExportTemplateSerializer, ['template_language']),
-        (serializers.GraphSerializer, ['type', 'template_language']),
-        (serializers.ObjectChangeSerializer, ['action']),
-    )
-
-
 #
 #
 # Custom field choices
 # Custom field choices
 #
 #

+ 9 - 172
netbox/extras/constants.py

@@ -1,129 +1,3 @@
-from django.db.models import Q
-
-
-# Models which support custom fields
-CUSTOMFIELD_MODELS = Q(
-    Q(app_label='circuits', model__in=[
-        'circuit',
-        'provider',
-    ]) |
-    Q(app_label='dcim', model__in=[
-        'device',
-        'devicetype',
-        'powerfeed',
-        'rack',
-        'site',
-    ]) |
-    Q(app_label='ipam', model__in=[
-        'aggregate',
-        'ipaddress',
-        'prefix',
-        'service',
-        'vlan',
-        'vrf',
-    ]) |
-    Q(app_label='secrets', model__in=[
-        'secret',
-    ]) |
-    Q(app_label='tenancy', model__in=[
-        'tenant',
-    ]) |
-    Q(app_label='virtualization', model__in=[
-        'cluster',
-        'virtualmachine',
-    ])
-)
-
-# Custom links
-CUSTOMLINK_MODELS = Q(
-    Q(app_label='circuits', model__in=[
-        'circuit',
-        'provider',
-    ]) |
-    Q(app_label='dcim', model__in=[
-        'cable',
-        'device',
-        'devicetype',
-        'powerpanel',
-        'powerfeed',
-        'rack',
-        'site',
-    ]) |
-    Q(app_label='ipam', model__in=[
-        'aggregate',
-        'ipaddress',
-        'prefix',
-        'service',
-        'vlan',
-        'vrf',
-    ]) |
-    Q(app_label='secrets', model__in=[
-        'secret',
-    ]) |
-    Q(app_label='tenancy', model__in=[
-        'tenant',
-    ]) |
-    Q(app_label='virtualization', model__in=[
-        'cluster',
-        'virtualmachine',
-    ])
-)
-
-# Models which can have Graphs associated with them
-GRAPH_MODELS = Q(
-    Q(app_label='circuits', model__in=[
-        'provider',
-    ]) |
-    Q(app_label='dcim', model__in=[
-        'device',
-        'interface',
-        'site',
-    ])
-)
-
-# Models which support export templates
-EXPORTTEMPLATE_MODELS = Q(
-    Q(app_label='circuits', model__in=[
-        'circuit',
-        'provider',
-    ]) |
-    Q(app_label='dcim', model__in=[
-        'cable',
-        'consoleport',
-        'device',
-        'devicetype',
-        'interface',
-        'inventoryitem',
-        'manufacturer',
-        'powerpanel',
-        'powerport',
-        'powerfeed',
-        'rack',
-        'rackgroup',
-        'region',
-        'site',
-        'virtualchassis',
-    ]) |
-    Q(app_label='ipam', model__in=[
-        'aggregate',
-        'ipaddress',
-        'prefix',
-        'service',
-        'vlan',
-        'vrf',
-    ]) |
-    Q(app_label='secrets', model__in=[
-        'secret',
-    ]) |
-    Q(app_label='tenancy', model__in=[
-        'tenant',
-    ]) |
-    Q(app_label='virtualization', model__in=[
-        'cluster',
-        'virtualmachine',
-    ])
-)
-
 # Report logging levels
 # Report logging levels
 LOG_DEFAULT = 0
 LOG_DEFAULT = 0
 LOG_SUCCESS = 10
 LOG_SUCCESS = 10
@@ -138,51 +12,14 @@ LOG_LEVEL_CODES = {
     LOG_FAILURE: 'failure',
     LOG_FAILURE: 'failure',
 }
 }
 
 
+# Webhook content types
 HTTP_CONTENT_TYPE_JSON = 'application/json'
 HTTP_CONTENT_TYPE_JSON = 'application/json'
 
 
-# Models which support registered webhooks
-WEBHOOK_MODELS = Q(
-    Q(app_label='circuits', model__in=[
-        'circuit',
-        'provider',
-    ]) |
-    Q(app_label='dcim', model__in=[
-        'cable',
-        'consoleport',
-        'consoleserverport',
-        'device',
-        'devicebay',
-        'devicetype',
-        'frontport',
-        'interface',
-        'inventoryitem',
-        'manufacturer',
-        'poweroutlet',
-        'powerpanel',
-        'powerport',
-        'powerfeed',
-        'rack',
-        'rearport',
-        'region',
-        'site',
-        'virtualchassis',
-    ]) |
-    Q(app_label='ipam', model__in=[
-        'aggregate',
-        'ipaddress',
-        'prefix',
-        'service',
-        'vlan',
-        'vrf',
-    ]) |
-    Q(app_label='secrets', model__in=[
-        'secret',
-    ]) |
-    Q(app_label='tenancy', model__in=[
-        'tenant',
-    ]) |
-    Q(app_label='virtualization', model__in=[
-        'cluster',
-        'virtualmachine',
-    ])
-)
+# Registerable extras features
+EXTRAS_FEATURES = [
+    'custom_fields',
+    'custom_links',
+    'graphs',
+    'export_templates',
+    'webhooks'
+]

+ 6 - 3
netbox/extras/forms.py

@@ -144,12 +144,11 @@ class CustomFieldFilterForm(forms.Form):
 
 
 class TagForm(BootstrapMixin, forms.ModelForm):
 class TagForm(BootstrapMixin, forms.ModelForm):
     slug = SlugField()
     slug = SlugField()
-    comments = CommentField()
 
 
     class Meta:
     class Meta:
         model = Tag
         model = Tag
         fields = [
         fields = [
-            'name', 'slug', 'color', 'comments'
+            'name', 'slug', 'color', 'description'
         ]
         ]
 
 
 
 
@@ -181,9 +180,13 @@ class TagBulkEditForm(BootstrapMixin, BulkEditForm):
         required=False,
         required=False,
         widget=ColorSelect()
         widget=ColorSelect()
     )
     )
+    description = forms.CharField(
+        max_length=200,
+        required=False
+    )
 
 
     class Meta:
     class Meta:
-        nullable_fields = []
+        nullable_fields = ['description']
 
 
 
 
 #
 #

+ 23 - 0
netbox/extras/migrations/0039_standardize_description.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0038_webhook_template_support'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='configcontext',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='customfield',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 40 - 0
netbox/extras/migrations/0039_update_features_content_types.py

@@ -0,0 +1,40 @@
+# Generated by Django 2.2.11 on 2020-03-14 06:50
+
+from django.db import migrations, models
+import django.db.models.deletion
+import extras.utils
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0038_webhook_template_support'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='customfield',
+            name='obj_type',
+            field=models.ManyToManyField(limit_choices_to=extras.utils.FeatureQuerySet('custom_fields'), related_name='custom_fields', to='contenttypes.ContentType'),
+        ),
+        migrations.AlterField(
+            model_name='customlink',
+            name='content_type',
+            field=models.ForeignKey(limit_choices_to=extras.utils.FeatureQuerySet('custom_links'), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
+        ),
+        migrations.AlterField(
+            model_name='exporttemplate',
+            name='content_type',
+            field=models.ForeignKey(limit_choices_to=extras.utils.FeatureQuerySet('export_templates'), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
+        ),
+        migrations.AlterField(
+            model_name='graph',
+            name='type',
+            field=models.ForeignKey(limit_choices_to=extras.utils.FeatureQuerySet('graphs'), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
+        ),
+        migrations.AlterField(
+            model_name='webhook',
+            name='obj_type',
+            field=models.ManyToManyField(limit_choices_to=extras.utils.FeatureQuerySet('webhooks'), related_name='webhooks', to='contenttypes.ContentType'),
+        ),
+    ]

+ 23 - 0
netbox/extras/migrations/0040_tag_description.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:46
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0039_standardize_description'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='tag',
+            name='comments',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.RenameField(
+            model_name='tag',
+            old_name='comments',
+            new_name='description',
+        ),
+    ]

+ 10 - 11
netbox/extras/models.py

@@ -22,6 +22,7 @@ from utilities.utils import deepmerge, render_jinja2
 from .choices import *
 from .choices import *
 from .constants import *
 from .constants import *
 from .querysets import ConfigContextQuerySet
 from .querysets import ConfigContextQuerySet
+from .utils import FeatureQuerySet
 
 
 
 
 __all__ = (
 __all__ = (
@@ -58,7 +59,7 @@ class Webhook(models.Model):
         to=ContentType,
         to=ContentType,
         related_name='webhooks',
         related_name='webhooks',
         verbose_name='Object types',
         verbose_name='Object types',
-        limit_choices_to=WEBHOOK_MODELS,
+        limit_choices_to=FeatureQuerySet('webhooks'),
         help_text="The object(s) to which this Webhook applies."
         help_text="The object(s) to which this Webhook applies."
     )
     )
     name = models.CharField(
     name = models.CharField(
@@ -223,7 +224,7 @@ class CustomField(models.Model):
         to=ContentType,
         to=ContentType,
         related_name='custom_fields',
         related_name='custom_fields',
         verbose_name='Object(s)',
         verbose_name='Object(s)',
-        limit_choices_to=CUSTOMFIELD_MODELS,
+        limit_choices_to=FeatureQuerySet('custom_fields'),
         help_text='The object(s) to which this field applies.'
         help_text='The object(s) to which this field applies.'
     )
     )
     type = models.CharField(
     type = models.CharField(
@@ -242,7 +243,7 @@ class CustomField(models.Model):
                   'the field\'s name will be used)'
                   'the field\'s name will be used)'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     required = models.BooleanField(
     required = models.BooleanField(
@@ -470,7 +471,7 @@ class CustomLink(models.Model):
     content_type = models.ForeignKey(
     content_type = models.ForeignKey(
         to=ContentType,
         to=ContentType,
         on_delete=models.CASCADE,
         on_delete=models.CASCADE,
-        limit_choices_to=CUSTOMLINK_MODELS
+        limit_choices_to=FeatureQuerySet('custom_links')
     )
     )
     name = models.CharField(
     name = models.CharField(
         max_length=100,
         max_length=100,
@@ -518,7 +519,7 @@ class Graph(models.Model):
     type = models.ForeignKey(
     type = models.ForeignKey(
         to=ContentType,
         to=ContentType,
         on_delete=models.CASCADE,
         on_delete=models.CASCADE,
-        limit_choices_to=GRAPH_MODELS
+        limit_choices_to=FeatureQuerySet('graphs')
     )
     )
     weight = models.PositiveSmallIntegerField(
     weight = models.PositiveSmallIntegerField(
         default=1000
         default=1000
@@ -550,7 +551,6 @@ class Graph(models.Model):
     def embed_url(self, obj):
     def embed_url(self, obj):
         context = {'obj': obj}
         context = {'obj': obj}
 
 
-        # TODO: Remove in v2.8
         if self.template_language == TemplateLanguageChoices.LANGUAGE_DJANGO:
         if self.template_language == TemplateLanguageChoices.LANGUAGE_DJANGO:
             template = Template(self.source)
             template = Template(self.source)
             return template.render(Context(context))
             return template.render(Context(context))
@@ -564,7 +564,6 @@ class Graph(models.Model):
 
 
         context = {'obj': obj}
         context = {'obj': obj}
 
 
-        # TODO: Remove in v2.8
         if self.template_language == TemplateLanguageChoices.LANGUAGE_DJANGO:
         if self.template_language == TemplateLanguageChoices.LANGUAGE_DJANGO:
             template = Template(self.link)
             template = Template(self.link)
             return template.render(Context(context))
             return template.render(Context(context))
@@ -581,7 +580,7 @@ class ExportTemplate(models.Model):
     content_type = models.ForeignKey(
     content_type = models.ForeignKey(
         to=ContentType,
         to=ContentType,
         on_delete=models.CASCADE,
         on_delete=models.CASCADE,
-        limit_choices_to=EXPORTTEMPLATE_MODELS
+        limit_choices_to=FeatureQuerySet('export_templates')
     )
     )
     name = models.CharField(
     name = models.CharField(
         max_length=100
         max_length=100
@@ -766,7 +765,7 @@ class ConfigContext(models.Model):
         default=1000
         default=1000
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     is_active = models.BooleanField(
     is_active = models.BooleanField(
@@ -1053,9 +1052,9 @@ class Tag(TagBase, ChangeLoggedModel):
     color = ColorField(
     color = ColorField(
         default='9e9e9e'
         default='9e9e9e'
     )
     )
-    comments = models.TextField(
+    description = models.CharField(
+        max_length=200,
         blank=True,
         blank=True,
-        default=''
     )
     )
 
 
     def get_absolute_url(self):
     def get_absolute_url(self):

+ 1 - 1
netbox/extras/tables.py

@@ -77,7 +77,7 @@ class TagTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = Tag
         model = Tag
-        fields = ('pk', 'name', 'items', 'slug', 'color', 'actions')
+        fields = ('pk', 'name', 'items', 'slug', 'color', 'description', 'actions')
 
 
 
 
 class TaggedItemTable(BaseTable):
 class TaggedItemTable(BaseTable):

+ 2 - 24
netbox/extras/tests/test_api.py

@@ -7,12 +7,11 @@ from rest_framework import status
 
 
 from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Platform, Rack, RackGroup, RackRole, Region, Site
 from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Platform, Rack, RackGroup, RackRole, Region, Site
 from extras.api.views import ScriptViewSet
 from extras.api.views import ScriptViewSet
-from extras.choices import *
-from extras.constants import GRAPH_MODELS
 from extras.models import ConfigContext, Graph, ExportTemplate, Tag
 from extras.models import ConfigContext, Graph, ExportTemplate, Tag
 from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
 from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
+from extras.utils import FeatureQuerySet
 from tenancy.models import Tenant, TenantGroup
 from tenancy.models import Tenant, TenantGroup
-from utilities.testing import APITestCase, choices_to_dict
+from utilities.testing import APITestCase
 
 
 
 
 class AppTest(APITestCase):
 class AppTest(APITestCase):
@@ -24,27 +23,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('extras-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
-        # ExportTemplate
-        self.assertEqual(choices_to_dict(response.data.get('export-template:template_language')), TemplateLanguageChoices.as_dict())
-
-        # Graph
-        content_types = ContentType.objects.filter(GRAPH_MODELS)
-        graph_type_choices = {
-            "{}.{}".format(ct.app_label, ct.model): str(ct) for ct in content_types
-        }
-        self.assertEqual(choices_to_dict(response.data.get('graph:type')), graph_type_choices)
-        self.assertEqual(choices_to_dict(response.data.get('graph:template_language')), TemplateLanguageChoices.as_dict())
-
-        # ObjectChange
-        self.assertEqual(choices_to_dict(response.data.get('object-change:action')), ObjectChangeActionChoices.as_dict())
-
 
 
 class GraphTest(APITestCase):
 class GraphTest(APITestCase):
 
 

+ 3 - 4
netbox/extras/tests/test_filters.py

@@ -3,8 +3,8 @@ from django.test import TestCase
 
 
 from dcim.models import DeviceRole, Platform, Region, Site
 from dcim.models import DeviceRole, Platform, Region, Site
 from extras.choices import *
 from extras.choices import *
-from extras.constants import GRAPH_MODELS
 from extras.filters import *
 from extras.filters import *
+from extras.utils import FeatureQuerySet
 from extras.models import ConfigContext, ExportTemplate, Graph
 from extras.models import ConfigContext, ExportTemplate, Graph
 from tenancy.models import Tenant, TenantGroup
 from tenancy.models import Tenant, TenantGroup
 from virtualization.models import Cluster, ClusterGroup, ClusterType
 from virtualization.models import Cluster, ClusterGroup, ClusterType
@@ -18,7 +18,7 @@ class GraphTestCase(TestCase):
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         # Get the first three available types
         # Get the first three available types
-        content_types = ContentType.objects.filter(GRAPH_MODELS)[:3]
+        content_types = ContentType.objects.filter(FeatureQuerySet('graphs').get_queryset())[:3]
 
 
         graphs = (
         graphs = (
             Graph(name='Graph 1', type=content_types[0], template_language=TemplateLanguageChoices.LANGUAGE_DJANGO, source='http://example.com/1'),
             Graph(name='Graph 1', type=content_types[0], template_language=TemplateLanguageChoices.LANGUAGE_DJANGO, source='http://example.com/1'),
@@ -32,11 +32,10 @@ class GraphTestCase(TestCase):
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
     def test_type(self):
     def test_type(self):
-        content_type = ContentType.objects.filter(GRAPH_MODELS).first()
+        content_type = ContentType.objects.filter(FeatureQuerySet('graphs').get_queryset()).first()
         params = {'type': content_type.pk}
         params = {'type': content_type.pk}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
 
 
-    # TODO: Remove in v2.8
     def test_template_language(self):
     def test_template_language(self):
         params = {'template_language': TemplateLanguageChoices.LANGUAGE_JINJA2}
         params = {'template_language': TemplateLanguageChoices.LANGUAGE_JINJA2}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

+ 68 - 0
netbox/extras/utils.py

@@ -1,6 +1,12 @@
+import collections
+
+from django.db.models import Q
+from django.utils.deconstruct import deconstructible
 from taggit.managers import _TaggableManager
 from taggit.managers import _TaggableManager
 from utilities.querysets import DummyQuerySet
 from utilities.querysets import DummyQuerySet
 
 
+from extras.constants import EXTRAS_FEATURES
+
 
 
 def is_taggable(obj):
 def is_taggable(obj):
     """
     """
@@ -13,3 +19,65 @@ def is_taggable(obj):
         if isinstance(obj.tags, DummyQuerySet):
         if isinstance(obj.tags, DummyQuerySet):
             return True
             return True
     return False
     return False
+
+
+#
+# Dynamic feature registration
+#
+
+class Registry:
+    """
+    The registry is a place to hook into for data storage across components
+    """
+
+    def add_store(self, store_name, initial_value=None):
+        """
+        Given the name of some new data parameter and an optional initial value, setup the registry store
+        """
+        if not hasattr(Registry, store_name):
+            setattr(Registry, store_name, initial_value)
+
+
+registry = Registry()
+
+
+@deconstructible
+class FeatureQuerySet:
+    """
+    Helper class that delays evaluation of the registry contents for the functionaility store
+    until it has been populated.
+    """
+
+    def __init__(self, feature):
+        self.feature = feature
+
+    def __call__(self):
+        return self.get_queryset()
+
+    def get_queryset(self):
+        """
+        Given an extras feature, return a Q object for content type lookup
+        """
+        query = Q()
+        for app_label, models in registry.model_feature_store[self.feature].items():
+            query |= Q(app_label=app_label, model__in=models)
+
+        return query
+
+
+registry.add_store('model_feature_store', {f: collections.defaultdict(list) for f in EXTRAS_FEATURES})
+
+
+def extras_features(*features):
+    """
+    Decorator used to register extras provided features to a model
+    """
+    def wrapper(model_class):
+        for feature in features:
+            if feature in EXTRAS_FEATURES:
+                app_label, model_name = model_class._meta.label_lower.split('.')
+                registry.model_feature_store[feature][app_label].append(model_name)
+            else:
+                raise ValueError('{} is not a valid extras feature!'.format(feature))
+        return model_class
+    return wrapper

+ 2 - 1
netbox/extras/webhooks.py

@@ -8,6 +8,7 @@ from extras.models import Webhook
 from utilities.api import get_serializer_for_model
 from utilities.api import get_serializer_for_model
 from .choices import *
 from .choices import *
 from .constants import *
 from .constants import *
+from .utils import FeatureQuerySet
 
 
 
 
 def generate_signature(request_body, secret):
 def generate_signature(request_body, secret):
@@ -29,7 +30,7 @@ def enqueue_webhooks(instance, user, request_id, action):
     """
     """
     obj_type = ContentType.objects.get_for_model(instance.__class__)
     obj_type = ContentType.objects.get_for_model(instance.__class__)
 
 
-    webhook_models = ContentType.objects.filter(WEBHOOK_MODELS)
+    webhook_models = ContentType.objects.filter(FeatureQuerySet('webhooks').get_queryset())
     if obj_type not in webhook_models:
     if obj_type not in webhook_models:
         return
         return
 
 

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

@@ -45,7 +45,7 @@ class RIRSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = RIR
         model = RIR
-        fields = ['id', 'name', 'slug', 'is_private', 'aggregate_count']
+        fields = ['id', 'name', 'slug', 'is_private', 'description', 'aggregate_count']
 
 
 
 
 class AggregateSerializer(TaggitSerializer, CustomFieldModelSerializer):
 class AggregateSerializer(TaggitSerializer, CustomFieldModelSerializer):
@@ -81,7 +81,7 @@ class VLANGroupSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = VLANGroup
         model = VLANGroup
-        fields = ['id', 'name', 'slug', 'site', 'vlan_count']
+        fields = ['id', 'name', 'slug', 'site', 'description', 'vlan_count']
         validators = []
         validators = []
 
 
     def validate(self, data):
     def validate(self, data):

+ 0 - 3
netbox/ipam/api/urls.py

@@ -14,9 +14,6 @@ class IPAMRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = IPAMRootView
 router.APIRootView = IPAMRootView
 
 
-# Field choices
-router.register('_choices', views.IPAMFieldChoicesViewSet, basename='field-choice')
-
 # VRFs
 # VRFs
 router.register('vrfs', views.VRFViewSet)
 router.register('vrfs', views.VRFViewSet)
 
 

+ 1 - 15
netbox/ipam/api/views.py

@@ -10,26 +10,12 @@ from rest_framework.response import Response
 from extras.api.views import CustomFieldModelViewSet
 from extras.api.views import CustomFieldModelViewSet
 from ipam import filters
 from ipam import filters
 from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
 from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
-from utilities.api import FieldChoicesViewSet, ModelViewSet
+from utilities.api import ModelViewSet
 from utilities.constants import ADVISORY_LOCK_KEYS
 from utilities.constants import ADVISORY_LOCK_KEYS
 from utilities.utils import get_subquery
 from utilities.utils import get_subquery
 from . import serializers
 from . import serializers
 
 
 
 
-#
-# Field choices
-#
-
-class IPAMFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = (
-        (serializers.AggregateSerializer, ['family']),
-        (serializers.PrefixSerializer, ['family', 'status']),
-        (serializers.IPAddressSerializer, ['family', 'status', 'role']),
-        (serializers.VLANSerializer, ['status']),
-        (serializers.ServiceSerializer, ['protocol']),
-    )
-
-
 #
 #
 # VRFs
 # VRFs
 #
 #

+ 2 - 2
netbox/ipam/filters.py

@@ -54,7 +54,7 @@ class RIRFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = RIR
         model = RIR
-        fields = ['name', 'slug', 'is_private']
+        fields = ['name', 'slug', 'is_private', 'description']
 
 
 
 
 class AggregateFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class AggregateFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
@@ -419,7 +419,7 @@ class VLANGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = VLANGroup
         model = VLANGroup
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class VLANFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class VLANFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):

+ 2 - 2
netbox/ipam/forms.py

@@ -119,7 +119,7 @@ class RIRForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = RIR
         model = RIR
         fields = [
         fields = [
-            'name', 'slug', 'is_private',
+            'name', 'slug', 'is_private', 'description',
         ]
         ]
 
 
 
 
@@ -1048,7 +1048,7 @@ class VLANGroupForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = VLANGroup
         model = VLANGroup
         fields = [
         fields = [
-            'site', 'name', 'slug',
+            'site', 'name', 'slug', 'description',
         ]
         ]
 
 
 
 

+ 58 - 0
netbox/ipam/migrations/0036_standardize_description.py

@@ -0,0 +1,58 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ipam', '0035_drop_ip_family'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='rir',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AddField(
+            model_name='vlangroup',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='aggregate',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='ipaddress',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='prefix',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='role',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='service',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='vlan',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='vrf',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 26 - 9
netbox/ipam/models.py

@@ -10,6 +10,7 @@ from taggit.managers import TaggableManager
 
 
 from dcim.models import Device, Interface
 from dcim.models import Device, Interface
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
+from extras.utils import extras_features
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from utilities.utils import serialize_object
 from utilities.utils import serialize_object
 from virtualization.models import VirtualMachine
 from virtualization.models import VirtualMachine
@@ -34,6 +35,7 @@ __all__ = (
 )
 )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class VRF(ChangeLoggedModel, CustomFieldModel):
 class VRF(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A virtual routing and forwarding (VRF) table represents a discrete layer three forwarding domain (e.g. a routing
     A virtual routing and forwarding (VRF) table represents a discrete layer three forwarding domain (e.g. a routing
@@ -63,7 +65,7 @@ class VRF(ChangeLoggedModel, CustomFieldModel):
         help_text='Prevent duplicate prefixes/IP addresses within this VRF'
         help_text='Prevent duplicate prefixes/IP addresses within this VRF'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(
@@ -123,8 +125,12 @@ class RIR(ChangeLoggedModel):
         verbose_name='Private',
         verbose_name='Private',
         help_text='IP space managed by this RIR is considered private'
         help_text='IP space managed by this RIR is considered private'
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug', 'is_private']
+    csv_headers = ['name', 'slug', 'is_private', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -142,9 +148,11 @@ class RIR(ChangeLoggedModel):
             self.name,
             self.name,
             self.slug,
             self.slug,
             self.is_private,
             self.is_private,
+            self.description,
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Aggregate(ChangeLoggedModel, CustomFieldModel):
 class Aggregate(ChangeLoggedModel, CustomFieldModel):
     """
     """
     An aggregate exists at the root level of the IP address space hierarchy in NetBox. Aggregates are used to organize
     An aggregate exists at the root level of the IP address space hierarchy in NetBox. Aggregates are used to organize
@@ -162,7 +170,7 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
         null=True
         null=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(
@@ -261,7 +269,7 @@ class Role(ChangeLoggedModel):
         default=1000
         default=1000
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True,
         blank=True,
     )
     )
 
 
@@ -282,6 +290,7 @@ class Role(ChangeLoggedModel):
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Prefix(ChangeLoggedModel, CustomFieldModel):
 class Prefix(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A Prefix represents an IPv4 or IPv6 network, including mask length. Prefixes can optionally be assigned to Sites and
     A Prefix represents an IPv4 or IPv6 network, including mask length. Prefixes can optionally be assigned to Sites and
@@ -342,7 +351,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
         help_text='All IP addresses within this prefix are considered usable'
         help_text='All IP addresses within this prefix are considered usable'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(
@@ -547,6 +556,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
             return int(float(child_count) / prefix_size * 100)
             return int(float(child_count) / prefix_size * 100)
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class IPAddress(ChangeLoggedModel, CustomFieldModel):
 class IPAddress(ChangeLoggedModel, CustomFieldModel):
     """
     """
     An IPAddress represents an individual IPv4 or IPv6 address and its mask. The mask length should match what is
     An IPAddress represents an individual IPv4 or IPv6 address and its mask. The mask length should match what is
@@ -612,7 +622,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
         help_text='Hostname or FQDN (not case-sensitive)'
         help_text='Hostname or FQDN (not case-sensitive)'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(
@@ -812,8 +822,12 @@ class VLANGroup(ChangeLoggedModel):
         blank=True,
         blank=True,
         null=True
         null=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug', 'site']
+    csv_headers = ['name', 'slug', 'site', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ('site', 'name', 'pk')  # (site, name) may be non-unique
         ordering = ('site', 'name', 'pk')  # (site, name) may be non-unique
@@ -835,6 +849,7 @@ class VLANGroup(ChangeLoggedModel):
             self.name,
             self.name,
             self.slug,
             self.slug,
             self.site.name if self.site else None,
             self.site.name if self.site else None,
+            self.description,
         )
         )
 
 
     def get_next_available_vid(self):
     def get_next_available_vid(self):
@@ -848,6 +863,7 @@ class VLANGroup(ChangeLoggedModel):
         return None
         return None
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class VLAN(ChangeLoggedModel, CustomFieldModel):
 class VLAN(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A VLAN is a distinct layer two forwarding domain identified by a 12-bit integer (1-4094). Each VLAN must be assigned
     A VLAN is a distinct layer two forwarding domain identified by a 12-bit integer (1-4094). Each VLAN must be assigned
@@ -898,7 +914,7 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
         null=True
         null=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(
@@ -972,6 +988,7 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
         ).distinct()
         ).distinct()
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Service(ChangeLoggedModel, CustomFieldModel):
 class Service(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A Service represents a layer-four service (e.g. HTTP or SSH) running on a Device or VirtualMachine. A Service may
     A Service represents a layer-four service (e.g. HTTP or SSH) running on a Device or VirtualMachine. A Service may
@@ -1010,7 +1027,7 @@ class Service(ChangeLoggedModel, CustomFieldModel):
         verbose_name='IP addresses'
         verbose_name='IP addresses'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
     custom_field_values = GenericRelation(
     custom_field_values = GenericRelation(

+ 2 - 2
netbox/ipam/tables.py

@@ -211,7 +211,7 @@ class RIRTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = RIR
         model = RIR
-        fields = ('pk', 'name', 'is_private', 'aggregate_count', 'actions')
+        fields = ('pk', 'name', 'is_private', 'aggregate_count', 'description', 'actions')
 
 
 
 
 class RIRDetailTable(RIRTable):
 class RIRDetailTable(RIRTable):
@@ -410,7 +410,7 @@ class VLANGroupTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = VLANGroup
         model = VLANGroup
-        fields = ('pk', 'name', 'site', 'vlan_count', 'slug', 'actions')
+        fields = ('pk', 'name', 'site', 'vlan_count', 'slug', 'description', 'actions')
 
 
 
 
 #
 #

+ 1 - 26
netbox/ipam/tests/test_api.py

@@ -7,7 +7,7 @@ from rest_framework import status
 from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
 from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
 from ipam.choices import *
 from ipam.choices import *
 from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
 from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
-from utilities.testing import APITestCase, choices_to_dict, disable_warnings
+from utilities.testing import APITestCase, disable_warnings
 
 
 
 
 class AppTest(APITestCase):
 class AppTest(APITestCase):
@@ -19,31 +19,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('ipam-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
-        # Aggregate
-        # self.assertEqual(choices_to_dict(response.data.get('aggregate:family')), )
-
-        # Prefix
-        # self.assertEqual(choices_to_dict(response.data.get('prefix:family')), )
-        self.assertEqual(choices_to_dict(response.data.get('prefix:status')), PrefixStatusChoices.as_dict())
-
-        # IPAddress
-        # self.assertEqual(choices_to_dict(response.data.get('ip-address:family')), )
-        self.assertEqual(choices_to_dict(response.data.get('ip-address:role')), IPAddressRoleChoices.as_dict())
-        self.assertEqual(choices_to_dict(response.data.get('ip-address:status')), IPAddressStatusChoices.as_dict())
-
-        # VLAN
-        self.assertEqual(choices_to_dict(response.data.get('vlan:status')), VLANStatusChoices.as_dict())
-
-        # Service
-        self.assertEqual(choices_to_dict(response.data.get('service:protocol')), ServiceProtocolChoices.as_dict())
-
 
 
 class VRFTest(APITestCase):
 class VRFTest(APITestCase):
 
 

+ 17 - 9
netbox/ipam/tests/test_filters.py

@@ -77,12 +77,12 @@ class RIRTestCase(TestCase):
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         rirs = (
         rirs = (
-            RIR(name='RIR 1', slug='rir-1', is_private=False),
-            RIR(name='RIR 2', slug='rir-2', is_private=False),
-            RIR(name='RIR 3', slug='rir-3', is_private=False),
-            RIR(name='RIR 4', slug='rir-4', is_private=True),
-            RIR(name='RIR 5', slug='rir-5', is_private=True),
-            RIR(name='RIR 6', slug='rir-6', is_private=True),
+            RIR(name='RIR 1', slug='rir-1', is_private=False, description='A'),
+            RIR(name='RIR 2', slug='rir-2', is_private=False, description='B'),
+            RIR(name='RIR 3', slug='rir-3', is_private=False, description='C'),
+            RIR(name='RIR 4', slug='rir-4', is_private=True, description='D'),
+            RIR(name='RIR 5', slug='rir-5', is_private=True, description='E'),
+            RIR(name='RIR 6', slug='rir-6', is_private=True, description='F'),
         )
         )
         RIR.objects.bulk_create(rirs)
         RIR.objects.bulk_create(rirs)
 
 
@@ -94,6 +94,10 @@ class RIRTestCase(TestCase):
         params = {'slug': ['rir-1', 'rir-2']}
         params = {'slug': ['rir-1', 'rir-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_is_private(self):
     def test_is_private(self):
         params = {'is_private': 'true'}
         params = {'is_private': 'true'}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
@@ -519,9 +523,9 @@ class VLANGroupTestCase(TestCase):
         Site.objects.bulk_create(sites)
         Site.objects.bulk_create(sites)
 
 
         vlan_groups = (
         vlan_groups = (
-            VLANGroup(name='VLAN Group 1', slug='vlan-group-1', site=sites[0]),
-            VLANGroup(name='VLAN Group 2', slug='vlan-group-2', site=sites[1]),
-            VLANGroup(name='VLAN Group 3', slug='vlan-group-3', site=sites[2]),
+            VLANGroup(name='VLAN Group 1', slug='vlan-group-1', site=sites[0], description='A'),
+            VLANGroup(name='VLAN Group 2', slug='vlan-group-2', site=sites[1], description='B'),
+            VLANGroup(name='VLAN Group 3', slug='vlan-group-3', site=sites[2], description='C'),
             VLANGroup(name='VLAN Group 4', slug='vlan-group-4', site=None),
             VLANGroup(name='VLAN Group 4', slug='vlan-group-4', site=None),
         )
         )
         VLANGroup.objects.bulk_create(vlan_groups)
         VLANGroup.objects.bulk_create(vlan_groups)
@@ -539,6 +543,10 @@ class VLANGroupTestCase(TestCase):
         params = {'slug': ['vlan-group-1', 'vlan-group-2']}
         params = {'slug': ['vlan-group-1', 'vlan-group-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_region(self):
     def test_region(self):
         regions = Region.objects.all()[:2]
         regions = Region.objects.all()[:2]
         params = {'region_id': [regions[0].pk, regions[1].pk]}
         params = {'region_id': [regions[0].pk, regions[1].pk]}

+ 10 - 8
netbox/ipam/tests/test_views.py

@@ -59,13 +59,14 @@ class RIRTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
             'name': 'RIR X',
             'name': 'RIR X',
             'slug': 'rir-x',
             'slug': 'rir-x',
             'is_private': True,
             'is_private': True,
+            'description': 'A new RIR',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "RIR 4,rir-4",
-            "RIR 5,rir-5",
-            "RIR 6,rir-6",
+            "name,slug,description",
+            "RIR 4,rir-4,Fourth RIR",
+            "RIR 5,rir-5,Fifth RIR",
+            "RIR 6,rir-6,Sixth RIR",
         )
         )
 
 
 
 
@@ -261,13 +262,14 @@ class VLANGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
             'name': 'VLAN Group X',
             'name': 'VLAN Group X',
             'slug': 'vlan-group-x',
             'slug': 'vlan-group-x',
             'site': site.pk,
             'site': site.pk,
+            'description': 'A new VLAN group',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "VLAN Group 4,vlan-group-4",
-            "VLAN Group 5,vlan-group-5",
-            "VLAN Group 6,vlan-group-6",
+            "name,slug,description",
+            "VLAN Group 4,vlan-group-4,Fourth VLAN group",
+            "VLAN Group 5,vlan-group-5,Fifth VLAN group",
+            "VLAN Group 6,vlan-group-6,Sixth VLAN group",
         )
         )
 
 
 
 

+ 2 - 8
netbox/netbox/settings.py

@@ -23,15 +23,9 @@ HOSTNAME = platform.node()
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 
 # Validate Python version
 # Validate Python version
-if platform.python_version_tuple() < ('3', '5'):
+if platform.python_version_tuple() < ('3', '6'):
     raise RuntimeError(
     raise RuntimeError(
-        "NetBox requires Python 3.5 or higher (current: Python {})".format(platform.python_version())
-    )
-elif platform.python_version_tuple() < ('3', '6'):
-    warnings.warn(
-        "Python 3.6 or higher will be required starting with NetBox v2.8 (current: Python {})".format(
-            platform.python_version()
-        )
+        "NetBox requires Python 3.6 or higher (current: Python {})".format(platform.python_version())
     )
     )
 
 
 
 

+ 0 - 3
netbox/secrets/api/urls.py

@@ -14,9 +14,6 @@ class SecretsRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = SecretsRootView
 router.APIRootView = SecretsRootView
 
 
-# Field choices
-router.register('_choices', views.SecretsFieldChoicesViewSet, basename='field-choice')
-
 # Secrets
 # Secrets
 router.register('secret-roles', views.SecretRoleViewSet)
 router.register('secret-roles', views.SecretRoleViewSet)
 router.register('secrets', views.SecretViewSet)
 router.register('secrets', views.SecretViewSet)

+ 1 - 9
netbox/secrets/api/views.py

@@ -11,7 +11,7 @@ from rest_framework.viewsets import ViewSet
 from secrets import filters
 from secrets import filters
 from secrets.exceptions import InvalidKey
 from secrets.exceptions import InvalidKey
 from secrets.models import Secret, SecretRole, SessionKey, UserKey
 from secrets.models import Secret, SecretRole, SessionKey, UserKey
-from utilities.api import FieldChoicesViewSet, ModelViewSet
+from utilities.api import ModelViewSet
 from . import serializers
 from . import serializers
 
 
 ERR_USERKEY_MISSING = "No UserKey found for the current user."
 ERR_USERKEY_MISSING = "No UserKey found for the current user."
@@ -20,14 +20,6 @@ ERR_PRIVKEY_MISSING = "Private key was not provided."
 ERR_PRIVKEY_INVALID = "Invalid private key."
 ERR_PRIVKEY_INVALID = "Invalid private key."
 
 
 
 
-#
-# Field choices
-#
-
-class SecretsFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = ()
-
-
 #
 #
 # Secret Roles
 # Secret Roles
 #
 #

+ 7 - 1
netbox/secrets/forms.py

@@ -71,6 +71,12 @@ class SecretRoleCSVForm(forms.ModelForm):
 #
 #
 
 
 class SecretForm(BootstrapMixin, CustomFieldModelForm):
 class SecretForm(BootstrapMixin, CustomFieldModelForm):
+    device = DynamicModelChoiceField(
+        queryset=Device.objects.all(),
+        widget=APISelect(
+            api_url="/api/dcim/devices/"
+        )
+    )
     plaintext = forms.CharField(
     plaintext = forms.CharField(
         max_length=SECRET_PLAINTEXT_MAX_LENGTH,
         max_length=SECRET_PLAINTEXT_MAX_LENGTH,
         required=False,
         required=False,
@@ -100,7 +106,7 @@ class SecretForm(BootstrapMixin, CustomFieldModelForm):
     class Meta:
     class Meta:
         model = Secret
         model = Secret
         fields = [
         fields = [
-            'role', 'name', 'plaintext', 'plaintext2', 'tags',
+            'device', 'role', 'name', 'plaintext', 'plaintext2', 'tags',
         ]
         ]
 
 
     def __init__(self, *args, **kwargs):
     def __init__(self, *args, **kwargs):

+ 18 - 0
netbox/secrets/migrations/0008_standardize_description.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('secrets', '0007_secretrole_description'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='secretrole',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 3 - 1
netbox/secrets/models.py

@@ -16,6 +16,7 @@ from taggit.managers import TaggableManager
 
 
 from dcim.models import Device
 from dcim.models import Device
 from extras.models import CustomFieldModel, TaggedItem
 from extras.models import CustomFieldModel, TaggedItem
+from extras.utils import extras_features
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from .exceptions import InvalidKey
 from .exceptions import InvalidKey
 from .hashers import SecretValidationHasher
 from .hashers import SecretValidationHasher
@@ -254,7 +255,7 @@ class SecretRole(ChangeLoggedModel):
         unique=True
         unique=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True,
         blank=True,
     )
     )
     users = models.ManyToManyField(
     users = models.ManyToManyField(
@@ -295,6 +296,7 @@ class SecretRole(ChangeLoggedModel):
         return user in self.users.all() or user.groups.filter(pk__in=self.groups.all()).exists()
         return user in self.users.all() or user.groups.filter(pk__in=self.groups.all()).exists()
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Secret(ChangeLoggedModel, CustomFieldModel):
 class Secret(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A Secret stores an AES256-encrypted copy of sensitive data, such as passwords or secret keys. An irreversible
     A Secret stores an AES256-encrypted copy of sensitive data, such as passwords or secret keys. An irreversible

+ 0 - 7
netbox/secrets/tests/test_api.py

@@ -19,13 +19,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('secrets-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
 
 
 class SecretRoleTest(APITestCase):
 class SecretRoleTest(APITestCase):
 
 

+ 1 - 0
netbox/secrets/urls.py

@@ -17,6 +17,7 @@ urlpatterns = [
 
 
     # Secrets
     # Secrets
     path('secrets/', views.SecretListView.as_view(), name='secret_list'),
     path('secrets/', views.SecretListView.as_view(), name='secret_list'),
+    path('secrets/add/', views.secret_add, name='secret_add'),
     path('secrets/import/', views.SecretBulkImportView.as_view(), name='secret_import'),
     path('secrets/import/', views.SecretBulkImportView.as_view(), name='secret_import'),
     path('secrets/edit/', views.SecretBulkEditView.as_view(), name='secret_bulk_edit'),
     path('secrets/edit/', views.SecretBulkEditView.as_view(), name='secret_bulk_edit'),
     path('secrets/delete/', views.SecretBulkDeleteView.as_view(), name='secret_bulk_delete'),
     path('secrets/delete/', views.SecretBulkDeleteView.as_view(), name='secret_bulk_delete'),

+ 9 - 10
netbox/secrets/views.py

@@ -8,9 +8,8 @@ from django.shortcuts import get_object_or_404, redirect, render
 from django.urls import reverse
 from django.urls import reverse
 from django.views.generic import View
 from django.views.generic import View
 
 
-from dcim.models import Device
 from utilities.views import (
 from utilities.views import (
-    BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
+    BulkDeleteView, BulkEditView, BulkImportView, GetReturnURLMixin, ObjectDeleteView, ObjectEditView, ObjectListView,
 )
 )
 from . import filters, forms, tables
 from . import filters, forms, tables
 from .decorators import userkey_required
 from .decorators import userkey_required
@@ -89,12 +88,9 @@ class SecretView(PermissionRequiredMixin, View):
 
 
 @permission_required('secrets.add_secret')
 @permission_required('secrets.add_secret')
 @userkey_required()
 @userkey_required()
-def secret_add(request, pk):
+def secret_add(request):
 
 
-    # Retrieve device
-    device = get_object_or_404(Device, pk=pk)
-
-    secret = Secret(device=device)
+    secret = Secret()
     session_key = get_session_key(request)
     session_key = get_session_key(request)
 
 
     if request.method == 'POST':
     if request.method == 'POST':
@@ -123,17 +119,20 @@ def secret_add(request, pk):
 
 
                     messages.success(request, "Added new secret: {}.".format(secret))
                     messages.success(request, "Added new secret: {}.".format(secret))
                     if '_addanother' in request.POST:
                     if '_addanother' in request.POST:
-                        return redirect('dcim:device_addsecret', pk=device.pk)
+                        return redirect('secrets:secret_add')
                     else:
                     else:
                         return redirect('secrets:secret', pk=secret.pk)
                         return redirect('secrets:secret', pk=secret.pk)
 
 
     else:
     else:
-        form = forms.SecretForm(instance=secret)
+        initial_data = {
+            'device': request.GET.get('device'),
+        }
+        form = forms.SecretForm(initial=initial_data)
 
 
     return render(request, 'secrets/secret_edit.html', {
     return render(request, 'secrets/secret_edit.html', {
         'secret': secret,
         'secret': secret,
         'form': form,
         'form': form,
-        'return_url': device.get_absolute_url(),
+        'return_url': GetReturnURLMixin().get_return_url(request, secret)
     })
     })
 
 
 
 

+ 1 - 1
netbox/templates/dcim/device.html

@@ -428,7 +428,7 @@
                             {% csrf_token %}
                             {% csrf_token %}
                         </form>
                         </form>
                         <div class="panel-footer text-right noprint">
                         <div class="panel-footer text-right noprint">
-                            <a href="{% url 'dcim:device_addsecret' pk=device.pk %}" class="btn btn-xs btn-primary">
+                            <a href="{% url 'secrets:secret_add' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}" class="btn btn-xs btn-primary">
                                 <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                                 <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                                 Add secret
                                 Add secret
                             </a>
                             </a>

+ 6 - 4
netbox/templates/dcim/rack.html

@@ -271,7 +271,9 @@
                     </tr>
                     </tr>
                     {% for resv in reservations %}
                     {% for resv in reservations %}
                         <tr>
                         <tr>
-                            <td>{{ resv.unit_list }}</td>
+                            <td>
+                                <a href="{{ resv.get_absolute_url }}">{{ resv.unit_list }}</a>
+                            </td>
                             <td>
                             <td>
                                 {% if resv.tenant %}
                                 {% if resv.tenant %}
                                     <a href="{{ resv.tenant.get_absolute_url }}">{{ resv.tenant }}</a>
                                     <a href="{{ resv.tenant.get_absolute_url }}">{{ resv.tenant }}</a>
@@ -285,12 +287,12 @@
                             </td>
                             </td>
                             <td class="text-right noprint">
                             <td class="text-right noprint">
                                 {% if perms.dcim.change_rackreservation %}
                                 {% if perms.dcim.change_rackreservation %}
-                                    <a href="{% url 'dcim:rackreservation_edit' pk=resv.pk %}" class="btn btn-warning btn-xs" title="Edit reservation">
+                                    <a href="{% url 'dcim:rackreservation_edit' pk=resv.pk %}&return_url={{ rack.get_absolute_url }}" class="btn btn-warning btn-xs" title="Edit reservation">
                                         <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
                                         <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
                                     </a>
                                     </a>
                                 {% endif %}
                                 {% endif %}
                                 {% if perms.dcim.delete_rackreservation %}
                                 {% if perms.dcim.delete_rackreservation %}
-                                    <a href="{% url 'dcim:rackreservation_delete' pk=resv.pk %}" class="btn btn-danger btn-xs" title="Delete reservation">
+                                    <a href="{% url 'dcim:rackreservation_delete' pk=resv.pk %}&return_url={{ rack.get_absolute_url }}" class="btn btn-danger btn-xs" title="Delete reservation">
                                         <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                         <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                     </a>
                                     </a>
                                 {% endif %}
                                 {% endif %}
@@ -303,7 +305,7 @@
             {% endif %}
             {% endif %}
             {% if perms.dcim.add_rackreservation %}
             {% if perms.dcim.add_rackreservation %}
                 <div class="panel-footer text-right noprint">
                 <div class="panel-footer text-right noprint">
-                    <a href="{% url 'dcim:rack_add_reservation' rack=rack.pk %}" class="btn btn-primary btn-xs">
+                    <a href="{% url 'dcim:rackreservation_add' %}?rack={{ rack.pk }}&return_url={{ rack.get_absolute_url }}" class="btn btn-primary btn-xs">
                         <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                         <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                         Add a reservation
                         Add a reservation
                     </a>
                     </a>

+ 146 - 0
netbox/templates/dcim/rackreservation.html

@@ -0,0 +1,146 @@
+{% extends '_base.html' %}
+{% load buttons %}
+{% load custom_links %}
+{% load helpers %}
+{% load static %}
+
+{% block header %}
+    <div class="row noprint">
+        <div class="col-sm-8 col-md-9">
+            <ol class="breadcrumb">
+                <li><a href="{% url 'dcim:rackreservation_list' %}">Rack Reservations</a></li>
+                <li><a href="{{ rackreservation.rack.get_absolute_url }}">{{ rackreservation.rack }}</a></li>
+                <li>Units {{ rackreservation.unit_list }}</li>
+            </ol>
+        </div>
+        <div class="col-sm-4 col-md-3">
+            <form action="{% url 'dcim:rackreservation_list' %}" method="get">
+                <div class="input-group">
+                    <input type="text" name="q" class="form-control" placeholder="Search racks" />
+                    <span class="input-group-btn">
+                        <button type="submit" class="btn btn-primary">
+                            <span class="fa fa-search" aria-hidden="true"></span>
+                        </button>
+                    </span>
+                </div>
+            </form>
+        </div>
+    </div>
+    <div class="pull-right noprint">
+        {% if perms.dcim.change_rackreservation %}
+            {% edit_button rackreservation %}
+        {% endif %}
+        {% if perms.dcim.delete_rackreservation %}
+            {% delete_button rackreservation %}
+        {% endif %}
+    </div>
+    <h1>{% block title %}{{ rackreservation }}{% endblock %}</h1>
+    {% include 'inc/created_updated.html' with obj=rackreservation %}
+    <ul class="nav nav-tabs">
+        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
+            <a href="{{ rackreservation.get_absolute_url }}">Rack</a>
+        </li>
+        {% if perms.extras.view_objectchange %}
+            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
+                <a href="{% url 'dcim:rackreservation_changelog' pk=rackreservation.pk %}">Change Log</a>
+            </li>
+        {% endif %}
+    </ul>
+{% endblock %}
+
+{% block content %}
+<div class="row">
+	<div class="col-md-6">
+        <div class="panel panel-default">
+            <div class="panel-heading">
+                <strong>Rack</strong>
+            </div>
+            <table class="table table-hover panel-body attr-table">
+                {% with rack=rackreservation.rack %}
+                    <tr>
+                        <td>Site</td>
+                        <td>
+                            {% if rack.site.region %}
+                                <a href="{{ rack.site.region.get_absolute_url }}">{{ rack.site.region }}</a>
+                                <i class="fa fa-angle-right"></i>
+                            {% endif %}
+                            <a href="{% url 'dcim:site' slug=rack.site.slug %}">{{ rack.site }}</a>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td>Group</td>
+                        <td>
+                            {% if rack.group %}
+                                <a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}&group={{ rack.group.slug }}">{{ rack.group }}</a>
+                            {% else %}
+                                <span class="text-muted">None</span>
+                            {% endif %}
+                        </td>
+                    </tr>
+                    <tr>
+                        <td>Rack</td>
+                        <td>
+                            <a href="{{ rack.get_absolute_url }}">{{ rack }}</a>
+                        </td>
+                    </tr>
+                {% endwith %}
+            </table>
+        </div>
+        <div class="panel panel-default">
+            <div class="panel-heading">
+                <strong>Reservation Details</strong>
+            </div>
+            <table class="table table-hover panel-body attr-table">
+                <tr>
+                    <td>Units</td>
+                    <td>{{ rackreservation.unit_list }}</td>
+                </tr>
+                <tr>
+                    <td>Tenant</td>
+                    <td>
+                        {% if rackreservation.tenant %}
+                            {% if rackreservation.tenant.group %}
+                                <a href="{{ rackreservation.tenant.group.get_absolute_url }}">{{ rackreservation.tenant.group }}</a>
+                                <i class="fa fa-angle-right"></i>
+                            {% endif %}
+                            <a href="{{ rackreservation.tenant.get_absolute_url }}">{{ rackreservation.tenant }}</a>
+                        {% else %}
+                            <span class="text-muted">None</span>
+                        {% endif %}
+                    </td>
+                </tr>
+                <tr>
+                    <td>User</td>
+                    <td>{{ rackreservation.user }}</td>
+                </tr>
+                <tr>
+                    <td>Description</td>
+                    <td>{{ rackreservation.description }}</td>
+                </tr>
+            </table>
+        </div>
+	</div>
+    <div class="col-md-6">
+        {% with rack=rackreservation.rack %}
+            <div class="row" style="margin-bottom: 20px">
+                <div class="col-md-6 col-sm-6 col-xs-12">
+                    <div class="rack_header">
+                        <h4>Front</h4>
+                    </div>
+                    {% include 'dcim/inc/rack_elevation.html' with face='front' %}
+                </div>
+                <div class="col-md-6 col-sm-6 col-xs-12">
+                    <div class="rack_header">
+                        <h4>Rear</h4>
+                    </div>
+                    {% include 'dcim/inc/rack_elevation.html' with face='rear' %}
+                </div>
+            </div>
+        {% endwith %}
+    </div>
+</div>
+{% endblock %}
+
+{% block javascript %}
+<script src="{% static 'js/rack_elevations.js' %}?v{{ settings.VERSION }}"></script>
+{% endblock %}

+ 21 - 0
netbox/templates/dcim/rackreservation_edit.html

@@ -0,0 +1,21 @@
+{% extends 'utilities/obj_edit.html' %}
+{% load form_helpers %}
+
+{% block form %}
+    <div class="panel panel-default">
+        <div class="panel-heading"><strong>{{ obj_type|capfirst }}</strong></div>
+        <div class="panel-body">
+            <div class="form-group">
+                <label class="col-md-3 control-label">Rack</label>
+                <div class="col-md-9">
+                    <p class="form-control-static">{{ obj.rack }}</p>
+                </div>
+            </div>
+            {% render_field form.units %}
+            {% render_field form.user %}
+            {% render_field form.tenant_group %}
+            {% render_field form.tenant %}
+            {% render_field form.description %}
+        </div>
+    </div>
+{% endblock %}

+ 5 - 12
netbox/templates/extras/tag.html

@@ -82,20 +82,13 @@
                             <span class="label color-block" style="background-color: #{{ tag.color }}">&nbsp;</span>
                             <span class="label color-block" style="background-color: #{{ tag.color }}">&nbsp;</span>
                         </td>
                         </td>
                     </tr>
                     </tr>
+                    <tr>
+                        <td>Description</td>
+                        <td>
+                            {{ tag.description }}
+                        </td>
                 </table>
                 </table>
             </div>
             </div>
-            <div class="panel panel-default">
-                <div class="panel-heading">
-                    <strong>Comments</strong>
-                </div>
-                <div class="panel-body rendered-markdown">
-                    {% if tag.comments %}
-                        {{ tag.comments|render_markdown }}
-                    {% else %}
-                        <span class="text-muted">None</span>
-                    {% endif %}
-                </div>
-            </div>
         </div>
         </div>
         <div class="col-md-6">
         <div class="col-md-6">
             {% include 'panel_table.html' with table=items_table heading='Tagged Objects' %}
             {% include 'panel_table.html' with table=items_table heading='Tagged Objects' %}

+ 1 - 6
netbox/templates/extras/tag_edit.html

@@ -8,12 +8,7 @@
             {% render_field form.name %}
             {% render_field form.name %}
             {% render_field form.slug %}
             {% render_field form.slug %}
             {% render_field form.color %}
             {% render_field form.color %}
-        </div>
-    </div>
-    <div class="panel panel-default">
-        <div class="panel-heading"><strong>Comments</strong></div>
-        <div class="panel-body">
-            {% render_field form.comments %}
+            {% render_field form.description %}
         </div>
         </div>
     </div>
     </div>
 {% endblock %}
 {% endblock %}

+ 1 - 1
netbox/templates/inc/custom_fields_panel.html

@@ -7,7 +7,7 @@
             <table class="table table-hover panel-body attr-table">
             <table class="table table-hover panel-body attr-table">
                 {% for field, value in custom_fields.items %}
                 {% for field, value in custom_fields.items %}
                     <tr>
                     <tr>
-                        <td>{{ field }}</td>
+                        <td><span title="{{ field.description }}">{{ field }}</span></td>
                         <td>
                         <td>
                             {% if field.type == 'boolean' and value == True %}
                             {% if field.type == 'boolean' and value == True %}
                                 <i class="glyphicon glyphicon-ok text-success" title="True"></i>
                                 <i class="glyphicon glyphicon-ok text-success" title="True"></i>

+ 1 - 0
netbox/templates/inc/nav_menu.html

@@ -462,6 +462,7 @@
                         <li{% if not perms.secrets.view_secret %} class="disabled"{% endif %}>
                         <li{% if not perms.secrets.view_secret %} class="disabled"{% endif %}>
                             {% if perms.secrets.add_secret %}
                             {% if perms.secrets.add_secret %}
                                 <div class="buttons pull-right">
                                 <div class="buttons pull-right">
+                                    <a href="{% url 'secrets:secret_add' %}" class="btn btn-xs btn-success" title="Add"><i class="fa fa-plus"></i></a>
                                     <a href="{% url 'secrets:secret_import' %}" class="btn btn-xs btn-info" title="Import"><i class="fa fa-download"></i></a>
                                     <a href="{% url 'secrets:secret_import' %}" class="btn btn-xs btn-info" title="Import"><i class="fa fa-download"></i></a>
                                 </div>
                                 </div>
                             {% endif %}
                             {% endif %}

+ 1 - 6
netbox/templates/secrets/secret_edit.html

@@ -21,12 +21,7 @@
             <div class="panel panel-default">
             <div class="panel panel-default">
                 <div class="panel-heading"><strong>Secret Attributes</strong></div>
                 <div class="panel-heading"><strong>Secret Attributes</strong></div>
                 <div class="panel-body">
                 <div class="panel-body">
-                    <div class="form-group">
-                        <label class="col-md-3 control-label required">Device</label>
-                        <div class="col-md-9">
-                            <p class="form-control-static">{{ secret.device }}</p>
-                        </div>
-                    </div>
+                    {% render_field form.device %}
                     {% render_field form.role %}
                     {% render_field form.role %}
                     {% render_field form.name %}
                     {% render_field form.name %}
                     {% render_field form.userkeys %}
                     {% render_field form.userkeys %}

+ 1 - 1
netbox/templates/utilities/obj_edit.html

@@ -51,7 +51,7 @@
             </div>
             </div>
         </div>
         </div>
     </form>
     </form>
-    {% if settings.DOCS_ROOT %}
+    {% if obj and settings.DOCS_ROOT %}
         {% include 'inc/modal.html' with name='docs' content=obj|get_docs %}
         {% include 'inc/modal.html' with name='docs' content=obj|get_docs %}
     {% endif %}
     {% endif %}
 {% endblock %}
 {% endblock %}

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

@@ -17,7 +17,7 @@ class TenantGroupSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = TenantGroup
         model = TenantGroup
-        fields = ['id', 'name', 'slug', 'parent', 'tenant_count']
+        fields = ['id', 'name', 'slug', 'parent', 'description', 'tenant_count']
 
 
 
 
 class TenantSerializer(TaggitSerializer, CustomFieldModelSerializer):
 class TenantSerializer(TaggitSerializer, CustomFieldModelSerializer):

+ 0 - 3
netbox/tenancy/api/urls.py

@@ -14,9 +14,6 @@ class TenancyRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = TenancyRootView
 router.APIRootView = TenancyRootView
 
 
-# Field choices
-router.register('_choices', views.TenancyFieldChoicesViewSet, basename='field-choice')
-
 # Tenants
 # Tenants
 router.register('tenant-groups', views.TenantGroupViewSet)
 router.register('tenant-groups', views.TenantGroupViewSet)
 router.register('tenants', views.TenantViewSet)
 router.register('tenants', views.TenantViewSet)

+ 1 - 9
netbox/tenancy/api/views.py

@@ -4,20 +4,12 @@ from extras.api.views import CustomFieldModelViewSet
 from ipam.models import IPAddress, Prefix, VLAN, VRF
 from ipam.models import IPAddress, Prefix, VLAN, VRF
 from tenancy import filters
 from tenancy import filters
 from tenancy.models import Tenant, TenantGroup
 from tenancy.models import Tenant, TenantGroup
-from utilities.api import FieldChoicesViewSet, ModelViewSet
+from utilities.api import ModelViewSet
 from utilities.utils import get_subquery
 from utilities.utils import get_subquery
 from virtualization.models import VirtualMachine
 from virtualization.models import VirtualMachine
 from . import serializers
 from . import serializers
 
 
 
 
-#
-# Field choices
-#
-
-class TenancyFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = ()
-
-
 #
 #
 # Tenant Groups
 # Tenant Groups
 #
 #

+ 1 - 1
netbox/tenancy/filters.py

@@ -27,7 +27,7 @@ class TenantGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = TenantGroup
         model = TenantGroup
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class TenantFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class TenantFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):

+ 1 - 1
netbox/tenancy/forms.py

@@ -28,7 +28,7 @@ class TenantGroupForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = TenantGroup
         model = TenantGroup
         fields = [
         fields = [
-            'parent', 'name', 'slug',
+            'parent', 'name', 'slug', 'description',
         ]
         ]
 
 
 
 

+ 23 - 0
netbox/tenancy/migrations/0009_standardize_description.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('tenancy', '0008_nested_tenantgroups_rebuild'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='tenantgroup',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AlterField(
+            model_name='tenant',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 10 - 4
netbox/tenancy/models.py

@@ -5,6 +5,7 @@ from mptt.models import MPTTModel, TreeForeignKey
 from taggit.managers import TaggableManager
 from taggit.managers import TaggableManager
 
 
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
 from extras.models import CustomFieldModel, ObjectChange, TaggedItem
+from extras.utils import extras_features
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from utilities.utils import serialize_object
 from utilities.utils import serialize_object
 
 
@@ -34,8 +35,12 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
         null=True,
         null=True,
         db_index=True
         db_index=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug', 'parent']
+    csv_headers = ['name', 'slug', 'parent', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -54,6 +59,7 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
             self.name,
             self.name,
             self.slug,
             self.slug,
             self.parent.name if self.parent else '',
             self.parent.name if self.parent else '',
+            self.description,
         )
         )
 
 
     def to_objectchange(self, action):
     def to_objectchange(self, action):
@@ -66,6 +72,7 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
         )
         )
 
 
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Tenant(ChangeLoggedModel, CustomFieldModel):
 class Tenant(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A Tenant represents an organization served by the NetBox owner. This is typically a customer or an internal
     A Tenant represents an organization served by the NetBox owner. This is typically a customer or an internal
@@ -86,9 +93,8 @@ class Tenant(ChangeLoggedModel, CustomFieldModel):
         null=True
         null=True
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
-        blank=True,
-        help_text='Long-form name (optional)'
+        max_length=200,
+        blank=True
     )
     )
     comments = models.TextField(
     comments = models.TextField(
         blank=True
         blank=True

+ 1 - 1
netbox/tenancy/tables.py

@@ -53,7 +53,7 @@ class TenantGroupTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = TenantGroup
         model = TenantGroup
-        fields = ('pk', 'name', 'tenant_count', 'slug', 'actions')
+        fields = ('pk', 'name', 'tenant_count', 'description', 'slug', 'actions')
 
 
 
 
 #
 #

+ 0 - 7
netbox/tenancy/tests/test_api.py

@@ -14,13 +14,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('tenancy-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
 
 
 class TenantGroupTest(APITestCase):
 class TenantGroupTest(APITestCase):
 
 

+ 7 - 3
netbox/tenancy/tests/test_filters.py

@@ -20,9 +20,9 @@ class TenantGroupTestCase(TestCase):
             tenantgroup.save()
             tenantgroup.save()
 
 
         tenant_groups = (
         tenant_groups = (
-            TenantGroup(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0]),
-            TenantGroup(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[1]),
-            TenantGroup(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[2]),
+            TenantGroup(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0], description='A'),
+            TenantGroup(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[1], description='B'),
+            TenantGroup(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[2], description='C'),
         )
         )
         for tenantgroup in tenant_groups:
         for tenantgroup in tenant_groups:
             tenantgroup.save()
             tenantgroup.save()
@@ -40,6 +40,10 @@ class TenantGroupTestCase(TestCase):
         params = {'slug': ['tenant-group-1', 'tenant-group-2']}
         params = {'slug': ['tenant-group-1', 'tenant-group-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_parent(self):
     def test_parent(self):
         parent_groups = TenantGroup.objects.filter(name__startswith='Parent')[:2]
         parent_groups = TenantGroup.objects.filter(name__startswith='Parent')[:2]
         params = {'parent_id': [parent_groups[0].pk, parent_groups[1].pk]}
         params = {'parent_id': [parent_groups[0].pk, parent_groups[1].pk]}

+ 5 - 4
netbox/tenancy/tests/test_views.py

@@ -19,13 +19,14 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
         cls.form_data = {
         cls.form_data = {
             'name': 'Tenant Group X',
             'name': 'Tenant Group X',
             'slug': 'tenant-group-x',
             'slug': 'tenant-group-x',
+            'description': 'A new tenant group',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Tenant Group 4,tenant-group-4",
-            "Tenant Group 5,tenant-group-5",
-            "Tenant Group 6,tenant-group-6",
+            "name,slug,description",
+            "Tenant Group 4,tenant-group-4,Fourth tenant group",
+            "Tenant Group 5,tenant-group-5,Fifth tenant group",
+            "Tenant Group 6,tenant-group-6,Sixth tenant group",
         )
         )
 
 
 
 

+ 18 - 0
netbox/users/migrations/0002_standardize_description.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('users', '0001_api_tokens_squashed_0003_token_permissions'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='token',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 1 - 1
netbox/users/models.py

@@ -39,7 +39,7 @@ class Token(models.Model):
         help_text='Permit create/update/delete operations using this key'
         help_text='Permit create/update/delete operations using this key'
     )
     )
     description = models.CharField(
     description = models.CharField(
-        max_length=100,
+        max_length=200,
         blank=True
         blank=True
     )
     )
 
 

+ 1 - 46
netbox/utilities/api.py

@@ -235,6 +235,7 @@ class ValidatedModelSerializer(ModelSerializer):
             for k, v in attrs.items():
             for k, v in attrs.items():
                 setattr(instance, k, v)
                 setattr(instance, k, v)
         instance.clean()
         instance.clean()
+        instance.validate_unique()
 
 
         return data
         return data
 
 
@@ -371,49 +372,3 @@ class ModelViewSet(_ModelViewSet):
         logger = logging.getLogger('netbox.api.views.ModelViewSet')
         logger = logging.getLogger('netbox.api.views.ModelViewSet')
         logger.info(f"Deleting {instance} (PK: {instance.pk})")
         logger.info(f"Deleting {instance} (PK: {instance.pk})")
         return super().perform_destroy(instance)
         return super().perform_destroy(instance)
-
-
-class FieldChoicesViewSet(ViewSet):
-    """
-    Expose the built-in numeric values which represent static choices for a model's field.
-    """
-    permission_classes = [IsAuthenticatedOrLoginNotRequired]
-    fields = []
-
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
-
-        # Compile a dict of all fields in this view
-        self._fields = OrderedDict()
-        for serializer_class, field_list in self.fields:
-            for field_name in field_list:
-
-                model_name = serializer_class.Meta.model._meta.verbose_name
-                key = ':'.join([model_name.lower().replace(' ', '-'), field_name])
-                serializer = serializer_class()
-                choices = []
-
-                for k, v in serializer.get_fields()[field_name].choices.items():
-                    if type(v) in [list, tuple]:
-                        for k2, v2 in v:
-                            choices.append({
-                                'value': k2,
-                                'label': v2,
-                            })
-                    else:
-                        choices.append({
-                            'value': k,
-                            'label': v,
-                        })
-                self._fields[key] = choices
-
-    def list(self, request):
-        return Response(self._fields)
-
-    def retrieve(self, request, pk):
-        if pk not in self._fields:
-            raise Http404
-        return Response(self._fields[pk])
-
-    def get_view_name(self):
-        return "Field Choices"

+ 2 - 2
netbox/utilities/templatetags/helpers.py

@@ -40,7 +40,7 @@ def render_markdown(value):
     value = strip_tags(value)
     value = strip_tags(value)
 
 
     # Render Markdown
     # Render Markdown
-    html = markdown(value, extensions=['fenced_code'])
+    html = markdown(value, extensions=['fenced_code', 'tables'])
 
 
     return mark_safe(html)
     return mark_safe(html)
 
 
@@ -196,7 +196,7 @@ def get_docs(model):
         return "Unable to load documentation, error reading file: {}".format(path)
         return "Unable to load documentation, error reading file: {}".format(path)
 
 
     # Render Markdown with the admonition extension
     # Render Markdown with the admonition extension
-    content = markdown(content, extensions=['admonition', 'fenced_code'])
+    content = markdown(content, extensions=['admonition', 'fenced_code', 'tables'])
 
 
     return mark_safe(content)
     return mark_safe(content)
 
 

+ 0 - 27
netbox/utilities/testing/utils.py

@@ -36,33 +36,6 @@ def create_test_user(username='testuser', permissions=None):
     return user
     return user
 
 
 
 
-def choices_to_dict(choices_list):
-    """
-    Convert a list of field choices to a dictionary suitable for direct comparison with a ChoiceSet. For example:
-
-        [
-            {
-                "value": "choice-1",
-                "label": "First Choice"
-            },
-            {
-                "value": "choice-2",
-                "label": "Second Choice"
-            }
-        ]
-
-    Becomes:
-
-        {
-            "choice-1": "First Choice",
-            "choice-2": "Second Choice
-        }
-    """
-    return {
-        choice['value']: choice['label'] for choice in choices_list
-    }
-
-
 @contextmanager
 @contextmanager
 def disable_warnings(logger_name):
 def disable_warnings(logger_name):
     """
     """

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

@@ -24,7 +24,7 @@ class ClusterTypeSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = ClusterType
         model = ClusterType
-        fields = ['id', 'name', 'slug', 'cluster_count']
+        fields = ['id', 'name', 'slug', 'description', 'cluster_count']
 
 
 
 
 class ClusterGroupSerializer(ValidatedModelSerializer):
 class ClusterGroupSerializer(ValidatedModelSerializer):
@@ -32,7 +32,7 @@ class ClusterGroupSerializer(ValidatedModelSerializer):
 
 
     class Meta:
     class Meta:
         model = ClusterGroup
         model = ClusterGroup
-        fields = ['id', 'name', 'slug', 'cluster_count']
+        fields = ['id', 'name', 'slug', 'description', 'cluster_count']
 
 
 
 
 class ClusterSerializer(TaggitSerializer, CustomFieldModelSerializer):
 class ClusterSerializer(TaggitSerializer, CustomFieldModelSerializer):

+ 0 - 3
netbox/virtualization/api/urls.py

@@ -14,9 +14,6 @@ class VirtualizationRootView(routers.APIRootView):
 router = routers.DefaultRouter()
 router = routers.DefaultRouter()
 router.APIRootView = VirtualizationRootView
 router.APIRootView = VirtualizationRootView
 
 
-# Field choices
-router.register('_choices', views.VirtualizationFieldChoicesViewSet, basename='field-choice')
-
 # Clusters
 # Clusters
 router.register('cluster-types', views.ClusterTypeViewSet)
 router.register('cluster-types', views.ClusterTypeViewSet)
 router.register('cluster-groups', views.ClusterGroupViewSet)
 router.register('cluster-groups', views.ClusterGroupViewSet)

+ 1 - 12
netbox/virtualization/api/views.py

@@ -2,24 +2,13 @@ from django.db.models import Count
 
 
 from dcim.models import Device, Interface
 from dcim.models import Device, Interface
 from extras.api.views import CustomFieldModelViewSet
 from extras.api.views import CustomFieldModelViewSet
-from utilities.api import FieldChoicesViewSet, ModelViewSet
+from utilities.api import ModelViewSet
 from utilities.utils import get_subquery
 from utilities.utils import get_subquery
 from virtualization import filters
 from virtualization import filters
 from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
 from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
 from . import serializers
 from . import serializers
 
 
 
 
-#
-# Field choices
-#
-
-class VirtualizationFieldChoicesViewSet(FieldChoicesViewSet):
-    fields = (
-        (serializers.VirtualMachineSerializer, ['status']),
-        (serializers.InterfaceSerializer, ['type']),
-    )
-
-
 #
 #
 # Clusters
 # Clusters
 #
 #

+ 2 - 2
netbox/virtualization/filters.py

@@ -24,14 +24,14 @@ class ClusterTypeFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = ClusterType
         model = ClusterType
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class ClusterGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 class ClusterGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
 
 
     class Meta:
     class Meta:
         model = ClusterGroup
         model = ClusterGroup
-        fields = ['id', 'name', 'slug']
+        fields = ['id', 'name', 'slug', 'description']
 
 
 
 
 class ClusterFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
 class ClusterFilterSet(BaseFilterSet, TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):

+ 2 - 2
netbox/virtualization/forms.py

@@ -31,7 +31,7 @@ class ClusterTypeForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = ClusterType
         model = ClusterType
         fields = [
         fields = [
-            'name', 'slug',
+            'name', 'slug', 'description',
         ]
         ]
 
 
 
 
@@ -56,7 +56,7 @@ class ClusterGroupForm(BootstrapMixin, forms.ModelForm):
     class Meta:
     class Meta:
         model = ClusterGroup
         model = ClusterGroup
         fields = [
         fields = [
-            'name', 'slug',
+            'name', 'slug', 'description',
         ]
         ]
 
 
 
 

+ 23 - 0
netbox/virtualization/migrations/0014_standardize_description.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.3 on 2020-03-13 20:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('virtualization', '0013_deterministic_ordering'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='clustergroup',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+        migrations.AddField(
+            model_name='clustertype',
+            name='description',
+            field=models.CharField(blank=True, max_length=200),
+        ),
+    ]

+ 15 - 2
netbox/virtualization/models.py

@@ -7,6 +7,7 @@ from taggit.managers import TaggableManager
 
 
 from dcim.models import Device
 from dcim.models import Device
 from extras.models import ConfigContextModel, CustomFieldModel, TaggedItem
 from extras.models import ConfigContextModel, CustomFieldModel, TaggedItem
+from extras.utils import extras_features
 from utilities.models import ChangeLoggedModel
 from utilities.models import ChangeLoggedModel
 from .choices import *
 from .choices import *
 
 
@@ -34,8 +35,12 @@ class ClusterType(ChangeLoggedModel):
     slug = models.SlugField(
     slug = models.SlugField(
         unique=True
         unique=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug']
+    csv_headers = ['name', 'slug', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -50,6 +55,7 @@ class ClusterType(ChangeLoggedModel):
         return (
         return (
             self.name,
             self.name,
             self.slug,
             self.slug,
+            self.description,
         )
         )
 
 
 
 
@@ -68,8 +74,12 @@ class ClusterGroup(ChangeLoggedModel):
     slug = models.SlugField(
     slug = models.SlugField(
         unique=True
         unique=True
     )
     )
+    description = models.CharField(
+        max_length=200,
+        blank=True
+    )
 
 
-    csv_headers = ['name', 'slug']
+    csv_headers = ['name', 'slug', 'description']
 
 
     class Meta:
     class Meta:
         ordering = ['name']
         ordering = ['name']
@@ -84,6 +94,7 @@ class ClusterGroup(ChangeLoggedModel):
         return (
         return (
             self.name,
             self.name,
             self.slug,
             self.slug,
+            self.description,
         )
         )
 
 
 
 
@@ -91,6 +102,7 @@ class ClusterGroup(ChangeLoggedModel):
 # Clusters
 # Clusters
 #
 #
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class Cluster(ChangeLoggedModel, CustomFieldModel):
 class Cluster(ChangeLoggedModel, CustomFieldModel):
     """
     """
     A cluster of VirtualMachines. Each Cluster may optionally be associated with one or more Devices.
     A cluster of VirtualMachines. Each Cluster may optionally be associated with one or more Devices.
@@ -177,6 +189,7 @@ class Cluster(ChangeLoggedModel, CustomFieldModel):
 # Virtual machines
 # Virtual machines
 #
 #
 
 
+@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
 class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
 class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
     """
     """
     A virtual machine which runs inside a Cluster.
     A virtual machine which runs inside a Cluster.

+ 2 - 2
netbox/virtualization/tables.py

@@ -55,7 +55,7 @@ class ClusterTypeTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = ClusterType
         model = ClusterType
-        fields = ('pk', 'name', 'cluster_count', 'actions')
+        fields = ('pk', 'name', 'cluster_count', 'description', 'actions')
 
 
 
 
 #
 #
@@ -74,7 +74,7 @@ class ClusterGroupTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = ClusterGroup
         model = ClusterGroup
-        fields = ('pk', 'name', 'cluster_count', 'actions')
+        fields = ('pk', 'name', 'cluster_count', 'description', 'actions')
 
 
 
 
 #
 #

+ 13 - 14
netbox/virtualization/tests/test_api.py

@@ -5,7 +5,7 @@ from rest_framework import status
 from dcim.choices import InterfaceModeChoices
 from dcim.choices import InterfaceModeChoices
 from dcim.models import Interface
 from dcim.models import Interface
 from ipam.models import IPAddress, VLAN
 from ipam.models import IPAddress, VLAN
-from utilities.testing import APITestCase, choices_to_dict, disable_warnings
+from utilities.testing import APITestCase, disable_warnings
 from virtualization.choices import *
 from virtualization.choices import *
 from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
 from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
 
 
@@ -19,19 +19,6 @@ class AppTest(APITestCase):
 
 
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.status_code, 200)
 
 
-    def test_choices(self):
-
-        url = reverse('virtualization-api:field-choice-list')
-        response = self.client.get(url, **self.header)
-
-        self.assertEqual(response.status_code, 200)
-
-        # VirtualMachine
-        self.assertEqual(choices_to_dict(response.data.get('virtual-machine:status')), VirtualMachineStatusChoices.as_dict())
-
-        # Interface
-        self.assertEqual(choices_to_dict(response.data.get('interface:type')), VMInterfaceTypeChoices.as_dict())
-
 
 
 class ClusterTypeTest(APITestCase):
 class ClusterTypeTest(APITestCase):
 
 
@@ -501,6 +488,18 @@ class VirtualMachineTest(APITestCase):
 
 
         self.assertFalse('config_context' in response.data['results'][0])
         self.assertFalse('config_context' in response.data['results'][0])
 
 
+    def test_unique_name_per_cluster_constraint(self):
+
+        data = {
+            'name': 'Test Virtual Machine 1',
+            'cluster': self.cluster1.pk,
+        }
+
+        url = reverse('virtualization-api:virtualmachine-list')
+        response = self.client.post(url, data, format='json', **self.header)
+
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+
 
 
 class InterfaceTest(APITestCase):
 class InterfaceTest(APITestCase):
 
 

+ 14 - 6
netbox/virtualization/tests/test_filters.py

@@ -15,9 +15,9 @@ class ClusterTypeTestCase(TestCase):
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         cluster_types = (
         cluster_types = (
-            ClusterType(name='Cluster Type 1', slug='cluster-type-1'),
-            ClusterType(name='Cluster Type 2', slug='cluster-type-2'),
-            ClusterType(name='Cluster Type 3', slug='cluster-type-3'),
+            ClusterType(name='Cluster Type 1', slug='cluster-type-1', description='A'),
+            ClusterType(name='Cluster Type 2', slug='cluster-type-2', description='B'),
+            ClusterType(name='Cluster Type 3', slug='cluster-type-3', description='C'),
         )
         )
         ClusterType.objects.bulk_create(cluster_types)
         ClusterType.objects.bulk_create(cluster_types)
 
 
@@ -34,6 +34,10 @@ class ClusterTypeTestCase(TestCase):
         params = {'slug': ['cluster-type-1', 'cluster-type-2']}
         params = {'slug': ['cluster-type-1', 'cluster-type-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
 
 
 class ClusterGroupTestCase(TestCase):
 class ClusterGroupTestCase(TestCase):
     queryset = ClusterGroup.objects.all()
     queryset = ClusterGroup.objects.all()
@@ -43,9 +47,9 @@ class ClusterGroupTestCase(TestCase):
     def setUpTestData(cls):
     def setUpTestData(cls):
 
 
         cluster_groups = (
         cluster_groups = (
-            ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'),
-            ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'),
-            ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'),
+            ClusterGroup(name='Cluster Group 1', slug='cluster-group-1', description='A'),
+            ClusterGroup(name='Cluster Group 2', slug='cluster-group-2', description='B'),
+            ClusterGroup(name='Cluster Group 3', slug='cluster-group-3', description='C'),
         )
         )
         ClusterGroup.objects.bulk_create(cluster_groups)
         ClusterGroup.objects.bulk_create(cluster_groups)
 
 
@@ -62,6 +66,10 @@ class ClusterGroupTestCase(TestCase):
         params = {'slug': ['cluster-group-1', 'cluster-group-2']}
         params = {'slug': ['cluster-group-1', 'cluster-group-2']}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
 
 
+    def test_description(self):
+        params = {'description': ['A', 'B']}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
 
 
 class ClusterTestCase(TestCase):
 class ClusterTestCase(TestCase):
     queryset = Cluster.objects.all()
     queryset = Cluster.objects.all()

+ 10 - 8
netbox/virtualization/tests/test_views.py

@@ -23,13 +23,14 @@ class ClusterGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
         cls.form_data = {
         cls.form_data = {
             'name': 'Cluster Group X',
             'name': 'Cluster Group X',
             'slug': 'cluster-group-x',
             'slug': 'cluster-group-x',
+            'description': 'A new cluster group',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Cluster Group 4,cluster-group-4",
-            "Cluster Group 5,cluster-group-5",
-            "Cluster Group 6,cluster-group-6",
+            "name,slug,description",
+            "Cluster Group 4,cluster-group-4,Fourth cluster group",
+            "Cluster Group 5,cluster-group-5,Fifth cluster group",
+            "Cluster Group 6,cluster-group-6,Sixth cluster group",
         )
         )
 
 
 
 
@@ -48,13 +49,14 @@ class ClusterTypeTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
         cls.form_data = {
         cls.form_data = {
             'name': 'Cluster Type X',
             'name': 'Cluster Type X',
             'slug': 'cluster-type-x',
             'slug': 'cluster-type-x',
+            'description': 'A new cluster type',
         }
         }
 
 
         cls.csv_data = (
         cls.csv_data = (
-            "name,slug",
-            "Cluster Type 4,cluster-type-4",
-            "Cluster Type 5,cluster-type-5",
-            "Cluster Type 6,cluster-type-6",
+            "name,slug,description",
+            "Cluster Type 4,cluster-type-4,Fourth cluster type",
+            "Cluster Type 5,cluster-type-5,Fifth cluster type",
+            "Cluster Type 6,cluster-type-6,Sixth cluster type",
         )
         )