Revision 29859cb7
b/lib/cmdlib.py | ||
---|---|---|
3143 | 3143 |
nics = [{"mac": self.op.mac, "ip": getattr(self.op, "ip", None), |
3144 | 3144 |
"bridge": self.op.bridge}] |
3145 | 3145 |
ial = IAllocator(self.cfg, self.sstore, |
3146 |
mode=constants.IALLOCATOR_MODE_ALLOC, |
|
3146 | 3147 |
name=self.op.instance_name, |
3147 | 3148 |
disk_template=self.op.disk_template, |
3148 | 3149 |
tags=[], |
... | ... | |
3151 | 3152 |
mem_size=self.op.mem_size, |
3152 | 3153 |
disks=disks, |
3153 | 3154 |
nics=nics, |
3154 |
mode=constants.IALLOCATOR_MODE_ALLOC)
|
|
3155 |
) |
|
3155 | 3156 |
|
3156 | 3157 |
ial.Run(self.op.iallocator) |
3157 | 3158 |
|
... | ... | |
4762 | 4763 |
easy usage |
4763 | 4764 |
|
4764 | 4765 |
""" |
4765 |
_KEYS = [ |
|
4766 |
"mode", "name", |
|
4766 |
_ALLO_KEYS = [ |
|
4767 | 4767 |
"mem_size", "disks", "disk_template", |
4768 | 4768 |
"os", "tags", "nics", "vcpus", |
4769 | 4769 |
] |
4770 |
_RELO_KEYS = [ |
|
4771 |
"relocate_from", |
|
4772 |
] |
|
4770 | 4773 |
|
4771 |
def __init__(self, cfg, sstore, **kwargs): |
|
4774 |
def __init__(self, cfg, sstore, mode, name, **kwargs):
|
|
4772 | 4775 |
self.cfg = cfg |
4773 | 4776 |
self.sstore = sstore |
4774 | 4777 |
# init buffer variables |
4775 | 4778 |
self.in_text = self.out_text = self.in_data = self.out_data = None |
4776 | 4779 |
# init all input fields so that pylint is happy |
4777 |
self.mode = self.name = None |
|
4780 |
self.mode = mode |
|
4781 |
self.name = name |
|
4778 | 4782 |
self.mem_size = self.disks = self.disk_template = None |
4779 | 4783 |
self.os = self.tags = self.nics = self.vcpus = None |
4784 |
self.relocate_from = None |
|
4780 | 4785 |
# computed fields |
4781 | 4786 |
self.required_nodes = None |
4782 | 4787 |
# init result fields |
4783 | 4788 |
self.success = self.info = self.nodes = None |
4789 |
if self.mode == constants.IALLOCATOR_MODE_ALLOC: |
|
4790 |
keyset = self._ALLO_KEYS |
|
4791 |
elif self.mode == constants.IALLOCATOR_MODE_RELOC: |
|
4792 |
keyset = self._RELO_KEYS |
|
4793 |
else: |
|
4794 |
raise errors.ProgrammerError("Unknown mode '%s' passed to the" |
|
4795 |
" IAllocator" % self.mode) |
|
4784 | 4796 |
for key in kwargs: |
4785 |
if key not in self._KEYS:
|
|
4797 |
if key not in keyset:
|
|
4786 | 4798 |
raise errors.ProgrammerError("Invalid input parameter '%s' to" |
4787 | 4799 |
" IAllocator" % key) |
4788 | 4800 |
setattr(self, key, kwargs[key]) |
4789 |
for key in self._KEYS:
|
|
4801 |
for key in keyset:
|
|
4790 | 4802 |
if key not in kwargs: |
4791 | 4803 |
raise errors.ProgrammerError("Missing input parameter '%s' to" |
4792 | 4804 |
" IAllocator" % key) |
... | ... | |
4930 | 4942 |
"name": self.name, |
4931 | 4943 |
"disk_space_total": disk_space, |
4932 | 4944 |
"required_nodes": self.required_nodes, |
4933 |
"nodes": list(instance.secondary_nodes),
|
|
4945 |
"relocate_from": self.relocate_from,
|
|
4934 | 4946 |
} |
4935 | 4947 |
self.in_data["request"] = request |
4936 | 4948 |
|
... | ... | |
5053 | 5065 |
raise errors.OpPrereqError("Instance '%s' not found for relocation" % |
5054 | 5066 |
self.op.name) |
5055 | 5067 |
self.op.name = fname |
5068 |
self.relocate_from = self.cfg.GetInstanceInfo(fname).secondary_nodes |
|
5056 | 5069 |
else: |
5057 | 5070 |
raise errors.OpPrereqError("Invalid test allocator mode '%s'" % |
5058 | 5071 |
self.op.mode) |
... | ... | |
5068 | 5081 |
"""Run the allocator test. |
5069 | 5082 |
|
5070 | 5083 |
""" |
5071 |
ial = IAllocator(self.cfg, self.sstore, |
|
5072 |
mode=self.op.mode, |
|
5073 |
name=self.op.name, |
|
5074 |
mem_size=self.op.mem_size, |
|
5075 |
disks=self.op.disks, |
|
5076 |
disk_template=self.op.disk_template, |
|
5077 |
os=self.op.os, |
|
5078 |
tags=self.op.tags, |
|
5079 |
nics=self.op.nics, |
|
5080 |
vcpus=self.op.vcpus, |
|
5081 |
) |
|
5084 |
if self.op.mode == constants.IALLOCATOR_MODE_ALLOC: |
|
5085 |
ial = IAllocator(self.cfg, self.sstore, |
|
5086 |
mode=self.op.mode, |
|
5087 |
name=self.op.name, |
|
5088 |
mem_size=self.op.mem_size, |
|
5089 |
disks=self.op.disks, |
|
5090 |
disk_template=self.op.disk_template, |
|
5091 |
os=self.op.os, |
|
5092 |
tags=self.op.tags, |
|
5093 |
nics=self.op.nics, |
|
5094 |
vcpus=self.op.vcpus, |
|
5095 |
) |
|
5096 |
else: |
|
5097 |
ial = IAllocator(self.cfg, self.sstore, |
|
5098 |
mode=self.op.mode, |
|
5099 |
name=self.op.name, |
|
5100 |
relocate_from=list(self.relocate_from), |
|
5101 |
) |
|
5082 | 5102 |
|
5083 | 5103 |
if self.op.direction == constants.IALLOCATOR_DIR_IN: |
5084 | 5104 |
result = ial.in_text |
Also available in: Unified diff