Revision fe7b0351

b/lib/cli.py
39 39
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", "SubmitOpCode",
40 40
           "cli_option", "OutputTable",
41 41
           "ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE",
42
           "USEUNITS_OPT", "FIELDS_OPT"]
42
           "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT"]
43 43

  
44 44
DEBUG_OPT = make_option("-d", "--debug", default=False,
45 45
                        action="store_true",
......
62 62
                         type="string", help="Select output fields",
63 63
                         metavar="FIELDS")
64 64

  
65
FORCE_OPT = make_option("-f", "--force", dest="force", action="store_true",
66
                        default=False, help="Force the operation")
67

  
65 68
_LOCK_OPT = make_option("--lock-retries", default=None,
66 69
                        type="int", help=SUPPRESS_HELP)
67 70

  
b/lib/cmdlib.py
1648 1648
  return disks_ok, device_info
1649 1649

  
1650 1650

  
1651
def _StartInstanceDisks(cfg, instance, force):
1652
  disks_ok, dummy = _AssembleInstanceDisks(instance, cfg,
1653
                                           ignore_secondaries=force)
1654
  if not disks_ok:
1655
    _ShutdownInstanceDisks(instance, cfg)
1656
    if force is not None and not force:
1657
      logger.Error("If the message above refers to a secondary node,"
1658
                   " you can retry the operation using '--force'.")
1659
    raise errors.OpExecError, ("Disk consistency error")
1660

  
1661

  
1651 1662
class LUDeactivateInstanceDisks(NoHooksLU):
1652 1663
  """Shutdown an instance's disks.
1653 1664

  
......
1776 1787
                                 (instance.name, node_current, memory,
1777 1788
                                  freememory))
1778 1789

  
1779
    disks_ok, dummy = _AssembleInstanceDisks(instance, self.cfg,
1780
                                             ignore_secondaries=force)
1781
    if not disks_ok:
1782
      _ShutdownInstanceDisks(instance, self.cfg)
1783
      if not force:
1784
        logger.Error("If the message above refers to a secondary node,"
1785
                     " you can retry the operation using '--force'.")
1786
      raise errors.OpExecError, ("Disk consistency error")
1790
    _StartInstanceDisks(self.cfg, instance, force)
1787 1791

  
1788 1792
    if not rpc.call_instance_start(node_current, instance, extra_args):
1789 1793
      _ShutdownInstanceDisks(instance, self.cfg)
......
1841 1845
    _ShutdownInstanceDisks(instance, self.cfg)
1842 1846

  
1843 1847

  
1848
class LUReinstallInstance(LogicalUnit):
1849
  """Reinstall an instance.
1850

  
1851
  """
1852
  HPATH = "instance-reinstall"
1853
  HTYPE = constants.HTYPE_INSTANCE
1854
  _OP_REQP = ["instance_name"]
1855

  
1856
  def BuildHooksEnv(self):
1857
    """Build hooks env.
1858

  
1859
    This runs on master, primary and secondary nodes of the instance.
1860

  
1861
    """
1862
    env = {
1863
      "INSTANCE_NAME": self.op.instance_name,
1864
      "INSTANCE_PRIMARY": self.instance.primary_node,
1865
      "INSTANCE_SECONDARIES": " ".join(self.instance.secondary_nodes),
1866
      }
1867
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
1868
          list(self.instance.secondary_nodes))
1869
    return env, nl, nl
1870

  
1871
  def CheckPrereq(self):
1872
    """Check prerequisites.
1873

  
1874
    This checks that the instance is in the cluster and is not running.
1875

  
1876
    """
1877
    instance = self.cfg.GetInstanceInfo(
1878
      self.cfg.ExpandInstanceName(self.op.instance_name))
1879
    if instance is None:
1880
      raise errors.OpPrereqError, ("Instance '%s' not known" %
1881
                                   self.op.instance_name)
1882
    if instance.disk_template == constants.DT_DISKLESS:
1883
      raise errors.OpPrereqError, ("Instance '%s' has no disks" %
1884
                                   self.op.instance_name)
1885
    if instance.status != "down":
1886
      raise errors.OpPrereqError, ("Instance '%s' is marked to be up" %
1887
                                   self.op.instance_name)
1888
    remote_info = rpc.call_instance_info(instance.primary_node, instance.name)
1889
    if remote_info:
1890
      raise errors.OpPrereqError, ("Instance '%s' is running on the node %s" %
1891
                                   (self.op.instance_name,
1892
                                    instance.primary_node))
1893
    self.instance = instance
1894

  
1895
  def Exec(self, feedback_fn):
1896
    """Reinstall the instance.
1897

  
1898
    """
1899
    inst = self.instance
1900

  
1901
    _StartInstanceDisks(self.cfg, inst, None)
1902
    try:
1903
      feedback_fn("Running the instance OS create scripts...")
1904
      if not rpc.call_instance_os_add(inst.primary_node, inst, "sda", "sdb"):
1905
        raise errors.OpExecError, ("Could not install OS for instance %s "
1906
                                   "on node %s" %
1907
                                   (inst.name, inst.primary_node))
1908
    finally:
1909
      _ShutdownInstanceDisks(inst, self.cfg)
1910

  
1911

  
1844 1912
class LURemoveInstance(LogicalUnit):
1845 1913
  """Remove an instance.
1846 1914

  
......
2395 2463
    # check primary node
2396 2464
    pnode = self.cfg.GetNodeInfo(self.cfg.ExpandNodeName(self.op.pnode))
2397 2465
    if pnode is None:
2398
      raise errors.OpPrereqError, ("Primary node '%s' is uknown" %
2466
      raise errors.OpPrereqError, ("Primary node '%s' is unknown" %
2399 2467
                                   self.op.pnode)
2400 2468
    self.op.pnode = pnode.name
2401 2469
    self.pnode = pnode
......
3264 3332
    self.dst_node = self.cfg.GetNodeInfo(dst_node_short)
3265 3333

  
3266 3334
    if self.dst_node is None:
3267
      raise errors.OpPrereqError, ("Destination node '%s' is uknown." %
3335
      raise errors.OpPrereqError, ("Destination node '%s' is unknown." %
3268 3336
                                   self.op.target_node)
3269 3337
    self.op.target_node = self.dst_node.name
3270 3338

  
b/lib/mcpu.py
63 63
    opcodes.OpRemoveNode: cmdlib.LURemoveNode,
64 64
    # instance lu
65 65
    opcodes.OpCreateInstance: cmdlib.LUCreateInstance,
66
    opcodes.OpReinstallInstance: cmdlib.LUReinstallInstance,
66 67
    opcodes.OpRemoveInstance: cmdlib.LURemoveInstance,
67 68
    opcodes.OpActivateInstanceDisks: cmdlib.LUActivateInstanceDisks,
68 69
    opcodes.OpShutdownInstance: cmdlib.LUShutdownInstance,
b/lib/opcodes.py
139 139
               "wait_for_sync"]
140 140

  
141 141

  
142
class OpReinstallInstance(OpCode):
143
  """Reinstall an instance."""
144
  OP_ID = "OP_INSTANCE_REINSTALL"
145
  __slots__ = ["instance_name"]
146

  
147

  
142 148
class OpRemoveInstance(OpCode):
143 149
  """Remove an instance."""
144 150
  OP_ID = "OP_INSTANCE_REMOVE"
b/scripts/gnt-backup
100 100
# options used in more than one cmd
101 101
node_opt = make_option("-n", "--node", dest="node", help="Target node",
102 102
                       metavar="<node>")
103
force_opt = make_option("-f", "--force", dest="force", action="store_true",
104
                        default=False, help="Force the operation")
105 103

  
106 104
# this is defined separately due to readability only
107 105
import_opts = [
......
143 141
            ],
144 142
           "", "Lists instance exports available in the ganeti cluster"),
145 143
  'export': (ExportInstance, ARGS_ONE,
146
             [node_opt, DEBUG_OPT, force_opt,
144
             [node_opt, DEBUG_OPT, FORCE_OPT,
147 145
              make_option("","--noshutdown", dest="shutdown",
148 146
                          action="store_false", default=True,
149 147
                          help="Don't shutdown the instance (unsafe)"), ],
b/scripts/gnt-instance
22 22
import sys
23 23
import os
24 24
from optparse import make_option
25
import textwrap
26 25
from cStringIO import StringIO
27 26

  
28 27
from ganeti.cli import *
......
96 95
  return 0
97 96

  
98 97

  
98
def ReinstallInstance(opts, args):
99
  """Reinstall an instance.
100

  
101
  Args:
102
    opts - class with options as members
103
    args - list containing a single element, the instance name
104

  
105
  """
106
  instance_name = args[0]
107

  
108
  if not opts.force:
109
    usertext = ("This will reinstall the instance %s and remove "
110
                "all data. Continue?") % instance_name
111
    if not opts._ask_user(usertext):
112
      return 1
113

  
114
  op = opcodes.OpReinstallInstance(instance_name=instance_name)
115
  SubmitOpCode(op)
116

  
117
  return 0
118

  
119

  
99 120
def RemoveInstance(opts, args):
100 121
  """Remove an instance.
101 122

  
......
244 265
    usertext = ("Failover will happen to image %s."
245 266
                " This requires a shutdown of the instance. Continue?" %
246 267
                (instance_name,))
247
    usertext = textwrap.fill(usertext)
248 268
    if not opts._ask_user(usertext):
249 269
      return 1
250 270

  
......
400 420
# options used in more than one cmd
401 421
node_opt = make_option("-n", "--node", dest="node", help="Target node",
402 422
                       metavar="<node>")
403
force_opt = make_option("-f", "--force", dest="force", action="store_true",
404
                        default=False, help="Force the operation")
405 423

  
406 424
# this is defined separately due to readability only
407 425
add_opts = [
......
448 466
              "<instance>",
449 467
              "Opens a console on the specified instance"),
450 468
  'failover': (FailoverInstance, ARGS_ONE,
451
               [DEBUG_OPT, force_opt,
469
               [DEBUG_OPT, FORCE_OPT,
452 470
                make_option("--ignore-consistency", dest="ignore_consistency",
453 471
                            action="store_true", default=False,
454 472
                            help="Ignore the consistency of the disks on"
......
462 480
  'list': (ListInstances, ARGS_NONE,
463 481
           [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
464 482
           "", "Lists the instances and their status"),
465
  'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, force_opt],
483
  'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
484
                "[-f] <instance>", "Reinstall the instance"),
485
  'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
466 486
             "[-f] <instance>", "Shuts down the instance and removes it"),
467 487
  'remove-mirror': (RemoveMDDRBDComponent, ARGS_ONE,
468 488
                   [DEBUG_OPT, node_opt,
......
484 504
                                       " change the secondary)"))],
485 505
                    "[-n NODE] <instance>",
486 506
                    "Replaces all disks for the instance"),
487

  
488 507
  'modify': (SetInstanceParms, ARGS_ONE,
489
             [DEBUG_OPT, force_opt,
508
             [DEBUG_OPT, FORCE_OPT,
490 509
              cli_option("-m", "--memory", dest="mem",
491 510
                         help="Memory size",
492 511
                         default=None, type="unit", metavar="<mem>"),
......
504 523
  'shutdown': (ShutdownInstance, ARGS_ONE, [DEBUG_OPT],
505 524
               "<instance>", "Stops an instance"),
506 525
  'startup': (StartupInstance, ARGS_ONE,
507
              [DEBUG_OPT, force_opt,
526
              [DEBUG_OPT, FORCE_OPT,
508 527
               make_option("-e", "--extra", dest="extra_args",
509 528
                           help="Extra arguments for the instance's kernel",
510 529
                           default=None, type="string", metavar="<PARAMS>"),

Also available in: Unified diff