diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 250ca7ac7..35c8e702b 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -1,4 +1,4 @@ -from netaddr import cidr_merge +from netaddr import IPNetwork, cidr_merge from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse @@ -214,6 +214,17 @@ class Prefix(models.Model): self.family = self.prefix.version super(Prefix, self).save(*args, **kwargs) + @property + def new_subnet(self): + if self.family == 4: + if self.prefix.prefixlen <= 30: + return IPNetwork('{}/{}'.format(self.prefix.network, self.prefix.prefixlen + 1)) + return None + if self.family == 6: + if self.prefix.prefixlen <= 126: + return IPNetwork('{}/{}'.format(self.prefix.network, self.prefix.prefixlen + 1)) + return None + class IPAddress(models.Model): """