noc.core.validators

Module Contents

noc.core.validators.rx_fqdn
noc.core.validators.rx_asset
noc.core.validators.rx_extension
noc.core.validators.rx_mimetype
noc.core.validators.rx_email
noc.core.validators.rx_oid
noc.core.validators.rx_objectid
noc.core.validators.is_int(v)
Check for valid integer
>>> is_int(10)
True
>>> is_int("10")
True
>>> is_int("Ten")
False
>>> is_int(None)
False
noc.core.validators.is_float(v)
Check for valid float
>>> is_float(10)
True
>>> is_float(10.2)
True
>>> is_float("10.2")
True
>>> is_float("Ten")
False
>>> is_float(None)
False
noc.core.validators.is_asn(v)
Check value is valid 2-byte or 4-byte autonomous system number
>>> is_asn(100)
True
>>> is_asn(100000)
True
>>> is_asn(-1)
False
noc.core.validators.is_ipv4(v)
Check value is valid IPv4 address
>>> is_ipv4("192.168.0.1")
True
>>> is_ipv4("192.168.0")
False
>>> is_ipv4("192.168.0.1.1")
False
>>> is_ipv4("192.168.1.256")
False
>>> is_ipv4("192.168.a.250")
False
>>> is_ipv4("11.24.0.09")
False
noc.core.validators.is_ipv6(v)
Check value is valid IPv6 address
>>> is_ipv6("::")
True
>>> is_ipv6("::1")
True
>>> is_ipv6("2001:db8::")
True
>>> is_ipv6("2001:db8:0000:0000:6232:6400::")
True
>>> is_ipv6("::ffff:192.168.0.1")
True
>>> is_ipv6("::ffff:192.168.0.256")
False
>>> is_ipv6("fe80::226:b0ff:fef7:c48c")
True
>>> is_ipv6("0:1:2:3:4:5:6:7:8")
False
>>> is_ipv6("0:1:2")
False
>>> is_ipv6("::g")
False
>>> is_ipv6("100:0:")
False
>>> is_ipv6("2a00:1118:f00f:fffe:c143:3284:1000::")
True
noc.core.validators.is_ipv4_prefix(v)
Check value is valid IPv4 prefix
>>> is_ipv4_prefix("192.168.0.0")
False
>>> is_ipv4_prefix("192.168.0.0/16")
True
>>> is_ipv4_prefix("192.168.256.0/24")
False
>>> is_ipv4_prefix("192.168.0.0/g")
False
>>> is_ipv4_prefix("192.168.0.0/-1")
False
>>> is_ipv4_prefix("192.168.0.0/33")
False
noc.core.validators.is_cidr
noc.core.validators.is_ipv6_prefix(v)
Check value is valid IPv6 prefix
>>> is_ipv6_prefix("1::/32")
True
>>> is_ipv6_prefix("1::/-1")
False
>>> is_ipv6_prefix("1::/129")
False
>>> is_ipv6_prefix("1::/1/2")
False
>>> is_ipv6_prefix("1::/g")
False
>>> is_ipv6_prefix("192.168.0.0/32")
False
noc.core.validators.is_prefix(v)
Check value is valid IPv4 or IPv6 prefix
>>> is_prefix("192.168.0.0/16")
True
>>> is_prefix("1::/32")
True
noc.core.validators.is_rd(v)
Check value is valid Route Distinguisher

Special case RD: 0:0 >>> is_rd(“0:0”) True

Type 0 RD: <2byte ASN> : <ID>

>>> is_rd("100:10")
True
>>> is_rd("100:0")
True
>>> is_rd("100:4294967295")
True
>>> is_rd("0:-10")
False
>>> is_rd("0:4294967296")
False

Type 1 RD: <IPv4> : <ID>

>>> is_rd("10.10.10.10:0")
True
>>> is_rd("10.10.10.10:65535")
True
>>> is_rd("10.10.10.10:-1")
False
>>> is_rd("10.10.10.10:65536")
False

Type 2 RD: <4byte ASN> : <ID>

>>> is_rd("100000:0")
True
>>> is_rd("100000:65535")
True

Error handling

>>> is_rd("100000:-1")
False
>>> is_rd("100000:65536")
False
>>> is_rd("10:20:30")
False
>>> is_rd("100:b")
False
noc.core.validators.is_as_set(v)
Check value is valuid AS-SET
>>> is_as_set("AS-TEST")
True
>>> is_as_set("AS100")
False
noc.core.validators.is_fqdn(v)
Check value is valid FQDN
>>> is_fqdn("test.example.com")
True
>>> is_fqdn("test")
False
noc.core.validators.is_re(v)
Check value is valid regular expression
>>> is_re("1{1,2}")
True
>>> is_re("1[")
False
noc.core.validators.is_vlan(v)
Check value is valid VLAN ID
>>> is_vlan(1)
True
>>> is_vlan(-1)
False
>>> is_vlan(4095)
True
>>> is_vlan(4096)
False
>>> is_vlan("g")
False
noc.core.validators.is_mac(v)
>>> is_mac("1234.5678.9ABC")
noc.core.validators.True()
>>> is_mac("1234.5678.9abc")
noc.core.validators.True()
>>> is_mac("0112.3456.789a.bc")
noc.core.validators.True()
>>> is_mac("1234.5678.9abc.def0")
noc.core.validators.False()
>>> is_mac("12:34:56:78:9A:BC")
noc.core.validators.True()
>>> is_mac("12-34-56-78-9A-BC")
noc.core.validators.True()
>>> is_mac("0:13:46:50:87:5")
noc.core.validators.True()
>>> is_mac("123456-789abc")
noc.core.validators.True()
>>> is_mac("12-34-56-78-9A-BC-DE")
noc.core.validators.False()
>>> is_mac("AB-CD-EF-GH-HJ-KL")
noc.core.validators.False()
>>> is_mac("aabb-ccdd-eeff")
noc.core.validators.True()
>>> is_mac("aabbccddeeff")
noc.core.validators.True()
>>> is_mac("AABBCCDDEEFF")
noc.core.validators.True()
>>> is_mac("xa8xf9Kx80xb4xc0")
noc.core.validators.False()
noc.core.validators.is_email(v)
Check value is valid email
>>> is_email("test@example.com")
True
>>> is_email("test")
False
noc.core.validators.is_oid(v)
Check OID
>>> is_oid("1.3.6.1.6.3.1.1.4.1.0")
True
>>> is_oid("1.3.6.1.6.3.1.1.4.a.1.0")
False
noc.core.validators.is_extension(v)
Check value is file extension starting with dot
>>> is_extension(".txt")
True
>>> is_extension("txt")
False
noc.core.validators.is_mimetype(v)
Check value is MIME Type
>>> is_mimetype("application/octet-stream")
True
>>> is_mimetype("application")
False
noc.core.validators.is_objectid(v)
Check value is mongodb's ObjectId
Parameters:v
Returns:
noc.core.validators.generic_validator(check, error_message)
Validator factory
>>> v = generic_validator(is_int, "invalid int")
>>> v(6)
6
>>> v("g")
Traceback (most recent call last):
...
ValidationError: [u'invalid int']
noc.core.validators.check_asn
noc.core.validators.check_prefix
noc.core.validators.check_ipv4
noc.core.validators.check_ipv6
noc.core.validators.check_ipv4_prefix
noc.core.validators.check_ipv6_prefix
noc.core.validators.check_cidr
noc.core.validators.check_rd
noc.core.validators.check_fqdn
noc.core.validators.check_re
noc.core.validators.check_as_set
noc.core.validators.check_vlan
noc.core.validators.check_email
noc.core.validators.check_extension
noc.core.validators.check_mimetype