def clean(self): """ Field validation """ super().clean() # Check prefix is of AFI type if self.afi == "4": check_ipv4(self.from_address) check_ipv4(self.to_address) elif self.afi == "6": check_ipv6(self.from_address) check_ipv6(self.to_address)
def clean(self): """ Field validation :return: """ super(Address, self).clean() # Get proper AFI self.afi = "6" if ":" in self.address else "4" # Check prefix is of AFI type if self.is_ipv4: check_ipv4(self.address) elif self.is_ipv6: check_ipv6(self.address) # Check VRF if not self.vrf: self.vrf = VRF.get_global() # Find parent prefix self.prefix = Prefix.get_parent(self.vrf, self.afi, self.address) # Check VRF group restrictions cv = self.get_collision(self.vrf, self.address) if cv: # Collision detected raise ValidationError("Address already exists in VRF %s" % cv)