diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py index cacf1f72b..671742f8e 100644 --- a/netbox/dcim/forms/bulk_edit.py +++ b/netbox/dcim/forms/bulk_edit.py @@ -291,6 +291,11 @@ class RackBulkEditForm(NetBoxModelBulkEditForm): required=False, label=_('Height (U)') ) + exclude_from_utilization = forms.NullBooleanField( + required=False, + widget=BulkEditNullBooleanSelect, + label=_('Descending units') + ) desc_units = forms.NullBooleanField( required=False, widget=BulkEditNullBooleanSelect, @@ -344,7 +349,8 @@ class RackBulkEditForm(NetBoxModelBulkEditForm): (_('Rack'), ('status', 'role', 'tenant', 'serial', 'asset_tag', 'description')), (_('Location'), ('region', 'site_group', 'site', 'location')), (_('Hardware'), ( - 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', + 'type', 'width', 'u_height', 'exclude_from_utilization', 'desc_units', 'outer_width', 'outer_depth', + 'outer_unit', 'mounting_depth', )), (_('Weight'), ('weight', 'max_weight', 'weight_unit')), ) @@ -420,6 +426,11 @@ class DeviceTypeBulkEditForm(NetBoxModelBulkEditForm): widget=BulkEditNullBooleanSelect(), label=_('Is full depth') ) + exclude_from_utilization = forms.NullBooleanField( + required=False, + widget=BulkEditNullBooleanSelect(), + label=_('Exclude from utilization') + ) airflow = forms.ChoiceField( label=_('Airflow'), choices=add_blank_choice(DeviceAirflowChoices), diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index e41e875e4..d63873b59 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -335,8 +335,8 @@ class DeviceTypeImportForm(NetBoxModelImportForm): class Meta: model = DeviceType fields = [ - 'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'airflow', 'description', 'weight', 'weight_unit', 'comments', 'tags', + 'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', 'exclude_from_utilization', + 'is_full_depth', 'subdevice_role', 'airflow', 'description', 'weight', 'weight_unit', 'comments', 'tags', ] diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 93e214598..3d626d201 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -302,7 +302,8 @@ class DeviceTypeForm(NetBoxModelForm): fieldsets = ( (_('Device Type'), ('manufacturer', 'model', 'slug', 'default_platform', 'description', 'tags')), (_('Chassis'), ( - 'u_height', 'is_full_depth', 'part_number', 'subdevice_role', 'airflow', 'weight', 'weight_unit', + 'u_height', 'exclude_from_utilization', 'is_full_depth', 'part_number', 'subdevice_role', 'airflow', + 'weight', 'weight_unit', )), (_('Images'), ('front_image', 'rear_image')), ) @@ -310,9 +311,9 @@ class DeviceTypeForm(NetBoxModelForm): class Meta: model = DeviceType fields = [ - 'manufacturer', 'model', 'slug', 'default_platform', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'airflow', 'weight', 'weight_unit', 'front_image', 'rear_image', 'description', - 'comments', 'tags', + 'manufacturer', 'model', 'slug', 'default_platform', 'part_number', 'u_height', 'exclude_from_utilization', + 'is_full_depth', 'subdevice_role', 'airflow', 'weight', 'weight_unit', 'front_image', 'rear_image', + 'description', 'comments', 'tags', ] widgets = { 'front_image': ClearableFileInput(attrs={ diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index ef0dde4da..a946ca865 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -357,7 +357,7 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin): return [u for u in elevation.values()] - def get_available_units(self, u_height=1, rack_face=None, exclude=None): + def get_available_units(self, u_height=1, rack_face=None, exclude=None, exclude_from_utilization=False): """ Return a list of units within the rack available to accommodate a device of a given U height (default 1). Optionally exclude one or more devices when calculating empty units (needed when moving a device from one @@ -369,6 +369,9 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin): """ # Gather all devices which consume U space within the rack devices = self.devices.prefetch_related('device_type').filter(position__gte=1) + if exclude_from_utilization: + devices = devices.exclude(device_type__exclude_from_utilization=True) + if exclude is not None: devices = devices.exclude(pk__in=exclude) @@ -453,7 +456,7 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin): """ # Determine unoccupied units total_units = len(list(self.units)) - available_units = self.get_available_units(u_height=0.5) + available_units = self.get_available_units(u_height=0.5, exclude_from_utilization=True) # Remove reserved units for ru in self.get_reserved_units(): diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index 7d8884fc1..fad238c6e 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -98,6 +98,7 @@ class DeviceTypeTable(NetBoxTable): verbose_name=_('U Height'), template_code='{{ value|floatformat }}' ) + exclude_from_utilization = columns.BooleanColumn() weight = columns.TemplateColumn( verbose_name=_('Weight'), template_code=WEIGHT, @@ -142,9 +143,9 @@ class DeviceTypeTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = models.DeviceType fields = ( - 'pk', 'id', 'model', 'manufacturer', 'default_platform', 'slug', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'airflow', 'weight', 'description', 'comments', 'instance_count', 'tags', 'created', - 'last_updated', + 'pk', 'id', 'model', 'manufacturer', 'default_platform', 'slug', 'part_number', 'u_height', + 'exclude_from_utilization', 'is_full_depth', 'subdevice_role', 'airflow', 'weight', + 'description', 'comments', 'instance_count', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count', diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 419ab7f00..35b089664 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -40,6 +40,10 @@