Revision 5f6d1b42 lib/client/gnt_node.py

b/lib/client/gnt_node.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
40 40
from ganeti import pathutils
41 41
from ganeti import ssh
42 42
from ganeti import compat
43
from cStringIO import StringIO
44 43

  
45 44
from ganeti import confd
46 45
from ganeti.confd import client as confd_client
......
517 516
  return rcode
518 517

  
519 518

  
519
def _FormatNodeInfo(node_info):
520
  """Format node information for L{cli.PrintGenericInfo()}.
521

  
522
  """
523
  (name, primary_ip, secondary_ip, pinst, sinst, is_mc, drained, offline,
524
   master_capable, vm_capable, powered, ndparams, ndparams_custom) = node_info
525
  info = [
526
    ("Node name", name),
527
    ("primary ip", primary_ip),
528
    ("secondary ip", secondary_ip),
529
    ("master candidate", is_mc),
530
    ("drained", drained),
531
    ("offline", offline),
532
    ]
533
  if powered is not None:
534
    info.append(("powered", powered))
535
  info.extend([
536
    ("master_capable", master_capable),
537
    ("vm_capable", vm_capable),
538
    ])
539
  if vm_capable:
540
    info.extend([
541
      ("primary for instances",
542
       [iname for iname in utils.NiceSort(pinst)]),
543
      ("secondary for instances",
544
       [iname for iname in utils.NiceSort(sinst)]),
545
      ])
546
  info.append(("node parameters",
547
               FormatParamsDictInfo(ndparams_custom, ndparams)))
548
  return info
549

  
550

  
520 551
def ShowNodeConfig(opts, args):
521 552
  """Show node information.
522 553

  
......
536 567
                                 "master_capable", "vm_capable", "powered",
537 568
                                 "ndparams", "custom_ndparams"],
538 569
                         names=args, use_locking=False)
539

  
540
  for (name, primary_ip, secondary_ip, pinst, sinst, is_mc, drained, offline,
541
       master_capable, vm_capable, powered, ndparams,
542
       ndparams_custom) in result:
543
    ToStdout("Node name: %s", name)
544
    ToStdout("  primary ip: %s", primary_ip)
545
    ToStdout("  secondary ip: %s", secondary_ip)
546
    ToStdout("  master candidate: %s", is_mc)
547
    ToStdout("  drained: %s", drained)
548
    ToStdout("  offline: %s", offline)
549
    if powered is not None:
550
      ToStdout("  powered: %s", powered)
551
    ToStdout("  master_capable: %s", master_capable)
552
    ToStdout("  vm_capable: %s", vm_capable)
553
    if vm_capable:
554
      if pinst:
555
        ToStdout("  primary for instances:")
556
        for iname in utils.NiceSort(pinst):
557
          ToStdout("    - %s", iname)
558
      else:
559
        ToStdout("  primary for no instances")
560
      if sinst:
561
        ToStdout("  secondary for instances:")
562
        for iname in utils.NiceSort(sinst):
563
          ToStdout("    - %s", iname)
564
      else:
565
        ToStdout("  secondary for no instances")
566
    ToStdout("  node parameters:")
567
    buf = StringIO()
568
    FormatParameterDict(buf, ndparams_custom, ndparams, level=2)
569
    ToStdout(buf.getvalue().rstrip("\n"))
570

  
570
  PrintGenericInfo([
571
    _FormatNodeInfo(node_info)
572
    for node_info in result
573
    ])
571 574
  return 0
572 575

  
573 576

  

Also available in: Unified diff