From 78e26ea5914fe0aa78a4fbc67c628daf1b1178ce Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 15 Jun 2023 12:46:18 -0700 Subject: [PATCH] verify devices can still fit if change rack starting_unit --- netbox/dcim/models/racks.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index f7d8c0d65..2c5976d3d 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -241,12 +241,25 @@ class Rack(PrimaryModel, WeightMixin): ).order_by('-position').first() if top_device: min_height = top_device.position + top_device.device_type.u_height - 1 - if self.u_height < min_height: + if self.u_height + self.start_unit < min_height: raise ValidationError({ 'u_height': "Rack must be at least {}U tall to house currently installed devices.".format( min_height ) }) + # Validate the Rack starting_unit > position of any installed devices + first_device = Device.objects.filter( + rack=self + ).exclude( + position__isnull=True + ).order_by('position').first() + if first_device: + if self.starting_unit > first_device.position: + raise ValidationError({ + 'starting_unit': "Rack must have a staring unit at most {} to house currently installed devices.".format( + first_device.position + ) + }) # Validate that Rack was assigned a Location of its same site, if applicable if self.location: if self.location.site != self.site: