From 176bd2396be49c9783b2a2e86a4acb3d6aeb4612 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 14 Oct 2021 14:48:00 -0400 Subject: [PATCH 1/3] Closes #6711: Add longtext custom field type with Markdown support --- docs/models/extras/customfield.md | 1 + docs/release-notes/version-3.1.md | 1 + netbox/extras/choices.py | 2 + netbox/extras/models/customfields.py | 21 ++++- netbox/extras/tests/test_customfields.py | 86 ++++++++++++++++--- netbox/extras/tests/test_forms.py | 3 + netbox/templates/inc/custom_fields_panel.html | 6 +- 7 files changed, 101 insertions(+), 19 deletions(-) diff --git a/docs/models/extras/customfield.md b/docs/models/extras/customfield.md index 52b8bab1e..7294fbd34 100644 --- a/docs/models/extras/customfield.md +++ b/docs/models/extras/customfield.md @@ -11,6 +11,7 @@ Within the database, custom fields are stored as JSON data directly alongside ea Custom fields may be created by navigating to Customization > Custom Fields. NetBox supports six types of custom field: * Text: Free-form text (up to 255 characters) +* Long text: Free-form of any length; supports Markdown rendering * Integer: A whole number (positive or negative) * Boolean: True or false * Date: A date in ISO 8601 format (YYYY-MM-DD) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 00a6e2fda..23567d68e 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -6,6 +6,7 @@ ### Enhancements * [#1337](https://github.com/netbox-community/netbox/issues/1337) - Add WWN field to interfaces +* [#6711](https://github.com/netbox-community/netbox/issues/6711) - Add `longtext` custom field type with Markdown support * [#6874](https://github.com/netbox-community/netbox/issues/6874) - Add tenant assignment for locations ### Other Changes diff --git a/netbox/extras/choices.py b/netbox/extras/choices.py index 4452b5aad..4f350fc9b 100644 --- a/netbox/extras/choices.py +++ b/netbox/extras/choices.py @@ -8,6 +8,7 @@ from utilities.choices import ChoiceSet class CustomFieldTypeChoices(ChoiceSet): TYPE_TEXT = 'text' + TYPE_LONGTEXT = 'longtext' TYPE_INTEGER = 'integer' TYPE_BOOLEAN = 'boolean' TYPE_DATE = 'date' @@ -17,6 +18,7 @@ class CustomFieldTypeChoices(ChoiceSet): CHOICES = ( (TYPE_TEXT, 'Text'), + (TYPE_LONGTEXT, 'Text (long)'), (TYPE_INTEGER, 'Integer'), (TYPE_BOOLEAN, 'Boolean (true/false)'), (TYPE_DATE, 'Date'), diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index d8e2e11c9..8c0193eaa 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -166,7 +166,10 @@ class CustomField(ChangeLoggedModel): # Validate the field's default value (if any) if self.default is not None: try: - default_value = str(self.default) if self.type == CustomFieldTypeChoices.TYPE_TEXT else self.default + if self.type in (CustomFieldTypeChoices.TYPE_TEXT, CustomFieldTypeChoices.TYPE_LONGTEXT): + default_value = str(self.default) + else: + default_value = self.default self.validate(default_value) except ValidationError as err: raise ValidationError({ @@ -184,7 +187,11 @@ class CustomField(ChangeLoggedModel): }) # Regex validation can be set only for text fields - regex_types = (CustomFieldTypeChoices.TYPE_TEXT, CustomFieldTypeChoices.TYPE_URL) + regex_types = ( + CustomFieldTypeChoices.TYPE_TEXT, + CustomFieldTypeChoices.TYPE_LONGTEXT, + CustomFieldTypeChoices.TYPE_URL, + ) if self.validation_regex and self.type not in regex_types: raise ValidationError({ 'validation_regex': "Regular expression validation is supported only for text and URL fields" @@ -275,7 +282,13 @@ class CustomField(ChangeLoggedModel): # Text else: - field = forms.CharField(max_length=255, required=required, initial=initial) + if self.type == CustomFieldTypeChoices.TYPE_LONGTEXT: + max_length = None + widget = forms.Textarea + else: + max_length = 255 + widget = None + field = forms.CharField(max_length=max_length, required=required, initial=initial, widget=widget) if self.validation_regex: field.validators = [ RegexValidator( @@ -298,7 +311,7 @@ class CustomField(ChangeLoggedModel): if value not in [None, '']: # Validate text field - if self.type == CustomFieldTypeChoices.TYPE_TEXT: + if self.type in (CustomFieldTypeChoices.TYPE_TEXT, CustomFieldTypeChoices.TYPE_LONGTEXT): if type(value) is not str: raise ValidationError(f"Value must be a string.") if self.validation_regex and not re.match(self.validation_regex, value): diff --git a/netbox/extras/tests/test_customfields.py b/netbox/extras/tests/test_customfields.py index 32c473678..0a40aeba9 100644 --- a/netbox/extras/tests/test_customfields.py +++ b/netbox/extras/tests/test_customfields.py @@ -24,13 +24,46 @@ class CustomFieldTest(TestCase): def test_simple_fields(self): DATA = ( - {'field_type': CustomFieldTypeChoices.TYPE_TEXT, 'field_value': 'Foobar!', 'empty_value': ''}, - {'field_type': CustomFieldTypeChoices.TYPE_INTEGER, 'field_value': 0, 'empty_value': None}, - {'field_type': CustomFieldTypeChoices.TYPE_INTEGER, 'field_value': 42, 'empty_value': None}, - {'field_type': CustomFieldTypeChoices.TYPE_BOOLEAN, 'field_value': True, 'empty_value': None}, - {'field_type': CustomFieldTypeChoices.TYPE_BOOLEAN, 'field_value': False, 'empty_value': None}, - {'field_type': CustomFieldTypeChoices.TYPE_DATE, 'field_value': '2016-06-23', 'empty_value': None}, - {'field_type': CustomFieldTypeChoices.TYPE_URL, 'field_value': 'http://example.com/', 'empty_value': ''}, + { + 'field_type': CustomFieldTypeChoices.TYPE_TEXT, + 'field_value': 'Foobar!', + 'empty_value': '', + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_LONGTEXT, + 'field_value': 'Text with **Markdown**', + 'empty_value': '', + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_INTEGER, + 'field_value': 0, + 'empty_value': None, + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_INTEGER, + 'field_value': 42, + 'empty_value': None, + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_BOOLEAN, + 'field_value': True, + 'empty_value': None, + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_BOOLEAN, + 'field_value': False, + 'empty_value': None, + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_DATE, + 'field_value': '2016-06-23', + 'empty_value': None, + }, + { + 'field_type': CustomFieldTypeChoices.TYPE_URL, + 'field_value': 'http://example.com/', + 'empty_value': '', + }, ) obj_type = ContentType.objects.get_for_model(Site) @@ -149,6 +182,11 @@ class CustomFieldAPITest(APITestCase): cls.cf_text.save() cls.cf_text.content_types.set([content_type]) + # Long text custom field + cls.cf_longtext = CustomField(type=CustomFieldTypeChoices.TYPE_LONGTEXT, name='longtext_field', default='ABC') + cls.cf_longtext.save() + cls.cf_longtext.content_types.set([content_type]) + # Integer custom field cls.cf_integer = CustomField(type=CustomFieldTypeChoices.TYPE_INTEGER, name='number_field', default=123) cls.cf_integer.save() @@ -185,6 +223,7 @@ class CustomFieldAPITest(APITestCase): # Assign custom field values for site 2 cls.sites[1].custom_field_data = { cls.cf_text.name: 'bar', + cls.cf_longtext.name: 'DEF', cls.cf_integer.name: 456, cls.cf_boolean.name: True, cls.cf_date.name: '2020-01-02', @@ -204,6 +243,7 @@ class CustomFieldAPITest(APITestCase): self.assertEqual(response.data['name'], self.sites[0].name) self.assertEqual(response.data['custom_fields'], { 'text_field': None, + 'longtext_field': None, 'number_field': None, 'boolean_field': None, 'date_field': None, @@ -222,6 +262,7 @@ class CustomFieldAPITest(APITestCase): response = self.client.get(url, **self.header) self.assertEqual(response.data['name'], self.sites[1].name) self.assertEqual(response.data['custom_fields']['text_field'], site2_cfvs['text_field']) + self.assertEqual(response.data['custom_fields']['longtext_field'], site2_cfvs['longtext_field']) self.assertEqual(response.data['custom_fields']['number_field'], site2_cfvs['number_field']) self.assertEqual(response.data['custom_fields']['boolean_field'], site2_cfvs['boolean_field']) self.assertEqual(response.data['custom_fields']['date_field'], site2_cfvs['date_field']) @@ -245,6 +286,7 @@ class CustomFieldAPITest(APITestCase): # Validate response data response_cf = response.data['custom_fields'] self.assertEqual(response_cf['text_field'], self.cf_text.default) + self.assertEqual(response_cf['longtext_field'], self.cf_longtext.default) self.assertEqual(response_cf['number_field'], self.cf_integer.default) self.assertEqual(response_cf['boolean_field'], self.cf_boolean.default) self.assertEqual(response_cf['date_field'], self.cf_date.default) @@ -254,6 +296,7 @@ class CustomFieldAPITest(APITestCase): # Validate database data site = Site.objects.get(pk=response.data['id']) self.assertEqual(site.custom_field_data['text_field'], self.cf_text.default) + self.assertEqual(site.custom_field_data['longtext_field'], self.cf_longtext.default) self.assertEqual(site.custom_field_data['number_field'], self.cf_integer.default) self.assertEqual(site.custom_field_data['boolean_field'], self.cf_boolean.default) self.assertEqual(str(site.custom_field_data['date_field']), self.cf_date.default) @@ -269,6 +312,7 @@ class CustomFieldAPITest(APITestCase): 'slug': 'site-3', 'custom_fields': { 'text_field': 'bar', + 'longtext_field': 'blah blah blah', 'number_field': 456, 'boolean_field': True, 'date_field': '2020-01-02', @@ -286,6 +330,7 @@ class CustomFieldAPITest(APITestCase): response_cf = response.data['custom_fields'] data_cf = data['custom_fields'] self.assertEqual(response_cf['text_field'], data_cf['text_field']) + self.assertEqual(response_cf['longtext_field'], data_cf['longtext_field']) self.assertEqual(response_cf['number_field'], data_cf['number_field']) self.assertEqual(response_cf['boolean_field'], data_cf['boolean_field']) self.assertEqual(response_cf['date_field'], data_cf['date_field']) @@ -295,6 +340,7 @@ class CustomFieldAPITest(APITestCase): # Validate database data site = Site.objects.get(pk=response.data['id']) self.assertEqual(site.custom_field_data['text_field'], data_cf['text_field']) + self.assertEqual(site.custom_field_data['longtext_field'], data_cf['longtext_field']) self.assertEqual(site.custom_field_data['number_field'], data_cf['number_field']) self.assertEqual(site.custom_field_data['boolean_field'], data_cf['boolean_field']) self.assertEqual(str(site.custom_field_data['date_field']), data_cf['date_field']) @@ -332,6 +378,7 @@ class CustomFieldAPITest(APITestCase): # Validate response data response_cf = response.data[i]['custom_fields'] self.assertEqual(response_cf['text_field'], self.cf_text.default) + self.assertEqual(response_cf['longtext_field'], self.cf_longtext.default) self.assertEqual(response_cf['number_field'], self.cf_integer.default) self.assertEqual(response_cf['boolean_field'], self.cf_boolean.default) self.assertEqual(response_cf['date_field'], self.cf_date.default) @@ -341,6 +388,7 @@ class CustomFieldAPITest(APITestCase): # Validate database data site = Site.objects.get(pk=response.data[i]['id']) self.assertEqual(site.custom_field_data['text_field'], self.cf_text.default) + self.assertEqual(site.custom_field_data['longtext_field'], self.cf_longtext.default) self.assertEqual(site.custom_field_data['number_field'], self.cf_integer.default) self.assertEqual(site.custom_field_data['boolean_field'], self.cf_boolean.default) self.assertEqual(str(site.custom_field_data['date_field']), self.cf_date.default) @@ -353,6 +401,7 @@ class CustomFieldAPITest(APITestCase): """ custom_field_data = { 'text_field': 'bar', + 'longtext_field': 'abcdefghij', 'number_field': 456, 'boolean_field': True, 'date_field': '2020-01-02', @@ -388,6 +437,7 @@ class CustomFieldAPITest(APITestCase): # Validate response data response_cf = response.data[i]['custom_fields'] self.assertEqual(response_cf['text_field'], custom_field_data['text_field']) + self.assertEqual(response_cf['longtext_field'], custom_field_data['longtext_field']) self.assertEqual(response_cf['number_field'], custom_field_data['number_field']) self.assertEqual(response_cf['boolean_field'], custom_field_data['boolean_field']) self.assertEqual(response_cf['date_field'], custom_field_data['date_field']) @@ -397,6 +447,7 @@ class CustomFieldAPITest(APITestCase): # Validate database data site = Site.objects.get(pk=response.data[i]['id']) self.assertEqual(site.custom_field_data['text_field'], custom_field_data['text_field']) + self.assertEqual(site.custom_field_data['longtext_field'], custom_field_data['longtext_field']) self.assertEqual(site.custom_field_data['number_field'], custom_field_data['number_field']) self.assertEqual(site.custom_field_data['boolean_field'], custom_field_data['boolean_field']) self.assertEqual(str(site.custom_field_data['date_field']), custom_field_data['date_field']) @@ -426,6 +477,7 @@ class CustomFieldAPITest(APITestCase): response_cf = response.data['custom_fields'] self.assertEqual(response_cf['text_field'], data['custom_fields']['text_field']) self.assertEqual(response_cf['number_field'], data['custom_fields']['number_field']) + self.assertEqual(response_cf['longtext_field'], original_cfvs['longtext_field']) self.assertEqual(response_cf['boolean_field'], original_cfvs['boolean_field']) self.assertEqual(response_cf['date_field'], original_cfvs['date_field']) self.assertEqual(response_cf['url_field'], original_cfvs['url_field']) @@ -435,6 +487,7 @@ class CustomFieldAPITest(APITestCase): site.refresh_from_db() self.assertEqual(site.custom_field_data['text_field'], data['custom_fields']['text_field']) self.assertEqual(site.custom_field_data['number_field'], data['custom_fields']['number_field']) + self.assertEqual(site.custom_field_data['longtext_field'], original_cfvs['longtext_field']) self.assertEqual(site.custom_field_data['boolean_field'], original_cfvs['boolean_field']) self.assertEqual(site.custom_field_data['date_field'], original_cfvs['date_field']) self.assertEqual(site.custom_field_data['url_field'], original_cfvs['url_field']) @@ -491,11 +544,14 @@ class CustomFieldImportTest(TestCase): custom_fields = ( CustomField(name='text', type=CustomFieldTypeChoices.TYPE_TEXT), + CustomField(name='longtext', type=CustomFieldTypeChoices.TYPE_LONGTEXT), CustomField(name='integer', type=CustomFieldTypeChoices.TYPE_INTEGER), CustomField(name='boolean', type=CustomFieldTypeChoices.TYPE_BOOLEAN), CustomField(name='date', type=CustomFieldTypeChoices.TYPE_DATE), CustomField(name='url', type=CustomFieldTypeChoices.TYPE_URL), - CustomField(name='select', type=CustomFieldTypeChoices.TYPE_SELECT, choices=['Choice A', 'Choice B', 'Choice C']), + CustomField(name='select', type=CustomFieldTypeChoices.TYPE_SELECT, choices=[ + 'Choice A', 'Choice B', 'Choice C', + ]), ) for cf in custom_fields: cf.save() @@ -506,10 +562,10 @@ class CustomFieldImportTest(TestCase): Import a Site in CSV format, including a value for each CustomField. """ data = ( - ('name', 'slug', 'status', 'cf_text', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'), - ('Site 1', 'site-1', 'active', 'ABC', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'), - ('Site 2', 'site-2', 'active', 'DEF', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'), - ('Site 3', 'site-3', 'active', '', '', '', '', '', ''), + ('name', 'slug', 'status', 'cf_text', 'cf_longtext', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'), + ('Site 1', 'site-1', 'active', 'ABC', 'Foo', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'), + ('Site 2', 'site-2', 'active', 'DEF', 'Bar', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'), + ('Site 3', 'site-3', 'active', '', '', '', '', '', '', ''), ) csv_data = '\n'.join(','.join(row) for row in data) @@ -518,8 +574,9 @@ class CustomFieldImportTest(TestCase): # Validate data for site 1 site1 = Site.objects.get(name='Site 1') - self.assertEqual(len(site1.custom_field_data), 6) + self.assertEqual(len(site1.custom_field_data), 7) self.assertEqual(site1.custom_field_data['text'], 'ABC') + self.assertEqual(site1.custom_field_data['longtext'], 'Foo') self.assertEqual(site1.custom_field_data['integer'], 123) self.assertEqual(site1.custom_field_data['boolean'], True) self.assertEqual(site1.custom_field_data['date'], '2020-01-01') @@ -528,8 +585,9 @@ class CustomFieldImportTest(TestCase): # Validate data for site 2 site2 = Site.objects.get(name='Site 2') - self.assertEqual(len(site2.custom_field_data), 6) + self.assertEqual(len(site2.custom_field_data), 7) self.assertEqual(site2.custom_field_data['text'], 'DEF') + self.assertEqual(site2.custom_field_data['longtext'], 'Bar') self.assertEqual(site2.custom_field_data['integer'], 456) self.assertEqual(site2.custom_field_data['boolean'], False) self.assertEqual(site2.custom_field_data['date'], '2020-01-02') diff --git a/netbox/extras/tests/test_forms.py b/netbox/extras/tests/test_forms.py index cb0a9c081..1ccc2332b 100644 --- a/netbox/extras/tests/test_forms.py +++ b/netbox/extras/tests/test_forms.py @@ -17,6 +17,9 @@ class CustomFieldModelFormTest(TestCase): cf_text = CustomField.objects.create(name='text', type=CustomFieldTypeChoices.TYPE_TEXT) cf_text.content_types.set([obj_type]) + cf_longtext = CustomField.objects.create(name='longtext', type=CustomFieldTypeChoices.TYPE_LONGTEXT) + cf_longtext.content_types.set([obj_type]) + cf_integer = CustomField.objects.create(name='integer', type=CustomFieldTypeChoices.TYPE_INTEGER) cf_integer.content_types.set([obj_type]) diff --git a/netbox/templates/inc/custom_fields_panel.html b/netbox/templates/inc/custom_fields_panel.html index fd0379961..eb6e490e7 100644 --- a/netbox/templates/inc/custom_fields_panel.html +++ b/netbox/templates/inc/custom_fields_panel.html @@ -1,3 +1,5 @@ +{% load helpers %} + {% with custom_fields=object.get_custom_fields %} {% if custom_fields %}
@@ -10,7 +12,9 @@ {{ field }} - {% if field.type == 'boolean' and value == True %} + {% if field.type == 'longtext' and value %} + {{ value|render_markdown }} + {% elif field.type == 'boolean' and value == True %} {% elif field.type == 'boolean' and value == False %} From 2c2c2e9060db4b4243dbd20a9afc352f4aaa9887 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 14 Oct 2021 15:38:29 -0400 Subject: [PATCH 2/3] 3839: Add airflow field to DeviceType --- netbox/dcim/api/serializers.py | 3 ++- netbox/dcim/choices.py | 19 +++++++++++++++++++ netbox/dcim/filtersets.py | 2 +- netbox/dcim/forms/bulk_edit.py | 5 +++++ netbox/dcim/forms/filtersets.py | 7 ++++++- netbox/dcim/forms/models.py | 7 +++++-- netbox/dcim/forms/object_import.py | 2 +- netbox/dcim/graphql/types.py | 3 +++ .../migrations/0136_devicetype_airflow.py | 18 ++++++++++++++++++ netbox/dcim/models/devices.py | 9 ++++++++- netbox/dcim/tables/devicetypes.py | 2 +- netbox/dcim/tests/test_filtersets.py | 8 ++++++-- netbox/templates/dcim/devicetype.html | 6 ++++++ 13 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 netbox/dcim/migrations/0136_devicetype_airflow.py diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index d6e44c281..e42b0246b 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -288,13 +288,14 @@ class DeviceTypeSerializer(PrimaryModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='dcim-api:devicetype-detail') manufacturer = NestedManufacturerSerializer() subdevice_role = ChoiceField(choices=SubdeviceRoleChoices, allow_blank=True, required=False) + airflow = ChoiceField(choices=DeviceAirflowChoices, allow_blank=True, required=False) device_count = serializers.IntegerField(read_only=True) class Meta: model = DeviceType fields = [ 'id', 'url', 'display', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'front_image', 'rear_image', 'comments', 'tags', 'custom_fields', 'created', + 'subdevice_role', 'airflow', 'front_image', 'rear_image', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count', ] diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py index acea294f8..a4c3cb983 100644 --- a/netbox/dcim/choices.py +++ b/netbox/dcim/choices.py @@ -174,6 +174,25 @@ class DeviceStatusChoices(ChoiceSet): } +class DeviceAirflowChoices(ChoiceSet): + + AIRFLOW_FRONT_TO_REAR = 'front-to-rear' + AIRFLOW_REAR_TO_FRONT = 'rear-to-front' + AIRFLOW_LEFT_TO_RIGHT = 'left-to-right' + AIRFLOW_RIGHT_TO_LEFT = 'right-to-left' + AIRFLOW_SIDE_TO_REAR = 'side-to-rear' + AIRFLOW_PASSIVE = 'passive' + + CHOICES = ( + (AIRFLOW_FRONT_TO_REAR, 'Front to rear'), + (AIRFLOW_REAR_TO_FRONT, 'Rear to front'), + (AIRFLOW_LEFT_TO_RIGHT, 'Left to right'), + (AIRFLOW_RIGHT_TO_LEFT, 'Right to left'), + (AIRFLOW_SIDE_TO_REAR, 'Side to rear'), + (AIRFLOW_PASSIVE, 'Passive'), + ) + + # # ConsolePorts # diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index 7f029097e..ee7957a92 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -441,7 +441,7 @@ class DeviceTypeFilterSet(PrimaryModelFilterSet): class Meta: model = DeviceType fields = [ - 'id', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', + 'id', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', ] def search(self, queryset, name, value): diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py index fd87d7304..1cc79ee48 100644 --- a/netbox/dcim/forms/bulk_edit.py +++ b/netbox/dcim/forms/bulk_edit.py @@ -335,6 +335,11 @@ class DeviceTypeBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldModel widget=BulkEditNullBooleanSelect(), label='Is full depth' ) + airflow = forms.ChoiceField( + choices=add_blank_choice(DeviceAirflowChoices), + required=False, + widget=StaticSelect() + ) class Meta: nullable_fields = [] diff --git a/netbox/dcim/forms/filtersets.py b/netbox/dcim/forms/filtersets.py index 4f4e10e96..e6b9ec8c4 100644 --- a/netbox/dcim/forms/filtersets.py +++ b/netbox/dcim/forms/filtersets.py @@ -385,7 +385,7 @@ class DeviceTypeFilterForm(BootstrapMixin, CustomFieldModelFilterForm): model = DeviceType field_groups = [ ['q', 'tag'], - ['manufacturer_id', 'subdevice_role'], + ['manufacturer_id', 'subdevice_role', 'airflow'], ['console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces', 'pass_through_ports'], ] q = forms.CharField( @@ -404,6 +404,11 @@ class DeviceTypeFilterForm(BootstrapMixin, CustomFieldModelFilterForm): required=False, widget=StaticSelectMultiple() ) + airflow = forms.MultipleChoiceField( + choices=add_blank_choice(DeviceAirflowChoices), + required=False, + widget=StaticSelectMultiple() + ) console_ports = forms.NullBooleanField( required=False, label='Has console ports', diff --git a/netbox/dcim/forms/models.py b/netbox/dcim/forms/models.py index a8c2991a4..f0059e770 100644 --- a/netbox/dcim/forms/models.py +++ b/netbox/dcim/forms/models.py @@ -367,12 +367,15 @@ class DeviceTypeForm(BootstrapMixin, CustomFieldModelForm): class Meta: model = DeviceType fields = [ - 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', + 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', 'front_image', 'rear_image', 'comments', 'tags', ] fieldsets = ( ('Device Type', ( - 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'tags', + 'manufacturer', 'model', 'slug', 'part_number', 'tags', + )), + ('Chassis', ( + 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', )), ('Images', ('front_image', 'rear_image')), ) diff --git a/netbox/dcim/forms/object_import.py b/netbox/dcim/forms/object_import.py index 0596261a6..03f040a00 100644 --- a/netbox/dcim/forms/object_import.py +++ b/netbox/dcim/forms/object_import.py @@ -26,7 +26,7 @@ class DeviceTypeImportForm(BootstrapMixin, forms.ModelForm): class Meta: model = DeviceType fields = [ - 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', + 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', 'comments', ] diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index be10556be..0f186c5d4 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -179,6 +179,9 @@ class DeviceTypeType(PrimaryObjectType): def resolve_subdevice_role(self, info): return self.subdevice_role or None + def resolve_airflow(self, info): + return self.airflow or None + class FrontPortType(ComponentObjectType): diff --git a/netbox/dcim/migrations/0136_devicetype_airflow.py b/netbox/dcim/migrations/0136_devicetype_airflow.py new file mode 100644 index 000000000..2b3bd215f --- /dev/null +++ b/netbox/dcim/migrations/0136_devicetype_airflow.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.8 on 2021-10-14 19:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0135_location_tenant'), + ] + + operations = [ + migrations.AddField( + model_name='devicetype', + name='airflow', + field=models.CharField(blank=True, max_length=50), + ), + ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 10cd35c13..2a4f58d10 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -115,6 +115,12 @@ class DeviceType(PrimaryModel): help_text='Parent devices house child devices in device bays. Leave blank ' 'if this device type is neither a parent nor a child.' ) + airflow = models.CharField( + max_length=50, + choices=DeviceAirflowChoices, + blank=True, + verbose_name='Airflow direction' + ) front_image = models.ImageField( upload_to='devicetype-images', blank=True @@ -130,7 +136,7 @@ class DeviceType(PrimaryModel): objects = RestrictedQuerySet.as_manager() clone_fields = [ - 'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', + 'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', ] class Meta: @@ -165,6 +171,7 @@ class DeviceType(PrimaryModel): ('u_height', self.u_height), ('is_full_depth', self.is_full_depth), ('subdevice_role', self.subdevice_role), + ('airflow', self.airflow), ('comments', self.comments), )) diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index 3b11a180b..b3310d5d2 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -77,7 +77,7 @@ class DeviceTypeTable(BaseTable): model = DeviceType fields = ( 'pk', 'model', 'manufacturer', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', - 'comments', 'instance_count', 'tags', + 'airflow', 'comments', 'instance_count', 'tags', ) default_columns = ( 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count', diff --git a/netbox/dcim/tests/test_filtersets.py b/netbox/dcim/tests/test_filtersets.py index fb94bde08..f9ecf103f 100644 --- a/netbox/dcim/tests/test_filtersets.py +++ b/netbox/dcim/tests/test_filtersets.py @@ -638,8 +638,8 @@ class DeviceTypeTestCase(TestCase, ChangeLoggedFilterSetTests): device_types = ( DeviceType(manufacturer=manufacturers[0], model='Model 1', slug='model-1', part_number='Part Number 1', u_height=1, is_full_depth=True), - DeviceType(manufacturer=manufacturers[1], model='Model 2', slug='model-2', part_number='Part Number 2', u_height=2, is_full_depth=True, subdevice_role=SubdeviceRoleChoices.ROLE_PARENT), - DeviceType(manufacturer=manufacturers[2], model='Model 3', slug='model-3', part_number='Part Number 3', u_height=3, is_full_depth=False, subdevice_role=SubdeviceRoleChoices.ROLE_CHILD), + DeviceType(manufacturer=manufacturers[1], model='Model 2', slug='model-2', part_number='Part Number 2', u_height=2, is_full_depth=True, subdevice_role=SubdeviceRoleChoices.ROLE_PARENT, airflow=DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR), + DeviceType(manufacturer=manufacturers[2], model='Model 3', slug='model-3', part_number='Part Number 3', u_height=3, is_full_depth=False, subdevice_role=SubdeviceRoleChoices.ROLE_CHILD, airflow=DeviceAirflowChoices.AIRFLOW_REAR_TO_FRONT), ) DeviceType.objects.bulk_create(device_types) @@ -704,6 +704,10 @@ class DeviceTypeTestCase(TestCase, ChangeLoggedFilterSetTests): params = {'subdevice_role': SubdeviceRoleChoices.ROLE_PARENT} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_airflow(self): + params = {'airflow': DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_manufacturer(self): manufacturers = Manufacturer.objects.all()[:2] params = {'manufacturer_id': [manufacturers[0].pk, manufacturers[1].pk]} diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 2a9f4a93b..2db37121f 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -90,6 +90,12 @@ {{ object.get_subdevice_role_display|placeholder }} + + Airflow direction + + {{ object.get_airflow_display|placeholder }} + + Front Image From 33ea8763d51e6fcc3d34a29fa227eefd9238ad2a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 14 Oct 2021 16:04:42 -0400 Subject: [PATCH 3/3] 3839: Add airflow field to Device --- docs/models/dcim/devicetype.md | 2 ++ docs/release-notes/version-3.1.md | 1 + netbox/dcim/api/serializers.py | 7 ++++--- netbox/dcim/filtersets.py | 2 +- netbox/dcim/forms/bulk_edit.py | 9 +++++++-- netbox/dcim/forms/bulk_import.py | 9 +++++++-- netbox/dcim/forms/filtersets.py | 7 ++++++- netbox/dcim/forms/models.py | 5 +++-- netbox/dcim/graphql/types.py | 3 +++ ...vicetype_airflow.py => 0136_device_airflow.py} | 7 +++++-- netbox/dcim/models/devices.py | 15 +++++++++++---- netbox/dcim/tables/devices.py | 4 ++-- netbox/dcim/tests/test_filtersets.py | 8 ++++++-- netbox/templates/dcim/device.html | 6 ++++++ netbox/templates/dcim/device_edit.html | 1 + netbox/templates/dcim/devicetype.html | 2 +- 16 files changed, 66 insertions(+), 22 deletions(-) rename netbox/dcim/migrations/{0136_devicetype_airflow.py => 0136_device_airflow.py} (67%) diff --git a/docs/models/dcim/devicetype.md b/docs/models/dcim/devicetype.md index a7e00dbc6..b919465c8 100644 --- a/docs/models/dcim/devicetype.md +++ b/docs/models/dcim/devicetype.md @@ -12,3 +12,5 @@ Some devices house child devices which share physical resources, like space and !!! note This parent/child relationship is **not** suitable for modeling chassis-based devices, wherein child members share a common control plane. Instead, line cards and similarly non-autonomous hardware should be modeled as inventory items within a device, with any associated interfaces or other components assigned directly to the device. + +A device type may optionally specify an airflow direction, such as front-to-rear, rear-to-front, or passive. Airflow direction may also be set separately per device. If it is not defined for a device at the time of its creation, it will inherit the airflow setting of its device type. diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 23567d68e..c49552edd 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -6,6 +6,7 @@ ### Enhancements * [#1337](https://github.com/netbox-community/netbox/issues/1337) - Add WWN field to interfaces +* [#3839](https://github.com/netbox-community/netbox/issues/3839) - Add `airflow` field for devices types and devices * [#6711](https://github.com/netbox-community/netbox/issues/6711) - Add `longtext` custom field type with Markdown support * [#6874](https://github.com/netbox-community/netbox/issues/6874) - Add tenant assignment for locations diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index e42b0246b..9d261d9e8 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -465,6 +465,7 @@ class DeviceSerializer(PrimaryModelSerializer): rack = NestedRackSerializer(required=False, allow_null=True) face = ChoiceField(choices=DeviceFaceChoices, allow_blank=True, required=False) status = ChoiceField(choices=DeviceStatusChoices, required=False) + airflow = ChoiceField(choices=DeviceAirflowChoices, allow_blank=True, required=False) primary_ip = NestedIPAddressSerializer(read_only=True) primary_ip4 = NestedIPAddressSerializer(required=False, allow_null=True) primary_ip6 = NestedIPAddressSerializer(required=False, allow_null=True) @@ -476,9 +477,9 @@ class DeviceSerializer(PrimaryModelSerializer): model = Device fields = [ 'id', 'url', 'display', 'name', 'device_type', 'device_role', 'tenant', 'platform', 'serial', 'asset_tag', - 'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4', - 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'local_context_data', - 'tags', 'custom_fields', 'created', 'last_updated', + 'site', 'location', 'rack', 'position', 'face', 'parent_device', 'status', 'airflow', 'primary_ip', + 'primary_ip4', 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', + 'local_context_data', 'tags', 'custom_fields', 'created', 'last_updated', ] validators = [] diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index ee7957a92..c3de7cb08 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -751,7 +751,7 @@ class DeviceFilterSet(PrimaryModelFilterSet, TenancyFilterSet, LocalConfigContex class Meta: model = Device - fields = ['id', 'name', 'asset_tag', 'face', 'position', 'vc_position', 'vc_priority'] + fields = ['id', 'name', 'asset_tag', 'face', 'position', 'airflow', 'vc_position', 'vc_priority'] def search(self, queryset, name, value): if not value.strip(): diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py index 1cc79ee48..289057be9 100644 --- a/netbox/dcim/forms/bulk_edit.py +++ b/netbox/dcim/forms/bulk_edit.py @@ -342,7 +342,7 @@ class DeviceTypeBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldModel ) class Meta: - nullable_fields = [] + nullable_fields = ['airflow'] class DeviceRoleBulkEditForm(BootstrapMixin, CustomFieldModelBulkEditForm): @@ -434,6 +434,11 @@ class DeviceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldModelBulk required=False, widget=StaticSelect() ) + airflow = forms.ChoiceField( + choices=add_blank_choice(DeviceAirflowChoices), + required=False, + widget=StaticSelect() + ) serial = forms.CharField( max_length=50, required=False, @@ -442,7 +447,7 @@ class DeviceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldModelBulk class Meta: nullable_fields = [ - 'tenant', 'platform', 'serial', + 'tenant', 'platform', 'serial', 'airflow', ] diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index ff9ab6fff..bd9e8cd4a 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -369,12 +369,17 @@ class DeviceCSVForm(BaseDeviceCSVForm): required=False, help_text='Mounted rack face' ) + airflow = CSVChoiceField( + choices=DeviceAirflowChoices, + required=False, + help_text='Airflow direction' + ) class Meta(BaseDeviceCSVForm.Meta): fields = [ 'name', 'device_role', 'tenant', 'manufacturer', 'device_type', 'platform', 'serial', 'asset_tag', 'status', - 'site', 'location', 'rack', 'position', 'face', 'virtual_chassis', 'vc_position', 'vc_priority', 'cluster', - 'comments', + 'site', 'location', 'rack', 'position', 'face', 'airflow', 'virtual_chassis', 'vc_position', 'vc_priority', + 'cluster', 'comments', ] def __init__(self, data=None, *args, **kwargs): diff --git a/netbox/dcim/forms/filtersets.py b/netbox/dcim/forms/filtersets.py index e6b9ec8c4..94e7bce05 100644 --- a/netbox/dcim/forms/filtersets.py +++ b/netbox/dcim/forms/filtersets.py @@ -490,7 +490,7 @@ class DeviceFilterForm(BootstrapMixin, LocalConfigContextFilterForm, TenancyFilt field_groups = [ ['q', 'tag'], ['region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id'], - ['status', 'role_id', 'serial', 'asset_tag', 'mac_address'], + ['status', 'role_id', 'airflow', 'serial', 'asset_tag', 'mac_address'], ['manufacturer_id', 'device_type_id', 'platform_id'], ['tenant_group_id', 'tenant_id'], [ @@ -579,6 +579,11 @@ class DeviceFilterForm(BootstrapMixin, LocalConfigContextFilterForm, TenancyFilt required=False, widget=StaticSelectMultiple() ) + airflow = forms.MultipleChoiceField( + choices=add_blank_choice(DeviceAirflowChoices), + required=False, + widget=StaticSelectMultiple() + ) serial = forms.CharField( required=False ) diff --git a/netbox/dcim/forms/models.py b/netbox/dcim/forms/models.py index f0059e770..cb690840f 100644 --- a/netbox/dcim/forms/models.py +++ b/netbox/dcim/forms/models.py @@ -522,8 +522,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): model = Device fields = [ 'name', 'device_role', 'device_type', 'serial', 'asset_tag', 'region', 'site_group', 'site', 'rack', - 'location', 'position', 'face', 'status', 'platform', 'primary_ip4', 'primary_ip6', 'cluster_group', - 'cluster', 'tenant_group', 'tenant', 'comments', 'tags', 'local_context_data' + 'location', 'position', 'face', 'status', 'airflow', 'platform', 'primary_ip4', 'primary_ip6', + 'cluster_group', 'cluster', 'tenant_group', 'tenant', 'comments', 'tags', 'local_context_data' ] help_texts = { 'device_role': "The function this device serves", @@ -534,6 +534,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): widgets = { 'face': StaticSelect(), 'status': StaticSelect(), + 'airflow': StaticSelect(), 'primary_ip4': StaticSelect(), 'primary_ip6': StaticSelect(), } diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index 0f186c5d4..80c32e66d 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -144,6 +144,9 @@ class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, PrimaryObjectType): def resolve_face(self, info): return self.face or None + def resolve_airflow(self, info): + return self.airflow or None + class DeviceBayType(ComponentObjectType): diff --git a/netbox/dcim/migrations/0136_devicetype_airflow.py b/netbox/dcim/migrations/0136_device_airflow.py similarity index 67% rename from netbox/dcim/migrations/0136_devicetype_airflow.py rename to netbox/dcim/migrations/0136_device_airflow.py index 2b3bd215f..a0887a0b4 100644 --- a/netbox/dcim/migrations/0136_devicetype_airflow.py +++ b/netbox/dcim/migrations/0136_device_airflow.py @@ -1,5 +1,3 @@ -# Generated by Django 3.2.8 on 2021-10-14 19:29 - from django.db import migrations, models @@ -15,4 +13,9 @@ class Migration(migrations.Migration): name='airflow', field=models.CharField(blank=True, max_length=50), ), + migrations.AddField( + model_name='device', + name='airflow', + field=models.CharField(blank=True, max_length=50), + ), ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 2a4f58d10..669f5cfbd 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -118,8 +118,7 @@ class DeviceType(PrimaryModel): airflow = models.CharField( max_length=50, choices=DeviceAirflowChoices, - blank=True, - verbose_name='Airflow direction' + blank=True ) front_image = models.ImageField( upload_to='devicetype-images', @@ -537,6 +536,11 @@ class Device(PrimaryModel, ConfigContextModel): choices=DeviceStatusChoices, default=DeviceStatusChoices.STATUS_ACTIVE ) + airflow = models.CharField( + max_length=50, + choices=DeviceAirflowChoices, + blank=True + ) primary_ip4 = models.OneToOneField( to='ipam.IPAddress', on_delete=models.SET_NULL, @@ -587,7 +591,7 @@ class Device(PrimaryModel, ConfigContextModel): objects = ConfigContextModelQuerySet.as_manager() clone_fields = [ - 'device_type', 'device_role', 'tenant', 'platform', 'site', 'location', 'rack', 'status', 'cluster', + 'device_type', 'device_role', 'tenant', 'platform', 'site', 'location', 'rack', 'status', 'airflow', 'cluster', ] class Meta: @@ -748,9 +752,12 @@ class Device(PrimaryModel, ConfigContextModel): }) def save(self, *args, **kwargs): - is_new = not bool(self.pk) + # Inherit airflow attribute from DeviceType if not set + if is_new and not self.airflow: + self.airflow = self.device_type.airflow + super().save(*args, **kwargs) # If this is a new Device, instantiate all of the related components per the DeviceType definition diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index c2b4b907b..a2d3f3da2 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -197,8 +197,8 @@ class DeviceTable(BaseTable): model = Device fields = ( 'pk', 'name', 'status', 'tenant', 'device_role', 'manufacturer', 'device_type', 'platform', 'serial', - 'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'primary_ip', 'primary_ip4', 'primary_ip6', - 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'tags', + 'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'airflow', 'primary_ip', 'primary_ip4', + 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'tags', ) default_columns = ( 'pk', 'name', 'status', 'tenant', 'site', 'location', 'rack', 'device_role', 'manufacturer', 'device_type', diff --git a/netbox/dcim/tests/test_filtersets.py b/netbox/dcim/tests/test_filtersets.py index f9ecf103f..fcee2914b 100644 --- a/netbox/dcim/tests/test_filtersets.py +++ b/netbox/dcim/tests/test_filtersets.py @@ -1239,8 +1239,8 @@ class DeviceTestCase(TestCase, ChangeLoggedFilterSetTests): devices = ( Device(name='Device 1', device_type=device_types[0], device_role=device_roles[0], platform=platforms[0], tenant=tenants[0], serial='ABC', asset_tag='1001', site=sites[0], location=locations[0], rack=racks[0], position=1, face=DeviceFaceChoices.FACE_FRONT, status=DeviceStatusChoices.STATUS_ACTIVE, cluster=clusters[0], local_context_data={"foo": 123}), - Device(name='Device 2', device_type=device_types[1], device_role=device_roles[1], platform=platforms[1], tenant=tenants[1], serial='DEF', asset_tag='1002', site=sites[1], location=locations[1], rack=racks[1], position=2, face=DeviceFaceChoices.FACE_FRONT, status=DeviceStatusChoices.STATUS_STAGED, cluster=clusters[1]), - Device(name='Device 3', device_type=device_types[2], device_role=device_roles[2], platform=platforms[2], tenant=tenants[2], serial='GHI', asset_tag='1003', site=sites[2], location=locations[2], rack=racks[2], position=3, face=DeviceFaceChoices.FACE_REAR, status=DeviceStatusChoices.STATUS_FAILED, cluster=clusters[2]), + Device(name='Device 2', device_type=device_types[1], device_role=device_roles[1], platform=platforms[1], tenant=tenants[1], serial='DEF', asset_tag='1002', site=sites[1], location=locations[1], rack=racks[1], position=2, face=DeviceFaceChoices.FACE_FRONT, status=DeviceStatusChoices.STATUS_STAGED, airflow=DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR, cluster=clusters[1]), + Device(name='Device 3', device_type=device_types[2], device_role=device_roles[2], platform=platforms[2], tenant=tenants[2], serial='GHI', asset_tag='1003', site=sites[2], location=locations[2], rack=racks[2], position=3, face=DeviceFaceChoices.FACE_REAR, status=DeviceStatusChoices.STATUS_FAILED, airflow=DeviceAirflowChoices.AIRFLOW_REAR_TO_FRONT, cluster=clusters[2]), ) Device.objects.bulk_create(devices) @@ -1394,6 +1394,10 @@ class DeviceTestCase(TestCase, ChangeLoggedFilterSetTests): params = {'is_full_depth': 'false'} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_airflow(self): + params = {'airflow': DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_mac_address(self): params = {'mac_address': ['00-00-00-00-00-01', '00-00-00-00-00-02']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 9d1868e1e..ec1ea3fa1 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -93,6 +93,12 @@ {{ object.device_type }} ({{ object.device_type.u_height }}U) + + Airflow + + {{ object.get_airflow_display|placeholder }} + + Serial Number {{ object.serial|placeholder }} diff --git a/netbox/templates/dcim/device_edit.html b/netbox/templates/dcim/device_edit.html index fbafa197d..1be272d3a 100644 --- a/netbox/templates/dcim/device_edit.html +++ b/netbox/templates/dcim/device_edit.html @@ -19,6 +19,7 @@
{% render_field form.manufacturer %} {% render_field form.device_type %} + {% render_field form.airflow %} {% render_field form.serial %} {% render_field form.asset_tag %} diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 2db37121f..40955f5d6 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -91,7 +91,7 @@ - Airflow direction + Airflow {{ object.get_airflow_display|placeholder }}