Revision 40ef0ed6

b/scripts/gnt-node
262 262
  return retcode
263 263

  
264 264

  
265
def MigrateNode(opts, args):
266
  """Migrate all primary instance on a node.
267

  
268
  """
269
  cl = GetClient()
270
  force = opts.force
271
  selected_fields = ["name", "pinst_list"]
272

  
273
  result = cl.QueryNodes(names=args, fields=selected_fields)
274
  node, pinst = result[0]
275

  
276
  if not pinst:
277
    ToStdout("No primary instances on node %s, exiting." % node)
278
    return 0
279

  
280
  pinst = utils.NiceSort(pinst)
281

  
282
  retcode = 0
283

  
284
  if not force and not AskUser("Migrate instance(s) %s?" %
285
                               (",".join("'%s'" % name for name in pinst))):
286
    return 2
287

  
288
  jex = JobExecutor(cl=cl)
289
  for iname in pinst:
290
    op = opcodes.OpMigrateInstance(instance_name=iname, live=opts.live,
291
                                   cleanup=False)
292
    jex.QueueJob(iname, op)
293

  
294
  results = jex.GetResults()
295
  bad_cnt = len([row for row in results if not row[0]])
296
  if bad_cnt == 0:
297
    ToStdout("All %d instance(s) migrated successfully.", len(results))
298
  else:
299
    ToStdout("There were errors during the migration:\n"
300
             "%d error(s) out of %d instance(s).", bad_cnt, len(results))
301
  return retcode
302

  
303

  
265 304
def ShowNodeConfig(opts, args):
266 305
  """Show node information.
267 306

  
......
425 464
               "[-f] <node>",
426 465
               "Stops the primary instances on a node and start them on their"
427 466
               " secondary node (only for instances with drbd disk template)"),
467
  'migrate': (MigrateNode, ARGS_ONE,
468
               [DEBUG_OPT, FORCE_OPT,
469
                make_option("--non-live", dest="live",
470
                            default=True, action="store_false",
471
                            help="Do a non-live migration (this usually means"
472
                            " freeze the instance, save the state,"
473
                            " transfer and only then resume running on the"
474
                            " secondary node)"),
475
                ],
476
               "[-f] <node>",
477
               "Migrate all the primary instance on a node away from it"
478
               " (only for instances of type drbd)"),
428 479
  'info': (ShowNodeConfig, ARGS_ANY, [DEBUG_OPT],
429 480
           "[<node_name>...]", "Show information about the node(s)"),
430 481
  'list': (ListNodes, ARGS_NONE,

Also available in: Unified diff