Revision 2a9bc156
b/lib/cmdlib.py | ||
---|---|---|
11771 | 11771 |
""" |
11772 | 11772 |
# pylint: disable-msg=R0902 |
11773 | 11773 |
# lots of instance attributes |
11774 |
_ALLO_KEYS = [ |
|
11775 |
"name", "mem_size", "disks", "disk_template", |
|
11776 |
"os", "tags", "nics", "vcpus", "hypervisor", |
|
11777 |
] |
|
11778 |
_RELO_KEYS = [ |
|
11779 |
"name", "relocate_from", |
|
11780 |
] |
|
11781 |
_EVAC_KEYS = [ |
|
11782 |
"evac_nodes", |
|
11783 |
] |
|
11784 | 11774 |
|
11785 | 11775 |
def __init__(self, cfg, rpc, mode, **kwargs): |
11786 | 11776 |
self.cfg = cfg |
... | ... | |
11799 | 11789 |
self.required_nodes = None |
11800 | 11790 |
# init result fields |
11801 | 11791 |
self.success = self.info = self.result = None |
11802 |
if self.mode == constants.IALLOCATOR_MODE_ALLOC: |
|
11803 |
keyset = self._ALLO_KEYS |
|
11804 |
fn = self._AddNewInstance |
|
11805 |
elif self.mode == constants.IALLOCATOR_MODE_RELOC: |
|
11806 |
keyset = self._RELO_KEYS |
|
11807 |
fn = self._AddRelocateInstance |
|
11808 |
elif self.mode == constants.IALLOCATOR_MODE_MEVAC: |
|
11809 |
keyset = self._EVAC_KEYS |
|
11810 |
fn = self._AddEvacuateNodes |
|
11811 |
else: |
|
11792 |
|
|
11793 |
try: |
|
11794 |
(fn, keyset) = self._MODE_DATA[self.mode] |
|
11795 |
except KeyError: |
|
11812 | 11796 |
raise errors.ProgrammerError("Unknown mode '%s' passed to the" |
11813 | 11797 |
" IAllocator" % self.mode) |
11798 |
|
|
11814 | 11799 |
for key in kwargs: |
11815 | 11800 |
if key not in keyset: |
11816 | 11801 |
raise errors.ProgrammerError("Invalid input parameter '%s' to" |
... | ... | |
11821 | 11806 |
if key not in kwargs: |
11822 | 11807 |
raise errors.ProgrammerError("Missing input parameter '%s' to" |
11823 | 11808 |
" IAllocator" % key) |
11824 |
self._BuildInputData(fn)
|
|
11809 |
self._BuildInputData(compat.partial(fn, self))
|
|
11825 | 11810 |
|
11826 | 11811 |
def _ComputeClusterData(self): |
11827 | 11812 |
"""Compute the generic allocator input data. |
... | ... | |
12096 | 12081 |
|
12097 | 12082 |
self.in_text = serializer.Dump(self.in_data) |
12098 | 12083 |
|
12084 |
_MODE_DATA = { |
|
12085 |
constants.IALLOCATOR_MODE_ALLOC: |
|
12086 |
(_AddNewInstance, |
|
12087 |
["name", "mem_size", "disks", "disk_template", "os", "tags", "nics", |
|
12088 |
"vcpus", "hypervisor"]), |
|
12089 |
constants.IALLOCATOR_MODE_RELOC: |
|
12090 |
(_AddRelocateInstance, ["name", "relocate_from"]), |
|
12091 |
constants.IALLOCATOR_MODE_MEVAC: |
|
12092 |
(_AddEvacuateNodes, ["evac_nodes"]), |
|
12093 |
} |
|
12094 |
|
|
12099 | 12095 |
def Run(self, name, validate=True, call_fn=None): |
12100 | 12096 |
"""Run an instance allocator and return the results. |
12101 | 12097 |
|
Also available in: Unified diff