Step 1: Move vm scripts to the right place
[integration/test.git] / tools / clustering / cluster-monitor / isolate.py
1 #!/usr/bin/python
2 """
3 Controller Isolation Tool
4 Author: Phillip Shea
5 Updated: 2015-May-07
6
7 This tool isolates an indicated controller from the cluster. The tool takes
8 a single integer argument corresponding to the number of a controller
9 in a json file's ordered list of controllers. This is the controller to
10 be isolated.
11
12 A file named 'cluster.json' containing a list of the IP addresses and
13 credentials of the controllers is required. It resides in the same
14 directory as monitor.py.
15
16 The file should look like this:
17
18     {
19         "cluster": {
20             "controllers": [
21                 "172.17.10.93",
22                 "172.17.10.94",
23                 "172.17.10.95"
24             ],
25             "user": "username",
26             "pass": "password"
27         }
28     }
29
30 Usage:python isolate.py [controller to be isolated]
31 """
32
33 import sys
34 sys.path.append('../../../csit/libraries')
35 import UtilLibrary
36 import json
37
38 try:
39     with open('cluster.json') as cluster_file:
40         data = json.load(cluster_file)
41 except:
42     print str(sys.exc_info())
43     print "unable to open the file cluster.json"
44     exit(1)
45 try:
46     cluster_list = data["cluster"]["controllers"]
47     user_name = data["cluster"]["user"]
48     user_pass = data["cluster"]["pass"]
49 except:
50     print str(sys.exc_info())
51     print 'Error reading the file cluster.json'
52     exit(1)
53 try:
54     isolate = int(sys.argv[1])
55 except:
56     print 'You must specify the number (e.g. 1, 2, 3) of the controller to isolate.'
57     exit(1)
58
59 print "isolating controller " + str(isolate)
60
61 print UtilLibrary.isolate_controller(cluster_list, user_name, user_pass, isolate)