From 2ae853c649f03b310527a4c291e839184a69f553 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Fri, 14 Jul 2017 01:38:47 +0000 Subject: Add API(v2) to get openrc info JIRA: YARDSTICK-721 API: /api/v2/yardstick/environments/openrcs/ METHOD: GET Change-Id: I57241381cf50fef0dc4eec3281c01ba106262a5a Signed-off-by: chenjiankun --- api/resources/v2/openrcs.py | 33 ++++++++++++++++++++++++++++++++- api/urls.py | 3 ++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'api') diff --git a/api/resources/v2/openrcs.py b/api/resources/v2/openrcs.py index cbe894629..afabcdec6 100644 --- a/api/resources/v2/openrcs.py +++ b/api/resources/v2/openrcs.py @@ -18,7 +18,7 @@ LOG = logging.getLogger(__name__) LOG.setLevel(logging.DEBUG) -class V2Openrc(ApiResource): +class V2Openrcs(ApiResource): def post(self): return self._dispatch_post() @@ -34,6 +34,11 @@ class V2Openrc(ApiResource): except KeyError: return result_handler(consts.API_ERROR, 'environment_id must be provided') + try: + uuid.UUID(environment_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid environment id') + LOG.info('writing openrc: %s', consts.OPENRC) makedirs(consts.CONF_DIR) upload_file.save(consts.OPENRC) @@ -70,6 +75,11 @@ class V2Openrc(ApiResource): except KeyError: return result_handler(consts.API_ERROR, 'environment_id must be provided') + try: + uuid.UUID(environment_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid environment id') + LOG.info('writing openrc: %s', consts.OPENRC) makedirs(consts.CONF_DIR) @@ -157,3 +167,24 @@ class V2Openrc(ApiResource): makedirs(consts.OPENSTACK_CONF_DIR) with open(consts.CLOUDS_CONF, 'w') as f: yaml.dump(ansible_conf, f, default_flow_style=False) + + +class V2Openrc(ApiResource): + + def get(self, openrc_id): + try: + uuid.UUID(openrc_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid openrc id') + + LOG.info('Geting openrc: %s', openrc_id) + openrc_handler = V2OpenrcHandler() + try: + openrc = openrc_handler.get_by_uuid(openrc_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such openrc id') + + LOG.info('load openrc content') + content = jsonutils.loads(openrc.content) + + return result_handler(consts.API_ERROR, {'openrc': content}) diff --git a/api/urls.py b/api/urls.py index efb7f8945..7fe64b200 100644 --- a/api/urls.py +++ b/api/urls.py @@ -26,5 +26,6 @@ urlpatterns = [ Url('/api/v2/yardstick/environments/action', 'v2_environments'), Url('/api/v2/yardstick/environments/', 'v2_environment'), - Url('/api/v2/yardstick/environments/openrcs/action', 'v2_openrc'), + Url('/api/v2/yardstick/environments/openrcs/action', 'v2_openrcs'), + Url('/api/v2/yardstick/environments/openrcs/', 'v2_openrc'), ] -- cgit 1.2.3-korg