summaryrefslogtreecommitdiffstats
path: root/api/resources/v2/tasks.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-07-19 09:33:04 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-07-19 09:33:04 +0000
commitd5a7303e3a1cf3b229ff505f5d0630360440106b (patch)
treeb9bef3229cc374d2eb5930262bf1c92e840dd0a8 /api/resources/v2/tasks.py
parent1d1f93bd3b3fe2533289955c1fc47b2d215dd4ae (diff)
Add API(v2) to add environment to task
JIRA: YARDSTICK-736 API: /api/v2/yardstick/tasks/<task_id> METHOD: PUT PARAMS: { 'action': 'add_environment', 'args': { 'environment_id': environment_id } } Change-Id: Idc31cb21de882d008202b6395158e9f9aa9244db Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources/v2/tasks.py')
-rw-r--r--api/resources/v2/tasks.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py
index 6366be847..550e43c2c 100644
--- a/api/resources/v2/tasks.py
+++ b/api/resources/v2/tasks.py
@@ -5,6 +5,7 @@ from datetime import datetime
from api import ApiResource
from api.database.v2.handlers import V2TaskHandler
from api.database.v2.handlers import V2ProjectHandler
+from api.database.v2.handlers import V2EnvironmentHandler
from yardstick.common.utils import result_handler
from yardstick.common import constants as consts
@@ -47,3 +48,46 @@ class V2Tasks(ApiResource):
project_handler.append_attr(project_id, {'tasks': task_id})
return result_handler(consts.API_SUCCESS, {'uuid': task_id})
+
+
+class V2Task(ApiResource):
+
+ def put(self, task_id):
+
+ try:
+ uuid.UUID(task_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid task id')
+
+ task_handler = V2TaskHandler()
+ try:
+ task_handler.get_by_uuid(task_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such task id')
+
+ return self._dispatch_post(task_id=task_id)
+
+ def add_environment(self, args):
+
+ task_id = args['task_id']
+ try:
+ environment_id = args['environment_id']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'environment_id must be provided')
+
+ try:
+ uuid.UUID(environment_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid environment id')
+
+ environment_handler = V2EnvironmentHandler()
+ try:
+ environment_handler.get_by_uuid(environment_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such environment id')
+
+ LOG.info('update environment_id in task')
+ task_handler = V2TaskHandler()
+ task_handler.update_attr(task_id, {'environment_id': environment_id})
+
+ return result_handler(consts.API_SUCCESS, {'uuid': task_id})