4 # Copyright (C) 2010 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 """Node group related commands"""
23 # pylint: disable-msg=W0401,W0614
24 # W0401: Wildcard import ganeti.cli
25 # W0614: Unused import %s from wildcard import (since we need cli)
27 from ganeti.cli import *
28 from ganeti import compat
31 #: default list of fields for L{ListGroups}
32 _LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt"]
35 #: headers (and full field list) for L{ListGroups}
37 "name": "Group", "uuid": "UUID",
38 "node_cnt": "Nodes", "node_list": "NodeList",
39 "pinst_cnt": "Instances", "pinst_list": "InstanceList",
43 def ListGroups(opts, args):
44 """List node groups and their properties.
46 @param opts: the command line options selected by the user
48 @param args: groups to list, or empty for all
50 @return: the desired exit code
53 desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
55 output = GetClient().QueryGroups(args, desired_fields, opts.do_locking)
60 headers = _LIST_HEADERS
62 int_type_fields = frozenset(["node_cnt", "pinst_cnt"])
63 list_type_fields = frozenset(["node_list", "pinst_list"])
66 for idx, field in enumerate(desired_fields):
69 if field in list_type_fields:
71 elif opts.roman_integers and field in int_type_fields:
72 val = compat.TryToRoman(val)
78 data = GenerateTable(separator=opts.separator, headers=headers,
79 fields=desired_fields, data=output)
89 ListGroups, ARGS_MANY_GROUPS,
90 [NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
91 "[<group_name>...]", "Lists the node groups in the cluster."),
96 return GenericMain(commands)