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