Revision 0fdf247d lib/cmdlib.py

b/lib/cmdlib.py
493 493
  #: Attribute holding field definitions
494 494
  FIELDS = None
495 495

  
496
  #: Field to sort by
497
  SORT_FIELD = "name"
498

  
496 499
  def __init__(self, qfilter, fields, use_locking):
497 500
    """Initializes this class.
498 501

  
......
500 503
    self.use_locking = use_locking
501 504

  
502 505
    self.query = query.Query(self.FIELDS, fields, qfilter=qfilter,
503
                             namefield="name")
506
                             namefield=self.SORT_FIELD)
504 507
    self.requested_data = self.query.RequestedData()
505 508
    self.names = self.query.RequestedNames()
506 509

  
......
13024 13027
  """
13025 13028
  REQ_BGL = False
13026 13029

  
13030
  def CheckArguments(self):
13031
    self.expq = _ExportQuery(qlang.MakeSimpleFilter("node", self.op.nodes),
13032
                             ["node", "export"], self.op.use_locking)
13033

  
13027 13034
  def ExpandNames(self):
13028
    self.needed_locks = {}
13029
    self.share_locks[locking.LEVEL_NODE] = 1
13030
    if not self.op.nodes:
13031
      self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
13032
    else:
13033
      self.needed_locks[locking.LEVEL_NODE] = \
13034
        _GetWantedNodes(self, self.op.nodes)
13035
    self.expq.ExpandNames(self)
13036

  
13037
  def DeclareLocks(self, level):
13038
    self.expq.DeclareLocks(self, level)
13035 13039

  
13036 13040
  def Exec(self, feedback_fn):
13037
    """Compute the list of all the exported system images.
13041
    result = {}
13038 13042

  
13039
    @rtype: dict
13040
    @return: a dictionary with the structure node->(export-list)
13041
        where export-list is a list of the instances exported on
13042
        that node.
13043
    for (node, expname) in self.expq.OldStyleQuery(self):
13044
      if expname is None:
13045
        result[node] = False
13046
      else:
13047
        result.setdefault(node, []).append(expname)
13048

  
13049
    return result
13050

  
13051

  
13052
class _ExportQuery(_QueryBase):
13053
  FIELDS = query.EXPORT_FIELDS
13054

  
13055
  #: The node name is not a unique key for this query
13056
  SORT_FIELD = "node"
13057

  
13058
  def ExpandNames(self, lu):
13059
    lu.needed_locks = {}
13060

  
13061
    # The following variables interact with _QueryBase._GetNames
13062
    if self.names:
13063
      self.wanted = _GetWantedNodes(lu, self.names)
13064
    else:
13065
      self.wanted = locking.ALL_SET
13066

  
13067
    self.do_locking = self.use_locking
13068

  
13069
    if self.do_locking:
13070
      lu.share_locks = _ShareAll()
13071
      lu.needed_locks = {
13072
        locking.LEVEL_NODE: self.wanted,
13073
        }
13074

  
13075
  def DeclareLocks(self, lu, level):
13076
    pass
13077

  
13078
  def _GetQueryData(self, lu):
13079
    """Computes the list of nodes and their attributes.
13043 13080

  
13044 13081
    """
13045
    self.nodes = self.owned_locks(locking.LEVEL_NODE)
13046
    rpcresult = self.rpc.call_export_list(self.nodes)
13047
    result = {}
13048
    for node in rpcresult:
13049
      if rpcresult[node].fail_msg:
13050
        result[node] = False
13082
    # Locking is not used
13083
    assert not (compat.any(lu.glm.is_owned(level)
13084
                           for level in locking.LEVELS
13085
                           if level != locking.LEVEL_CLUSTER) or
13086
                self.do_locking or self.use_locking)
13087

  
13088
    nodes = self._GetNames(lu, lu.cfg.GetNodeList(), locking.LEVEL_NODE)
13089

  
13090
    result = []
13091

  
13092
    for (node, nres) in lu.rpc.call_export_list(nodes).items():
13093
      if nres.fail_msg:
13094
        result.append((node, None))
13051 13095
      else:
13052
        result[node] = rpcresult[node].payload
13096
        result.extend((node, expname) for expname in nres.payload)
13053 13097

  
13054 13098
    return result
13055 13099

  
......
15174 15218
  constants.QR_NODE: _NodeQuery,
15175 15219
  constants.QR_GROUP: _GroupQuery,
15176 15220
  constants.QR_OS: _OsQuery,
15221
  constants.QR_EXPORT: _ExportQuery,
15177 15222
  }
15178 15223

  
15179 15224
assert set(_QUERY_IMPL.keys()) == constants.QR_VIA_OP

Also available in: Unified diff