Revision 862beeab lib/cmdlib/node.py

b/lib/cmdlib/node.py
30 30
from ganeti import netutils
31 31
from ganeti import objects
32 32
from ganeti import opcodes
33
from ganeti import qlang
34 33
from ganeti import query
35 34
from ganeti import rpc
36 35
from ganeti import utils
......
1175 1174
  FIELDS = query.NODE_FIELDS
1176 1175

  
1177 1176
  def ExpandNames(self, lu):
1178
    lu.needed_locks = {}
1179
    lu.share_locks = ShareAll()
1180

  
1181
    if self.names:
1182
      (self.wanted, _) = GetWantedNodes(lu, self.names)
1183
    else:
1184
      self.wanted = locking.ALL_SET
1185

  
1186
    self.do_locking = (self.use_locking and
1187
                       query.NQ_LIVE in self.requested_data)
1188

  
1189
    if self.do_locking:
1190
      # If any non-static field is requested we need to lock the nodes
1191
      lu.needed_locks[locking.LEVEL_NODE] = self.wanted
1192
      lu.needed_locks[locking.LEVEL_NODE_ALLOC] = locking.ALL_SET
1177
    raise NotImplementedError
1193 1178

  
1194 1179
  def DeclareLocks(self, lu, level):
1195 1180
    pass
1196 1181

  
1197 1182
  def _GetQueryData(self, lu):
1198
    """Computes the list of nodes and their attributes.
1199

  
1200
    """
1201
    all_info = lu.cfg.GetAllNodesInfo()
1202

  
1203
    node_uuids = self._GetNames(lu, all_info.keys(), locking.LEVEL_NODE)
1204

  
1205
    # Gather data as requested
1206
    if query.NQ_LIVE in self.requested_data:
1207
      # filter out non-vm_capable nodes
1208
      toquery_node_uuids = [node.uuid for node in all_info.values()
1209
                            if node.vm_capable and node.uuid in node_uuids]
1210
      default_template = lu.cfg.GetClusterInfo().enabled_disk_templates[0]
1211
      raw_storage_units = utils.storage.GetStorageUnits(
1212
          lu.cfg, [default_template])
1213
      storage_units = rpc.PrepareStorageUnitsForNodes(
1214
          lu.cfg, raw_storage_units, toquery_node_uuids)
1215
      default_hypervisor = lu.cfg.GetHypervisorType()
1216
      hvparams = lu.cfg.GetClusterInfo().hvparams[default_hypervisor]
1217
      hvspecs = [(default_hypervisor, hvparams)]
1218
      node_data = lu.rpc.call_node_info(toquery_node_uuids, storage_units,
1219
                                        hvspecs)
1220
      live_data = dict(
1221
          (uuid, rpc.MakeLegacyNodeInfo(nresult.payload, default_template))
1222
          for (uuid, nresult) in node_data.items()
1223
          if not nresult.fail_msg and nresult.payload)
1224
    else:
1225
      live_data = None
1226

  
1227
    if query.NQ_INST in self.requested_data:
1228
      node_to_primary = dict([(uuid, set()) for uuid in node_uuids])
1229
      node_to_secondary = dict([(uuid, set()) for uuid in node_uuids])
1230

  
1231
      inst_data = lu.cfg.GetAllInstancesInfo()
1232
      inst_uuid_to_inst_name = {}
1233

  
1234
      for inst in inst_data.values():
1235
        inst_uuid_to_inst_name[inst.uuid] = inst.name
1236
        if inst.primary_node in node_to_primary:
1237
          node_to_primary[inst.primary_node].add(inst.uuid)
1238
        for secnode in inst.secondary_nodes:
1239
          if secnode in node_to_secondary:
1240
            node_to_secondary[secnode].add(inst.uuid)
1241
    else:
1242
      node_to_primary = None
1243
      node_to_secondary = None
1244
      inst_uuid_to_inst_name = None
1245

  
1246
    if query.NQ_OOB in self.requested_data:
1247
      oob_support = dict((uuid, bool(SupportsOob(lu.cfg, node)))
1248
                         for uuid, node in all_info.iteritems())
1249
    else:
1250
      oob_support = None
1251

  
1252
    if query.NQ_GROUP in self.requested_data:
1253
      groups = lu.cfg.GetAllNodeGroupsInfo()
1254
    else:
1255
      groups = {}
1256

  
1257
    return query.NodeQueryData([all_info[uuid] for uuid in node_uuids],
1258
                               live_data, lu.cfg.GetMasterNode(),
1259
                               node_to_primary, node_to_secondary,
1260
                               inst_uuid_to_inst_name, groups, oob_support,
1261
                               lu.cfg.GetClusterInfo())
1183
    raise NotImplementedError
1262 1184

  
1263 1185

  
1264 1186
class LUNodeQuery(NoHooksLU):
......
1269 1191
  REQ_BGL = False
1270 1192

  
1271 1193
  def CheckArguments(self):
1272
    self.nq = NodeQuery(qlang.MakeSimpleFilter("name", self.op.names),
1273
                         self.op.output_fields, self.op.use_locking)
1194
    raise NotImplementedError
1274 1195

  
1275 1196
  def ExpandNames(self):
1276
    self.nq.ExpandNames(self)
1197
    raise NotImplementedError
1277 1198

  
1278 1199
  def DeclareLocks(self, level):
1279
    self.nq.DeclareLocks(self, level)
1200
    raise NotImplementedError
1280 1201

  
1281 1202
  def Exec(self, feedback_fn):
1282
    return self.nq.OldStyleQuery(self)
1203
    raise NotImplementedError
1283 1204

  
1284 1205

  
1285 1206
def _CheckOutputFields(fields, selected):

Also available in: Unified diff