Browse Source

Ensure relative coherence of pool and subnet objects, even when they are modified

Baptiste Jonglez 11 years ago
parent
commit
cce9581f30
1 changed files with 8 additions and 0 deletions
  1. 8 0
      coin/resources/models.py

+ 8 - 0
coin/resources/models.py

@@ -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