aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-21 01:07:18 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:07:19 +0000
commitedec11f71207d6df007460cd19ccab08201d60c6 (patch)
tree8854200678379d8df48ef314491c6d4ac5cda34f /api/resources/v2
parentac1f30a97b9c26762d66f2914928f1cb7e9a7697 (diff)
parentd5a7303e3a1cf3b229ff505f5d0630360440106b (diff)
Merge "Add API(v2) to add environment to task"
Diffstat (limited to 'api/resources/v2')
-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})