-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_file_writter.py
More file actions
59 lines (55 loc) · 1.89 KB
/
config_file_writter.py
File metadata and controls
59 lines (55 loc) · 1.89 KB
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
49
50
51
52
53
54
55
56
57
58
59
"""
[ndb_mgmd]
hostname=ip-172-31-88-28.ec2.internal
datadir=/opt/mysqlcluster/deploy/ndb_data
nodeid=1
[ndbd default]
noofreplicas=1
[ndbd]
hostname=ip-172-31-91-195.ec2.internal
nodeid=3
datadir=/opt/mysqlcluster/deploy/ndb_data
[mysqld]
nodeid=50
"""
import os
def write_file_content(mgmt_node_hs, first_slave_hs, second_slave_hs, third_slave_hs):
"""
Description: Writes config.ini used in cluster setup
:param mgmt_node_hs: The host name of the master node where the mysql database is installed
:param first_slave_hs: The hostname of the first data node
:param second_slave_hs: The hostname of the second data node
:param third_slave_hs: The hostname of the third data node
"""
ret = "[ndb_mgmd]\n" +\
"hostname={}\n".format(mgmt_node_hs) +\
"datadir=/opt/mysqlcluster/deploy/ndb_data\n" +\
"nodeid=1\n"\
+ "[ndbd default]\n" \
+ "noofreplicas=3\n" \
+ "datadir=/opt/mysqlcluster/deploy/ndb_data\n" \
+ "[ndbd]\n" \
+ "hostname={}\n".format(first_slave_hs) \
+ "nodeid=3\n" \
+ "datadir=/opt/mysqlcluster/deploy/ndb_data\n"\
+ "[ndbd]\n" \
+ "hostname={}\n".format(second_slave_hs) \
+ "nodeid=4\n" \
+ "datadir=/opt/mysqlcluster/deploy/ndb_data\n" \
+ "[ndbd]\n" \
+ "hostname={}\n".format(third_slave_hs) \
+ "nodeid=5\n" \
+ "datadir=/opt/mysqlcluster/deploy/ndb_data\n" \
+ "[mysqld]\n"\
+ "nodeid=50"
print(ret)
path_folder = os.path.curdir
path_file = os.path.join(path_folder, 'config.ini')
f = open(path_file, "w")
f.write(ret)
f.close()
"""
Driver to test the write function
"""
if __name__ == "__main__":
write_file_content("ip-172-31-88-28.ec2.internal", "ip-172-31-91-195.ec2.internal", "ip-172-31-91-195.ec2.internal", "ip-172-31-91-195.ec2.internal")