Revision bd315bfa lib/cmdlib.py

b/lib/cmdlib.py
3626 3626
      _ShutdownInstanceDisks(self, inst)
3627 3627

  
3628 3628

  
3629
class LURecreateInstanceDisks(LogicalUnit):
3630
  """Recreate an instance's missing disks.
3631

  
3632
  """
3633
  HPATH = "instance-recreate-disks"
3634
  HTYPE = constants.HTYPE_INSTANCE
3635
  _OP_REQP = ["instance_name", "disks"]
3636
  REQ_BGL = False
3637

  
3638
  def CheckArguments(self):
3639
    """Check the arguments.
3640

  
3641
    """
3642
    if not isinstance(self.op.disks, list):
3643
      raise errors.OpPrereqError("Invalid disks parameter")
3644
    for item in self.op.disks:
3645
      if (not isinstance(item, int) or
3646
          item < 0):
3647
        raise errors.OpPrereqError("Invalid disk specification '%s'" %
3648
                                   str(item))
3649

  
3650
  def ExpandNames(self):
3651
    self._ExpandAndLockInstance()
3652

  
3653
  def BuildHooksEnv(self):
3654
    """Build hooks env.
3655

  
3656
    This runs on master, primary and secondary nodes of the instance.
3657

  
3658
    """
3659
    env = _BuildInstanceHookEnvByObject(self, self.instance)
3660
    nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes)
3661
    return env, nl, nl
3662

  
3663
  def CheckPrereq(self):
3664
    """Check prerequisites.
3665

  
3666
    This checks that the instance is in the cluster and is not running.
3667

  
3668
    """
3669
    instance = self.cfg.GetInstanceInfo(self.op.instance_name)
3670
    assert instance is not None, \
3671
      "Cannot retrieve locked instance %s" % self.op.instance_name
3672
    _CheckNodeOnline(self, instance.primary_node)
3673

  
3674
    if instance.disk_template == constants.DT_DISKLESS:
3675
      raise errors.OpPrereqError("Instance '%s' has no disks" %
3676
                                 self.op.instance_name)
3677
    if instance.admin_up:
3678
      raise errors.OpPrereqError("Instance '%s' is marked to be up" %
3679
                                 self.op.instance_name)
3680
    remote_info = self.rpc.call_instance_info(instance.primary_node,
3681
                                              instance.name,
3682
                                              instance.hypervisor)
3683
    remote_info.Raise("Error checking node %s" % instance.primary_node,
3684
                      prereq=True)
3685
    if remote_info.payload:
3686
      raise errors.OpPrereqError("Instance '%s' is running on the node %s" %
3687
                                 (self.op.instance_name,
3688
                                  instance.primary_node))
3689

  
3690
    if not self.op.disks:
3691
      self.op.disks = range(len(instance.disks))
3692
    else:
3693
      for idx in self.op.disks:
3694
        if idx >= len(instance.disks):
3695
          raise errors.OpPrereqError("Invalid disk index passed '%s'" % idx)
3696

  
3697
    self.instance = instance
3698

  
3699
  def Exec(self, feedback_fn):
3700
    """Recreate the disks.
3701

  
3702
    """
3703
    to_skip = []
3704
    for idx, disk in enumerate(self.instance.disks):
3705
      if idx not in self.op.disks: # disk idx has not been passed in
3706
        to_skip.append(idx)
3707
        continue
3708

  
3709
    _CreateDisks(self, self.instance, to_skip=to_skip)
3710

  
3711

  
3629 3712
class LURenameInstance(LogicalUnit):
3630 3713
  """Rename an instance.
3631 3714

  
......
4818 4901
  return "originstname+%s" % instance.name
4819 4902

  
4820 4903

  
4821
def _CreateDisks(lu, instance):
4904
def _CreateDisks(lu, instance, to_skip=None):
4822 4905
  """Create all disks for an instance.
4823 4906

  
4824 4907
  This abstracts away some work from AddInstance.
......
4827 4910
  @param lu: the logical unit on whose behalf we execute
4828 4911
  @type instance: L{objects.Instance}
4829 4912
  @param instance: the instance whose disks we should create
4913
  @type to_skip: list
4914
  @param to_skip: list of indices to skip
4830 4915
  @rtype: boolean
4831 4916
  @return: the success of the creation
4832 4917

  
......
4843 4928

  
4844 4929
  # Note: this needs to be kept in sync with adding of disks in
4845 4930
  # LUSetInstanceParams
4846
  for device in instance.disks:
4931
  for idx, device in enumerate(instance.disks):
4932
    if to_skip and idx in to_skip:
4933
      continue
4847 4934
    logging.info("Creating volume %s for instance %s",
4848 4935
                 device.iv_name, instance.name)
4849 4936
    #HARDCODE

Also available in: Unified diff