grpc added node service file and service action
This commit is contained in:
parent
f24376d66c
commit
a62a03e6b9
3 changed files with 107 additions and 0 deletions
|
@ -278,6 +278,22 @@ class CoreApiClient(object):
|
|||
request.service = service
|
||||
return self.stub.GetNodeService(request)
|
||||
|
||||
def get_node_service_file(self, session, _id, service, file_name):
|
||||
request = core_pb2.GetNodeServiceFileRequest()
|
||||
request.session = session
|
||||
request.id = _id
|
||||
request.service = service
|
||||
request.file = file_name
|
||||
return self.stub.GetNodeServiceFile(request)
|
||||
|
||||
def service_action(self, session, _id, service, action):
|
||||
request = core_pb2.ServiceActionRequest()
|
||||
request.session = session
|
||||
request.id = _id
|
||||
request.service = service
|
||||
request.action = action
|
||||
return self.stub.ServiceAction(request)
|
||||
|
||||
def get_wlan_config(self, session, _id):
|
||||
request = core_pb2.GetWlanConfigRequest()
|
||||
request.session = session
|
||||
|
|
|
@ -633,6 +633,64 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
|
|||
response.service.meta = service.meta
|
||||
return response
|
||||
|
||||
def GetNodeServiceFile(self, request, context):
|
||||
session = self.coreemu.sessions.get(request.session)
|
||||
if not session:
|
||||
raise Exception("no session found")
|
||||
node = session.get_object(request.id)
|
||||
if not node:
|
||||
raise Exception("no node found")
|
||||
|
||||
service = None
|
||||
for current_service in node.services:
|
||||
if current_service.name == request.service:
|
||||
service = current_service
|
||||
break
|
||||
|
||||
response = core_pb2.GetNodeServiceFileResponse()
|
||||
if not service:
|
||||
return response
|
||||
file_data = session.services.get_service_file(node, request.service, request.file)
|
||||
response.data = file_data.data
|
||||
return response
|
||||
|
||||
def ServiceAction(self, request, context):
|
||||
session = self.coreemu.sessions.get(request.session)
|
||||
if not session:
|
||||
raise Exception("no session found")
|
||||
node = session.get_object(request.id)
|
||||
if not node:
|
||||
raise Exception("no node found")
|
||||
|
||||
service = None
|
||||
for current_service in node.services:
|
||||
if current_service.name == request.service:
|
||||
service = current_service
|
||||
break
|
||||
|
||||
response = core_pb2.ServiceActionResponse()
|
||||
response.result = False
|
||||
|
||||
if not service:
|
||||
return response
|
||||
|
||||
status = -1
|
||||
if request.action == core_pb2.START:
|
||||
status = session.services.startup_service(node, service, wait=True)
|
||||
elif request.action == core_pb2.STOP:
|
||||
status = session.services.stop_service(node, service)
|
||||
elif request.action == core_pb2.RESTART:
|
||||
status = session.services.stop_service(node, service)
|
||||
if not status:
|
||||
status = session.services.startup_service(node, service, wait=True)
|
||||
elif request.action == core_pb2.VALIDATE:
|
||||
status = session.services.validate_service(node, service)
|
||||
|
||||
if not status:
|
||||
response.result = True
|
||||
|
||||
return response
|
||||
|
||||
def GetWlanConfig(self, request, context):
|
||||
session = self.coreemu.sessions.get(request.session)
|
||||
if not session:
|
||||
|
|
|
@ -62,6 +62,10 @@ service CoreApi {
|
|||
}
|
||||
rpc GetNodeService (GetNodeServiceRequest) returns (GetNodeServiceResponse) {
|
||||
}
|
||||
rpc GetNodeServiceFile (GetNodeServiceFileRequest) returns (GetNodeServiceFileResponse) {
|
||||
}
|
||||
rpc ServiceAction (ServiceActionRequest) returns (ServiceActionResponse) {
|
||||
}
|
||||
|
||||
// wlan rpc
|
||||
rpc GetWlanConfig (GetWlanConfigRequest) returns (GetWlanConfigResponse) {
|
||||
|
@ -323,6 +327,28 @@ message GetNodeServiceResponse {
|
|||
NodeServiceData service = 1;
|
||||
}
|
||||
|
||||
message GetNodeServiceFileRequest {
|
||||
int32 session = 1;
|
||||
int32 id = 2;
|
||||
string service = 3;
|
||||
string file = 4;
|
||||
}
|
||||
|
||||
message GetNodeServiceFileResponse {
|
||||
bytes data = 1;
|
||||
}
|
||||
|
||||
message ServiceActionRequest {
|
||||
int32 session = 1;
|
||||
int32 id = 2;
|
||||
string service = 3;
|
||||
ServiceAction action = 4;
|
||||
}
|
||||
|
||||
message ServiceActionResponse {
|
||||
bool result = 1;
|
||||
}
|
||||
|
||||
message GetWlanConfigRequest {
|
||||
int32 session = 1;
|
||||
int32 id = 2;
|
||||
|
@ -451,6 +477,13 @@ enum ServiceValidationMode {
|
|||
TIMER = 2;
|
||||
}
|
||||
|
||||
enum ServiceAction {
|
||||
START = 0;
|
||||
STOP = 1;
|
||||
RESTART = 2;
|
||||
VALIDATE = 3;
|
||||
}
|
||||
|
||||
message Hook {
|
||||
SessionState state = 1;
|
||||
string file = 2;
|
||||
|
|
Loading…
Reference in a new issue