Revision 3d2ca95d scripts/gnt-instance

b/scripts/gnt-instance
116 116
  return inames
117 117

  
118 118

  
119
def _ConfirmOperation(inames, text):
119
def _ConfirmOperation(inames, text, extra=""):
120 120
  """Ask the user to confirm an operation on a list of instances.
121 121

  
122 122
  This function is used to request confirmation for doing an operation
......
133 133

  
134 134
  """
135 135
  count = len(inames)
136
  msg = ("The %s will operate on %d instances.\n"
137
         "Do you want to continue?" % (text, count))
136
  msg = ("The %s will operate on %d instances.\n%s"
137
         "Do you want to continue?" % (text, count, extra))
138 138
  affected = ("\nAffected instances:\n" +
139 139
              "\n".join(["  %s" % name for name in inames]))
140 140

  
......
506 506
  @return: the desired exit code
507 507

  
508 508
  """
509
  instance_name = args[0]
509
  # first, compute the desired name list
510
  if opts.multi_mode is None:
511
    opts.multi_mode = _SHUTDOWN_INSTANCES
512

  
513
  inames = _ExpandMultiNames(opts.multi_mode, args)
514
  if not inames:
515
    raise errors.OpPrereqError("Selection filter does not match any instances")
510 516

  
517
  # second, if requested, ask for an OS
511 518
  if opts.select_os is True:
512 519
    op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
513 520
    result = SubmitOpCode(op)
......
529 536
                       choices)
530 537

  
531 538
    if selected == 'exit':
532
      ToStdout("User aborted reinstall, exiting")
539
      ToStderr("User aborted reinstall, exiting")
533 540
      return 1
534 541

  
535 542
    os_name = selected
536 543
  else:
537 544
    os_name = opts.os
538 545

  
539
  if not opts.force:
540
    usertext = ("This will reinstall the instance %s and remove"
541
                " all data. Continue?") % instance_name
542
    if not AskUser(usertext):
546
  # third, get confirmation: multi-reinstall requires --force-multi
547
  # *and* --force, single-reinstall just --force
548
  multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
549
  if multi_on:
550
    warn_msg = "Note: this will remove *all* data for the below instances!\n"
551
    if not ((opts.force_multi and opts.force) or
552
            _ConfirmOperation(inames, "reinstall", extra=warn_msg)):
543 553
      return 1
554
  else:
555
    if not opts.force:
556
      usertext = ("This will reinstall the instance %s and remove"
557
                  " all data. Continue?") % instance_name
558
      if not AskUser(usertext):
559
        return 1
560

  
561
  jex = JobExecutor(verbose=multi_on)
562
  for instance_name in inames:
563
    op = opcodes.OpReinstallInstance(instance_name=instance_name,
564
                                     os_type=os_name)
565
    jex.QueueJob(instance_name, op)
544 566

  
545
  op = opcodes.OpReinstallInstance(instance_name=instance_name,
546
                                   os_type=os_name)
547
  SubmitOrSend(op, opts)
548

  
567
  jex.WaitOrShow(not opts.submit_only)
549 568
  return 0
550 569

  
551 570

  
......
1377 1396
           " The default field"
1378 1397
           " list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
1379 1398
           ),
1380
  'reinstall': (ReinstallInstance, ARGS_ONE,
1399
  'reinstall': (ReinstallInstance, ARGS_ANY,
1381 1400
                [DEBUG_OPT, FORCE_OPT, os_opt,
1401
                 m_force_multi,
1402
                 m_node_opt, m_pri_node_opt, m_sec_node_opt,
1403
                 m_clust_opt, m_inst_opt,
1382 1404
                 make_option("--select-os", dest="select_os",
1383 1405
                             action="store_true", default=False,
1384 1406
                             help="Interactive OS reinstall, lists available"

Also available in: Unified diff