Repository navigation
Expand file tree
/
Copy pathclustershell.py
More file actions
executable file
·76 lines (57 loc) · 2.07 KB
/
Copy pathclustershell.py
File metadata and controls
executable file
·76 lines (57 loc) · 2.07 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
# Copyright (c) 2010-2014 Stanford University
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import smux
import sys
import os
from time import sleep
import getopt
def create(serverRanges):
if "," in serverRanges:
serverRanges = serverRanges.split(",")
else:
serverRanges = [serverRanges]
servers = []
for serverRange in serverRanges:
if '-' in serverRange:
left,right = serverRange.split("-")
left,right = int(left),int(right)
for x in xrange(left, right + 1):
servers.append(["ssh rc%02d" % x])
else:
x = int(serverRange)
servers.append(["ssh rc%02d" % x])
smux.create(len(servers), servers, executeBeforeAttach=lambda : smux.tcmd("setw synchronize-panes on"))
def usage():
doc_string = '''
Usage: clusterreplay.py <serverlist>
ServerList is specified as a comma-delmited list of ranges, such as 1-3,5-7,10-12
Options:
-h, --help Prints this help
'''
print doc_string
sys.exit(1)
def main():
if len(sys.argv) < 2: usage()
try:
opts, args = getopt.getopt(sys.argv[1:], 'h', ['help'])
except getopt.GetoptError as err:
print str(err)
usage()
sys.exit(2)
for o, a in opts:
if o in ('--help', '-h') : usage()
if len(args) == 0: usage()
create(args[0])
if __name__ == "__main__": main()