grpc support for get session options and location
This commit is contained in:
parent
b573eb641e
commit
e819b706bc
4 changed files with 153 additions and 65 deletions
|
@ -21,6 +21,16 @@ class CoreApiClient(object):
|
|||
request.id = _id
|
||||
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
|
||||
def connect(self):
|
||||
channel = grpc.insecure_channel(self.address)
|
||||
|
@ -42,6 +52,9 @@ def main():
|
|||
session = client.get_session(session_data.id)
|
||||
print(session)
|
||||
|
||||
print(client.get_session_options(session_data.id))
|
||||
print(client.get_session_location(session_data.id))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig()
|
||||
|
|
|
@ -91,6 +91,48 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
|
|||
session_data.nodes = session.get_node_count()
|
||||
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):
|
||||
session = self.coreemu.sessions.get(request.id)
|
||||
if not request:
|
||||
|
@ -103,35 +145,32 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
|
|||
if not isinstance(node.objid, int):
|
||||
continue
|
||||
|
||||
node_data = response.nodes.add()
|
||||
node_data.id = node.objid
|
||||
node_data.name = node.name
|
||||
node_data.type = nodeutils.get_node_type(node.__class__).value
|
||||
node_proto = response.nodes.add()
|
||||
node_proto.id = node.objid
|
||||
node_proto.name = node.name
|
||||
node_proto.type = nodeutils.get_node_type(node.__class__).value
|
||||
model = getattr(node, "type", None)
|
||||
if model:
|
||||
node_data.model = model
|
||||
if model is not None:
|
||||
node_proto.model = model
|
||||
|
||||
x = node.position.x
|
||||
if x is not None:
|
||||
node_data.position.x = x
|
||||
y = node.position.y
|
||||
if y is not None:
|
||||
node_data.position.y = y
|
||||
update_proto(
|
||||
node_proto.position,
|
||||
x=node.position.x,
|
||||
y=node.position.y,
|
||||
z=node.position.z
|
||||
if z is not None:
|
||||
node_data.position.z = z
|
||||
)
|
||||
|
||||
services = getattr(node, "services", [])
|
||||
if services is None:
|
||||
services = []
|
||||
services = [x.name for x in services]
|
||||
node_data.services.extend(services)
|
||||
node_proto.services.extend(services)
|
||||
|
||||
emane_model = None
|
||||
if nodeutils.is_node(node, NodeTypes.EMANE):
|
||||
emane_model = node.model.name
|
||||
if emane_model:
|
||||
node_data.emane = emane_model
|
||||
if emane_model is not None:
|
||||
node_proto.emane = emane_model
|
||||
|
||||
links_data = node.all_link_data(0)
|
||||
for link_data in links_data:
|
||||
|
|
|
@ -3,8 +3,14 @@ syntax = "proto3";
|
|||
package core;
|
||||
|
||||
service CoreApi {
|
||||
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {}
|
||||
rpc GetSession (SessionRequest) returns (SessionResponse) {}
|
||||
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {
|
||||
}
|
||||
rpc GetSession (SessionRequest) returns (SessionResponse) {
|
||||
}
|
||||
rpc GetSessionOptions (SessionOptionsRequest) returns (SessionOptionsResponse) {
|
||||
}
|
||||
rpc GetSessionLocation (SessionLocationRequest) returns (SessionLocationResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
message SessionsRequest {
|
||||
|
@ -24,6 +30,36 @@ message SessionResponse {
|
|||
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 {
|
||||
int32 id = 1;
|
||||
int32 state = 2;
|
||||
|
@ -74,9 +110,9 @@ message Interface {
|
|||
}
|
||||
|
||||
message Position {
|
||||
int32 x = 1;
|
||||
int32 y = 2;
|
||||
int32 z = 3;
|
||||
float x = 1;
|
||||
float y = 2;
|
||||
float z = 3;
|
||||
float lat = 4;
|
||||
float lon = 5;
|
||||
float alt = 6;
|
||||
|
|
0
daemon/scripts/core-daemon
Normal file → Executable file
0
daemon/scripts/core-daemon
Normal file → Executable file
Loading…
Reference in a new issue