aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-21 01:03:42 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:03:42 +0000
commitbc750fbee81d0b3a9edbd16c88c02e785f87dd7f (patch)
treed4f72614bdd5025758333ecd01ffa8e1ddb2b5d6 /api/resources/v2
parent53825a386d6b7edd47754db41113bedfacc34432 (diff)
parent6bc4d2c813460cba201c390cc2380fb99bdc2c9d (diff)
Merge changes from topics 'get_project', 'get_projects'
* changes: Add API(V2) to get certain project info Add API(v2) to get all projects info
Diffstat (limited to 'api/resources/v2')
-rw-r--r--api/resources/v2/projects.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py
index e787cc333..7d51cf040 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()
@@ -31,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})