Revision fe7b0351 lib/cmdlib.py

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

  

Also available in: Unified diff