From 933cf69b72bb61450ba5e4fa857303e2e05f95b3 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Fri, 14 Jul 2017 07:12:03 +0000 Subject: Initial all url of api v2 JIRA: YARDSTICK-648 Change-Id: I915889a974da9c49188c25fe2443ece481987ecb Signed-off-by: chenjiankun --- api/server.py | 13 ++++++++----- api/urls.py | 26 ++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/api/server.py b/api/server.py index c1548ca10..158b8a508 100644 --- a/api/server.py +++ b/api/server.py @@ -32,7 +32,7 @@ try: except ImportError: from urllib.parse import urljoin -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) app = Flask(__name__) @@ -62,7 +62,7 @@ def init_db(): return False subclses = filter(func, inspect.getmembers(models, inspect.isclass)) - logger.debug('Import models: %s', [a[1] for a in subclses]) + LOG.debug('Import models: %s', [a[1] for a in subclses]) Base.metadata.create_all(bind=engine) @@ -77,12 +77,15 @@ def get_endpoint(url): for u in urlpatterns: - api.add_resource(get_resource(u.target), u.url, endpoint=get_endpoint(u.url)) + try: + api.add_resource(get_resource(u.target), u.url, endpoint=get_endpoint(u.url)) + except StopIteration: + LOG.error('url resource not found: %s', u.url) if __name__ == '__main__': _init_logging() - logger.setLevel(logging.DEBUG) - logger.info('Starting server') + LOG.setLevel(logging.DEBUG) + LOG.info('Starting server') init_db() app.run(host='0.0.0.0') diff --git a/api/urls.py b/api/urls.py index 82df17541..5c7e9f7b5 100644 --- a/api/urls.py +++ b/api/urls.py @@ -26,9 +26,31 @@ urlpatterns = [ Url('/api/v2/yardstick/environments/action', 'v2_environments'), Url('/api/v2/yardstick/environments/', 'v2_environment'), - Url('/api/v2/yardstick/environments/openrcs/action', 'v2_openrcs'), - Url('/api/v2/yardstick/environments/openrcs/', 'v2_openrc'), + Url('/api/v2/yardstick/openrcs/action', 'v2_openrcs'), + Url('/api/v2/yardstick/openrcs/', 'v2_openrc'), Url('/api/v2/yardstick/pods/action', 'v2_pods'), Url('/api/v2/yardstick/pods/', 'v2_pod'), + + Url('/api/v2/yardstick/images', 'v2_images'), + Url('/api/v2/yardstick/images/action', 'v2_images'), + + Url('/api/v2/yardstick/containers/action', 'v2_containers'), + Url('/api/v2/yardstick/containers/', 'v2_container'), + + Url('/api/v2/yardstick/projects', 'v2_projects'), + Url('/api/v2/yardstick/projects/action', 'v2_projects'), + Url('/api/v2/yardstick/projects/', 'v2_project'), + + Url('/api/v2/yardstick/tasks', 'v2_tasks'), + Url('/api/v2/yardstick/tasks/action', 'v2_tasks'), + Url('/api/v2/yardstick/tasks/', 'v2_task'), + + Url('/api/v2/yardstick/testcases', 'v2_testcases'), + Url('/api/v2/yardstick/testcases/action', 'v2_testcases'), + Url('/api/v2/yardstick/testcases/', 'v2_testcase'), + + Url('/api/v2/yardstick/testsuites', 'v2_testsuites'), + Url('/api/v2/yardstick/testsuites/action', 'v2_testsuites'), + Url('/api/v2/yardstick/testsuites/', 'v2_testsuites') ] -- cgit 1.2.3-korg