--- lib/client/gnt_instance.py | 37 +++++++++++++++++++++++++++++++++++++ man/gnt-instance.rst | 17 +++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py index 96eaef5..f1274e2 100644 --- a/lib/client/gnt_instance.py +++ b/lib/client/gnt_instance.py @@ -1313,6 +1313,39 @@ def SetInstanceParams(opts, args): return 0 +def ChangeGroup(opts, args): + """Moves an instance to another group. + + """ + (instance_name, ) = args + + cl = GetClient() + + op = opcodes.OpInstanceChangeGroup(instance_name=instance_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("Instance '%s' changed group successfully.", instance_name) + rcode = constants.EXIT_SUCCESS + else: + ToStdout("There were %s errors while changing group of instance '%s'.", + bad_cnt, instance_name) + rcode = constants.EXIT_FAILURE + + return rcode + + # multi-instance selection options m_force_multi = cli_option("--force-multiple", dest="force_multi", help="Do not ask for confirmation when more than" @@ -1488,6 +1521,10 @@ commands = { ArgUnknown(min=1, max=1)], [SUBMIT_OPT, NWSYNC_OPT, DRY_RUN_OPT, PRIORITY_OPT], "<instance> <disk> <size>", "Grow an instance's disk"), + "change-group": ( + ChangeGroup, ARGS_ONE_INSTANCE, + [TO_GROUP_OPT, IALLOCATOR_OPT, EARLY_RELEASE_OPT], + "[-I <iallocator>] [--to <group>]", "Change group of instance"), "list-tags": ( ListTags, ARGS_ONE_INSTANCE, [PRIORITY_OPT], "<instance_name>", "List the tags of the given instance"), diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst index afc0ad9..28f6064 100644 --- a/man/gnt-instance.rst +++ b/man/gnt-instance.rst @@ -1382,6 +1382,23 @@ Example:: # gnt-instance move -n node3.example.com instance1.example.com +CHANGE-GROUP +~~~~~~~~~~~~ + +**change-group** [--iallocator *NAME*] [--to *GROUP*...] {*instance*} + +This command moves an instance to another node group. The move is +calculated 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 one containing the instance are considered. + +Example:: + + # gnt-instance change-group -I hail --to rack2 inst1.example.com + + TAGS ~~~~ -- 1.7.6