diff --git a/lib/utils.py b/lib/utils.py index 887a74e4b57cb4ebda0f8af7f6870072930f6759..e527d00f6e99a112aeb46fa11af68387bddd058b 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -92,6 +92,9 @@ _STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED) _MCL_CURRENT = 1 _MCL_FUTURE = 2 +#: MAC checker regexp +_MAC_CHECK = re.compile("^([0-9a-f]{2}:){5}[0-9a-f]{2}$", re.I) + class RunResult(object): """Holds the result of running external programs. @@ -1697,8 +1700,7 @@ def NormalizeAndValidateMac(mac): @raise errors.OpPrereqError: If the MAC isn't valid """ - mac_check = re.compile("^([0-9a-f]{2}(:|$)){6}$", re.I) - if not mac_check.match(mac): + if not _MAC_CHECK.match(mac): raise errors.OpPrereqError("Invalid MAC address specified: %s" % mac, errors.ECODE_INVAL)