grpc added get/set service defaults and get node service data

This commit is contained in:
bharnden 2019-03-14 22:33:10 -07:00
parent 0c20e76630
commit 5753c91906
3 changed files with 133 additions and 0 deletions

View file

@ -216,6 +216,29 @@ class CoreApiClient(object):
request = core_pb2.GetServicesRequest()
return self.stub.GetServices(request)
def get_service_defaults(self, session):
request = core_pb2.GetServiceDefaultsRequest()
request.session = session
return self.stub.GetServiceDefaults(request)
def set_service_defaults(self, session, service_defaults):
request = core_pb2.SetServiceDefaultsRequest()
request.session = session
for node_type in service_defaults:
services = service_defaults[node_type]
service_defaults_proto = request.defaults.add()
service_defaults_proto.node_type = node_type
service_defaults_proto.services.extend(services)
return self.stub.SetServiceDefaults(request)
def get_node_service(self, session, _id, service):
request = core_pb2.GetNodeServiceRequest()
request.session = session
request.id = _id
request.service = service
return self.stub.GetNodeService(request)
def get_emane_config(self, session):
request = core_pb2.GetEmaneConfigRequest()
request.session = session
@ -260,6 +283,8 @@ def main():
session_data = client.create_session()
print("created session: %s" % session_data)
print("default services: %s" % client.get_service_defaults(session_data.id))
response = client.get_sessions()
print("core client received: %s" % response)
@ -301,6 +326,8 @@ def main():
print("edit node: %s" % client.edit_node(session_data.id, node_id, node_options))
print("get node: %s" % client.get_node(session_data.id, node_id))
print("node service: %s" % client.get_node_service(session_data.id, node_id, "zebra"))
# create link
interface_one = InterfaceData(
_id=None, name=None, mac=None,

View file

@ -513,6 +513,55 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
service_proto.name = service.name
return response
def GetServiceDefaults(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
response = core_pb2.GetServiceDefaultsResponse()
for node_type in session.services.default_services:
services = session.services.default_services[node_type]
service_defaults = response.defaults.add()
service_defaults.node_type = node_type
service_defaults.services.extend(services)
return response
def SetServiceDefaults(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
session.services.default_services.clear()
for service_defaults in request.defaults:
session.services.default_services[service_defaults.node_type] = service_defaults.services
response = core_pb2.SetServiceDefaultsResponse()
response.result = True
return response
def GetNodeService(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 = session.services.get_service(node.objid, request.service, default_service=True)
response = core_pb2.GetNodeServiceResponse()
response.service.executables.extend(service.executables)
response.service.dependencies.extend(service.dependencies)
response.service.dirs.extend(service.dirs)
response.service.configs.extend(service.configs)
response.service.startup.extend(service.startup)
response.service.validate.extend(service.validate)
response.service.validation_mode = service.validation_mode.value
response.service.validation_timer = service.validation_timer
response.service.shutdown.extend(service.shutdown)
if service.meta:
response.service.meta = service.meta
return response
def GetEmaneConfig(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:

View file

@ -37,6 +37,12 @@ service CoreApi {
}
rpc GetServices (GetServicesRequest) returns (GetServicesResponse) {
}
rpc GetServiceDefaults (GetServiceDefaultsRequest) returns (GetServiceDefaultsResponse) {
}
rpc SetServiceDefaults (SetServiceDefaultsRequest) returns (SetServiceDefaultsResponse) {
}
rpc GetNodeService (GetNodeServiceRequest) returns (GetNodeServiceResponse) {
}
rpc GetEmaneConfig (GetEmaneConfigRequest) returns (GetEmaneConfigResponse) {
}
rpc SaveXml (SaveXmlRequest) returns (SaveXmlResponse) {
@ -212,6 +218,33 @@ message GetServicesResponse {
repeated Service services = 1;
}
message GetServiceDefaultsRequest {
int32 session = 1;
}
message GetServiceDefaultsResponse {
repeated ServiceDefaults defaults = 1;
}
message SetServiceDefaultsRequest {
int32 session = 1;
repeated ServiceDefaults defaults = 2;
}
message SetServiceDefaultsResponse {
bool result = 1;
}
message GetNodeServiceRequest {
int32 session = 1;
int32 id = 2;
string service = 3;
}
message GetNodeServiceResponse {
NodeServiceData service = 1;
}
message GetEmaneConfigRequest {
int32 session = 1;
}
@ -265,11 +298,35 @@ enum NodeType {
EMANE_NET = 14;
}
enum ServiceValidationMode {
BLOCKING = 0;
NON_BLOCKING = 1;
TIMER = 2;
}
message ServiceDefaults {
string node_type = 1;
repeated string services = 2;
}
message Service {
string group = 1;
string name = 2;
}
message NodeServiceData {
repeated string executables = 1;
repeated string dependencies = 2;
repeated string dirs = 3;
repeated string configs = 4;
repeated string startup = 5;
repeated string validate = 6;
ServiceValidationMode validation_mode = 7;
int32 validation_timer = 8;
repeated string shutdown = 9;
string meta = 10;
}
message ConfigGroup {
string name = 1;
repeated ConfigOption options = 2;