-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.py
49 lines (37 loc) · 1.48 KB
/
worker.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
from concurrent import futures
import logging
import grpc
import ecfault_pb2
import ecfault_pb2_grpc
import subprocess
class RemoteNVMeDevServicer(ecfault_pb2_grpc.RemoteNVMeDevServicer):
def get_avail_dev(self, request, context):
cmd = "nvme list"
info = subprocess.call(cmd, shell=True)
return ecfault_pb2.DevInfo(dev_info = cmd)
def nvme_dev_create(self, request, context):
return ecfault_pb2.Stat(stat = 0)
# return ecfault_pb2.DevInfo(dev_info = "nvme_dev_create")
def nvme_dev_create_multiple(self, request, context):
# return ecfault_pb2.Stat(stat = 0)
return ecfault_pb2.DevInfo(dev_info = "nvme_dev_create_multiple")
def nvme_dev_remove(self, request, context):
# return ecfault_pb2.Stat(stat = 0)
return ecfault_pb2.DevInfo(dev_info = "nvme_dev_remove")
class FaultInjectionServicer(ecfault_pb2_grpc.FaultInjectionServicer):
def inject_fault(self, request, context):
# return ecfault_pb2.Stat(stat = 0)
return ecfault_pb2.DevInfo(dev_info = "inject_fault")
def worker_run():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
ecfault_pb2_grpc.add_RemoteNVMeDevServicer_to_server(RemoteNVMeDevServicer(), server)
ecfault_pb2_grpc.add_FaultInjectionServicer_to_server(FaultInjectionServicer(), server)
server.add_insecure_port("[::]:50051")
print("server start")
server.start()
print("server started")
server.wait_for_termination()
print("server term")
if __name__ == "__main__":
logging.basicConfig()
worker_run()