aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2/environments.py
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-14 03:53:12 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-14 03:53:12 +0000
commit3ac36ece91447e3ee8fdf687c8af82778482a0a4 (patch)
treec44d9240a8353d744b5b9e4896006c1e1713d4e2 /api/resources/v2/environments.py
parent9b8563948c561d11de44cb6668f6c5c6641562ac (diff)
parent49be6a8c0f42c9a12af305721beac95285f74b2b (diff)
Merge "Add API to create environment"
Diffstat (limited to 'api/resources/v2/environments.py')
-rw-r--r--api/resources/v2/environments.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/api/resources/v2/environments.py b/api/resources/v2/environments.py
new file mode 100644
index 000000000..dc6eac725
--- /dev/null
+++ b/api/resources/v2/environments.py
@@ -0,0 +1,33 @@
+import uuid
+import logging
+
+from api import ApiResource
+from api.database.v2.handlers import V2EnvironmentHandler
+from yardstick.common.utils import result_handler
+from yardstick.common import constants as consts
+
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
+
+
+class V2Environments(ApiResource):
+
+ def post(self):
+ return self._dispatch_post()
+
+ def create_environment(self, args):
+ try:
+ name = args['name']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'name must be provided')
+
+ env_id = str(uuid.uuid4())
+
+ environment_handler = V2EnvironmentHandler()
+ env_init_data = {
+ 'name': name,
+ 'uuid': env_id
+ }
+ environment_handler.insert(env_init_data)
+
+ return result_handler(consts.API_SUCCESS, {'uuid': env_id})