Revision 7eb9d8f7 lib/cmdlib.py

b/lib/cmdlib.py
2452 2452

  
2453 2453
  """
2454 2454
  _OP_REQP = ["output_fields", "names"]
2455
  REQ_BGL = False
2455 2456

  
2456
  def CheckPrereq(self):
2457
    """Check prerequisites.
2458

  
2459
    This checks that the fields required are valid output fields.
2460

  
2461
    """
2457
  def ExpandNames(self):
2462 2458
    self.dynamic_fields = frozenset(["oper_state", "oper_ram", "status"])
2463 2459
    _CheckOutputFields(static=["name", "os", "pnode", "snodes",
2464 2460
                               "admin_state", "admin_ram",
......
2467 2463
                       dynamic=self.dynamic_fields,
2468 2464
                       selected=self.op.output_fields)
2469 2465

  
2470
    self.wanted = _GetWantedInstances(self, self.op.names)
2466
    self.needed_locks = {}
2467
    self.share_locks[locking.LEVEL_INSTANCE] = 1
2468
    self.share_locks[locking.LEVEL_NODE] = 1
2469

  
2470
    # TODO: we could lock instances (and nodes) only if the user asked for
2471
    # dynamic fields. For that we need atomic ways to get info for a group of
2472
    # instances from the config, though.
2473
    if not self.op.names:
2474
      self.needed_locks[locking.LEVEL_INSTANCE] = None # Acquire all
2475
    else:
2476
      self.needed_locks[locking.LEVEL_INSTANCE] = \
2477
        _GetWantedInstances(self, self.op.names)
2478

  
2479
    self.needed_locks[locking.LEVEL_NODE] = []
2480
    self.recalculate_locks[locking.LEVEL_NODE] = 'replace'
2481

  
2482
  def DeclareLocks(self, level):
2483
    # TODO: locking of nodes could be avoided when not querying them
2484
    if level == locking.LEVEL_NODE:
2485
      self._LockInstancesNodes()
2486

  
2487
  def CheckPrereq(self):
2488
    """Check prerequisites.
2489

  
2490
    """
2491
    # This of course is valid only if we locked the instances
2492
    self.wanted = self.needed_locks[locking.LEVEL_INSTANCE]
2471 2493

  
2472 2494
  def Exec(self, feedback_fn):
2473 2495
    """Computes the list of nodes and their attributes.

Also available in: Unified diff