Revision 538ca33a lib/utils/__init__.py

b/lib/utils/__init__.py
255 255
  return cpu_list
256 256

  
257 257

  
258
def ParseMultiCpuMask(cpu_mask):
259
  """Parse a multiple CPU mask definition and return the list of CPU IDs.
260

  
261
  CPU mask format: colon-separated list of comma-separated list of CPU IDs
262
  or dash-separated ID ranges, with optional "all" as CPU value
263
  Example: "0-2,5:all:1,5,6:2" -> [ [ 0,1,2,5 ], [ -1 ], [ 1, 5, 6 ], [ 2 ] ]
264

  
265
  @type cpu_mask: str
266
  @param cpu_mask: multiple CPU mask definition
267
  @rtype: list of lists of int
268
  @return: list of lists of CPU IDs
269

  
270
  """
271
  if not cpu_mask:
272
    return []
273
  cpu_list = []
274
  for range_def in cpu_mask.split(constants.CPU_PINNING_SEP):
275
    if range_def == constants.CPU_PINNING_ALL:
276
      cpu_list.append([constants.CPU_PINNING_ALL_VAL, ])
277
    else:
278
      # Uniquify and sort the list before adding
279
      cpu_list.append(sorted(set(ParseCpuMask(range_def))))
280

  
281
  return cpu_list
282

  
283

  
258 284
def GetHomeDir(user, default=None):
259 285
  """Try to get the homedir of the given user.
260 286

  

Also available in: Unified diff