Revision 8572f1fe lib/query.py

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):

Also available in: Unified diff