Add “gnt-instance change-group” command
authorMichael Hanselmann <hansmi@google.com>
Wed, 3 Aug 2011 09:46:10 +0000 (11:46 +0200)
committerMichael Hanselmann <hansmi@google.com>
Thu, 4 Aug 2011 13:18:59 +0000 (15:18 +0200)
Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/client/gnt_instance.py
man/gnt-instance.rst

index 58e242e..f3cb845 100644 (file)
@@ -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"
@@ -1490,6 +1523,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"),
index 7193ef9..a2c2c81 100644 (file)
@@ -1386,6 +1386,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
 ~~~~