Revision ca4ac9c9

b/lib/client/gnt_group.py
25 25
# W0614: Unused import %s from wildcard import (since we need cli)
26 26

  
27 27
from ganeti.cli import *
28
from ganeti import compat
28
from ganeti import constants
29 29
from ganeti import opcodes
30 30
from ganeti import utils
31 31

  
......
34 34
_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy"]
35 35

  
36 36

  
37
#: headers (and full field list) for L{ListGroups}
38
_LIST_HEADERS = {
39
  "name": "Group", "uuid": "UUID", "alloc_policy": "AllocPolicy",
40
  "node_cnt": "Nodes", "node_list": "NodeList",
41
  "pinst_cnt": "Instances", "pinst_list": "InstanceList",
42
  "ctime": "CTime", "mtime": "MTime", "serial_no": "SerialNo",
43
}
44

  
45

  
46 37
def AddGroup(opts, args):
47 38
  """Add a node group to the cluster.
48 39

  
......
70 61

  
71 62
  """
72 63
  desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
64
  fmtoverride = dict.fromkeys(["node_list", "pinst_list"], (",".join, False))
73 65

  
74
  output = GetClient().QueryGroups(args, desired_fields, opts.do_locking)
75

  
76
  if opts.no_headers:
77
    headers = None
78
  else:
79
    headers = _LIST_HEADERS
80

  
81
  int_type_fields = frozenset(["node_cnt", "pinst_cnt", "serial_no"])
82
  list_type_fields = frozenset(["node_list", "pinst_list"])
83
  date_type_fields = frozenset(["mtime", "ctime"])
84

  
85
  for row in output:
86
    for idx, field in enumerate(desired_fields):
87
      val = row[idx]
88

  
89
      if field in list_type_fields:
90
        val = ",".join(val)
91
      elif opts.roman_integers and field in int_type_fields:
92
        val = compat.TryToRoman(val)
93
      elif field in date_type_fields:
94
        val = utils.FormatTime(val)
95
      elif val is None:
96
        val = "?"
66
  return GenericList(constants.QR_GROUP, desired_fields, args, None,
67
                     opts.separator, not opts.no_headers,
68
                     format_override=fmtoverride)
97 69

  
98
      row[idx] = str(val)
99 70

  
100
  data = GenerateTable(separator=opts.separator, headers=headers,
101
                       fields=desired_fields, data=output)
71
def ListGroupFields(opts, args):
72
  """List node fields.
102 73

  
103
  for line in data:
104
    ToStdout(line)
74
  @param opts: the command line options selected by the user
75
  @type args: list
76
  @param args: fields to list, or empty for all
77
  @rtype: int
78
  @return: the desired exit code
105 79

  
106
  return 0
80
  """
81
  return GenericListFields(constants.QR_GROUP, args, opts.separator,
82
                           not opts.no_headers)
107 83

  
108 84

  
109 85
def SetGroupParams(opts, args):
......
174 150
    "<group_name>", "Add a new node group to the cluster"),
175 151
  "list": (
176 152
    ListGroups, ARGS_MANY_GROUPS,
177
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
153
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT],
178 154
    "[<group_name>...]",
179
    "Lists the node groups in the cluster. The available fields are (see"
180
    " the man page for details): %s. The default list is (in order): %s." %
181
    (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
155
    "Lists the node groups in the cluster. The available fields can be shown"
156
    " using the \"list-fields\" command (see the man page for details)."
157
    " The default list is (in order): %s." % utils.CommaJoin(_LIST_DEF_FIELDS)),
158
  "list-fields": (
159
    ListGroupFields, [ArgUnknown()], [NOHDR_OPT, SEP_OPT], "[fields...]",
160
    "Lists all available fields for node groups"),
182 161
  "modify": (
183 162
    SetGroupParams, ARGS_ONE_GROUP,
184 163
    [DRY_RUN_OPT, SUBMIT_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT],
b/man/gnt-group.rst
135 135
If no group names are given, then all groups are included. Otherwise,
136 136
only the named groups will be listed.
137 137

  
138
LIST-FIELDS
139
~~~~~~~~~~~
140

  
141
**list-fields** [field...]
142

  
143
List available fields for node groups.
144

  
138 145
RENAME
139 146
~~~~~~
140 147

  

Also available in: Unified diff