1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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
15 def write_hosts(hosts_ip):
17 yardstick_flag = "# SUT hosts info for Yardstick"
18 hosts_list = ('\n{} {} {}'.format(ip, host_name, yardstick_flag)
19 for host_name, ip in hosts_ip.items())
21 with open("/etc/hosts", 'r') as f:
22 origin_lines = [line for line in f if yardstick_flag not in line]
24 with open("/etc/hosts", 'w') as f:
25 f.writelines(origin_lines)
26 f.write(yardstick_flag)
27 f.writelines(hosts_list)
30 if __name__ == "__main__":
31 write_hosts(json.load(sys.stdin))