-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathminion.py
44 lines (34 loc) · 1.05 KB
/
minion.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
import rpyc
import uuid
import os
from rpyc.utils.server import ThreadedServer
DATA_DIR="/tmp/minion/"
class MinionService(rpyc.Service):
class exposed_Minion():
blocks = {}
def exposed_put(self,block_uuid,data,minions):
with open(DATA_DIR+str(block_uuid),'w') as f:
f.write(data)
if len(minions)>0:
self.forward(block_uuid,data,minions)
def exposed_get(self,block_uuid):
block_addr=DATA_DIR+str(block_uuid)
if not os.path.isfile(block_addr):
return None
with open(block_addr) as f:
return f.read()
def forward(self,block_uuid,data,minions):
print "8888: forwaring to:"
print block_uuid, minions
minion=minions[0]
minions=minions[1:]
host,port=minion
con=rpyc.connect(host,port=port)
minion = con.root.Minion()
minion.put(block_uuid,data,minions)
def delete_block(self,uuid):
pass
if __name__ == "__main__":
if not os.path.isdir(DATA_DIR): os.mkdir(DATA_DIR)
t = ThreadedServer(MinionService, port = 8888)
t.start()