summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-07-19 07:21:24 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-07-19 07:21:24 +0000
commit7d67a9a3bb7eddf9505d7a232e121c6c59bde287 (patch)
tree97d3e56f2e2b494d020f382138821cbb84d0ad75 /api
parent7ea08628579d2e8e50e748ae1bf337687235ca62 (diff)
Add API(v2) to get all projects info
JIRA: YARDSTICK-732 API: /api/v2/yardstick/projects METHOD: GET Change-Id: Ifd67f11f516270d96c0e80b5b8c76a939583d9e5 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api')
-rw-r--r--api/database/v2/handlers.py3
-rw-r--r--api/resources/v2/projects.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/api/database/v2/handlers.py b/api/database/v2/handlers.py
index 095ad724c..7aa02a0a5 100644
--- a/api/database/v2/handlers.py
+++ b/api/database/v2/handlers.py
@@ -130,6 +130,9 @@ class V2ContainerHandler(object):
class V2ProjectHandler(object):
+ def list_all(self):
+ return V2Project.query.all()
+
def insert(self, kwargs):
project = V2Project(**kwargs)
db_session.add(project)
diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py
index e787cc333..1c3c76ba2 100644
--- a/api/resources/v2/projects.py
+++ b/api/resources/v2/projects.py
@@ -5,11 +5,22 @@ from datetime import datetime
from api import ApiResource
from api.database.v2.handlers import V2ProjectHandler
from yardstick.common.utils import result_handler
+from yardstick.common.utils import change_obj_to_dict
from yardstick.common import constants as consts
class V2Projects(ApiResource):
+ def get(self):
+ project_handler = V2ProjectHandler()
+ projects = [change_obj_to_dict(p) for p in project_handler.list_all()]
+
+ for p in projects:
+ tasks = p['tasks']
+ p['tasks'] = tasks.split(',') if tasks else []
+
+ return result_handler(consts.API_SUCCESS, {'projects': projects})
+
def post(self):
return self._dispatch_post()