Revision 82187135 lib/utils.py

b/lib/utils.py
1398 1398
  return [i for i in seq if i not in seen and not seen.add(i)]
1399 1399

  
1400 1400

  
1401
def IsValidMac(mac):
1402
  """Predicate to check if a MAC address is valid.
1401
def NormalizeAndValidateMac(mac):
1402
  """Normalizes and check if a MAC address is valid.
1403 1403

  
1404 1404
  Checks whether the supplied MAC address is formally correct, only
1405
  accepts colon separated format.
1405
  accepts colon separated format. Normalize it to all lower.
1406 1406

  
1407 1407
  @type mac: str
1408 1408
  @param mac: the MAC to be validated
1409
  @rtype: boolean
1410
  @return: True is the MAC seems valid
1409
  @rtype: str
1410
  @return: returns the normalized and validated MAC.
1411

  
1412
  @raise errors.OpPrereqError: If the MAC isn't valid
1411 1413

  
1412 1414
  """
1413
  mac_check = re.compile("^([0-9a-f]{2}(:|$)){6}$")
1414
  return mac_check.match(mac) is not None
1415
  mac_check = re.compile("^([0-9a-f]{2}(:|$)){6}$", re.I)
1416
  if not mac_check.match(mac):
1417
    raise errors.OpPrereqError("Invalid MAC address specified: %s" %
1418
                               mac, errors.ECODE_INVAL)
1419

  
1420
  return mac.lower()
1415 1421

  
1416 1422

  
1417 1423
def TestDelay(duration):

Also available in: Unified diff