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: