Explorar el Código

Fixes #136: Trigger error on prefix w/host bits set instead of silently converting it

Jeremy Stretch hace 9 años
padre
commit
c9bf10421b
Se han modificado 1 ficheros con 6 adiciones y 0 borrados
  1. 6 0
      netbox/ipam/fields.py

+ 6 - 0
netbox/ipam/fields.py

@@ -10,7 +10,13 @@ from .lookups import (
 )
 )
 
 
 
 
+def prefix_validator(prefix):
+    if prefix.ip != prefix.cidr.ip:
+        raise ValidationError("{} is not a valid prefix. Did you mean {}?".format(prefix, prefix.cidr))
+
+
 class BaseIPField(models.Field):
 class BaseIPField(models.Field):
+    default_validators = [prefix_validator]
 
 
     def python_type(self):
     def python_type(self):
         return IPNetwork
         return IPNetwork