summaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-06-27 07:20:33 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-06-27 07:20:33 +0000
commit832d3e4e449c28438aacba396ba9afa9bbc0d6d2 (patch)
treefbd0e9555e7ed07cf2a21a46696299d6e1b4e68d /api/resources
parent1ff9df7e724eb0c981aebd5f5b8aa90db0da292b (diff)
parent62e417c18464f9d9f6bcad31b61ecdc18180812a (diff)
Merge "Add API to update hosts info about SUT"
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/env_action.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 3536559b7..62ec78640 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -362,3 +362,16 @@ def upload_pod_file(args):
logger.info('Writing finished')
return result_handler(consts.API_SUCCESS, {'pod_info': data})
+
+
+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')