3 Controller Isolation Tool
7 This tool isolates an indicated controller for a specified duration.
8 The tool's first integer argument corresponds to the number of a controller
9 in a json file's ordered list of controllers. This is the controller to
10 be isolated. The second argument is the duration of isolation in
13 A file named 'cluster.json' containing a list of the IP addresses and
14 credentials of the controllers is required. It resides in the same
15 directory as monitor.py.
17 The file should look like this:
22 {"ip": "172.17.10.93", "port": "8181"},
23 {"ip": "172.17.10.93", "port": "8181"},
24 {"ip": "172.17.10.93", "port": "8181"}
31 Usage:python timed_isolation.py [controller to be isolated] [duration of isolation in seconds]
38 def import_utility_modules():
39 global UtilLibrary, json
41 sys.path.append('../../../csit/libraries')
46 import_utility_modules()
49 with open('cluster.json') as cluster_file:
50 data = json.load(cluster_file)
52 print str(sys.exc_info())
53 print 'unable to open the file cluster.json'
56 cluster_list = data["cluster"]["controllers"]
58 for controller in cluster_list:
59 cluster_ips.append(controller["ip"])
60 user_name = data["cluster"]["user"]
61 user_pass = data["cluster"]["pass"]
63 print str(sys.exc_info())
64 print 'Error reading the file cluster.json'
67 isolate = int(sys.argv[1])
68 duration = int(sys.argv[2])
70 print 'You must specify the number (e.g. 1, 2, 3) of the controller to isolate.'
73 print 'Isolating controller ' + str(isolate)
75 print UtilLibrary.isolate_controller(cluster_ips, user_name, user_pass, isolate)
77 print 'Pausing for ' + str(duration) + ' seconds...'
80 print UtilLibrary.flush_iptables(cluster_ips, user_name, user_pass)