Revision 8d528b7c lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
5005 | 5005 |
|
5006 | 5006 |
self.in_text = serializer.Dump(self.in_data) |
5007 | 5007 |
|
5008 |
def Run(self, name, validate=True): |
|
5008 |
def Run(self, name, validate=True, call_fn=rpc.call_iallocator_runner):
|
|
5009 | 5009 |
"""Run an instance allocator and return the results. |
5010 | 5010 |
|
5011 | 5011 |
""" |
5012 | 5012 |
data = self.in_text |
5013 | 5013 |
|
5014 |
alloc_script = utils.FindFile(name, constants.IALLOCATOR_SEARCH_PATH, |
|
5015 |
os.path.isfile) |
|
5016 |
if alloc_script is None: |
|
5017 |
raise errors.OpExecError("Can't find allocator '%s'" % name) |
|
5014 |
result = call_fn(self.sstore.GetMasterNode(), name, self.in_text) |
|
5018 | 5015 |
|
5019 |
fd, fin_name = tempfile.mkstemp(prefix="ganeti-iallocator.") |
|
5020 |
try: |
|
5021 |
os.write(fd, data) |
|
5022 |
os.close(fd) |
|
5023 |
result = utils.RunCmd([alloc_script, fin_name]) |
|
5024 |
if result.failed: |
|
5016 |
if not isinstance(result, tuple) or len(result) != 4: |
|
5017 |
raise errors.OpExecError("Invalid result from master iallocator runner") |
|
5018 |
|
|
5019 |
rcode, stdout, stderr, fail = result |
|
5020 |
|
|
5021 |
if rcode == constants.IARUN_NOTFOUND: |
|
5022 |
raise errors.OpExecError("Can't find allocator '%s'" % name) |
|
5023 |
elif rcode == constants.IARUN_FAILURE: |
|
5025 | 5024 |
raise errors.OpExecError("Instance allocator call failed: %s," |
5026 | 5025 |
" output: %s" % |
5027 |
(result.fail_reason, result.output)) |
|
5028 |
finally: |
|
5029 |
os.unlink(fin_name) |
|
5030 |
self.out_text = result.stdout |
|
5026 |
(fail, stdout+stderr)) |
|
5027 |
self.out_text = stdout |
|
5031 | 5028 |
if validate: |
5032 | 5029 |
self._ValidateResult() |
5033 | 5030 |
|
Also available in: Unified diff