def clean(self): """ Field validation :return: """ super(PrefixAccess, self).clean() # Check prefix is of AFI type if self.afi == "4": check_ipv4_prefix(self.prefix) elif self.afi == "6": check_ipv6_prefix(self.prefix)
def clean_prefix(self): vrf = self.cleaned_data["vrf"] afi = self.cleaned_data["afi"] prefix = self.cleaned_data.get("prefix", "").strip() if afi == "4": check_ipv4_prefix(prefix) elif afi == "6": check_ipv6_prefix(prefix) try: return Prefix.objects.get(vrf=vrf, afi=afi, prefix=prefix) except Prefix.DoesNotExist: raise ValidationError(_("Prefix not found"))
def clean(self): """ Field validation """ super(Prefix, self).clean() # Check prefix is of AFI type if self.afi == "4": check_ipv4_prefix(self.prefix) elif self.afi == "6": check_ipv6_prefix(self.prefix) # Check root prefix have no parent if self.is_root and self.parent: raise ValidationError("Root prefix cannot have parent")
def __init__(self, prefix, netmask=None): """ :param prefix: String in format X.X.X.X or X.X.X.X/Y :type prefix: str :param netmask: Optional netmask in X.X.X.X format :type netmask: str """ if "/" not in prefix: if netmask: prefix += "/%d" % self.netmask_to_len(netmask) else: prefix += "/32" check_ipv4_prefix(prefix) super(IPv4, self).__init__(prefix) # Convert to int self.d = struct.unpack("!I", socket.inet_aton(self.address))[0]
def __init__(self, prefix, netmask=None): """ :param prefix: String in format X.X.X.X or X.X.X.X/Y :type prefix: str :param netmask: Optional netmask in X.X.X.X format :type netmask: str """ if "/" not in prefix: if netmask: prefix += "/%d" % self.netmask_to_len(netmask) else: prefix += "/32" check_ipv4_prefix(prefix) super(IPv4, self).__init__(prefix) # Convert to int self.d = 0 m = 24 for d in self._get_parts(): self.d += d << m m -= 8
def clean(self): """ Field validation """ super(Prefix, self).clean() # Set defaults self.afi = "6" if ":" in self.prefix else "4" # Check prefix is of AFI type if self.is_ipv4: check_ipv4_prefix(self.prefix) elif self.is_ipv6: check_ipv6_prefix(self.prefix) # Set defaults if not self.vrf: self.vrf = VRF.get_global() if not self.is_root: # Set proper parent self.parent = Prefix.get_parent(self.vrf, self.afi, self.prefix) # Check root prefix have no parent if self.is_root and self.parent: raise ValidationError("Root prefix cannot have parent")