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:
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 controllers = data["cluster"]["controllers"]
57 user_name = data["cluster"]["user"]
58 user_pass = data["cluster"]["pass"]
60 print str(sys.exc_info())
61 print 'Error reading the file cluster.json'
64 isolate = int(sys.argv[1])
65 duration = int(sys.argv[2])
67 print 'You must specify the number (e.g. 1, 2, 3) of the controller to isolate.'
70 print 'Isolating controller ' + str(isolate)
72 print UtilLibrary.isolate_controller(controllers, user_name, user_pass, isolate)
74 print 'Pausing for ' + str(duration) + ' seconds...'
77 print UtilLibrary.flush_iptables(controllers, user_name, user_pass)