-
Notifications
You must be signed in to change notification settings - Fork 10
/
build_cluster.py
48 lines (38 loc) · 1.18 KB
/
build_cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: Andrea Giacomo Baldan
# License: MIT
# Description: Create cluster configurations for a defined number of nodes
from glob import glob
import os
import sys
import uuid
def main():
"""
Main access point, parse arguments and create configuration files needed
to form a cluster
"""
# remove any conf file to avoid inconsistencies
for filename in glob("*.conf"):
os.remove(filename)
# generate random uuids for each node
uuids = {}
for x in sys.argv[1:]:
uid = uuid.uuid4()
uuids[uid.hex] = x
# write ip address, port and names to each conf file
for idx, key in enumerate(uuids):
count = 0
with open("node{}.conf".format(idx), "a+") as fh:
fh.write("# node{} configuration file\n".format(idx))
for k, v in uuids.items():
self = "0"
peer = v.split(":")
if count == idx:
self = "1"
fh.write(peer[0] + "\t" + str(int(peer[1]) + 100) + "\t" + k + "\t" + self + "\n")
count += 1
fh.close()
if __name__ == '__main__':
exit(main())