aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2/tasks.py
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-21 01:05:44 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:05:44 +0000
commitac1f30a97b9c26762d66f2914928f1cb7e9a7697 (patch)
tree95b4abfaa9090fee5f11f0d500ea17d72ee4b809 /api/resources/v2/tasks.py
parentf8e09865fe1fb8fe26bb7b686db96b72e8b480ef (diff)
parent1d1f93bd3b3fe2533289955c1fc47b2d215dd4ae (diff)
Merge "Add API(v2) to create task"
Diffstat (limited to 'api/resources/v2/tasks.py')
-rw-r--r--api/resources/v2/tasks.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py
new file mode 100644
index 000000000..6366be847
--- /dev/null
+++ b/api/resources/v2/tasks.py
@@ -0,0 +1,49 @@
+import uuid
+import logging
+from datetime import datetime
+
+from api import ApiResource
+from api.database.v2.handlers import V2TaskHandler
+from api.database.v2.handlers import V2ProjectHandler
+from yardstick.common.utils import result_handler
+from yardstick.common import constants as consts
+
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
+
+
+class V2Tasks(ApiResource):
+
+ def post(self):
+ return self._dispatch_post()
+
+ def create_task(self, args):
+ try:
+ name = args['name']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'name must be provided')
+
+ try:
+ project_id = args['project_id']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'project_id must be provided')
+
+ task_id = str(uuid.uuid4())
+ create_time = datetime.now()
+ task_handler = V2TaskHandler()
+
+ LOG.info('create task in database')
+ task_init_data = {
+ 'uuid': task_id,
+ 'project_id': project_id,
+ 'name': name,
+ 'time': create_time,
+ 'status': -1
+ }
+ task_handler.insert(task_init_data)
+
+ LOG.info('create task in project')
+ project_handler = V2ProjectHandler()
+ project_handler.append_attr(project_id, {'tasks': task_id})
+
+ return result_handler(consts.API_SUCCESS, {'uuid': task_id})