Add API(v2) to create project 33/37733/1
authorchenjiankun <chenjiankun1@huawei.com>
Wed, 19 Jul 2017 06:52:52 +0000 (06:52 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Wed, 19 Jul 2017 06:52:52 +0000 (06:52 +0000)
JIRA: YARDSTICK-731

API: /api/v2/yardstick/projects/action
METHOD: POST
PARAMS:
{
    'action': 'create_project',
    'args': {
        'name': 'project1'
    }
}

Change-Id: I92332dec8dcf3253f0cbf1668332ce5110111d73
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/resources/v2/projects.py [new file with mode: 0644]

diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py
new file mode 100644 (file)
index 0000000..e787cc3
--- /dev/null
@@ -0,0 +1,33 @@
+import uuid
+
+from datetime import datetime
+
+from api import ApiResource
+from api.database.v2.handlers import V2ProjectHandler
+from yardstick.common.utils import result_handler
+from yardstick.common import constants as consts
+
+
+class V2Projects(ApiResource):
+
+    def post(self):
+        return self._dispatch_post()
+
+    def create_project(self, args):
+        try:
+            name = args['name']
+        except KeyError:
+            return result_handler(consts.API_ERROR, 'name must be provided')
+
+        project_id = str(uuid.uuid4())
+        create_time = datetime.now()
+        project_handler = V2ProjectHandler()
+
+        project_init_data = {
+            'uuid': project_id,
+            'name': name,
+            'time': create_time
+        }
+        project_handler.insert(project_init_data)
+
+        return result_handler(consts.API_SUCCESS, {'uuid': project_id})