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 ##############################################################################
9 from __future__ import absolute_import
13 from flask import jsonify
16 from api.utils.daemonthread import DaemonThread
17 from yardstick.cmd.cli import YardstickCLI
19 logger = logging.getLogger(__name__)
22 def translate_to_str(obj):
23 if isinstance(obj, collections.Mapping):
24 return {str(k): translate_to_str(v) for k, v in obj.items()}
25 elif isinstance(obj, list):
26 return [translate_to_str(ele) for ele in obj]
27 elif isinstance(obj, six.text_type):
32 def get_command_list(command_list, opts, args):
34 command_list.append(args)
36 command_list.extend(('--{}'.format(k) for k in opts if k != 'task-args'))
38 task_args = opts.get('task-args', '')
40 command_list.extend(['--task-args', str(task_args)])
45 def exec_command_task(command_list, task_dict): # pragma: no cover
46 daemonthread = DaemonThread(YardstickCLI().api, (command_list, task_dict))
50 def error_handler(message):
56 return jsonify(result)
59 def result_handler(status, data):
64 return jsonify(result)
69 def __init__(self, url, resource, endpoint):
70 super(Url, self).__init__()
72 self.resource = resource
73 self.endpoint = endpoint