Revision 8572f1fe

b/lib/client/gnt_node.py
34 34
from ganeti import constants
35 35
from ganeti import errors
36 36
from ganeti import netutils
37
from cStringIO import StringIO
37 38

  
38 39

  
39 40
#: default list of field for L{ListNodes}
......
388 389
  result = cl.QueryNodes(fields=["name", "pip", "sip",
389 390
                                 "pinst_list", "sinst_list",
390 391
                                 "master_candidate", "drained", "offline",
391
                                 "master_capable", "vm_capable", "powered"],
392
                                 "master_capable", "vm_capable", "powered",
393
                                 "ndparams", "custom_ndparams"],
392 394
                         names=args, use_locking=False)
393 395

  
394
  for (name, primary_ip, secondary_ip, pinst, sinst,
395
       is_mc, drained, offline, master_capable, vm_capable, powered) in result:
396
  for (name, primary_ip, secondary_ip, pinst, sinst, is_mc, drained, offline,
397
       master_capable, vm_capable, powered, ndparams,
398
       ndparams_custom) in result:
396 399
    ToStdout("Node name: %s", name)
397 400
    ToStdout("  primary ip: %s", primary_ip)
398 401
    ToStdout("  secondary ip: %s", secondary_ip)
......
416 419
          ToStdout("    - %s", iname)
417 420
      else:
418 421
        ToStdout("  secondary for no instances")
422
    ToStdout("  node parameters:")
423
    buf = StringIO()
424
    FormatParameterDict(buf, ndparams_custom, ndparams, level=2)
425
    ToStdout(buf.getvalue().rstrip("\n"))
419 426

  
420 427
  return 0
421 428

  
b/lib/cmdlib.py
3595 3595
    return query.NodeQueryData([all_info[name] for name in nodenames],
3596 3596
                               live_data, lu.cfg.GetMasterNode(),
3597 3597
                               node_to_primary, node_to_secondary, groups,
3598
                               oob_support)
3598
                               oob_support, lu.cfg.GetClusterInfo())
3599 3599

  
3600 3600

  
3601 3601
class LUQueryNodes(NoHooksLU):
b/lib/query.py
358 358

  
359 359
  """
360 360
  def __init__(self, nodes, live_data, master_name, node_to_primary,
361
               node_to_secondary, groups, oob_support):
361
               node_to_secondary, groups, oob_support, cluster):
362 362
    """Initializes this class.
363 363

  
364 364
    """
......
369 369
    self.node_to_secondary = node_to_secondary
370 370
    self.groups = groups
371 371
    self.oob_support = oob_support
372
    self.cluster = cluster
372 373

  
373 374
    # Used for individual rows
374 375
    self.curlive_data = None
......
415 416
  }
416 417

  
417 418

  
418
def _GetNodeGroup(ctx, node):
419
def _GetGroup(cb):
420
  """Build function for calling another function with an node group.
421

  
422
  @param cb: The callback to be called with the nodegroup
423

  
424
  """
425
  def fn(ctx, node):
426
    """Get group data for a node.
427

  
428
    @type ctx: L{NodeQueryData}
429
    @type inst: L{objects.Node}
430
    @param inst: Node object
431

  
432
    """
433
    ng = ctx.groups.get(node.group, None)
434
    if ng is None:
435
      # Nodes always have a group, or the configuration is corrupt
436
      return (constants.QRFS_UNAVAIL, None)
437

  
438
    return cb(ctx, node, ng)
439

  
440
  return fn
441

  
442

  
443
def _GetNodeGroup(ctx, node, ng): # pylint: disable-msg=W0613
419 444
  """Returns the name of a node's group.
420 445

  
421 446
  @type ctx: L{NodeQueryData}
422 447
  @type node: L{objects.Node}
423 448
  @param node: Node object
449
  @type ng: L{objects.NodeGroup}
450
  @param ng: The node group this node belongs to
424 451

  
425 452
  """
426
  ng = ctx.groups.get(node.group, None)
427
  if ng is None:
428
    # Nodes always have a group, or the configuration is corrupt
429
    return (constants.QRFS_UNAVAIL, None)
430

  
431 453
  return (constants.QRFS_NORMAL, ng.name)
432 454

  
433 455

  
......
445 467
  return (constants.QRFS_UNAVAIL, None)
446 468

  
447 469

  
470
def _GetNdParams(ctx, node, ng):
471
  """Returns the ndparams for this node.
472

  
473
  @type ctx: L{NodeQueryData}
474
  @type node: L{objects.Node}
475
  @param node: Node object
476
  @type ng: L{objects.NodeGroup}
477
  @param ng: The node group this node belongs to
478

  
479
  """
480
  return (constants.QRFS_NORMAL, ctx.cluster.SimpleFillND(ng.FillND(node)))
481

  
482

  
448 483
def _GetLiveNodeField(field, kind, ctx, node):
449 484
  """Gets the value of a "live" field from L{NodeQueryData}.
450 485

  
......
496 531
    (_MakeField("role", "Role", constants.QFT_TEXT), NQ_CONFIG,
497 532
     lambda ctx, node: (constants.QRFS_NORMAL,
498 533
                        _GetNodeRole(node, ctx.master_name))),
499
    (_MakeField("group", "Group", constants.QFT_TEXT), NQ_GROUP, _GetNodeGroup),
534
    (_MakeField("group", "Group", constants.QFT_TEXT), NQ_GROUP,
535
     _GetGroup(_GetNodeGroup)),
500 536
    (_MakeField("group.uuid", "GroupUUID", constants.QFT_TEXT),
501 537
     NQ_CONFIG, lambda ctx, node: (constants.QRFS_NORMAL, node.group)),
502 538
    (_MakeField("powered", "Powered", constants.QFT_BOOL), NQ_OOB,
503 539
      _GetNodePower),
540
    (_MakeField("ndparams", "NodeParameters", constants.QFT_OTHER), NQ_GROUP,
541
      _GetGroup(_GetNdParams)),
542
    (_MakeField("custom_ndparams", "CustomNodeParameters", constants.QFT_OTHER),
543
      NQ_GROUP, lambda ctx, node: (constants.QRFS_NORMAL, node.ndparams)),
504 544
    ]
505 545

  
506 546
  def _GetLength(getter):
b/test/ganeti.query_unittest.py
289 289
      objects.Node(name="node3", drained=False),
290 290
      ]
291 291
    for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]:
292
      nqd = query.NodeQueryData(nodes, live_data, None, None, None, None, None)
292
      nqd = query.NodeQueryData(nodes, live_data, None, None, None, None, None,
293
                                None)
293 294

  
294 295
      q = self._Create(["name", "drained"])
295 296
      self.assertEqual(q.RequestedData(), set([query.NQ_CONFIG]))
......
315 316
                     set([query.NQ_CONFIG, query.NQ_LIVE, query.NQ_INST,
316 317
                          query.NQ_GROUP, query.NQ_OOB]))
317 318

  
319
    cluster = objects.Cluster(cluster_name="testcluster",
320
      hvparams=constants.HVC_DEFAULTS,
321
      beparams={
322
        constants.PP_DEFAULT: constants.BEC_DEFAULTS,
323
        },
324
      nicparams={
325
        constants.PP_DEFAULT: constants.NICC_DEFAULTS,
326
        },
327
      ndparams=constants.NDC_DEFAULTS,
328
        )
329

  
318 330
    node_names = ["node%s" % i for i in range(20)]
319 331
    master_name = node_names[3]
320 332
    nodes = [
......
327 339
                   drained=False,
328 340
                   vm_capable=False,
329 341
                   master_capable=False,
342
                   ndparams={},
330 343
                   group="default",
331 344
                   ctime=1290006900,
332 345
                   mtime=1290006913,
......
373 386

  
374 387
    ng_uuid = "492b4b74-8670-478a-b98d-4c53a76238e6"
375 388
    groups = {
376
      ng_uuid: objects.NodeGroup(name="ng1", uuid=ng_uuid),
389
      ng_uuid: objects.NodeGroup(name="ng1", uuid=ng_uuid, ndparams={}),
377 390
      }
378 391

  
379 392
    oob_support = dict((name, False) for name in node_names)
......
382 395

  
383 396
    nqd = query.NodeQueryData(nodes, live_data, master_name,
384 397
                              node_to_primary, node_to_secondary, groups,
385
                              oob_support)
398
                              oob_support, cluster)
386 399
    result = q.Query(nqd)
387 400
    self.assert_(compat.all(len(row) == len(selected) for row in result))
388 401
    self.assertEqual([row[field_index["name"]] for row in result],
......
445 458
    live_data = dict.fromkeys([node.name for node in nodes], {})
446 459

  
447 460
    # No data
448
    nqd = query.NodeQueryData(None, None, None, None, None, None, None)
461
    nqd = query.NodeQueryData(None, None, None, None, None, None, None, None)
449 462
    self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER,
450 463
                                             nqd, nodes[0]),
451 464
                     (constants.QRFS_NODATA, None))

Also available in: Unified diff