예제 #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):
     """
     :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]
예제 #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")