Group operations: CLI code for add/remove/rename a group
authorAdeodato Simo <dato@google.com>
Fri, 3 Dec 2010 12:41:14 +0000 (12:41 +0000)
committerAdeodato Simo <dato@google.com>
Wed, 8 Dec 2010 12:27:32 +0000 (12:27 +0000)
Also, minor update to the 2.3 design doc, which was indicating the remove
operation would be `gnt-group del` and not `gnt-group remove` (the latter
being consistent with gnt-node and gnt-instance).

Signed-off-by: Adeodato Simo <dato@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

doc/design-2.3.rst
lib/client/gnt_group.py
man/gnt-group.rst

index 31fd3cc..debcd40 100644 (file)
@@ -52,7 +52,7 @@ To manage node groups and the nodes belonging to them, the following new
 commands and flags will be introduced::
 
   gnt-group add <group> # add a new node group
-  gnt-group del <group> # delete an empty node group
+  gnt-group remove <group> # delete an empty node group
   gnt-group list # list node groups
   gnt-group rename <oldname> <newname> # rename a node group
   gnt-node {list,info} -g <group> # list only nodes belonging to a node group
index 5477b11..9ddd499 100644 (file)
@@ -26,6 +26,7 @@
 
 from ganeti.cli import *
 from ganeti import compat
+from ganeti import opcodes
 from ganeti import utils
 
 
@@ -42,6 +43,21 @@ _LIST_HEADERS = {
 }
 
 
+def AddGroup(opts, args):
+  """Add a node group to the cluster.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: a list of length 1 with the name of the group to create
+  @rtype: int
+  @return: the desired exit code
+
+  """
+  (group_name,) = args
+  op = opcodes.OpAddGroup(group_name=group_name)
+  SubmitOpCode(op, opts=opts)
+
+
 def ListGroups(opts, args):
   """List node groups and their properties.
 
@@ -89,7 +105,40 @@ def ListGroups(opts, args):
   return 0
 
 
+def RemoveGroup(opts, args):
+  """Remove a node group from the cluster.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: a list of length 1 with the name of the group to remove
+  @rtype: int
+  @return: the desired exit code
+
+  """
+  (group_name,) = args
+  op = opcodes.OpRemoveGroup(group_name=group_name)
+  SubmitOpCode(op, opts=opts)
+
+
+def RenameGroup(opts, args):
+  """Rename a node group.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: a list of length 2, [old_name, new_name]
+  @rtype: int
+  @return: the desired exit code
+
+  """
+  old_name, new_name = args
+  op = opcodes.OpRenameGroup(old_name=old_name, new_name=new_name)
+  SubmitOpCode(op, opts=opts)
+
+
 commands = {
+  "add": (
+    AddGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],
+    "<group_name>", "Add a new node group to the cluster"),
   "list": (
     ListGroups, ARGS_MANY_GROUPS,
     [NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
@@ -97,6 +146,13 @@ commands = {
     "Lists the node groups in the cluster. The available fields are (see"
     " the man page for details): %s. The default list is (in order): %s." %
     (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
+  "remove": (
+    RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],
+    "[--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"),
 }
 
 
index 086d648..e43a8b9 100644 (file)
@@ -20,6 +20,21 @@ the Ganeti system.
 COMMANDS
 --------
 
+ADD
+~~~
+
+| **add** {*group*}
+
+Creates a new group with the given name. The node group will be
+initially empty.
+
+REMOVE
+~~~~~~
+
+| **remove** {*group*}
+
+Deletes the indicated node group, which must be empty.
+
 LIST
 ~~~~
 
@@ -78,3 +93,10 @@ serial_no
 
 If no group names are given, then all groups are included. Otherwise,
 only the named groups will be listed.
+
+RENAME
+~~~~~~
+
+| **rename** {*oldname*} {*newname*}
+
+Renames a given group from *oldname* to *newname*.