-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocatekeys2slave.py
59 lines (51 loc) · 1.29 KB
/
allocatekeys2slave.py
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
import os,sys
from subprocess import Popen, PIPE
if __name__=="__main__":
argv=sys.argv
totalkeyslst=argv[1]
print totalkeyslst
slavelst=argv[2]
print slavelst
sl=open(slavelst,"r")
ips=[]
smap=[]
alkmap=[]
totalmem=0
ts=0
for i in sl.readlines():
line=i.strip("\n")
ip,mem=line.split(" ")
ips.append(ip)
smap.append(mem)
totalmem=totalmem+int(mem)
ts=ts+1
tk=len(open(totalkeyslst,"r").readlines())
tmp=0
for i in range(ts):
t=int(tk*int(smap[i])/totalmem)
alkmap.append(t)
tmp=tmp+t
#print smap[i],alkmap[i]
alkmap[i]=tk-tmp+t
for i in alkmap:
print i
onlst=[]
d,ext=os.path.splitext(totalkeyslst)
for i in range(ts):
onlst.append(d+str(i+1)+ext)
j=0
ct=0
for i in range(ts):
if j==0:
cmd="head -"+str(alkmap[i])+" "+totalkeyslst+" >"+onlst[j]
else:
cmd="head -"+str(ct+alkmap[i])+" "+totalkeyslst+"|tail -"+str(alkmap[i])+" >"+onlst[j]
os.system(cmd)
print cmd
if j==0:
pass
else:
cmd="scp "+onlst[j]+" is_admin@"+ips[j]+":"+totalkeyslst
os.system(cmd)
ct=ct+alkmap[i]
j=j+1