Revision d0834de3

b/lib/cmdlib.py
1887 1887
      raise errors.OpPrereqError, ("Instance '%s' is running on the node %s" %
1888 1888
                                   (self.op.instance_name,
1889 1889
                                    instance.primary_node))
1890

  
1891
    self.op.os_type = getattr(self.op, "os_type", None)
1892
    if self.op.os_type is not None:
1893
      # OS verification
1894
      pnode = self.cfg.GetNodeInfo(
1895
        self.cfg.ExpandNodeName(instance.primary_node))
1896
      if pnode is None:
1897
        raise errors.OpPrereqError, ("Primary node '%s' is unknown" %
1898
                                     self.op.pnode)
1899
      os_obj = rpc.call_os_get([pnode.name], self.op.os_type)[pnode.name]
1900
      if not isinstance(os_obj, objects.OS):
1901
        raise errors.OpPrereqError, ("OS '%s' not in supported OS list for"
1902
                                     " primary node"  % self.op.os_type)
1903

  
1890 1904
    self.instance = instance
1891 1905

  
1892 1906
  def Exec(self, feedback_fn):
......
1895 1909
    """
1896 1910
    inst = self.instance
1897 1911

  
1912
    if self.op.os_type is not None:
1913
      feedback_fn("Changing OS to '%s'..." % self.op.os_type)
1914
      inst.os = self.op.os_type
1915
      self.cfg.AddInstance(inst)
1916

  
1898 1917
    _StartInstanceDisks(self.cfg, inst, None)
1899 1918
    try:
1900 1919
      feedback_fn("Running the instance OS create scripts...")
b/lib/opcodes.py
142 142
class OpReinstallInstance(OpCode):
143 143
  """Reinstall an instance."""
144 144
  OP_ID = "OP_INSTANCE_REINSTALL"
145
  __slots__ = ["instance_name"]
145
  __slots__ = ["instance_name", "os_type"]
146 146

  
147 147

  
148 148
class OpRemoveInstance(OpCode):
b/man/gnt-instance.sgml
377 377
        </para>
378 378
      </refsect3>
379 379

  
380
      <refsect3>
381
        <title>REINSTALL</title>
382

  
383
        <cmdsynopsis>
384
          <command>reinstall</command>
385
          <arg choice="opt">-o <replaceable>os-type</replaceable></arg>
386
          <arg choice="opt">-f <replaceable>force</replaceable></arg>
387
          <arg choice="req"><replaceable>instance</replaceable></arg>
388
        </cmdsynopsis>
389

  
390
        <para>
391
          Reinstalls the operating system on the given instance. The instance
392
          must be stopped when running this command. If the
393
          <option>--os-type</option> is specified, the operating system is
394
          changed.
395
        </para>
396
      </refsect3>
397

  
380 398
    </refsect2>
381 399

  
382 400
    <refsect2>
b/scripts/gnt-instance
111 111
    if not opts._ask_user(usertext):
112 112
      return 1
113 113

  
114
  op = opcodes.OpReinstallInstance(instance_name=instance_name)
114
  op = opcodes.OpReinstallInstance(instance_name=instance_name,
115
                                   os_type=opts.os)
115 116
  SubmitOpCode(op)
116 117

  
117 118
  return 0
......
421 422
node_opt = make_option("-n", "--node", dest="node", help="Target node",
422 423
                       metavar="<node>")
423 424

  
425
os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run",
426
                    metavar="<os>"),
427

  
424 428
# this is defined separately due to readability only
425 429
add_opts = [
426 430
  DEBUG_OPT,
......
429 433
             default=20 * 1024, type="unit", metavar="<size>"),
430 434
  cli_option("--swap-size", dest="swap", help="Swap size",
431 435
             default=4 * 1024, type="unit", metavar="<size>"),
432
  cli_option("-o", "--os-type", dest="os", help="What OS to run",
433
             metavar="<os>"),
436
  os_opt,
434 437
  cli_option("-m", "--memory", dest="mem", help="Memory size",
435 438
              default=128, type="unit", metavar="<mem>"),
436 439
  make_option("-p", "--cpu", dest="vcpus", help="Number of virtual CPUs",
......
480 483
  'list': (ListInstances, ARGS_NONE,
481 484
           [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
482 485
           "", "Lists the instances and their status"),
483
  'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
486
  'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
484 487
                "[-f] <instance>", "Reinstall the instance"),
485 488
  'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
486 489
             "[-f] <instance>", "Shuts down the instance and removes it"),

Also available in: Unified diff