Revision 7d4f1b45 qa/qa_config.py

b/qa/qa_config.py
296 296
  return node
297 297

  
298 298

  
299
def AcquireManyNodes(num, exclude=None):
300
  """Return the least used nodes.
301

  
302
  @type num: int
303
  @param num: Number of nodes; can be 0.
304
  @type exclude: list of nodes or C{None}
305
  @param exclude: nodes to be excluded from the choice
306
  @rtype: list of nodes
307
  @return: C{num} different nodes
308

  
309
  """
310
  nodes = []
311
  if exclude is None:
312
    exclude = []
313
  elif isinstance(exclude, (list, tuple)):
314
    # Don't modify the incoming argument
315
    exclude = list(exclude)
316
  else:
317
    exclude = [exclude]
318

  
319
  try:
320
    for _ in range(0, num):
321
      n = AcquireNode(exclude=exclude)
322
      nodes.append(n)
323
      exclude.append(n)
324
  except qa_error.OutOfNodesError:
325
    ReleaseManyNodes(nodes)
326
    raise
327
  return nodes
328

  
329

  
299 330
def ReleaseNode(node):
300 331
  node["_count"] = node.get("_count", 0) - 1
332

  
333

  
334
def ReleaseManyNodes(nodes):
335
  for n in nodes:
336
    ReleaseNode(n)

Also available in: Unified diff