Revision f0edfcf6 lib/cmdlib.py

b/lib/cmdlib.py
12759 12759
    self.hypervisor = None
12760 12760
    self.relocate_from = None
12761 12761
    self.name = None
12762
    self.evac_nodes = None
12763 12762
    self.instances = None
12764 12763
    self.evac_mode = None
12765 12764
    self.target_groups = []
......
13041 13040
      }
13042 13041
    return request
13043 13042

  
13044
  def _AddEvacuateNodes(self):
13045
    """Add evacuate nodes data to allocator structure.
13046

  
13047
    """
13048
    request = {
13049
      "evac_nodes": self.evac_nodes
13050
      }
13051
    return request
13052

  
13053 13043
  def _AddNodeEvacuate(self):
13054 13044
    """Get data for node-evacuate requests.
13055 13045

  
......
13130 13120
      (_AddRelocateInstance,
13131 13121
       [("name", ht.TString), ("relocate_from", _STRING_LIST)],
13132 13122
       ht.TList),
13133
    constants.IALLOCATOR_MODE_MEVAC:
13134
      (_AddEvacuateNodes, [("evac_nodes", _STRING_LIST)],
13135
       ht.TListOf(ht.TAnd(ht.TIsLength(2), _STRING_LIST))),
13136 13123
     constants.IALLOCATOR_MODE_NODE_EVAC:
13137 13124
      (_AddNodeEvacuate, [
13138 13125
        ("instances", _STRING_LIST),
......
13191 13178
                               (self._result_check, self.result),
13192 13179
                               errors.ECODE_INVAL)
13193 13180

  
13194
    if self.mode in (constants.IALLOCATOR_MODE_RELOC,
13195
                     constants.IALLOCATOR_MODE_MEVAC):
13181
    if self.mode == constants.IALLOCATOR_MODE_RELOC:
13196 13182
      node2group = dict((name, ndata["group"])
13197 13183
                        for (name, ndata) in self.in_data["nodes"].items())
13198 13184

  
......
13211 13197
                                   " differ from original groups (%s)" %
13212 13198
                                   (utils.CommaJoin(result_groups),
13213 13199
                                    utils.CommaJoin(request_groups)))
13214
      elif self.mode == constants.IALLOCATOR_MODE_MEVAC:
13215
        request_groups = fn(self.evac_nodes)
13216
        for (instance_name, secnode) in self.result:
13217
          result_groups = fn([secnode])
13218
          if result_groups != request_groups:
13219
            raise errors.OpExecError("Iallocator returned new secondary node"
13220
                                     " '%s' (group '%s') for instance '%s'"
13221
                                     " which is not in original group '%s'" %
13222
                                     (secnode, utils.CommaJoin(result_groups),
13223
                                      instance_name,
13224
                                      utils.CommaJoin(request_groups)))
13225 13200
      else:
13226 13201
        raise errors.ProgrammerError("Unhandled mode '%s'" % self.mode)
13227 13202

  
......
13307 13282
      self.op.name = fname
13308 13283
      self.relocate_from = \
13309 13284
          list(self.cfg.GetInstanceInfo(fname).secondary_nodes)
13310
    elif self.op.mode == constants.IALLOCATOR_MODE_MEVAC:
13311
      if not hasattr(self.op, "evac_nodes"):
13312
        raise errors.OpPrereqError("Missing attribute 'evac_nodes' on"
13313
                                   " opcode input", errors.ECODE_INVAL)
13314 13285
    elif self.op.mode in (constants.IALLOCATOR_MODE_CHG_GROUP,
13315 13286
                          constants.IALLOCATOR_MODE_NODE_EVAC):
13316 13287
      if not self.op.instances:
......
13351 13322
                       name=self.op.name,
13352 13323
                       relocate_from=list(self.relocate_from),
13353 13324
                       )
13354
    elif self.op.mode == constants.IALLOCATOR_MODE_MEVAC:
13355
      ial = IAllocator(self.cfg, self.rpc,
13356
                       mode=self.op.mode,
13357
                       evac_nodes=self.op.evac_nodes)
13358 13325
    elif self.op.mode == constants.IALLOCATOR_MODE_CHG_GROUP:
13359 13326
      ial = IAllocator(self.cfg, self.rpc,
13360 13327
                       mode=self.op.mode,

Also available in: Unified diff