+ "%d error(s) out of %d instance(s).", bad_cnt, len(results))
+ return retcode
+
+
+def MigrateNode(opts, args):
+ """Migrate all primary instance on a node.
+
+ """
+ cl = GetClient()
+ force = opts.force
+ selected_fields = ["name", "pinst_list"]
+
+ result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False)
+ node, pinst = result[0]
+
+ if not pinst:
+ ToStdout("No primary instances on node %s, exiting." % node)
+ return 0
+
+ pinst = utils.NiceSort(pinst)
+
+ retcode = 0
+
+ if not force and not AskUser("Migrate instance(s) %s?" %
+ (",".join("'%s'" % name for name in pinst))):
+ return 2
+
+ jex = JobExecutor(cl=cl)
+ for iname in pinst:
+ op = opcodes.OpMigrateInstance(instance_name=iname, live=opts.live,
+ cleanup=False)
+ jex.QueueJob(iname, op)
+
+ results = jex.GetResults()
+ bad_cnt = len([row for row in results if not row[0]])
+ if bad_cnt == 0:
+ ToStdout("All %d instance(s) migrated successfully.", len(results))
+ else:
+ ToStdout("There were errors during the migration:\n"
+ "%d error(s) out of %d instance(s).", bad_cnt, len(results))