Revision efd990e4 lib/cmdlib.py

b/lib/cmdlib.py
3523 3523
  HPATH = "mirrors-replace"
3524 3524
  HTYPE = constants.HTYPE_INSTANCE
3525 3525
  _OP_REQP = ["instance_name", "mode", "disks"]
3526
  REQ_BGL = False
3527

  
3528
  def ExpandNames(self):
3529
    self._ExpandAndLockInstance()
3530

  
3531
    if not hasattr(self.op, "remote_node"):
3532
      self.op.remote_node = None
3533

  
3534
    ia_name = getattr(self.op, "iallocator", None)
3535
    if ia_name is not None:
3536
      if self.op.remote_node is not None:
3537
        raise errors.OpPrereqError("Give either the iallocator or the new"
3538
                                   " secondary, not both")
3539
      self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
3540
    elif self.op.remote_node is not None:
3541
      remote_node = self.cfg.ExpandNodeName(self.op.remote_node)
3542
      if remote_node is None:
3543
        raise errors.OpPrereqError("Node '%s' not known" %
3544
                                   self.op.remote_node)
3545
      self.op.remote_node = remote_node
3546
      self.needed_locks[locking.LEVEL_NODE] = [remote_node]
3547
      self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_APPEND
3548
    else:
3549
      self.needed_locks[locking.LEVEL_NODE] = []
3550
      self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
3551

  
3552
  def DeclareLocks(self, level):
3553
    # If we're not already locking all nodes in the set we have to declare the
3554
    # instance's primary/secondary nodes.
3555
    if (level == locking.LEVEL_NODE and
3556
        self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET):
3557
      self._LockInstancesNodes()
3526 3558

  
3527 3559
  def _RunAllocator(self):
3528 3560
    """Compute a new secondary node using an IAllocator.
......
3573 3605
    This checks that the instance is in the cluster.
3574 3606

  
3575 3607
    """
3576
    if not hasattr(self.op, "remote_node"):
3577
      self.op.remote_node = None
3578

  
3579
    instance = self.cfg.GetInstanceInfo(
3580
      self.cfg.ExpandInstanceName(self.op.instance_name))
3581
    if instance is None:
3582
      raise errors.OpPrereqError("Instance '%s' not known" %
3583
                                 self.op.instance_name)
3608
    instance = self.cfg.GetInstanceInfo(self.op.instance_name)
3609
    assert instance is not None, \
3610
      "Cannot retrieve locked instance %s" % self.op.instance_name
3584 3611
    self.instance = instance
3585
    self.op.instance_name = instance.name
3586 3612

  
3587 3613
    if instance.disk_template not in constants.DTS_NET_MIRROR:
3588 3614
      raise errors.OpPrereqError("Instance's disk layout is not"
......
3597 3623

  
3598 3624
    ia_name = getattr(self.op, "iallocator", None)
3599 3625
    if ia_name is not None:
3600
      if self.op.remote_node is not None:
3601
        raise errors.OpPrereqError("Give either the iallocator or the new"
3602
                                   " secondary, not both")
3603 3626
      self._RunAllocator()
3604 3627

  
3605 3628
    remote_node = self.op.remote_node
3606 3629
    if remote_node is not None:
3607
      remote_node = self.cfg.ExpandNodeName(remote_node)
3608
      if remote_node is None:
3609
        raise errors.OpPrereqError("Node '%s' not known" %
3610
                                   self.op.remote_node)
3611 3630
      self.remote_node_info = self.cfg.GetNodeInfo(remote_node)
3631
      assert self.remote_node_info is not None, \
3632
        "Cannot retrieve locked node %s" % remote_node
3612 3633
    else:
3613 3634
      self.remote_node_info = None
3614 3635
    if remote_node == instance.primary_node:
......
3649 3670
      if instance.FindDisk(name) is None:
3650 3671
        raise errors.OpPrereqError("Disk '%s' not found for instance '%s'" %
3651 3672
                                   (name, instance.name))
3652
    self.op.remote_node = remote_node
3653 3673

  
3654 3674
  def _ExecD8DiskOnly(self, feedback_fn):
3655 3675
    """Replace a disk on the primary or secondary for dbrd8.

Also available in: Unified diff