def validate_address_space(prefix): """ validate an ip prefix according to peeringdb specs Arguments: - prefix: ipaddress.IPv4Network or an ipaddress.IPv6Network Raises: - ValidationError on failed validation """ prefix = validate_prefix(prefix) if not network_is_pdb_valid(prefix): raise ValidationError(_("Address space invalid: {}").format(prefix)) prefixlen_min = getattr(settings, f"DATA_QUALITY_MIN_PREFIXLEN_V{prefix.version}") prefixlen_max = getattr(settings, f"DATA_QUALITY_MAX_PREFIXLEN_V{prefix.version}") if prefix.prefixlen < prefixlen_min: raise ValidationError( _("Maximum allowed prefix length is {}").format(prefixlen_min) ) elif prefix.prefixlen > prefixlen_max: raise ValidationError( _("Minimum allowed prefix length is {}").format(prefixlen_max) )
def validate_address_space(prefix): """ validate an ipaddress according to peeringdb specs Arguments: - prefix: ipaddress.IPv4Network or an ipaddress.IPv6Network Raises: - ValidationError on failed validation """ if isinstance(prefix, unicode): try: prefix = ipaddress.ip_network(prefix) except ValueError as exc: raise ValidationError(_("Invalid prefix: {}").format(prefix)) if not network_is_pdb_valid(prefix): raise ValidationError(_("Address space invalid: {}").format(prefix)) prefixlen_min = getattr(settings, "DATA_QUALITY_MIN_PREFIXLEN_V{}".format(prefix.version)) prefixlen_max = getattr(settings, "DATA_QUALITY_MAX_PREFIXLEN_V{}".format(prefix.version)) if prefix.prefixlen < prefixlen_min: raise ValidationError( _("Minimum allowed prefix length is {}").format(prefixlen_min)) elif prefix.prefixlen > prefixlen_max: raise ValidationError( _("Maximum allowed prefix length is {}").format(prefixlen_max))
def validate_address_space(prefix): """ validate an ipaddress according to peeringdb specs Arguments: - prefix: ipaddress.IPv4Network or an ipaddress.IPv6Network Raises: - ValidationError on failed validation """ if isinstance(prefix, unicode): try: prefix = ipaddress.ip_network(prefix) except ValueError as exc: raise ValidationError(_("Invalid prefix: {}").format(prefix)) if not network_is_pdb_valid(prefix): raise ValidationError(_("Address space invalid: {}").format(prefix))