示例#1
0
 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)
示例#2
0
文件: views.py 项目: nbashev/noc
 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"))
示例#3
0
 def __init__(self, prefix, netmask=None):
     if "/" not in prefix:
         if netmask:
             prefix += "/%s" % IPv6.mask_to_bits(netmask)
         else:
             prefix += "/128"
     check_ipv6_prefix(prefix)
     super(IPv6, self).__init__(prefix)
     # Convert to 4 ints
     p = self._get_parts()
     self.d0 = (p[0] << 16) + p[1]
     self.d1 = (p[2] << 16) + p[3]
     self.d2 = (p[4] << 16) + p[5]
     self.d3 = (p[6] << 16) + p[7]
示例#4
0
 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")