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):
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)
22 if __name__ == "__main__":
23 write_hosts(json.load(sys.stdin))