Revision 36c87212 scripts/gnt-instance

b/scripts/gnt-instance
465 465
    force - whether to failover without asking questions.
466 466

  
467 467
  """
468
  instance_name = args[0]
469
  force = opts.force
468
  if opts.multi_mode is None:
469
    opts.multi_mode = _SHUTDOWN_INSTANCES
470
  inames = _ExpandMultiNames(opts.multi_mode, args)
471
  if not inames:
472
    logger.ToStderr("No instances match the selected options")
473
    return 1
474
  multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
475
  if not (opts.force_multi or not multi_on
476
          or _ConfirmOperation(inames, "failover (including shutdown)")):
477
    return 1
470 478

  
471
  if not force:
472
    usertext = ("Failover will happen to image %s."
473
                " This requires a shutdown of the instance. Continue?" %
474
                (instance_name,))
475
    if not AskUser(usertext):
476
      return 1
479
  result = 0
480
  for name in inames:
481
    op = opcodes.OpFailoverInstance(instance_name=name,
482
                                    ignore_consistency=opts.ignore_consistency)
483
    if multi_on:
484
      logger.ToStdout("Failing over instance %s" % name)
485
    try:
486
      SubmitOpCode(op)
487
    except errors.OpExecError, err:
488
      result = 1
489
      _, err_msg = FormatError(err)
490
      logger.ToStderr(err_msg)
477 491

  
478
  op = opcodes.OpFailoverInstance(instance_name=instance_name,
479
                                  ignore_consistency=opts.ignore_consistency)
480
  SubmitOpCode(op)
481
  return 0
492
  return result
482 493

  
483 494

  
484 495
def ConnectToInstanceConsole(opts, args):
......
710 721
  'console': (ConnectToInstanceConsole, ARGS_ONE, [DEBUG_OPT],
711 722
              "<instance>",
712 723
              "Opens a console on the specified instance"),
713
  'failover': (FailoverInstance, ARGS_ONE,
724
  'failover': (FailoverInstance, ARGS_ATLEAST(1),
714 725
               [DEBUG_OPT, FORCE_OPT,
715 726
                make_option("--ignore-consistency", dest="ignore_consistency",
716 727
                            action="store_true", default=False,
717 728
                            help="Ignore the consistency of the disks on"
718 729
                            " the secondary"),
730
                m_pri_node_opt, m_sec_node_opt, m_inst_opt, m_force_multi,
719 731
                ],
720 732
               "[-f] <instance>",
721 733
               "Stops the instance and starts it on the backup node, using"

Also available in: Unified diff