From 2b2cfebd2383e38fc375eb308c3f96ef20d75881 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 13 Jul 2017 07:24:35 +0000 Subject: Add API to get single environment info JIRA: YARDSTICK-717 API: /api/v2/yardstick/environments/ METHOD: GET Change-Id: I9fe42a48520cc17d0f5416080b3595bd6c269761 Signed-off-by: chenjiankun --- api/resources/v2/environments.py | 20 ++++++++++++++++++++ api/urls.py | 1 + 2 files changed, 21 insertions(+) (limited to 'api') diff --git a/api/resources/v2/environments.py b/api/resources/v2/environments.py index 4b27c45b8..f83c0a941 100644 --- a/api/resources/v2/environments.py +++ b/api/resources/v2/environments.py @@ -49,3 +49,23 @@ class V2Environments(ApiResource): environment_handler.insert(env_init_data) return result_handler(consts.API_SUCCESS, {'uuid': env_id}) + + +class V2Environment(ApiResource): + + def get(self, environment_id): + try: + uuid.UUID(environment_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid environment id') + + environment_handler = V2EnvironmentHandler() + try: + environment = environment_handler.get_by_uuid(environment_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such environment id') + + environment = change_obj_to_dict(environment) + container_id = environment['container_id'] + environment['container_id'] = jsonutils.loads(container_id) if container_id else {} + return result_handler(consts.API_SUCCESS, {'environment': environment}) diff --git a/api/urls.py b/api/urls.py index 0c63fb040..70d69f881 100644 --- a/api/urls.py +++ b/api/urls.py @@ -24,4 +24,5 @@ urlpatterns = [ # api v2 Url('/api/v2/yardstick/environments', 'v2_environments'), Url('/api/v2/yardstick/environments/action', 'v2_environments'), + Url('/api/v2/yardstick/environments/', 'v2_environment'), ] -- cgit 1.2.3-korg