X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=api%2Fresources%2Fv2%2Fopenrcs.py;h=cb506d0e8bec3ebaa61e1192a67ff2ddf9cd4a8a;hb=d5ff38b3ff3309cb1fed11266c98aca23001ea44;hp=cbe89462912d85c73cbb3c9b8328f75bff504095;hpb=0da3e8ad7c1374b3d0c25bd12b75b2e3b04688b0;p=yardstick.git diff --git a/api/resources/v2/openrcs.py b/api/resources/v2/openrcs.py index cbe894629..cb506d0e8 100644 --- a/api/resources/v2/openrcs.py +++ b/api/resources/v2/openrcs.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## import uuid import logging import re @@ -18,7 +26,7 @@ LOG = logging.getLogger(__name__) LOG.setLevel(logging.DEBUG) -class V2Openrc(ApiResource): +class V2Openrcs(ApiResource): def post(self): return self._dispatch_post() @@ -34,6 +42,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 +83,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 +175,45 @@ 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}) + + def delete(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('update openrc in environment') + environment_handler = V2EnvironmentHandler() + environment_handler.update_attr(openrc.environment_id, {'openrc_id': None}) + + openrc_handler.delete_by_uuid(openrc_id) + + return result_handler(consts.API_SUCCESS, {'openrc': openrc_id})