grpc added set node service, set node service file, set session options

This commit is contained in:
bharnden 2019-03-16 21:40:15 -07:00
parent a62a03e6b9
commit 9185c6b8eb
3 changed files with 124 additions and 31 deletions

View file

@ -35,18 +35,24 @@ class CoreApiClient(object):
return self.stub.DeleteSession(request)
def get_sessions(self):
return self.stub.GetSessions(core_pb2.SessionsRequest())
return self.stub.GetSessions(core_pb2.GetSessionsRequest())
def get_session(self, _id):
request = core_pb2.SessionRequest()
request = core_pb2.GetSessionRequest()
request.id = _id
return self.stub.GetSession(request)
def get_session_options(self, _id):
request = core_pb2.SessionOptionsRequest()
request = core_pb2.GetSessionOptionsRequest()
request.id = _id
return self.stub.GetSessionOptions(request)
def set_session_options(self, _id, config):
request = core_pb2.SetSessionOptionsRequest()
request.id = _id
request.config.update(config)
return self.stub.SetSessionOptions(request)
def get_session_location(self, _id):
request = core_pb2.GetSessionLocationRequest()
request.id = _id
@ -286,6 +292,25 @@ class CoreApiClient(object):
request.file = file_name
return self.stub.GetNodeServiceFile(request)
def set_node_service(self, session, _id, service, startup, validate, shutdown):
request = core_pb2.SetNodeServiceRequest()
request.session = session
request.id = _id
request.service = service
request.startup.extend(startup)
request.validate.extend(validate)
request.shutdown.extend(shutdown)
return self.stub.SetNodeService(request)
def set_node_service_file(self, session, _id, service, file_name, data):
request = core_pb2.SetNodeServiceFileRequest()
request.session = session
request.id = _id
request.service = service
request.file = file_name
request.data = data
return self.stub.SetNodeServiceFile(request)
def service_action(self, session, _id, service, action):
request = core_pb2.ServiceActionRequest()
request.session = session

View file

@ -129,7 +129,7 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
return response
def GetSessions(self, request, context):
response = core_pb2.SessionsResponse()
response = core_pb2.GetSessionsResponse()
for session_id in self.coreemu.sessions:
session = self.coreemu.sessions[session_id]
session_data = response.sessions.add()
@ -201,16 +201,26 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
groups = get_config_groups(defaults, session.options)
response = core_pb2.SessionOptionsResponse()
response = core_pb2.GetSessionOptionsResponse()
response.groups.extend(groups)
return response
def SetSessionOptions(self, request, context):
session = self.coreemu.sessions.get(request.id)
if not session:
raise Exception("no session found")
session.options.set_configs(request.config)
response = core_pb2.SetSessionOptionsResponse()
response.result = True
return response
def GetSession(self, request, context):
session = self.coreemu.sessions.get(request.id)
if not session:
raise Exception("no session found")
response = core_pb2.SessionResponse()
response = core_pb2.GetSessionResponse()
response.state = session.state
for node_id in session.objects:
@ -614,11 +624,8 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
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 = session.services.get_service(node.objid, request.service, default_service=True)
service = session.services.get_service(request.id, request.service, default_service=True)
response = core_pb2.GetNodeServiceResponse()
response.service.executables.extend(service.executables)
response.service.dependencies.extend(service.dependencies)
@ -654,6 +661,36 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
response.data = file_data.data
return response
def SetNodeService(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
# guarantee custom service exists
session.services.set_service(request.id, request.service)
service = session.services.get_service(request.id, request.service)
service.startup = tuple(request.startup)
logging.info("custom startup: %s", service.startup)
service.validate = tuple(request.validate)
logging.info("custom validate: %s", service.validate)
service.shutdown = tuple(request.shutdown)
logging.info("custom shutdown: %s", service.shutdown)
response = core_pb2.SetNodeServiceResponse()
response.result = True
return response
def SetNodeServiceFile(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
session.services.set_service_file(request.id, request.service, request.file, request.data)
response = core_pb2.SetNodeServiceFileResponse()
response.result = True
return response
def ServiceAction(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
@ -695,11 +732,8 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
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")
config = session.mobility.get_model_config(node.objid, BasicRangeModel.name)
config = session.mobility.get_model_config(request.id, BasicRangeModel.name)
groups = get_config_groups(config, BasicRangeModel)
response = core_pb2.GetWlanConfigResponse()
response.groups.extend(groups)
@ -709,11 +743,8 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
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")
session.mobility.set_model_config(node.objid, BasicRangeModel.name, request.config)
session.mobility.set_model_config(request.id, BasicRangeModel.name, request.config)
response = core_pb2.SetWlanConfigResponse()
response.result = True
return response
@ -757,12 +788,9 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
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")
model = session.emane.models[request.model]
config = session.emane.get_model_config(node.objid, request.model)
config = session.emane.get_model_config(request.id, request.model)
groups = get_config_groups(config, model)
response = core_pb2.GetEmaneModelConfigResponse()
response.groups.extend(groups)

View file

@ -8,11 +8,13 @@ service CoreApi {
}
rpc DeleteSession (DeleteSessionRequest) returns (DeleteSessionResponse) {
}
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {
rpc GetSessions (GetSessionsRequest) returns (GetSessionsResponse) {
}
rpc GetSession (SessionRequest) returns (SessionResponse) {
rpc GetSession (GetSessionRequest) returns (GetSessionResponse) {
}
rpc GetSessionOptions (SessionOptionsRequest) returns (SessionOptionsResponse) {
rpc GetSessionOptions (GetSessionOptionsRequest) returns (GetSessionOptionsResponse) {
}
rpc SetSessionOptions (SetSessionOptionsRequest) returns (SetSessionOptionsResponse) {
}
rpc GetSessionLocation (GetSessionLocationRequest) returns (GetSessionLocationResponse) {
}
@ -64,6 +66,10 @@ service CoreApi {
}
rpc GetNodeServiceFile (GetNodeServiceFileRequest) returns (GetNodeServiceFileResponse) {
}
rpc SetNodeService (SetNodeServiceRequest) returns (SetNodeServiceResponse) {
}
rpc SetNodeServiceFile (SetNodeServiceFileRequest) returns (SetNodeServiceFileResponse) {
}
rpc ServiceAction (ServiceActionRequest) returns (ServiceActionResponse) {
}
@ -112,31 +118,40 @@ message DeleteSessionResponse {
bool result = 1;
}
message SessionsRequest {
message GetSessionsRequest {
}
message SessionsResponse {
message GetSessionsResponse {
repeated Session sessions = 1;
}
message SessionRequest {
message GetSessionRequest {
int32 id = 1;
}
message SessionResponse {
message GetSessionResponse {
int32 state = 1;
repeated Node nodes = 2;
repeated Link links = 3;
}
message SessionOptionsRequest {
message GetSessionOptionsRequest {
int32 id = 1;
}
message SessionOptionsResponse {
message GetSessionOptionsResponse {
repeated ConfigGroup groups = 1;
}
message SetSessionOptionsRequest {
int32 id = 1;
map<string, string> config = 2;
}
message SetSessionOptionsResponse {
bool result = 1;
}
message GetSessionLocationRequest {
int32 id = 1;
}
@ -338,6 +353,31 @@ message GetNodeServiceFileResponse {
bytes data = 1;
}
message SetNodeServiceRequest {
int32 session = 1;
int32 id = 2;
string service = 3;
repeated string startup = 4;
repeated string validate = 5;
repeated string shutdown = 6;
}
message SetNodeServiceResponse {
bool result = 1;
}
message SetNodeServiceFileRequest {
int32 session = 1;
int32 id = 2;
string service = 3;
string file = 4;
bytes data = 5;
}
message SetNodeServiceFileResponse {
bool result = 1;
}
message ServiceActionRequest {
int32 session = 1;
int32 id = 2;