gnt-node list: Query filter support
[ganeti-local] / lib / client / gnt_group.py
index 9b14c25..9395875 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2010 Google Inc.
+# Copyright (C) 2010, 2011 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
@@ -31,7 +31,7 @@ from ganeti import utils
 
 
 #: default list of fields for L{ListGroups}
-_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy"]
+_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy", "ndparams"]
 
 
 def AddGroup(opts, args):
@@ -45,7 +45,7 @@ def AddGroup(opts, args):
 
   """
   (group_name,) = args
-  op = opcodes.OpAddGroup(group_name=group_name, ndparams=opts.ndparams,
+  op = opcodes.OpGroupAdd(group_name=group_name, ndparams=opts.ndparams,
                           alloc_policy=opts.alloc_policy)
   SubmitOpCode(op, opts=opts)
 
@@ -63,11 +63,25 @@ def AssignNodes(opts, args):
   group_name = args[0]
   node_names = args[1:]
 
-  op = opcodes.OpAssignGroupNodes(group_name=group_name, nodes=node_names,
+  op = opcodes.OpGroupAssignNodes(group_name=group_name, nodes=node_names,
                                   force=opts.force)
   SubmitOpCode(op, opts=opts)
 
 
+def _FmtDict(data):
+  """Format dict data into command-line format.
+
+  @param data: The input dict to be formatted
+  @return: The formatted dict
+
+  """
+  if not data:
+    return "(empty)"
+
+  return utils.CommaJoin(["%s=%s" % (key, value)
+                          for key, value in data.items()])
+
+
 def ListGroups(opts, args):
   """List node groups and their properties.
 
@@ -79,11 +93,15 @@ def ListGroups(opts, args):
 
   """
   desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
-  fmtoverride = dict.fromkeys(["node_list", "pinst_list"], (",".join, False))
+  fmtoverride = {
+    "node_list": (",".join, False),
+    "pinst_list": (",".join, False),
+    "ndparams": (_FmtDict, False),
+    }
 
   return GenericList(constants.QR_GROUP, desired_fields, args, None,
                      opts.separator, not opts.no_headers,
-                     format_override=fmtoverride)
+                     format_override=fmtoverride, verbose=opts.verbose)
 
 
 def ListGroupFields(opts, args):
@@ -103,7 +121,7 @@ def ListGroupFields(opts, args):
 def SetGroupParams(opts, args):
   """Modifies a node group's parameters.
 
-  @param opts: the command line options seletect by the user
+  @param opts: the command line options selected by the user
   @type args: list
   @param args: should contain only one element, the node group name
 
@@ -120,7 +138,7 @@ def SetGroupParams(opts, args):
     ToStderr("Please give at least one of the parameters.")
     return 1
 
-  op = opcodes.OpSetGroupParams(group_name=args[0], # pylint: disable-msg=W0142
+  op = opcodes.OpGroupSetParams(group_name=args[0], # pylint: disable-msg=W0142
                                 **all_changes)
   result = SubmitOrSend(op, opts)
 
@@ -143,7 +161,7 @@ def RemoveGroup(opts, args):
 
   """
   (group_name,) = args
-  op = opcodes.OpRemoveGroup(group_name=group_name)
+  op = opcodes.OpGroupRemove(group_name=group_name)
   SubmitOpCode(op, opts=opts)
 
 
@@ -157,8 +175,8 @@ def RenameGroup(opts, args):
   @return: the desired exit code
 
   """
-  old_name, new_name = args
-  op = opcodes.OpRenameGroup(old_name=old_name, new_name=new_name)
+  group_name, new_name = args
+  op = opcodes.OpGroupRename(group_name=group_name, new_name=new_name)
   SubmitOpCode(op, opts=opts)
 
 
@@ -171,7 +189,7 @@ commands = {
     "<group_name> <node>...", "Assign nodes to a group"),
   "list": (
     ListGroups, ARGS_MANY_GROUPS,
-    [NOHDR_OPT, SEP_OPT, FIELDS_OPT],
+    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, VERBOSE_OPT],
     "[<group_name>...]",
     "Lists the node groups in the cluster. The available fields can be shown"
     " using the \"list-fields\" command (see the man page for details)."
@@ -185,11 +203,11 @@ commands = {
     "<group_name>", "Alters the parameters of a node group"),
   "remove": (
     RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],
-    "[--dry-run] <group_name>",
+    "[--dry-run] <group-name>",
     "Remove an (empty) node group from the cluster"),
   "rename": (
     RenameGroup, [ArgGroup(min=2, max=2)], [DRY_RUN_OPT],
-    "[--dry-run] <old_name> <new_name>", "Rename a node group"),
+    "[--dry-run] <group-name> <new-name>", "Rename a node group"),
 }