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
12 from flask import request
13 from flask_restful import Resource
15 from yardstick import _init_logging
16 from yardstick.common import constants as consts
17 from yardstick.common import utils as common_utils
20 LOG = logging.getLogger(__name__)
21 LOG.setLevel(logging.DEBUG)
24 class ApiResource(Resource):
27 data = request.json if request.json else {}
28 params = common_utils.translate_to_str(data)
29 action = params.get('action', request.form.get('action', ''))
30 args = params.get('args', {})
33 args['file'] = request.files['file']
37 args.update({k: v for k, v in request.form.items()})
38 LOG.debug('Input args is: action: %s, args: %s', action, args)
43 args = common_utils.translate_to_str(request.args)
44 LOG.debug('Input args is: args: %s', args)
48 def _dispatch_post(self, **kwargs):
49 action, args = self._post_args()
51 return self._dispatch(args, action)
53 def _dispatch(self, args, action):
55 return getattr(self, action)(args)
56 except AttributeError:
57 common_utils.result_handler(consts.API_ERROR, 'No such action')
62 def __init__(self, url, target):
63 super(Url, self).__init__()
67 common_utils.import_modules_from_package("api.resources")