diff options
-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}) |