+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
+
+