From 9b16f272b86f73c39ab20e60c6ea527caeae79cc Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 13 Dec 2019 11:48:36 -0800 Subject: [PATCH] added get wlan configs, made use of it in coretk, updated node context to allow wlan config during runtime --- coretk/coretk/coreclient.py | 12 +++++++----- coretk/coretk/graph/node.py | 2 ++ daemon/core/api/grpc/client.py | 12 ++++++++++++ daemon/core/api/grpc/server.py | 25 +++++++++++++++++++++++++ daemon/proto/core/api/grpc/core.proto | 10 ++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index a5f407b7..f9ac0384 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -239,15 +239,17 @@ class CoreClient: node_id, config.model, config.config, interface ) + # get wlan configurations + response = self.client.get_wlan_configs(self.session_id) + for _id in response.configs: + mapped_config = response.configs[_id] + self.wlan_configs[_id] = mapped_config.config + # save and retrieve data, needed for session nodes for node in session.nodes: # get node service config and file config - # get wlan configs for wlan nodes - if node.type == core_pb2.NodeType.WIRELESS_LAN: - response = self.client.get_wlan_config(self.session_id, node.id) - self.wlan_configs[node.id] = response.config # retrieve service configurations data for default nodes - elif node.type == core_pb2.NodeType.DEFAULT: + if node.type == core_pb2.NodeType.DEFAULT: for service in node.services: response = self.client.get_node_service( self.session_id, node.id, service diff --git a/coretk/coretk/graph/node.py b/coretk/coretk/graph/node.py index 0d0f8706..93b6c390 100644 --- a/coretk/coretk/graph/node.py +++ b/coretk/coretk/graph/node.py @@ -173,6 +173,8 @@ class CanvasNode: context.add_command(label="Configure", command=self.show_config) if NodeUtils.is_container_node(self.core_node.type): context.add_command(label="Services", state=tk.DISABLED) + if is_wlan: + context.add_command(label="WLAN Config", command=self.show_wlan_config) if is_wlan and self.core_node.id in self.app.core.mobility_players: context.add_command( label="Mobility Player", command=self.show_mobility_player diff --git a/daemon/core/api/grpc/client.py b/daemon/core/api/grpc/client.py index 05380b79..7887d5e8 100644 --- a/daemon/core/api/grpc/client.py +++ b/daemon/core/api/grpc/client.py @@ -827,6 +827,18 @@ class CoreGrpcClient: ) return self.stub.ServiceAction(request) + def get_wlan_configs(self, session_id): + """ + Get all wlan configurations. + + :param int session_id: session id + :return: response with a dict of node ids to wlan configurations + :rtype: core_pb2.GetWlanConfigsResponse + :raises grpc.RpcError: when session doesn't exist + """ + request = core_pb2.GetWlanConfigsRequest(session_id=session_id) + return self.stub.GetWlanConfigs(request) + def get_wlan_config(self, session_id, node_id): """ Get wlan configuration for a node. diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index 27b069f0..9b8c51c7 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -1236,6 +1236,31 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): return core_pb2.ServiceActionResponse(result=result) + def GetWlanConfigs(self, request, context): + """ + Retrieve all wireless-lan configurations. + + :param core.api.grpc.core_pb2.GetWlanConfigsRequest request: request + :param context: core.api.grpc.core_pb2.GetWlanConfigResponse + :return: all wlan configurations + :rtype: core.api.grpc.core_pb2.GetWlanConfigsResponse + """ + logging.debug("get wlan configs: %s", request) + session = self.get_session(request.session_id, context) + response = core_pb2.GetWlanConfigsResponse() + for node_id in session.mobility.node_configurations: + model_config = session.mobility.node_configurations[node_id] + if node_id == -1: + continue + for model_name in model_config: + if model_name != BasicRangeModel.name: + continue + current_config = session.mobility.get_model_config(node_id, model_name) + config = get_config_options(current_config, BasicRangeModel) + mapped_config = core_pb2.MappedConfig(config=config) + response.configs[node_id].CopyFrom(mapped_config) + return response + def GetWlanConfig(self, request, context): """ Retrieve wireless-lan configuration of a node diff --git a/daemon/proto/core/api/grpc/core.proto b/daemon/proto/core/api/grpc/core.proto index 253102bf..609316f8 100644 --- a/daemon/proto/core/api/grpc/core.proto +++ b/daemon/proto/core/api/grpc/core.proto @@ -101,6 +101,8 @@ service CoreApi { } // wlan rpc + rpc GetWlanConfigs (GetWlanConfigsRequest) returns (GetWlanConfigsResponse) { + } rpc GetWlanConfig (GetWlanConfigRequest) returns (GetWlanConfigResponse) { } rpc SetWlanConfig (SetWlanConfigRequest) returns (SetWlanConfigResponse) { @@ -585,6 +587,14 @@ message ServiceActionResponse { bool result = 1; } +message GetWlanConfigsRequest { + int32 session_id = 1; +} + +message GetWlanConfigsResponse { + map configs = 1; +} + message GetWlanConfigRequest { int32 session_id = 1; int32 node_id = 2;