|
@@ -13,9 +13,9 @@ def validate_subnet(cidr):
|
|
"""Checks that a CIDR object is indeed a subnet, i.e. the host bits are
|
|
"""Checks that a CIDR object is indeed a subnet, i.e. the host bits are
|
|
all set to zero."""
|
|
all set to zero."""
|
|
if not isinstance(cidr, IPNetwork):
|
|
if not isinstance(cidr, IPNetwork):
|
|
- raise ValidationError("Internal error, expected IPNetwork object")
|
|
|
|
|
|
+ raise ValidationError("Erreur, objet IPNetwork attendu.")
|
|
if cidr.ip != cidr.network:
|
|
if cidr.ip != cidr.network:
|
|
- raise ValidationError("{} is not a proper subnet, you probably mean {}".format(cidr, cidr.cidr))
|
|
|
|
|
|
+ raise ValidationError("{} n'est pas un sous-réseau valide, voulez-vous dire {} ?".format(cidr, cidr.cidr))
|
|
|
|
|
|
|
|
|
|
class IPPool(models.Model):
|
|
class IPPool(models.Model):
|
|
@@ -36,14 +36,14 @@ class IPPool(models.Model):
|
|
if self.inet:
|
|
if self.inet:
|
|
max_subnetsize = 64 if self.inet.version == 6 else 32
|
|
max_subnetsize = 64 if self.inet.version == 6 else 32
|
|
if not self.inet.prefixlen <= self.default_subnetsize <= max_subnetsize:
|
|
if not self.inet.prefixlen <= self.default_subnetsize <= max_subnetsize:
|
|
- raise ValidationError('Invalid default subnet size')
|
|
|
|
|
|
+ raise ValidationError('Taille de sous-réseau invalide')
|
|
# Check that related subnet are in the pool (useful when
|
|
# Check that related subnet are in the pool (useful when
|
|
# modifying an existing pool that already has subnets
|
|
# modifying an existing pool that already has subnets
|
|
# allocated in it)
|
|
# allocated in it)
|
|
incorrect = [str(subnet) for subnet in self.ipsubnet_set.all()
|
|
incorrect = [str(subnet) for subnet in self.ipsubnet_set.all()
|
|
if not subnet.inet in self.inet]
|
|
if not subnet.inet in self.inet]
|
|
if incorrect:
|
|
if incorrect:
|
|
- err = 'Some subnets allocated in this pool are outside the pool: {}'.format(incorrect)
|
|
|
|
|
|
+ err = "Des sous-réseaux se retrouveraient en-dehors du bloc d'IP: {}".format(incorrect)
|
|
raise ValidationError(err)
|
|
raise ValidationError(err)
|
|
|
|
|
|
def __unicode__(self):
|
|
def __unicode__(self):
|
|
@@ -90,24 +90,24 @@ class IPSubnet(models.Model):
|
|
try:
|
|
try:
|
|
first_free = available.next()
|
|
first_free = available.next()
|
|
except StopIteration:
|
|
except StopIteration:
|
|
- raise ValidationError('Unable to allocate an IP subnet in the specified pool: not enough space left.')
|
|
|
|
|
|
+ raise ValidationError("Impossible d'allouer un sous-réseau : bloc d'IP rempli.")
|
|
self.inet = first_free.subnet(self.ip_pool.default_subnetsize, 1).next()
|
|
self.inet = first_free.subnet(self.ip_pool.default_subnetsize, 1).next()
|
|
|
|
|
|
def validate_inclusion(self):
|
|
def validate_inclusion(self):
|
|
"""Check that we are included in the IP pool"""
|
|
"""Check that we are included in the IP pool"""
|
|
if not self.inet in self.ip_pool.inet:
|
|
if not self.inet in self.ip_pool.inet:
|
|
- raise ValidationError('Subnet must be included in the IP pool.')
|
|
|
|
|
|
+ raise ValidationError("Le sous-réseau doit être inclus dans le bloc d'IP.")
|
|
# Check that we don't conflict with existing subnets.
|
|
# Check that we don't conflict with existing subnets.
|
|
conflicting = self.ip_pool.ipsubnet_set.filter(Q(inet__net_contained_or_equal=self.inet) |
|
|
conflicting = self.ip_pool.ipsubnet_set.filter(Q(inet__net_contained_or_equal=self.inet) |
|
|
Q(inet__net_contains_or_equals=self.inet)).exclude(id=self.id)
|
|
Q(inet__net_contains_or_equals=self.inet)).exclude(id=self.id)
|
|
if conflicting:
|
|
if conflicting:
|
|
- raise ValidationError('Subnet must not intersect with existing subnets.\nIntersected subnets: {}.'.format(conflicting))
|
|
|
|
|
|
+ raise ValidationError("Le sous-réseau est en conflit avec des sous-réseaux existants: {}.".format(conflicting))
|
|
|
|
|
|
def validate_reverse_dns(self):
|
|
def validate_reverse_dns(self):
|
|
"""Check that reverse DNS entries, if any, are included in the subnet"""
|
|
"""Check that reverse DNS entries, if any, are included in the subnet"""
|
|
incorrect = [str(rev.ip) for rev in self.reversednsentry_set.all() if not rev.ip in self.inet]
|
|
incorrect = [str(rev.ip) for rev in self.reversednsentry_set.all() if not rev.ip in self.inet]
|
|
if incorrect:
|
|
if incorrect:
|
|
- raise ValidationError('Some reverse DNS entries are not in the subnet: {}.'.format(incorrect))
|
|
|
|
|
|
+ raise ValidationError("Des entrées DNS inverse ne sont pas dans le sous-réseau: {}.".format(incorrect))
|
|
|
|
|
|
def clean(self):
|
|
def clean(self):
|
|
if not self.inet:
|
|
if not self.inet:
|