1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from flask import jsonify
14 from api.utils.daemonthread import DaemonThread
15 from yardstick.cmd.cli import YardstickCLI
17 logger = logging.getLogger(__name__)
20 def translate_to_str(object):
21 if isinstance(object, collections.Mapping):
22 return {str(k): translate_to_str(v) for k, v in object.items()}
23 elif isinstance(object, list):
24 return [translate_to_str(ele) for ele in object]
25 elif isinstance(object, unicode):
30 def get_command_list(command_list, opts, args):
32 command_list.append(args)
34 command_list.extend(('--{}'.format(k) for k in opts if 'task-args' != k))
36 task_args = opts.get('task-args', '')
38 command_list.extend(['--task-args', str(task_args)])
43 def exec_command_task(command_list, task_id): # pragma: no cover
44 daemonthread = DaemonThread(YardstickCLI().api, (command_list, task_id))
48 def error_handler(message):
54 return jsonify(result)
57 def result_handler(status, data):
62 return jsonify(result)
67 def __init__(self, url, resource, endpoint):
68 super(Url, self).__init__()
70 self.resource = resource
71 self.endpoint = endpoint