Revision 3d2ca95d

b/man/gnt-instance.sgml
1229 1229
        <cmdsynopsis>
1230 1230
          <command>reinstall</command>
1231 1231
          <arg choice="opt">-o <replaceable>os-type</replaceable></arg>
1232
          <arg choice="opt">-f <replaceable>force</replaceable></arg>
1233 1232
          <arg>--select-os</arg>
1233
          <arg choice="opt">-f <replaceable>force</replaceable></arg>
1234
          <arg>--force-multiple</arg>
1235
          <sbr>
1236
          <group choice="opt">
1237
            <arg>--instance</arg>
1238
            <arg>--node</arg>
1239
            <arg>--primary</arg>
1240
            <arg>--secondary</arg>
1241
            <arg>--all</arg>
1242
          </group>
1234 1243
          <arg>--submit</arg>
1235
          <arg choice="req"><replaceable>instance</replaceable></arg>
1244
          <arg choice="opt" rep="repeat"><replaceable>instance</replaceable></arg>
1236 1245
        </cmdsynopsis>
1237 1246

  
1238 1247
        <para>
1239
          Reinstalls the operating system on the given instance. The
1240
          instance must be stopped when running this command. If the
1248
          Reinstalls the operating system on the given instance(s). The
1249
          instance(s) must be stopped when running this command. If the
1241 1250
          <option>--os-type</option> is specified, the operating
1242 1251
          system is changed.
1243 1252
        </para>
1244 1253

  
1245 1254
        <para>
1246
          Since reinstall is potentially dangerous command, the user
1247
          will be required to confirm this action, unless the
1248
          <option>-f</option> flag is passed.
1249
        </para>
1250

  
1251
        <para>
1252 1255
          The <option>--select-os</option> option switches to an
1253 1256
          interactive OS reinstall. The user is prompted to select the OS
1254 1257
          template from the list of available OS templates.
1255 1258
        </para>
1256 1259

  
1257 1260
        <para>
1261
          Since this is a potentially dangerous command, the user will
1262
          be required to confirm this action, unless the
1263
          <option>-f</option> flag is passed. When multiple instances
1264
          are selected (either by passing multiple arguments or by
1265
          using the <option>--node</option>,
1266
          <option>--primary</option>, <option>--secondary</option> or
1267
          <option>--all</option> options), the user must pass both the
1268
          <option>--force</option> and
1269
          <option>--force-multiple</option> options to skip the
1270
          interactive confirmation.
1271
        </para>
1272

  
1273
        <para>
1258 1274
          The <option>--submit</option> option is used to send the job to
1259 1275
          the master daemon but not wait for its completion. The job
1260 1276
          ID will be shown so that it can be examined via
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