aboutsummaryrefslogtreecommitdiffstats
path: root/api/server.py
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-12 01:35:03 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-12 01:35:03 +0000
commit7949507437f8b1b1d9100bd13cf2d90bae60279d (patch)
treef6030e60eeeebeae7670f2022c06f13296c6bb2a /api/server.py
parent7ee54db221fbb4173de011585a425f0750dd6ccf (diff)
parent0d18f9d3299480cb43e6b335180e5cbdb58505c3 (diff)
Merge "Yardstick API architecture improvement"
Diffstat (limited to 'api/server.py')
-rw-r--r--api/server.py12
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)