Revision 55efe6da 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

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

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

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

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

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

  
534 541
    os_name = selected
535 542
  else:
536 543
    os_name = opts.os
537 544

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

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

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

  
566
  jex.WaitOrShow(not opts.submit_only)
548 567
  return 0
549 568

  
550 569

  
......
1372 1391
           " The default field"
1373 1392
           " list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
1374 1393
           ),
1375
  'reinstall': (ReinstallInstance, ARGS_ONE,
1394
  'reinstall': (ReinstallInstance, ARGS_ANY,
1376 1395
                [DEBUG_OPT, FORCE_OPT, os_opt,
1396
                 m_force_multi,
1397
                 m_node_opt, m_pri_node_opt, m_sec_node_opt,
1398
                 m_clust_opt, m_inst_opt,
1377 1399
                 make_option("--select-os", dest="select_os",
1378 1400
                             action="store_true", default=False,
1379 1401
                             help="Interactive OS reinstall, lists available"

Also available in: Unified diff