def clean_prefix(self): vrf = self.cleaned_data.get("vrf") if not vrf: raise ValidationError(_("VRF Required")) 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 delete(self, *args, **kwargs): """ Delete prefix """ if self.is_root and not getattr(self, "_disable_delete_protection", False): raise ValidationError("Cannot delete root prefix") # Reconnect children prefixes self.children_set.update(parent=self.parent) # Reconnect children addresses self.address_set.update(prefix=self.parent) # Unlink dual-stack allocations # self.clear_transition() # Remove bookmarks self.prefixbookmark_set.all().delete() # Finally delete super(Prefix, self).delete(*args, **kwargs)
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")
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)