|
@@ -30,6 +30,14 @@ class IPPool(models.Model):
|
|
|
max_subnetsize = 64 if self.inet.version == 6 else 32
|
|
|
if not self.inet.prefixlen <= self.default_subnetsize <= max_subnetsize:
|
|
|
raise ValidationError('Invalid default subnet size')
|
|
|
+ # Check that related subnet are in the pool (useful when
|
|
|
+ # modifying an existing pool that already has subnets
|
|
|
+ # allocated in it)
|
|
|
+ incorrect = [str(subnet) for subnet in self.ipsubnet_set.all()
|
|
|
+ if not subnet.inet in self.inet]
|
|
|
+ if incorrect:
|
|
|
+ err = 'Some subnets allocated in this pool are outside the pool: {}'.format(incorrect)
|
|
|
+ raise ValidationError(err)
|
|
|
|
|
|
def __unicode__(self):
|
|
|
return self.name
|