Revision 297b0cd3 lib/cmdlib.py
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