Commit f6eb380d authored by Michael Hanselmann's avatar Michael Hanselmann

gnt-group: Add command to evacuate whole group

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 08f8c82c
......@@ -168,6 +168,7 @@ __all__ = [
"TAG_ADD_OPT",
"TAG_SRC_OPT",
"TIMEOUT_OPT",
"TO_GROUP_OPT",
"UIDPOOL_OPT",
"USEUNITS_OPT",
"USE_REPL_NET_OPT",
......@@ -1228,6 +1229,11 @@ STARTUP_PAUSED_OPT = cli_option("--paused", dest="startup_paused",
action="store_true", default=False,
help="Pause instance at startup")
TO_GROUP_OPT = cli_option("--to", dest="to", metavar="<group>",
help="Destination node group (name or uuid)",
default=None, action="append",
completion_suggest=OPT_COMPL_ONE_NODEGROUP)
#: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT]
......
......@@ -181,6 +181,37 @@ def RenameGroup(opts, args):
SubmitOpCode(op, opts=opts)
def EvacuateGroup(opts, args):
"""Evacuate a node group.
"""
(group_name, ) = args
cl = GetClient()
op = opcodes.OpGroupEvacuate(group_name=group_name,
iallocator=opts.iallocator,
target_groups=opts.to,
early_release=opts.early_release)
result = SubmitOpCode(op, cl=cl, opts=opts)
# Keep track of submitted jobs
jex = JobExecutor(cl=cl, opts=opts)
for (status, job_id) in result[constants.JOB_IDS_KEY]:
jex.AddJobId(None, status, job_id)
results = jex.GetResults()
bad_cnt = len([row for row in results if not row[0]])
if bad_cnt == 0:
ToStdout("All instances evacuated successfully.")
rcode = constants.EXIT_SUCCESS
else:
ToStdout("There were %s errors during the evacuation.", bad_cnt)
rcode = constants.EXIT_FAILURE
return rcode
commands = {
"add": (
AddGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT],
......@@ -209,6 +240,10 @@ commands = {
"rename": (
RenameGroup, [ArgGroup(min=2, max=2)], [DRY_RUN_OPT],
"[--dry-run] <group-name> <new-name>", "Rename a node group"),
"evacuate": (
EvacuateGroup, [ArgGroup(min=1, max=1)],
[TO_GROUP_OPT, IALLOCATOR_OPT, EARLY_RELEASE_OPT],
"-I <iallocator> [--to <group>]", "Evacuate all instances within a group"),
"list-tags": (
ListTags, ARGS_ONE_GROUP, [PRIORITY_OPT],
"<instance_name>", "List the tags of the given instance"),
......
......@@ -138,6 +138,23 @@ RENAME
Renames a given group from *oldname* to *newname*.
EVACUATE
~~~~~~~~
**evacuate** [--iallocator *NAME*] [--to *GROUP*...] {*group*}
This command will move all instances out of the given node group.
Instances are placed in a new group by an iallocator, either given on
the command line or as a cluster default.
If no specific destination groups are specified using ``--to``, all
groups except the evacuated group are considered.
Example::
# gnt-group evacuate -I hail --to rack4 rack1
TAGS
~~~~
......
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