Step 1: Move vm scripts to the right place
[integration/test.git] / test / tools / clustering / cluster-monitor / rejoin.py
1 #!/usr/bin/python
2 """
3 Cluster Rejoin Tool
4 Author: Phillip Shea
5 Updated: 2015-May-07
6
7 This tool rejoins any isolated controllers to the cluster.
8
9 A file named 'cluster.json' containing a list of the IP addresses and
10 credentials of the controllers is required. It resides in the same
11 directory as monitor.py.
12
13 The file should look like this:
14
15     {
16         "cluster": {
17             "controllers": [
18                 "172.17.10.93",
19                 "172.17.10.94",
20                 "172.17.10.95"
21             ],
22             "user": "username",
23             "pass": "password"
24         }
25     }
26
27 Usage:python rejoin.py
28  """
29
30 import sys
31 sys.path.append('../../../csit/libraries')
32 import UtilLibrary
33 import json
34
35 try:
36     with open('cluster.json') as cluster_file:
37         data = json.load(cluster_file)
38 except:
39     print str(sys.exc_info())
40     print "unable to open the file cluster.json"
41     exit(1)
42 try:
43     cluster_list = data["cluster"]["controllers"]
44     user_name = data["cluster"]["user"]
45     user_pass = data["cluster"]["pass"]
46 except:
47     print str(sys.exc_info())
48     print 'Error reading the file cluster.json'
49     exit(1)
50
51 print UtilLibrary.flush_iptables(cluster_list, user_name, user_pass)