Merge "Yardstick install storperf update"
[yardstick.git] / api / resources / write_hosts.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
10
11 import sys
12 import json
13
14
15 def write_hosts(hosts_ip):
16     hosts_list = ('\n{} {}'.format(ip, host_name)
17                   for host_name, ip in hosts_ip.items())
18     with open("/etc/hosts", 'a') as f:
19         f.writelines(hosts_list)
20         f.write("\n")
21
22 if __name__ == "__main__":
23     write_hosts(json.load(sys.stdin))