Commit 66e884e1 authored by Adeodato Simo's avatar Adeodato Simo

Group operations: CLI code for add/remove/rename a group

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: default avatarAdeodato Simo <dato@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 4fe5cf90
...@@ -52,7 +52,7 @@ To manage node groups and the nodes belonging to them, the following new ...@@ -52,7 +52,7 @@ To manage node groups and the nodes belonging to them, the following new
commands and flags will be introduced:: commands and flags will be introduced::
gnt-group add <group> # add a new node group 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 list # list node groups
gnt-group rename <oldname> <newname> # rename a node group gnt-group rename <oldname> <newname> # rename a node group
gnt-node {list,info} -g <group> # list only nodes belonging to a node group gnt-node {list,info} -g <group> # list only nodes belonging to a node group
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
from ganeti.cli import * from ganeti.cli import *
from ganeti import compat from ganeti import compat
from ganeti import opcodes
from ganeti import utils from ganeti import utils
...@@ -42,6 +43,21 @@ _LIST_HEADERS = { ...@@ -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): def ListGroups(opts, args):
"""List node groups and their properties. """List node groups and their properties.
...@@ -89,7 +105,40 @@ def ListGroups(opts, args): ...@@ -89,7 +105,40 @@ def ListGroups(opts, args):
return 0 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 = { commands = {
"add": (
AddGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],
"<group_name>", "Add a new node group to the cluster"),
"list": ( "list": (
ListGroups, ARGS_MANY_GROUPS, ListGroups, ARGS_MANY_GROUPS,
[NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT], [NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
...@@ -97,6 +146,13 @@ commands = { ...@@ -97,6 +146,13 @@ commands = {
"Lists the node groups in the cluster. The available fields are (see" "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." % " the man page for details): %s. The default list is (in order): %s." %
(utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))), (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"),
} }
......
...@@ -20,6 +20,21 @@ the Ganeti system. ...@@ -20,6 +20,21 @@ the Ganeti system.
COMMANDS 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 LIST
~~~~ ~~~~
...@@ -78,3 +93,10 @@ serial_no ...@@ -78,3 +93,10 @@ serial_no
If no group names are given, then all groups are included. Otherwise, If no group names are given, then all groups are included. Otherwise,
only the named groups will be listed. only the named groups will be listed.
RENAME
~~~~~~
| **rename** {*oldname*} {*newname*}
Renames a given group from *oldname* to *newname*.
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