diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-07-14 01:01:19 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-07-14 04:22:03 +0000 |
commit | 0da3e8ad7c1374b3d0c25bd12b75b2e3b04688b0 (patch) | |
tree | 1537def072f9fb5caa22b9e90c43d32bcd06b538 /api | |
parent | 1a83219677fd0ce48f59e09f5a787d8296ba9261 (diff) |
Add API(v2) to update openrc
JIRA: YARDSTICK-720
API: /api/v2/yardstick/environments/openrcs/action
METHOD: POST
PARAMS:
{
'action': 'update_openrc',
'args': {
'openrc': {
"EXTERNAL_NETWORK": "ext-net",
"OS_AUTH_URL": "http://192.168.23.51:5000/v3",
"OS_IDENTITY_API_VERSION": "3",
"OS_IMAGE_API_VERSION": "2",
"OS_PASSWORD": "console",
"OS_PROJECT_DOMAIN_NAME": "default",
"OS_PROJECT_NAME": "admin",
"OS_TENANT_NAME": "admin",
"OS_USERNAME": "admin",
"OS_USER_DOMAIN_NAME": "default"
},
'environment_id': environment_id
}
}
Change-Id: Ie9a1614190a01456fd0896f0bdfd05f9d0724fc6
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/resources/v2/openrcs.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/api/resources/v2/openrcs.py b/api/resources/v2/openrcs.py index b78c696df..cbe894629 100644 --- a/api/resources/v2/openrcs.py +++ b/api/resources/v2/openrcs.py @@ -59,6 +59,47 @@ class V2Openrc(ApiResource): return result_handler(consts.API_SUCCESS, {'openrc': openrc_data, 'uuid': openrc_id}) + def update_openrc(self, args): + try: + openrc_vars = args['openrc'] + except KeyError: + return result_handler(consts.API_ERROR, 'openrc must be provided') + + try: + environment_id = args['environment_id'] + except KeyError: + return result_handler(consts.API_ERROR, 'environment_id must be provided') + + LOG.info('writing openrc: %s', consts.OPENRC) + makedirs(consts.CONF_DIR) + + lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()] + LOG.debug('writing: %s', ''.join(lines)) + with open(consts.OPENRC, 'w') as f: + f.writelines(lines) + LOG.info('writing openrc: Done') + + LOG.info('source openrc: %s', consts.OPENRC) + try: + source_env(consts.OPENRC) + except Exception: + LOG.exception('source openrc failed') + return result_handler(consts.API_ERROR, 'source openrc failed') + LOG.info('source openrc: Done') + + openrc_id = str(uuid.uuid4()) + self._write_into_database(environment_id, openrc_id, openrc_vars) + + LOG.info('writing ansible cloud conf') + try: + self._generate_ansible_conf_file(openrc_vars) + except Exception: + LOG.exception('write cloud conf failed') + return result_handler(consts.API_ERROR, 'genarate ansible conf failed') + LOG.info('finish writing ansible cloud conf') + + return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars, 'uuid': openrc_id}) + def _write_into_database(self, environment_id, openrc_id, openrc_data): LOG.info('writing openrc to database') openrc_handler = V2OpenrcHandler() |