Revision 297b0cd3
b/doc/iallocator.rst | ||
---|---|---|
205 | 205 |
name |
206 | 206 |
the name of the instance; if the request is a realocation, then this |
207 | 207 |
name will be found in the list of instances (see below), otherwise |
208 |
is the FQDN of the new instance |
|
208 |
is the FQDN of the new instance; type *string*
|
|
209 | 209 |
|
210 | 210 |
required_nodes |
211 | 211 |
how many nodes should the algorithm return; while this information |
212 | 212 |
can be deduced from the instace's disk template, it's better if |
213 | 213 |
this computation is left to Ganeti as then allocator scripts are |
214 |
less sensitive to changes to the disk templates |
|
214 |
less sensitive to changes to the disk templates; type *integer*
|
|
215 | 215 |
|
216 | 216 |
disk_space_total |
217 | 217 |
the total disk space that will be used by this instance on the |
218 | 218 |
(new) nodes; again, this information can be computed from the list |
219 | 219 |
of instance disks and its template type, but Ganeti is better |
220 |
suited to compute it |
|
220 |
suited to compute it; type *integer*
|
|
221 | 221 |
|
222 | 222 |
.. pyassert:: |
223 | 223 |
|
... | ... | |
274 | 274 |
relocate_from |
275 | 275 |
a list of nodes to move the instance away from (note that with |
276 | 276 |
Ganeti 2.0, this list will always contain a single node, the |
277 |
current secondary of the instance) |
|
277 |
current secondary of the instance); type *list of strings*
|
|
278 | 278 |
|
279 | 279 |
As for ``multi-relocate``, it needs the three following request |
280 | 280 |
arguments: |
281 | 281 |
|
282 | 282 |
instances |
283 |
a list of instance names to relocate |
|
283 |
a list of instance names to relocate; type *list of strings*
|
|
284 | 284 |
|
285 | 285 |
reloc_mode |
286 | 286 |
a string indicating the relocation mode; there are three possible |
... | ... | |
292 | 292 |
this argument is only accepted when ``reloc_mode``, as explained |
293 | 293 |
above, is *change_group*; if present, it must either be the empty |
294 | 294 |
list, or contain a list of group UUIDs that should be considered for |
295 |
relocating instances to |
|
295 |
relocating instances to; type *list of strings*
|
|
296 | 296 |
|
297 | 297 |
Finally, in the case of multi-evacuate, there's one single request |
298 | 298 |
argument (in addition to ``type``): |
299 | 299 |
|
300 | 300 |
evac_nodes |
301 |
the names of the nodes to be evacuated |
|
301 |
the names of the nodes to be evacuated; type *list of strings*
|
|
302 | 302 |
|
303 | 303 |
Response message |
304 | 304 |
~~~~~~~~~~~~~~~~ |
b/lib/cmdlib.py | ||
---|---|---|
12020 | 12020 |
self.success = self.info = self.result = None |
12021 | 12021 |
|
12022 | 12022 |
try: |
12023 |
(fn, keyset, self._result_check) = self._MODE_DATA[self.mode]
|
|
12023 |
(fn, keydata, self._result_check) = self._MODE_DATA[self.mode]
|
|
12024 | 12024 |
except KeyError: |
12025 | 12025 |
raise errors.ProgrammerError("Unknown mode '%s' passed to the" |
12026 | 12026 |
" IAllocator" % self.mode) |
12027 | 12027 |
|
12028 |
keyset = [n for (n, _) in keydata] |
|
12029 |
|
|
12028 | 12030 |
for key in kwargs: |
12029 | 12031 |
if key not in keyset: |
12030 | 12032 |
raise errors.ProgrammerError("Invalid input parameter '%s' to" |
... | ... | |
12035 | 12037 |
if key not in kwargs: |
12036 | 12038 |
raise errors.ProgrammerError("Missing input parameter '%s' to" |
12037 | 12039 |
" IAllocator" % key) |
12038 |
self._BuildInputData(compat.partial(fn, self)) |
|
12040 |
self._BuildInputData(compat.partial(fn, self), keydata)
|
|
12039 | 12041 |
|
12040 | 12042 |
def _ComputeClusterData(self): |
12041 | 12043 |
"""Compute the generic allocator input data. |
... | ... | |
12310 | 12312 |
"target_groups": self.target_groups, |
12311 | 12313 |
} |
12312 | 12314 |
|
12313 |
def _BuildInputData(self, fn): |
|
12315 |
def _BuildInputData(self, fn, keydata):
|
|
12314 | 12316 |
"""Build input data structures. |
12315 | 12317 |
|
12316 | 12318 |
""" |
... | ... | |
12318 | 12320 |
|
12319 | 12321 |
request = fn() |
12320 | 12322 |
request["type"] = self.mode |
12323 |
for keyname, keytype in keydata: |
|
12324 |
if keyname not in request: |
|
12325 |
raise errors.ProgrammerError("Request parameter %s is missing" % |
|
12326 |
keyname) |
|
12327 |
val = request[keyname] |
|
12328 |
if not keytype(val): |
|
12329 |
raise errors.ProgrammerError("Request parameter %s doesn't pass" |
|
12330 |
" validation, value %s, expected" |
|
12331 |
" type %s" % (keyname, val, keytype)) |
|
12321 | 12332 |
self.in_data["request"] = request |
12322 | 12333 |
|
12323 | 12334 |
self.in_text = serializer.Dump(self.in_data) |
12324 | 12335 |
|
12336 |
_STRING_LIST = ht.TListOf(ht.TString) |
|
12325 | 12337 |
_MODE_DATA = { |
12326 | 12338 |
constants.IALLOCATOR_MODE_ALLOC: |
12327 | 12339 |
(_AddNewInstance, |
12328 |
["name", "memory", "disks", "disk_template", "os", "tags", "nics", |
|
12329 |
"vcpus", "hypervisor"], ht.TList), |
|
12340 |
[ |
|
12341 |
("name", ht.TString), |
|
12342 |
("memory", ht.TInt), |
|
12343 |
("disks", ht.TListOf(ht.TDict)), |
|
12344 |
("disk_template", ht.TString), |
|
12345 |
("os", ht.TString), |
|
12346 |
("tags", _STRING_LIST), |
|
12347 |
("nics", ht.TListOf(ht.TDict)), |
|
12348 |
("vcpus", ht.TInt), |
|
12349 |
("hypervisor", ht.TString), |
|
12350 |
], ht.TList), |
|
12330 | 12351 |
constants.IALLOCATOR_MODE_RELOC: |
12331 |
(_AddRelocateInstance, ["name", "relocate_from"], ht.TList), |
|
12352 |
(_AddRelocateInstance, |
|
12353 |
[("name", ht.TString), ("relocate_from", _STRING_LIST)], |
|
12354 |
ht.TList), |
|
12332 | 12355 |
constants.IALLOCATOR_MODE_MEVAC: |
12333 |
(_AddEvacuateNodes, ["evac_nodes"], |
|
12334 |
ht.TListOf(ht.TAnd(ht.TIsLength(2), |
|
12335 |
ht.TListOf(ht.TString)))), |
|
12356 |
(_AddEvacuateNodes, [("evac_nodes", _STRING_LIST)], |
|
12357 |
ht.TListOf(ht.TAnd(ht.TIsLength(2), _STRING_LIST))), |
|
12336 | 12358 |
constants.IALLOCATOR_MODE_MRELOC: |
12337 |
(_AddMultiRelocate, ["instances", "reloc_mode", "target_groups"], |
|
12359 |
(_AddMultiRelocate, [ |
|
12360 |
("instances", _STRING_LIST), |
|
12361 |
("reloc_mode", ht.TElemOf(constants.IALLOCATOR_MRELOC_MODES)), |
|
12362 |
("target_groups", _STRING_LIST), |
|
12363 |
], |
|
12338 | 12364 |
ht.TListOf(ht.TListOf(ht.TStrictDict(True, False, { |
12339 | 12365 |
# pylint: disable-msg=E1101 |
12340 | 12366 |
# Class '...' has no 'OP_ID' member |
Also available in: Unified diff