From 3cbda69c275530f385fde29f698d45e6738f2103 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 24 Oct 2023 08:00:17 -0700 Subject: [PATCH] 13230 review feedback --- netbox/dcim/api/serializers.py | 6 +++--- netbox/dcim/filtersets.py | 3 ++- netbox/dcim/models/racks.py | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index b43611dad..32dcdc5bb 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -343,9 +343,9 @@ class DeviceTypeSerializer(NetBoxModelSerializer): model = DeviceType fields = [ 'id', 'url', 'display', 'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', - 'is_full_depth', 'subdevice_role', 'airflow', 'weight', 'weight_unit', 'front_image', 'rear_image', - 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count', - 'console_port_template_count', 'console_server_port_template_count', 'power_port_template_count', + 'exclude_from_utilization', 'is_full_depth', 'subdevice_role', 'airflow', 'weight', 'weight_unit', + 'front_image', 'rear_image', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', + 'device_count', 'console_port_template_count', 'console_server_port_template_count', 'power_port_template_count', 'power_outlet_template_count', 'interface_template_count', 'front_port_template_count', 'rear_port_template_count', 'device_bay_template_count', 'module_bay_template_count', 'inventory_item_template_count', diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index d600667d7..c65110d9a 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -496,7 +496,8 @@ class DeviceTypeFilterSet(NetBoxModelFilterSet): class Meta: model = DeviceType fields = [ - 'id', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', 'weight', 'weight_unit', + 'id', 'model', 'slug', 'part_number', 'u_height', 'exclude_from_utilization', 'is_full_depth', 'subdevice_role', + 'airflow', 'weight', 'weight_unit', ] def search(self, queryset, name, value): diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index a946ca865..ab1027d1b 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, exclude_from_utilization=False): + def get_available_units(self, u_height=1, rack_face=None, exclude=None, ignore_excluded_devices=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 @@ -366,10 +366,11 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, WeightMixin): :param u_height: Minimum number of contiguous free units required :param rack_face: The face of the rack (front or rear) required; 'None' if device is full depth :param exclude: List of devices IDs to exclude (useful when moving a device within a rack) + :param ignore_excluded_devices: Ignore devices that are marked to exclude from utilization calculations """ # 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: + if ignore_excluded_devices: devices = devices.exclude(device_type__exclude_from_utilization=True) if exclude is not None: @@ -456,7 +457,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, exclude_from_utilization=True) + available_units = self.get_available_units(u_height=0.5, ignore_excluded_devices=True) # Remove reserved units for ru in self.get_reserved_units():