Revision b6e82a65 lib/cmdlib.py

b/lib/cmdlib.py
3571 3571
  HTYPE = constants.HTYPE_INSTANCE
3572 3572
  _OP_REQP = ["instance_name", "mode", "disks"]
3573 3573

  
3574
  def _RunAllocator(self):
3575
    """Compute a new secondary node using an IAllocator.
3576

  
3577
    """
3578
    ial = IAllocator(self.cfg, self.sstore,
3579
                     mode=constants.IALLOCATOR_MODE_RELOC,
3580
                     name=self.op.instance_name,
3581
                     relocate_from=[self.sec_node])
3582

  
3583
    ial.Run(self.op.iallocator)
3584

  
3585
    if not ial.success:
3586
      raise errors.OpPrereqError("Can't compute nodes using"
3587
                                 " iallocator '%s': %s" % (self.op.iallocator,
3588
                                                           ial.info))
3589
    if len(ial.nodes) != ial.required_nodes:
3590
      raise errors.OpPrereqError("iallocator '%s' returned invalid number"
3591
                                 " of nodes (%s), required %s" %
3592
                                 (len(ial.nodes), ial.required_nodes))
3593
    self.op.remote_node = ial.nodes[0]
3594
    logger.ToStdout("Selected new secondary for the instance: %s" %
3595
                    self.op.remote_node)
3596

  
3574 3597
  def BuildHooksEnv(self):
3575 3598
    """Build hooks env.
3576 3599

  
......
3597 3620
    This checks that the instance is in the cluster.
3598 3621

  
3599 3622
    """
3623
    if not hasattr(self.op, "remote_node"):
3624
      self.op.remote_node = None
3625

  
3600 3626
    instance = self.cfg.GetInstanceInfo(
3601 3627
      self.cfg.ExpandInstanceName(self.op.instance_name))
3602 3628
    if instance is None:
......
3616 3642

  
3617 3643
    self.sec_node = instance.secondary_nodes[0]
3618 3644

  
3619
    remote_node = getattr(self.op, "remote_node", None)
3645
    ia_name = getattr(self.op, "iallocator", None)
3646
    if ia_name is not None:
3647
      if self.op.remote_node is not None:
3648
        raise errors.OpPrereqError("Give either the iallocator or the new"
3649
                                   " secondary, not both")
3650
      self.op.remote_node = self._RunAllocator()
3651

  
3652
    remote_node = self.op.remote_node
3620 3653
    if remote_node is not None:
3621 3654
      remote_node = self.cfg.ExpandNodeName(remote_node)
3622 3655
      if remote_node is None:

Also available in: Unified diff