From 255d12309a4cec652d660b102c1b5848a7513413 Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 21 Jan 2020 15:50:38 +0100 Subject: [PATCH 1/6] dcim: fix #3965 by adding an option to get_rack_units --- netbox/dcim/models/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index 4ff15141c..c1c47cf23 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -468,7 +468,7 @@ class RackElevationHelperMixin: :param unit_height: Height of each rack unit for the rendered drawing. Note this is not the total height of the elevation """ - elevation = self.get_rack_units(face=face, expand_devices=False) + elevation = self.get_rack_units(face=face, expand_devices=False, always_show_device=True) reserved_units = self.get_reserved_units().keys() return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height) @@ -694,7 +694,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): def get_status_class(self): return self.STATUS_CLASS_MAP.get(self.status) - def get_rack_units(self, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True): + def get_rack_units(self, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True, always_show_device=False): """ Return a list of rack units as dictionaries. Example: {'device': None, 'face': 0, 'id': 48, 'name': 'U48'} Each key 'device' is either a Device or None. By default, multi-U devices are repeated for each U they occupy. @@ -704,6 +704,8 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): :param expand_devices: When True, all units that a device occupies will be listed with each containing a reference to the device. When False, only the bottom most unit for a device is included and that unit contains a height attribute for the device + :param always_show_device: When True it will always show the device, no matter its orientation. + When False it will only show full-width devices or those with the right orientation in the rack. """ elevation = OrderedDict() @@ -723,9 +725,11 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): ).filter( rack=self, position__gt=0 - ).filter( - Q(face=face) | Q(device_type__is_full_depth=True) ) + if not always_show_device: + queryset = queryset.filter( + Q(face=face) | Q(device_type__is_full_depth=True) + ) for device in queryset: if expand_devices: for u in range(device.position, device.position + device.device_type.u_height): From e421c15bddb37e9fc34405107cc6d0b0cb365432 Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 21 Jan 2020 16:56:06 +0100 Subject: [PATCH 2/6] dcim: merge elevations as necessary --- netbox/dcim/models/__init__.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index c1c47cf23..e95c3e7b5 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -459,6 +459,21 @@ class RackElevationHelperMixin: return drawing + def merge_elevations(self, face): + elevation = self.get_rack_units(face=face, expand_devices=False) + other_face = DeviceFaceChoices.FACE_FRONT if face==DeviceFaceChoices.FACE_REAR else DeviceFaceChoices.FACE_REAR + other = self.get_rack_units(face=other_face) + + unit_cursor = 0 + for u in elevation: + o = other[unit_cursor] + if not u['device'] and o['device']: + u['device'] = o['device'] + u['height'] = 1 + unit_cursor += u.get('height', 1) + + return elevation + def get_elevation_svg(self, face=DeviceFaceChoices.FACE_FRONT, unit_width=230, unit_height=20): """ Return an SVG of the rack elevation @@ -468,7 +483,7 @@ class RackElevationHelperMixin: :param unit_height: Height of each rack unit for the rendered drawing. Note this is not the total height of the elevation """ - elevation = self.get_rack_units(face=face, expand_devices=False, always_show_device=True) + elevation = self.merge_elevations(face) reserved_units = self.get_reserved_units().keys() return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height) @@ -694,7 +709,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): def get_status_class(self): return self.STATUS_CLASS_MAP.get(self.status) - def get_rack_units(self, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True, always_show_device=False): + def get_rack_units(self, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True): """ Return a list of rack units as dictionaries. Example: {'device': None, 'face': 0, 'id': 48, 'name': 'U48'} Each key 'device' is either a Device or None. By default, multi-U devices are repeated for each U they occupy. @@ -704,8 +719,6 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): :param expand_devices: When True, all units that a device occupies will be listed with each containing a reference to the device. When False, only the bottom most unit for a device is included and that unit contains a height attribute for the device - :param always_show_device: When True it will always show the device, no matter its orientation. - When False it will only show full-width devices or those with the right orientation in the rack. """ elevation = OrderedDict() @@ -725,11 +738,9 @@ class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin): ).filter( rack=self, position__gt=0 + ).filter( + Q(face=face) | Q(device_type__is_full_depth=True) ) - if not always_show_device: - queryset = queryset.filter( - Q(face=face) | Q(device_type__is_full_depth=True) - ) for device in queryset: if expand_devices: for u in range(device.position, device.position + device.device_type.u_height): From e184eb3521238f93ce0750558a4c1bb9ee3a06ab Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 21 Jan 2020 17:01:48 +0100 Subject: [PATCH 3/6] dcim: make pep happy --- netbox/dcim/models/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index e95c3e7b5..5629edc37 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -461,7 +461,7 @@ class RackElevationHelperMixin: def merge_elevations(self, face): elevation = self.get_rack_units(face=face, expand_devices=False) - other_face = DeviceFaceChoices.FACE_FRONT if face==DeviceFaceChoices.FACE_REAR else DeviceFaceChoices.FACE_REAR + other_face = DeviceFaceChoices.FACE_FRONT if face == DeviceFaceChoices.FACE_REAR else DeviceFaceChoices.FACE_REAR other = self.get_rack_units(face=other_face) unit_cursor = 0 From aa4b89f751659b588e4eaf90674c96074ac2f1af Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 21 Jan 2020 13:56:25 -0500 Subject: [PATCH 4/6] Changelog for #3965 --- docs/release-notes/version-2.7.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index e7e42470c..5592648c2 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -9,13 +9,14 @@ ## Bug Fixes * [#3721](https://github.com/netbox-community/netbox/issues/3721) - Allow Unicode characters in tag slugs +* [#3923](https://github.com/netbox-community/netbox/issues/3923) - Indicate validation failure when using SSH-style RSA keys * [#3951](https://github.com/netbox-community/netbox/issues/3951) - Fix exception in webhook worker due to missing constant -* [#3923](https://github.com/netbox-community/netbox/issues/3923) - Fix user key validation * [#3953](https://github.com/netbox-community/netbox/issues/3953) - Fix validation error when creating child devices * [#3960](https://github.com/netbox-community/netbox/issues/3960) - Fix legacy device status choice * [#3962](https://github.com/netbox-community/netbox/issues/3962) - Fix display of unnamed devices in rack elevations * [#3963](https://github.com/netbox-community/netbox/issues/3963) - Restore tooltip for devices in rack elevations * [#3964](https://github.com/netbox-community/netbox/issues/3964) - Show borders around devices in rack elevations +* [#3965](https://github.com/netbox-community/netbox/issues/3965) - Indicate the presence of "background" devices in rack elevations * [#3966](https://github.com/netbox-community/netbox/issues/3966) - Fix filtering of device components by region/site * [#3967](https://github.com/netbox-community/netbox/issues/3967) - Resolve migration of "other" interface type From 2581a55214485ed47605ae68c8d2d06b4c6e0b0d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 21 Jan 2020 15:04:09 -0500 Subject: [PATCH 5/6] Release v2.7.2 --- docs/release-notes/version-2.7.md | 2 +- netbox/netbox/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 5592648c2..fb544d8a8 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -1,4 +1,4 @@ -# v2.7.2 (FUTURE) +# v2.7.2 (2020-01-21) ## Enhancements diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index d3cc3169f..d558acc62 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured # Environment setup # -VERSION = '2.7.2-dev' +VERSION = '2.7.2' # Hostname HOSTNAME = platform.node() From b06bed368bc0d8f19565063dffcf14d3ccd8165a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 21 Jan 2020 15:13:49 -0500 Subject: [PATCH 6/6] Post-release version bump --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index d558acc62..e5925184d 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured # Environment setup # -VERSION = '2.7.2' +VERSION = '2.7.3-dev' # Hostname HOSTNAME = platform.node()