From 7d67a9a3bb7eddf9505d7a232e121c6c59bde287 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Wed, 19 Jul 2017 07:21:24 +0000 Subject: 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 --- api/resources/v2/projects.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'api/resources/v2') 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() -- cgit 1.2.3-korg From 6bc4d2c813460cba201c390cc2380fb99bdc2c9d Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Wed, 19 Jul 2017 08:02:40 +0000 Subject: Add API(V2) to get certain project info JIRA: YARDSTICK-733 API: /api/v2/yardstick/projects/ METHOD: GET Change-Id: I20a615af96229aefac6ef86566a7b9c5d42f9633 Signed-off-by: chenjiankun --- api/resources/v2/projects.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'api/resources/v2') diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py index 1c3c76ba2..7d51cf040 100644 --- a/api/resources/v2/projects.py +++ b/api/resources/v2/projects.py @@ -42,3 +42,24 @@ class V2Projects(ApiResource): project_handler.insert(project_init_data) return result_handler(consts.API_SUCCESS, {'uuid': project_id}) + + +class V2Project(ApiResource): + + def get(self, project_id): + try: + uuid.UUID(project_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid project id') + + project_handler = V2ProjectHandler() + try: + project = project_handler.get_by_uuid(project_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such project id') + + project_info = change_obj_to_dict(project) + tasks = project_info['tasks'] + project_info['tasks'] = tasks.split(',') if tasks else [] + + return result_handler(consts.API_SUCCESS, {'project': project_info}) -- cgit 1.2.3-korg