summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/resources/env_action.py30
-rw-r--r--yardstick/common/constants.py1
2 files changed, 31 insertions, 0 deletions
diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 3c47252dd..4eda73368 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -362,3 +362,33 @@ def upload_pod_file(args):
logger.info('Writing finished')
return result_handler(consts.API_SUCCESS, {'pod_info': data})
+
+
+def update_pod_file(args):
+ try:
+ pod_dic = args['pod']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'pod must be provided')
+ else:
+ if not isinstance(pod_dic, collections.Mapping):
+ return result_handler(consts.API_ERROR, 'pod should be a dict')
+
+ logger.info('Writing file')
+ with open(consts.POD_FILE, 'w') as f:
+ yaml.dump(pod_dic, f, default_flow_style=False)
+ logger.info('Writing finished')
+
+ return result_handler(consts.API_SUCCESS, {'pod_info': pod_dic})
+
+
+def update_hosts(hosts_ip):
+ if not isinstance(hosts_ip, dict):
+ return result_handler(consts.API_ERROR, 'Error, args should be a dict')
+ logger.info('Writing hosts: Writing')
+ hosts_list = ['\n{} {}'.format(ip, host_name)
+ for host_name, ip in hosts_ip.items()]
+ logger.debug('Writing: %s', hosts_list)
+ with open(consts.ETC_HOSTS, 'a') as f:
+ f.writelines(hosts_list)
+ logger.info('Writing hosts: Done')
+ return result_handler(consts.API_SUCCESS, 'success')
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index 9edf78650..d445e86e6 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -42,6 +42,7 @@ TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
# file
OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
+ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
CONF_FILE = join(CONF_DIR, 'yardstick.conf')
POD_FILE = join(CONF_DIR, 'pod.yaml')
CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')