Commit 667dbd6b authored by Adeodato Simo's avatar Adeodato Simo Committed by Iustin Pop

Querying node groups: add client/gnt_group.py

This implements `gnt-group list`.
Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a79ef2a5
......@@ -76,6 +76,7 @@
/scripts/gnt-backup
/scripts/gnt-cluster
/scripts/gnt-debug
/scripts/gnt-group
/scripts/gnt-instance
/scripts/gnt-job
/scripts/gnt-node
......
......@@ -156,6 +156,7 @@ client_PYTHON = \
lib/client/gnt_backup.py \
lib/client/gnt_cluster.py \
lib/client/gnt_debug.py \
lib/client/gnt_group.py \
lib/client/gnt_instance.py \
lib/client/gnt_job.py \
lib/client/gnt_node.py \
......@@ -286,6 +287,7 @@ gnt_scripts = \
scripts/gnt-backup \
scripts/gnt-cluster \
scripts/gnt-debug \
scripts/gnt-group \
scripts/gnt-instance \
scripts/gnt-job \
scripts/gnt-node \
......@@ -300,6 +302,7 @@ PYTHON_BOOTSTRAP = \
scripts/gnt-backup \
scripts/gnt-cluster \
scripts/gnt-debug \
scripts/gnt-group \
scripts/gnt-instance \
scripts/gnt-job \
scripts/gnt-node \
......@@ -396,6 +399,7 @@ man_MANS = \
man/gnt-backup.8 \
man/gnt-cluster.8 \
man/gnt-debug.8 \
man/gnt-group.8 \
man/gnt-instance.8 \
man/gnt-job.8 \
man/gnt-node.8 \
......
......@@ -434,6 +434,8 @@ class CompletionWriter:
choices = "$(_ganeti_instances)"
elif isinstance(arg, cli.ArgNode):
choices = "$(_ganeti_nodes)"
elif isinstance(arg, cli.ArgGroup):
choices = "$(_ganeti_nodegroup)"
elif isinstance(arg, cli.ArgJobId):
choices = "$(_ganeti_jobs)"
elif isinstance(arg, cli.ArgOs):
......
......@@ -183,13 +183,16 @@ __all__ = [
# command line options support infrastructure
"ARGS_MANY_INSTANCES",
"ARGS_MANY_NODES",
"ARGS_MANY_GROUPS",
"ARGS_NONE",
"ARGS_ONE_INSTANCE",
"ARGS_ONE_NODE",
"ARGS_ONE_GROUP",
"ARGS_ONE_OS",
"ArgChoice",
"ArgCommand",
"ArgFile",
"ArgGroup",
"ArgHost",
"ArgInstance",
"ArgJobId",
......@@ -279,6 +282,13 @@ class ArgNode(_Argument):
"""
class ArgGroup(_Argument):
"""Node group argument.
"""
class ArgJobId(_Argument):
"""Job ID argument.
......@@ -312,8 +322,10 @@ class ArgOs(_Argument):
ARGS_NONE = []
ARGS_MANY_INSTANCES = [ArgInstance()]
ARGS_MANY_NODES = [ArgNode()]
ARGS_MANY_GROUPS = [ArgGroup()]
ARGS_ONE_INSTANCE = [ArgInstance(min=1, max=1)]
ARGS_ONE_NODE = [ArgNode(min=1, max=1)]
ARGS_ONE_GROUP = [ArgInstance(min=1, max=1)]
ARGS_ONE_OS = [ArgOs(min=1, max=1)]
......
#
#
# Copyright (C) 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Node group related commands"""
# pylint: disable-msg=W0401,W0614
# W0401: Wildcard import ganeti.cli
# W0614: Unused import %s from wildcard import (since we need cli)
from ganeti.cli import *
from ganeti import compat
#: default list of fields for L{ListGroups}
_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt"]
#: headers (and full field list) for L{ListGroups}
_LIST_HEADERS = {
"name": "Group", "uuid": "UUID",
"node_cnt": "Nodes", "node_list": "NodeList",
"pinst_cnt": "Instances", "pinst_list": "InstanceList",
}
def ListGroups(opts, args):
"""List node groups and their properties.
@param opts: the command line options selected by the user
@type args: list
@param args: groups to list, or empty for all
@rtype: int
@return: the desired exit code
"""
desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
output = GetClient().QueryGroups(args, desired_fields, opts.do_locking)
if opts.no_headers:
headers = None
else:
headers = _LIST_HEADERS
int_type_fields = frozenset(["node_cnt", "pinst_cnt"])
list_type_fields = frozenset(["node_list", "pinst_list"])
for row in output:
for idx, field in enumerate(desired_fields):
val = row[idx]
if field in list_type_fields:
val = ",".join(val)
elif opts.roman_integers and field in int_type_fields:
val = compat.TryToRoman(val)
elif val is None:
val = "?"
row[idx] = str(val)
data = GenerateTable(separator=opts.separator, headers=headers,
fields=desired_fields, data=output)
for line in data:
ToStdout(line)
return 0
commands = {
"list": (
ListGroups, ARGS_MANY_GROUPS,
[NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
"[<group_name>...]", "Lists the node groups in the cluster."),
}
def Main():
return GenericMain(commands)
......@@ -14,8 +14,9 @@ Ganeti overview and specifications: **ganeti**(7) (general overview),
Ganeti commands: **gnt-cluster**(8) (cluster-wide commands),
**gnt-job**(8) (job-related commands), **gnt-node**(8) (node-related
commands), **gnt-instance**(8) (instance commands), **gnt-os**(8)
(guest OS commands), **gnt-backup**(8) (instance import/export
commands), **gnt-debug**(8) (debug commands).
(guest OS commands), **gnt-group**(8) (node group commands),
**gnt-backup**(8) (instance import/export commands), **gnt-debug**(8)
(debug commands).
Ganeti daemons: **ganeti-watcher**(8) (automatic instance restarter),
**ganeti-cleaner**(8) (job queue cleaner), **ganeti-noded**(8) (node
......
gnt-group(8) Ganeti | Version @GANETI_VERSION@
==============================================
Name
----
gnt-group - Ganeti node-group administration
Synopsis
--------
**gnt-group** {command} [arguments...]
DESCRIPTION
-----------
The **gnt-group** command is used for node group administration in
the Ganeti system.
COMMANDS
--------
LIST
~~~~
| **list** [--no-headers] [--separator=*SEPARATOR*]
| [-o *[+]FIELD,...*] [group...]
Lists all existing node groups in the cluster.
The ``--no-headers`` option will skip the initial header line. The
``--separator`` option takes an argument which denotes what will be
used between the output fields. Both these options are to help
scripting.
The ``-o`` option takes a comma-separated list of output fields.
If the value of the option starts with the character ``+``, the new
fields will be added to the default list. This allows to quickly
see the default list plus a few other fields, instead of retyping
the entire list of fields.
The available fields and their meaning are:
name
the group name
uuid
the group's UUID
node_cnt
the number of nodes in the node group
node_list
the list of nodes that belong to this group
pinst_cnt
the number of primary instances in the group (i.e., the number of
primary instances nodes in this group have)
pinst_list
the list of primary instances in the group
If no group names are given, then all groups are included. Otherwise,
only the named groups will be listed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment