Revision 7f5443a0

b/lib/client/gnt_node.py
31 31
from ganeti import opcodes
32 32
from ganeti import utils
33 33
from ganeti import constants
34
from ganeti import compat
35 34
from ganeti import errors
36 35
from ganeti import netutils
37 36

  
......
60 59
  ]
61 60

  
62 61

  
63
#: headers (and full field list) for L{ListNodes}
64
_LIST_HEADERS = {
65
  "name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst",
66
  "pinst_list": "PriInstances", "sinst_list": "SecInstances",
67
  "pip": "PrimaryIP", "sip": "SecondaryIP",
68
  "dtotal": "DTotal", "dfree": "DFree",
69
  "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
70
  "bootid": "BootID",
71
  "ctotal": "CTotal", "cnodes": "CNodes", "csockets": "CSockets",
72
  "tags": "Tags",
73
  "serial_no": "SerialNo",
74
  "master_candidate": "MasterC",
75
  "master": "IsMaster",
76
  "offline": "Offline", "drained": "Drained",
77
  "role": "Role",
78
  "ctime": "CTime", "mtime": "MTime", "uuid": "UUID",
79
  "master_capable": "MasterCapable", "vm_capable": "VMCapable",
80
  "group": "Group", "group.uuid": "GroupUUID",
81
  }
82

  
83

  
84 62
#: headers (and full field list) for L{ListStorage}
85 63
_LIST_STOR_HEADERS = {
86 64
  constants.SF_NODE: "Node",
......
232 210
  """
233 211
  selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
234 212

  
235
  output = GetClient().QueryNodes(args, selected_fields, opts.do_locking)
213
  fmtoverride = dict.fromkeys(["pinst_list", "sinst_list", "tags"],
214
                              (lambda value: ",".join(value), False))
236 215

  
237
  if not opts.no_headers:
238
    headers = _LIST_HEADERS
239
  else:
240
    headers = None
216
  return GenericList(constants.QR_NODE, selected_fields, args, opts.units,
217
                     opts.separator, not opts.no_headers,
218
                     format_override=fmtoverride)
241 219

  
242
  unitfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree"]
243 220

  
244
  numfields = ["dtotal", "dfree",
245
               "mtotal", "mnode", "mfree",
246
               "pinst_cnt", "sinst_cnt",
247
               "ctotal", "serial_no"]
221
def ListNodeFields(opts, args):
222
  """List node fields.
248 223

  
249
  list_type_fields = ("pinst_list", "sinst_list", "tags")
250
  # change raw values to nicer strings
251
  for row in output:
252
    for idx, field in enumerate(selected_fields):
253
      val = row[idx]
254
      if field in list_type_fields:
255
        val = ",".join(val)
256
      elif field in ('master', 'master_candidate', 'offline', 'drained',
257
                     'master_capable', 'vm_capable'):
258
        if val:
259
          val = 'Y'
260
        else:
261
          val = 'N'
262
      elif field == "ctime" or field == "mtime":
263
        val = utils.FormatTime(val)
264
      elif val is None:
265
        val = "?"
266
      elif opts.roman_integers and isinstance(val, int):
267
        val = compat.TryToRoman(val)
268
      row[idx] = str(val)
269

  
270
  data = GenerateTable(separator=opts.separator, headers=headers,
271
                       fields=selected_fields, unitfields=unitfields,
272
                       numfields=numfields, data=output, units=opts.units)
273
  for line in data:
274
    ToStdout(line)
224
  @param opts: the command line options selected by the user
225
  @type args: list
226
  @param args: fields to list, or empty for all
227
  @rtype: int
228
  @return: the desired exit code
275 229

  
276
  return 0
230
  """
231
  return GenericListFields(constants.QR_NODE, args, opts.separator,
232
                           not opts.no_headers)
277 233

  
278 234

  
279 235
def EvacuateNode(opts, args):
......
716 672
    "[<node_name>...]", "Show information about the node(s)"),
717 673
  'list': (
718 674
    ListNodes, ARGS_MANY_NODES,
719
    [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
675
    [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
720 676
    "[nodes...]",
721
    "Lists the nodes in the cluster. The available fields are (see the man"
722
    " page for details): %s. The default field list is (in order): %s." %
723
    (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
677
    "Lists the nodes in the cluster. The available fields can be shown using"
678
    " the \"list-fields\" command (see the man page for details)."
679
    " The default field list is (in order): %s." %
680
    utils.CommaJoin(_LIST_DEF_FIELDS)),
681
  "list-fields": (
682
    ListNodeFields, [ArgUnknown()],
683
    [NOHDR_OPT, SEP_OPT],
684
    "[fields...]",
685
    "Lists all available fields for nodes"),
724 686
  'modify': (
725 687
    SetNodeParams, ARGS_ONE_NODE,
726 688
    [FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT,
b/man/gnt-node.rst
143 143
LIST
144 144
~~~~
145 145

  
146
| **list** [--sync]
146
| **list**
147 147
| [--no-headers] [--separator=*SEPARATOR*]
148 148
| [--units=*UNITS*] [-o *[+]FIELD,...*]
149
| [--roman]
150 149
| [node...]
151 150

  
152 151
Lists the nodes in the cluster.
......
163 162
parsing by scripts. In both cases, the ``--units`` option can be
164 163
used to enforce a given output unit.
165 164

  
166
By default, the query of nodes will be done in parallel with any
167
running jobs. This might give inconsistent results for the free
168
disk/memory. The ``--sync`` can be used to grab locks for all the
169
nodes and ensure consistent view of the cluster (but this might
170
stall the query for a long time).
171

  
172
Passing the ``--roman`` option gnt-node list will try to output
173
some of its fields in a latin-friendly way. This is not the default
174
for backwards compatibility.
165
Queries of nodes will be done in parallel with any running jobs. This might
166
give inconsistent results for the free disk/memory.
175 167

  
176 168
The ``-o`` option takes a comma-separated list of output fields.
177 169
The available fields and their meaning are:
......
319 311
If no node names are given, then all nodes are queried. Otherwise,
320 312
only the given nodes will be listed.
321 313

  
314

  
315
LIST-FIELDS
316
~~~~~~~~~~~
317

  
318
**list-fields** [field...]
319

  
320
Lists available fields for nodes.
321

  
322

  
322 323
LIST-TAGS
323 324
~~~~~~~~~
324 325

  

Also available in: Unified diff