diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-07-07 03:13:36 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-07-11 09:47:30 +0000 |
commit | 0d18f9d3299480cb43e6b335180e5cbdb58505c3 (patch) | |
tree | a35aa6373a88eddb3d13f4fdb7cd3db9bad1a4ee /api/server.py | |
parent | 41136dafb30d0c410e92f9f7a7c19eae60f224e2 (diff) |
Yardstick API architecture improvement
JIRA: YARDSTICK-710
Since we have the plan to upload api v2 and gui.
We need to add put and delete method.
So the architecture need to be improved.
Change-Id: Ie20a79c26ef6c581897ce4e63980fa2895b162d2
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/server.py')
-rw-r--r-- | api/server.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/api/server.py b/api/server.py index d39c44544..344874c77 100644 --- a/api/server.py +++ b/api/server.py @@ -21,7 +21,9 @@ from api.database import db_session from api.database import engine from api.database.v1 import models from api.urls import urlpatterns +from api import ApiResource from yardstick import _init_logging +from yardstick.common import utils logger = logging.getLogger(__name__) @@ -37,8 +39,10 @@ def shutdown_session(exception=None): db_session.remove() -for u in urlpatterns: - api.add_resource(u.resource, u.url, endpoint=u.endpoint) +def get_resource(resource_name): + name = ''.join(resource_name.split('_')) + return next((r for r in utils.itersubclasses(ApiResource) + if r.__name__.lower() == name)) def init_db(): @@ -60,6 +64,10 @@ def app_wrapper(*args, **kwargs): return app(*args, **kwargs) +for u in urlpatterns: + api.add_resource(get_resource(u.endpoint), u.url, endpoint=u.endpoint) + + if __name__ == '__main__': _init_logging() logger.setLevel(logging.DEBUG) |