From 49be6a8c0f42c9a12af305721beac95285f74b2b Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 13 Jul 2017 02:26:19 +0000 Subject: Add API to create environment JIRA: YARDSTICK-715 API: /api/v2/yardstick/environments/action METHOD: POST PARAM: { 'action': 'create_environment' } Change-Id: I58086be3c70cdc3c4c93516bcfd53ba725486600 Signed-off-by: chenjiankun --- api/resources/v2/__init__.py | 0 api/resources/v2/environments.py | 33 +++++++++++++++++++++++++++++++++ api/urls.py | 5 ++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 api/resources/v2/__init__.py create mode 100644 api/resources/v2/environments.py (limited to 'api') diff --git a/api/resources/v2/__init__.py b/api/resources/v2/__init__.py new file mode 100644 index 000000000..e69de29bb 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}) diff --git a/api/urls.py b/api/urls.py index 4b9d4d191..0ffba89c9 100644 --- a/api/urls.py +++ b/api/urls.py @@ -19,5 +19,8 @@ urlpatterns = [ Url('/yardstick/testcases//docs', 'v1_case_docs'), Url('/yardstick/testsuites/action', 'v1_test_suite'), Url('/yardstick/results', 'v1_result'), - Url('/yardstick/env/action', 'v1_env') + Url('/yardstick/env/action', 'v1_env'), + + # api v2 + Url('/api/v2/yardstick/environments/action', 'v2_environments'), ] -- cgit 1.2.3-korg