1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-10-31 19:44:16 +00:00

Add mac addr validation

This commit is contained in:
catborise 2019-01-22 09:01:18 +03:00
parent 8da5527a2b
commit d568680747

View file

@ -153,3 +153,15 @@ def validate_uuid(val):
val = (val[0:8] + "-" + val[8:12] + "-" + val[12:16] +
"-" + val[16:20] + "-" + val[20:32])
return val
def validate_macaddr(val):
if val is None:
return
if not (isinstance(val, str) or isinstance(val, basestring)):
raise ValueError("MAC address must be a string.")
form = re.match("^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$", val)
if form is None:
raise ValueError("MAC address must be of the format AA:BB:CC:DD:EE:FF, was '%s'" % val)