diff options
author | Rex Lee <limingjiang@huawei.com> | 2017-07-21 01:07:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-07-21 01:07:19 +0000 |
commit | edec11f71207d6df007460cd19ccab08201d60c6 (patch) | |
tree | 8854200678379d8df48ef314491c6d4ac5cda34f /api | |
parent | ac1f30a97b9c26762d66f2914928f1cb7e9a7697 (diff) | |
parent | d5a7303e3a1cf3b229ff505f5d0630360440106b (diff) |
Merge "Add API(v2) to add environment to task"
Diffstat (limited to 'api')
-rw-r--r-- | api/__init__.py | 3 | ||||
-rw-r--r-- | api/resources/v2/tasks.py | 44 |
2 files changed, 46 insertions, 1 deletions
diff --git a/api/__init__.py b/api/__init__.py index 3195c971b..c5aefffe8 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -45,8 +45,9 @@ class ApiResource(Resource): return args - def _dispatch_post(self): + def _dispatch_post(self, **kwargs): action, args = self._post_args() + args.update(kwargs) return self._dispatch(args, action) def _dispatch(self, args, action): 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}) |