grpc support for get session options and location

This commit is contained in:
bharnden 2019-02-20 21:19:35 -08:00
parent b573eb641e
commit e819b706bc
4 changed files with 153 additions and 65 deletions

View file

@ -21,6 +21,16 @@ class CoreApiClient(object):
request.id = _id request.id = _id
return self.stub.GetSession(request) return self.stub.GetSession(request)
def get_session_options(self, _id):
request = core_pb2.SessionOptionsRequest()
request.id = _id
return self.stub.GetSessionOptions(request)
def get_session_location(self, _id):
request = core_pb2.SessionLocationRequest()
request.id = _id
return self.stub.GetSessionLocation(request)
@contextmanager @contextmanager
def connect(self): def connect(self):
channel = grpc.insecure_channel(self.address) channel = grpc.insecure_channel(self.address)
@ -42,6 +52,9 @@ def main():
session = client.get_session(session_data.id) session = client.get_session(session_data.id)
print(session) print(session)
print(client.get_session_options(session_data.id))
print(client.get_session_location(session_data.id))
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig() logging.basicConfig()

View file

@ -91,6 +91,48 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
session_data.nodes = session.get_node_count() session_data.nodes = session.get_node_count()
return response return response
def GetSessionLocation(self, request, context):
session = self.coreemu.sessions.get(request.id)
x, y, z = session.location.refxyz
lat, lon, alt = session.location.refgeo
response = core_pb2.SessionLocationResponse()
update_proto(
response.position,
x=x,
y=y,
z=z,
lat=lat,
lon=lon,
alt=alt
)
update_proto(response, scale=session.location.refscale)
return response
def GetSessionOptions(self, request, context):
session = self.coreemu.sessions.get(request.id)
config = session.options.get_configs()
response = core_pb2.SessionOptionsResponse()
config_options = []
for configuration in session.options.configurations():
value = config[configuration.id]
config_option = core_pb2.ConfigOption()
config_option.label = configuration.label
config_option.name = configuration.id
config_option.value = value
config_option.type = configuration.type.value
config_option.select.extend(configuration.options)
config_options.append(config_option)
for config_group in session.options.config_groups():
start = config_group.start - 1
stop = config_group.stop
config_group_proto = response.groups.add()
config_group_proto.name = config_group.name
config_group_proto.options.extend(config_options[start: stop])
return response
def GetSession(self, request, context): def GetSession(self, request, context):
session = self.coreemu.sessions.get(request.id) session = self.coreemu.sessions.get(request.id)
if not request: if not request:
@ -103,35 +145,32 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
if not isinstance(node.objid, int): if not isinstance(node.objid, int):
continue continue
node_data = response.nodes.add() node_proto = response.nodes.add()
node_data.id = node.objid node_proto.id = node.objid
node_data.name = node.name node_proto.name = node.name
node_data.type = nodeutils.get_node_type(node.__class__).value node_proto.type = nodeutils.get_node_type(node.__class__).value
model = getattr(node, "type", None) model = getattr(node, "type", None)
if model: if model is not None:
node_data.model = model node_proto.model = model
x = node.position.x update_proto(
if x is not None: node_proto.position,
node_data.position.x = x x=node.position.x,
y = node.position.y y=node.position.y,
if y is not None:
node_data.position.y = y
z=node.position.z z=node.position.z
if z is not None: )
node_data.position.z = z
services = getattr(node, "services", []) services = getattr(node, "services", [])
if services is None: if services is None:
services = [] services = []
services = [x.name for x in services] services = [x.name for x in services]
node_data.services.extend(services) node_proto.services.extend(services)
emane_model = None emane_model = None
if nodeutils.is_node(node, NodeTypes.EMANE): if nodeutils.is_node(node, NodeTypes.EMANE):
emane_model = node.model.name emane_model = node.model.name
if emane_model: if emane_model is not None:
node_data.emane = emane_model node_proto.emane = emane_model
links_data = node.all_link_data(0) links_data = node.all_link_data(0)
for link_data in links_data: for link_data in links_data:

View file

@ -3,8 +3,14 @@ syntax = "proto3";
package core; package core;
service CoreApi { service CoreApi {
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {} rpc GetSessions (SessionsRequest) returns (SessionsResponse) {
rpc GetSession (SessionRequest) returns (SessionResponse) {} }
rpc GetSession (SessionRequest) returns (SessionResponse) {
}
rpc GetSessionOptions (SessionOptionsRequest) returns (SessionOptionsResponse) {
}
rpc GetSessionLocation (SessionLocationRequest) returns (SessionLocationResponse) {
}
} }
message SessionsRequest { message SessionsRequest {
@ -24,6 +30,36 @@ message SessionResponse {
repeated Link links = 3; repeated Link links = 3;
} }
message SessionOptionsRequest {
int32 id = 1;
}
message SessionOptionsResponse {
repeated ConfigGroup groups = 1;
}
message SessionLocationRequest {
int32 id = 1;
}
message SessionLocationResponse {
Position position = 1;
float scale = 2;
}
message ConfigGroup {
string name = 1;
repeated ConfigOption options = 2;
}
message ConfigOption {
string label = 1;
string name = 2;
string value = 3;
int32 type = 4;
repeated string select = 5;
}
message Session { message Session {
int32 id = 1; int32 id = 1;
int32 state = 2; int32 state = 2;
@ -74,9 +110,9 @@ message Interface {
} }
message Position { message Position {
int32 x = 1; float x = 1;
int32 y = 2; float y = 2;
int32 z = 3; float z = 3;
float lat = 4; float lat = 4;
float lon = 5; float lon = 5;
float alt = 6; float alt = 6;

0
daemon/scripts/core-daemon Normal file → Executable file
View file