From 7cf437e11b5377a46dcbe23f13cc3d1215b848fd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 13:53:39 -0400 Subject: [PATCH] Fixes #26: Added rack height validation --- netbox/dcim/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 0fe3bc30c..5ff233c9c 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -183,6 +183,16 @@ class Rack(CreatedUpdatedModel): def get_absolute_url(self): return reverse('dcim:rack', args=[self.pk]) + def clean(self): + + # Validate that Rack is tall enough to house the installed Devices + if self.pk: + top_device = Device.objects.filter(rack=self).order_by('-position').first() + min_height = top_device.position + top_device.device_type.u_height - 1 + if self.u_height < min_height: + raise ValidationError("Rack must be at least {}U tall with currently installed devices." + .format(min_height)) + def to_csv(self): return ','.join([ self.site.name,