def edit_hosts():
f = os.popen('/usr/local/bin/etcdctl ls --sort --recursive /hosts')
hosts_str = f.read()
hosts_arr = hosts_str.strip('\n').split('\n')
hosts_fd = open('/tmp/hosts', 'w')
fcntl.flock(hosts_fd.fileno(), fcntl.LOCK_EX)
hosts_fd.write('127.0.0.1 localhost cluster' + '\n')
i = 0
for host_ip in hosts_arr:
host_ip = host_ip[host_ip.rfind('/') + 1:]
if host_ip[0] == '0':
hosts_fd.write(host_ip[1:] + ' cluster-' + str(i) + '\n')
else:
hosts_fd.write(host_ip + ' cluster-' + str(i) + '\n')
i += 1
hosts_fd.flush()
os.system('/bin/cp /tmp/hosts /etc/hosts')
hosts_fd.close()
评论列表
文章目录