Revision c8d8b4c8

b/lib/cmdlib.py
1405 1405
      "ctotal",
1406 1406
      ])
1407 1407

  
1408
    _CheckOutputFields(static=["name", "pinst_cnt", "sinst_cnt",
1409
                               "pinst_list", "sinst_list",
1410
                               "pip", "sip", "tags"],
1408
    self.static_fields = frozenset([
1409
      "name", "pinst_cnt", "sinst_cnt",
1410
      "pinst_list", "sinst_list",
1411
      "pip", "sip", "tags",
1412
      ])
1413

  
1414
    _CheckOutputFields(static=self.static_fields,
1411 1415
                       dynamic=self.dynamic_fields,
1412 1416
                       selected=self.op.output_fields)
1413 1417

  
1414 1418
    self.needed_locks = {}
1415 1419
    self.share_locks[locking.LEVEL_NODE] = 1
1416
    # TODO: we could lock nodes only if the user asked for dynamic fields. For
1417
    # that we need atomic ways to get info for a group of nodes from the
1418
    # config, though.
1419
    if not self.op.names:
1420
      self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
1420

  
1421
    if self.op.names:
1422
      self.wanted = _GetWantedNodes(self, self.op.names)
1421 1423
    else:
1422
      self.needed_locks[locking.LEVEL_NODE] = \
1423
        _GetWantedNodes(self, self.op.names)
1424
      self.wanted = locking.ALL_SET
1425

  
1426
    self.do_locking = not self.static_fields.issuperset(self.op.output_fields)
1427
    if self.do_locking:
1428
      # if we don't request only static fields, we need to lock the nodes
1429
      self.needed_locks[locking.LEVEL_NODE] = self.wanted
1430

  
1424 1431

  
1425 1432
  def CheckPrereq(self):
1426 1433
    """Check prerequisites.
1427 1434

  
1428 1435
    """
1429
    # This of course is valid only if we locked the nodes
1430
    self.wanted = self.acquired_locks[locking.LEVEL_NODE]
1436
    # The validation of the node list is done in the _GetWantedNodes,
1437
    # if non empty, and if empty, there's no validation to do
1438
    pass
1431 1439

  
1432 1440
  def Exec(self, feedback_fn):
1433 1441
    """Computes the list of nodes and their attributes.
1434 1442

  
1435 1443
    """
1436
    nodenames = self.wanted
1437
    nodelist = [self.cfg.GetNodeInfo(name) for name in nodenames]
1444
    all_info = self.cfg.GetAllNodesInfo()
1445
    if self.do_locking:
1446
      nodenames = self.acquired_locks[locking.LEVEL_NODE]
1447
    else:
1448
      nodenames = all_info.keys()
1449
    nodelist = [all_info[name] for name in nodenames]
1438 1450

  
1439 1451
    # begin data gathering
1440 1452

  

Also available in: Unified diff