From 216d23c0bb47d312edb654cecdce3b5489f2e59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Fri, 11 May 2012 15:27:58 +0200 Subject: [PATCH] gnt-group: Add info command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/client/gnt_group.py | 41 +++++++++++++++++++++++++++++++++++++++++ man/gnt-group.rst | 8 ++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/client/gnt_group.py b/lib/client/gnt_group.py index 3d8e66d46..0e9284810 100644 --- a/lib/client/gnt_group.py +++ b/lib/client/gnt_group.py @@ -29,6 +29,7 @@ from ganeti import constants from ganeti import objects from ganeti import opcodes from ganeti import utils +from cStringIO import StringIO #: default list of fields for L{ListGroups} @@ -273,6 +274,44 @@ def EvacuateGroup(opts, args): return rcode + +def _FormatDict(custom, actual, level=2): + """Helper function to L{cli.FormatParameterDict}. + + @param custom: The customized dict + @param actual: The fully filled dict + + """ + buf = StringIO() + FormatParameterDict(buf, custom, actual, level=level) + return buf.getvalue().rstrip("\n") + + +def GroupInfo(_, args): + """Shows info about node group. + + """ + cl = GetClient() + selected_fields = ["name", + "ndparams", "custom_ndparams", + "diskparams", "custom_diskparams", + "ipolicy", "custom_ipolicy"] + result = cl.QueryGroups(names=args, fields=selected_fields, + use_locking=False) + + for (name, + ndparams, custom_ndparams, + diskparams, custom_diskparams, + ipolicy, custom_ipolicy) in result: + ToStdout("Node group: %s" % name) + ToStdout(" Node parameters:") + ToStdout(_FormatDict(custom_ndparams, ndparams)) + ToStdout(" Disk parameters:") + ToStdout(_FormatDict(custom_diskparams, diskparams)) + ToStdout(" Instance policy:") + ToStdout(_FormatDict(custom_ipolicy, ipolicy)) + + commands = { "add": ( AddGroup, ARGS_ONE_GROUP, @@ -323,6 +362,8 @@ commands = { RemoveTags, [ArgGroup(min=1, max=1), ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT], "<group_name> tag...", "Remove tags from the given group"), + "info": ( + GroupInfo, ARGS_MANY_GROUPS, [], "<group_name>", "Show group information"), } diff --git a/man/gnt-group.rst b/man/gnt-group.rst index 2d59c28e1..319f4fc2b 100644 --- a/man/gnt-group.rst +++ b/man/gnt-group.rst @@ -248,6 +248,14 @@ this case, there is not need to pass tags on the command line (if you do, tags from both sources will be removed). A file name of ``-`` will be interpreted as stdin. +INFO +~~~~ + +**info** [group...] + +Shows config information for all (or given) groups. + + .. vim: set textwidth=72 : .. Local Variables: .. mode: rst -- GitLab