Revision cb92e7a1

b/lib/client/gnt_node.py
276 276
                               " --secondary-only options can be passed",
277 277
                               errors.ECODE_INVAL)
278 278
  elif opts.primary_only:
279
    mode = constants.IALLOCATOR_NEVAC_PRI
279
    mode = constants.NODE_EVAC_PRI
280 280
  elif opts.secondary_only:
281
    mode = constants.IALLOCATOR_NEVAC_SEC
281
    mode = constants.NODE_EVAC_SEC
282 282
  else:
283
    mode = constants.IALLOCATOR_NEVAC_ALL
283
    mode = constants.NODE_EVAC_ALL
284 284

  
285 285
  # Determine affected instances
286 286
  fields = []
b/lib/cmdlib.py
10145 10145
  """
10146 10146
  REQ_BGL = False
10147 10147

  
10148
  _MODE2IALLOCATOR = {
10149
    constants.NODE_EVAC_PRI: constants.IALLOCATOR_NEVAC_PRI,
10150
    constants.NODE_EVAC_SEC: constants.IALLOCATOR_NEVAC_SEC,
10151
    constants.NODE_EVAC_ALL: constants.IALLOCATOR_NEVAC_ALL,
10152
    }
10153
  assert frozenset(_MODE2IALLOCATOR.keys()) == constants.NODE_EVAC_MODES
10154
  assert (frozenset(_MODE2IALLOCATOR.values()) ==
10155
          constants.IALLOCATOR_NEVAC_MODES)
10156

  
10148 10157
  def CheckArguments(self):
10149 10158
    _CheckIAllocatorOrNode(self, "iallocator", "remote_node")
10150 10159

  
......
10159 10168
        raise errors.OpPrereqError("Can not use evacuated node as a new"
10160 10169
                                   " secondary node", errors.ECODE_INVAL)
10161 10170

  
10162
      if self.op.mode != constants.IALLOCATOR_NEVAC_SEC:
10171
      if self.op.mode != constants.NODE_EVAC_SEC:
10163 10172
        raise errors.OpPrereqError("Without the use of an iallocator only"
10164 10173
                                   " secondary instances can be evacuated",
10165 10174
                                   errors.ECODE_INVAL)
......
10185 10194
    """Builds list of instances to operate on.
10186 10195

  
10187 10196
    """
10188
    assert self.op.mode in constants.IALLOCATOR_NEVAC_MODES
10197
    assert self.op.mode in constants.NODE_EVAC_MODES
10189 10198

  
10190
    if self.op.mode == constants.IALLOCATOR_NEVAC_PRI:
10199
    if self.op.mode == constants.NODE_EVAC_PRI:
10191 10200
      # Primary instances only
10192 10201
      inst_fn = _GetNodePrimaryInstances
10193 10202
      assert self.op.remote_node is None, \
10194 10203
        "Evacuating primary instances requires iallocator"
10195
    elif self.op.mode == constants.IALLOCATOR_NEVAC_SEC:
10204
    elif self.op.mode == constants.NODE_EVAC_SEC:
10196 10205
      # Secondary instances only
10197 10206
      inst_fn = _GetNodeSecondaryInstances
10198 10207
    else:
10199 10208
      # All instances
10200
      assert self.op.mode == constants.IALLOCATOR_NEVAC_ALL
10209
      assert self.op.mode == constants.NODE_EVAC_ALL
10201 10210
      inst_fn = _GetNodeInstances
10202 10211

  
10203 10212
    return inst_fn(self.cfg, self.op.node_name)
......
10272 10281
    elif self.op.iallocator is not None:
10273 10282
      # TODO: Implement relocation to other group
10274 10283
      ial = IAllocator(self.cfg, self.rpc, constants.IALLOCATOR_MODE_NODE_EVAC,
10275
                       evac_mode=self.op.mode,
10284
                       evac_mode=self._MODE2IALLOCATOR[self.op.mode],
10276 10285
                       instances=list(self.instance_names))
10277 10286

  
10278 10287
      ial.Run(self.op.iallocator)
......
10286 10295
      jobs = _LoadNodeEvacResult(self, ial.result, self.op.early_release, True)
10287 10296

  
10288 10297
    elif self.op.remote_node is not None:
10289
      assert self.op.mode == constants.IALLOCATOR_NEVAC_SEC
10298
      assert self.op.mode == constants.NODE_EVAC_SEC
10290 10299
      jobs = [
10291 10300
        [opcodes.OpInstanceReplaceDisks(instance_name=instance_name,
10292 10301
                                        remote_node=self.op.remote_node,
b/lib/constants.py
1116 1116
  IALLOCATOR_NEVAC_ALL,
1117 1117
  ])
1118 1118

  
1119
# Node evacuation
1120
NODE_EVAC_PRI = "primary-only"
1121
NODE_EVAC_SEC = "secondary-only"
1122
NODE_EVAC_ALL = "all"
1123
NODE_EVAC_MODES = frozenset([
1124
  NODE_EVAC_PRI,
1125
  NODE_EVAC_SEC,
1126
  NODE_EVAC_ALL,
1127
  ])
1128

  
1119 1129
# Job queue
1120 1130
JOB_QUEUE_VERSION = 1
1121 1131
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
b/lib/opcodes.py
1014 1014
    _PNodeName,
1015 1015
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1016 1016
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1017
    ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
1017
    ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1018 1018
     "Node evacuation mode"),
1019 1019
    ]
1020 1020
  OP_RESULT = TJobIdListOnly
b/test/ganeti.rapi.client_unittest.py
166 166
    self.assertEqual(client.JOB_STATUS_ALL, constants.JOB_STATUS_ALL)
167 167

  
168 168
    # Node evacuation
169
    self.assertEqual(client.NODE_EVAC_PRI, constants.IALLOCATOR_NEVAC_PRI)
170
    self.assertEqual(client.NODE_EVAC_SEC, constants.IALLOCATOR_NEVAC_SEC)
171
    self.assertEqual(client.NODE_EVAC_ALL, constants.IALLOCATOR_NEVAC_ALL)
169
    self.assertEqual(client.NODE_EVAC_PRI, constants.NODE_EVAC_PRI)
170
    self.assertEqual(client.NODE_EVAC_SEC, constants.NODE_EVAC_SEC)
171
    self.assertEqual(client.NODE_EVAC_ALL, constants.NODE_EVAC_ALL)
172 172

  
173 173
    # Legacy name
174 174
    self.assertEqual(client.JOB_STATUS_WAITLOCK, constants.JOB_STATUS_WAITING)
......
866 866
    self.rapi.AddResponse(serializer.DumpJson([rlib2._NODE_EVAC_RES1]))
867 867
    self.rapi.AddResponse("8888")
868 868
    job_id = self.client.EvacuateNode("node-3", iallocator="hail", dry_run=True,
869
                                      mode=constants.IALLOCATOR_NEVAC_ALL,
869
                                      mode=constants.NODE_EVAC_ALL,
870 870
                                      early_release=True)
871 871
    self.assertEqual(8888, job_id)
872 872
    self.assertItems(["node-3"])

Also available in: Unified diff