fixed protobuf generation to avoid grpc generation for files with no definitions, added service config tab display to coretk
This commit is contained in:
parent
a4f3abf27c
commit
83e7853821
9 changed files with 65 additions and 33 deletions
|
@ -3,7 +3,7 @@ import time
|
||||||
from typing import Any, Dict, List, Tuple, Type
|
from typing import Any, Dict, List, Tuple, Type
|
||||||
|
|
||||||
from core import utils
|
from core import utils
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import common_pb2, core_pb2
|
||||||
from core.config import ConfigurableOptions
|
from core.config import ConfigurableOptions
|
||||||
from core.emulator.data import LinkData
|
from core.emulator.data import LinkData
|
||||||
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
|
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
|
||||||
|
@ -190,7 +190,7 @@ def convert_value(value: Any) -> str:
|
||||||
|
|
||||||
def get_config_options(
|
def get_config_options(
|
||||||
config: Dict[str, str], configurable_options: Type[ConfigurableOptions]
|
config: Dict[str, str], configurable_options: Type[ConfigurableOptions]
|
||||||
) -> Dict[str, core_pb2.ConfigOption]:
|
) -> Dict[str, common_pb2.ConfigOption]:
|
||||||
"""
|
"""
|
||||||
Retrieve configuration options in a form that is used by the grpc server.
|
Retrieve configuration options in a form that is used by the grpc server.
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ def get_config_options(
|
||||||
results = {}
|
results = {}
|
||||||
for configuration in configurable_options.configurations():
|
for configuration in configurable_options.configurations():
|
||||||
value = config[configuration.id]
|
value = config[configuration.id]
|
||||||
config_option = core_pb2.ConfigOption(
|
config_option = common_pb2.ConfigOption(
|
||||||
label=configuration.label,
|
label=configuration.label,
|
||||||
name=configuration.id,
|
name=configuration.id,
|
||||||
value=value,
|
value=value,
|
||||||
|
|
|
@ -10,7 +10,7 @@ from typing import Type
|
||||||
import grpc
|
import grpc
|
||||||
from grpc import ServicerContext
|
from grpc import ServicerContext
|
||||||
|
|
||||||
from core.api.grpc import core_pb2, core_pb2_grpc, grpcutils
|
from core.api.grpc import common_pb2, core_pb2, core_pb2_grpc, grpcutils
|
||||||
from core.api.grpc.configservices_pb2 import (
|
from core.api.grpc.configservices_pb2 import (
|
||||||
ConfigService,
|
ConfigService,
|
||||||
GetConfigServiceDefaultsRequest,
|
GetConfigServiceDefaultsRequest,
|
||||||
|
@ -1494,7 +1494,17 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
service_class = self.validate_service(request.name, context)
|
service_class = self.validate_service(request.name, context)
|
||||||
service = service_class(None)
|
service = service_class(None)
|
||||||
templates = service.get_templates()
|
templates = service.get_templates()
|
||||||
config = service.render_config()
|
config = {}
|
||||||
|
for configuration in service.default_configs:
|
||||||
|
config_option = common_pb2.ConfigOption(
|
||||||
|
label=configuration.label,
|
||||||
|
name=configuration.id,
|
||||||
|
value=configuration.default,
|
||||||
|
type=configuration.type.value,
|
||||||
|
select=configuration.options,
|
||||||
|
group="Settings",
|
||||||
|
)
|
||||||
|
config[configuration.id] = config_option
|
||||||
return GetConfigServiceDefaultsResponse(templates=templates, config=config)
|
return GetConfigServiceDefaultsResponse(templates=templates, config=config)
|
||||||
|
|
||||||
def GetNodeConfigServices(
|
def GetNodeConfigServices(
|
||||||
|
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Dict, List
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
from core.api.grpc import client, core_pb2
|
from core.api.grpc import client, common_pb2, core_pb2
|
||||||
from core.gui import appconfig
|
from core.gui import appconfig
|
||||||
from core.gui.dialogs.mobilityplayer import MobilityPlayer
|
from core.gui.dialogs.mobilityplayer import MobilityPlayer
|
||||||
from core.gui.dialogs.sessions import SessionsDialog
|
from core.gui.dialogs.sessions import SessionsDialog
|
||||||
|
@ -875,14 +875,14 @@ class CoreClient:
|
||||||
logging.info("running node(%s) cmd: %s", node_id, self.observer)
|
logging.info("running node(%s) cmd: %s", node_id, self.observer)
|
||||||
return self.client.node_command(self.session_id, node_id, self.observer).output
|
return self.client.node_command(self.session_id, node_id, self.observer).output
|
||||||
|
|
||||||
def get_wlan_config(self, node_id: int) -> Dict[str, core_pb2.ConfigOption]:
|
def get_wlan_config(self, node_id: int) -> Dict[str, common_pb2.ConfigOption]:
|
||||||
config = self.wlan_configs.get(node_id)
|
config = self.wlan_configs.get(node_id)
|
||||||
if not config:
|
if not config:
|
||||||
response = self.client.get_wlan_config(self.session_id, node_id)
|
response = self.client.get_wlan_config(self.session_id, node_id)
|
||||||
config = response.config
|
config = response.config
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def get_mobility_config(self, node_id: int) -> Dict[str, core_pb2.ConfigOption]:
|
def get_mobility_config(self, node_id: int) -> Dict[str, common_pb2.ConfigOption]:
|
||||||
config = self.mobility_configs.get(node_id)
|
config = self.mobility_configs.get(node_id)
|
||||||
if not config:
|
if not config:
|
||||||
response = self.client.get_mobility_config(self.session_id, node_id)
|
response = self.client.get_mobility_config(self.session_id, node_id)
|
||||||
|
@ -891,7 +891,7 @@ class CoreClient:
|
||||||
|
|
||||||
def get_emane_model_config(
|
def get_emane_model_config(
|
||||||
self, node_id: int, model: str, interface: int = None
|
self, node_id: int, model: str, interface: int = None
|
||||||
) -> Dict[str, core_pb2.ConfigOption]:
|
) -> Dict[str, common_pb2.ConfigOption]:
|
||||||
logging.info("getting emane model config: %s %s %s", node_id, model, interface)
|
logging.info("getting emane model config: %s %s %s", node_id, model, interface)
|
||||||
config = self.emane_model_configs.get((node_id, model, interface))
|
config = self.emane_model_configs.get((node_id, model, interface))
|
||||||
if not config:
|
if not config:
|
||||||
|
@ -907,7 +907,7 @@ class CoreClient:
|
||||||
self,
|
self,
|
||||||
node_id: int,
|
node_id: int,
|
||||||
model: str,
|
model: str,
|
||||||
config: Dict[str, core_pb2.ConfigOption],
|
config: Dict[str, common_pb2.ConfigOption],
|
||||||
interface: int = None,
|
interface: int = None,
|
||||||
):
|
):
|
||||||
logging.info("setting emane model config: %s %s %s", node_id, model, interface)
|
logging.info("setting emane model config: %s %s %s", node_id, model, interface)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Service configuration dialog
|
Service configuration dialog
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from typing import TYPE_CHECKING, Any, List
|
from typing import TYPE_CHECKING, Any, List
|
||||||
|
@ -13,7 +14,7 @@ from core.gui.dialogs.dialog import Dialog
|
||||||
from core.gui.errors import show_grpc_error
|
from core.gui.errors import show_grpc_error
|
||||||
from core.gui.images import ImageEnum, Images
|
from core.gui.images import ImageEnum, Images
|
||||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||||
from core.gui.widgets import CodeText, ListboxScroll
|
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.gui.app import Application
|
from core.gui.app import Application
|
||||||
|
@ -61,6 +62,8 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
self.original_service_files = {}
|
self.original_service_files = {}
|
||||||
self.temp_service_files = {}
|
self.temp_service_files = {}
|
||||||
self.modified_files = set()
|
self.modified_files = set()
|
||||||
|
self.config_frame = None
|
||||||
|
self.config = None
|
||||||
self.load()
|
self.load()
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
@ -81,6 +84,7 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
response = self.core.client.get_config_service_defaults(self.service_name)
|
response = self.core.client.get_config_service_defaults(self.service_name)
|
||||||
self.original_service_files = response.templates
|
self.original_service_files = response.templates
|
||||||
self.temp_service_files = dict(self.original_service_files)
|
self.temp_service_files = dict(self.original_service_files)
|
||||||
|
self.config = response.config
|
||||||
|
|
||||||
node_configs = self.service_configs.get(self.node_id, {})
|
node_configs = self.service_configs.get(self.node_id, {})
|
||||||
service_config = node_configs.get(self.service_name, {})
|
service_config = node_configs.get(self.service_name, {})
|
||||||
|
@ -98,9 +102,10 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
self.notebook = ttk.Notebook(self.top)
|
self.notebook = ttk.Notebook(self.top)
|
||||||
self.notebook.grid(sticky="nsew", pady=PADY)
|
self.notebook.grid(sticky="nsew", pady=PADY)
|
||||||
self.draw_tab_files()
|
self.draw_tab_files()
|
||||||
|
self.draw_tab_config()
|
||||||
self.draw_tab_directories()
|
self.draw_tab_directories()
|
||||||
self.draw_tab_startstop()
|
self.draw_tab_startstop()
|
||||||
self.draw_tab_configuration()
|
self.draw_tab_validation()
|
||||||
|
|
||||||
self.draw_buttons()
|
self.draw_buttons()
|
||||||
|
|
||||||
|
@ -184,6 +189,16 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
"<FocusOut>", self.update_temp_service_file_data
|
"<FocusOut>", self.update_temp_service_file_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def draw_tab_config(self):
|
||||||
|
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||||
|
tab.grid(sticky="nsew")
|
||||||
|
tab.columnconfigure(0, weight=1)
|
||||||
|
self.notebook.add(tab, text="Configuration")
|
||||||
|
logging.info("config service config: %s", self.config)
|
||||||
|
self.config_frame = ConfigFrame(tab, self.app, self.config)
|
||||||
|
self.config_frame.draw_config()
|
||||||
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
||||||
|
|
||||||
def draw_tab_directories(self):
|
def draw_tab_directories(self):
|
||||||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||||
tab.grid(sticky="nsew")
|
tab.grid(sticky="nsew")
|
||||||
|
@ -250,7 +265,7 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
elif i == 2:
|
elif i == 2:
|
||||||
self.validate_commands_listbox = listbox_scroll.listbox
|
self.validate_commands_listbox = listbox_scroll.listbox
|
||||||
|
|
||||||
def draw_tab_configuration(self):
|
def draw_tab_validation(self):
|
||||||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||||
tab.grid(sticky="nsew")
|
tab.grid(sticky="nsew")
|
||||||
tab.columnconfigure(0, weight=1)
|
tab.columnconfigure(0, weight=1)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from pathlib import PosixPath
|
||||||
from tkinter import filedialog, font, ttk
|
from tkinter import filedialog, font, ttk
|
||||||
from typing import TYPE_CHECKING, Dict
|
from typing import TYPE_CHECKING, Dict
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import common_pb2, core_pb2
|
||||||
from core.gui import themes
|
from core.gui import themes
|
||||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class ConfigFrame(ttk.Notebook):
|
||||||
self,
|
self,
|
||||||
master: tk.Widget,
|
master: tk.Widget,
|
||||||
app: "Application",
|
app: "Application",
|
||||||
config: Dict[str, core_pb2.ConfigOption],
|
config: Dict[str, common_pb2.ConfigOption],
|
||||||
**kw
|
**kw
|
||||||
):
|
):
|
||||||
super().__init__(master, **kw)
|
super().__init__(master, **kw)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
all:
|
all:
|
||||||
$(PYTHON) -m grpc_tools.protoc -I . --python_out=.. --grpc_python_out=.. core/api/grpc/*.proto
|
$(PYTHON) -m grpc_tools.protoc -I . --python_out=.. core/api/grpc/*.proto
|
||||||
|
$(PYTHON) -m grpc_tools.protoc -I . --grpc_python_out=.. core/api/grpc/core.proto
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f ../core/api/grpc/*_pb2*
|
-rm -f ../core/api/grpc/*_pb2*
|
||||||
|
|
12
daemon/proto/core/api/grpc/common.proto
Normal file
12
daemon/proto/core/api/grpc/common.proto
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package common;
|
||||||
|
|
||||||
|
message ConfigOption {
|
||||||
|
string label = 1;
|
||||||
|
string name = 2;
|
||||||
|
string value = 3;
|
||||||
|
int32 type = 4;
|
||||||
|
repeated string select = 5;
|
||||||
|
string group = 6;
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ syntax = "proto3";
|
||||||
|
|
||||||
package configservices;
|
package configservices;
|
||||||
|
|
||||||
|
import "core/api/grpc/common.proto";
|
||||||
|
|
||||||
message ConfigServiceValidationMode {
|
message ConfigServiceValidationMode {
|
||||||
enum Enum {
|
enum Enum {
|
||||||
BLOCKING = 0;
|
BLOCKING = 0;
|
||||||
|
@ -39,7 +41,7 @@ message GetConfigServiceDefaultsRequest {
|
||||||
|
|
||||||
message GetConfigServiceDefaultsResponse {
|
message GetConfigServiceDefaultsResponse {
|
||||||
map<string, string> templates = 1;
|
map<string, string> templates = 1;
|
||||||
map<string, string> config = 2;
|
map<string, common.ConfigOption> config = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetNodeConfigServiceRequest {
|
message GetNodeConfigServiceRequest {
|
||||||
|
|
|
@ -6,6 +6,7 @@ option java_package = "com.core.client.grpc";
|
||||||
option java_outer_classname = "CoreProto";
|
option java_outer_classname = "CoreProto";
|
||||||
|
|
||||||
import "core/api/grpc/configservices.proto";
|
import "core/api/grpc/configservices.proto";
|
||||||
|
import "core/api/grpc/common.proto";
|
||||||
|
|
||||||
service CoreApi {
|
service CoreApi {
|
||||||
// session rpc
|
// session rpc
|
||||||
|
@ -217,7 +218,7 @@ message GetSessionOptionsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetSessionOptionsResponse {
|
message GetSessionOptionsResponse {
|
||||||
map<string, ConfigOption> config = 2;
|
map<string, common.ConfigOption> config = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetSessionOptionsRequest {
|
message SetSessionOptionsRequest {
|
||||||
|
@ -508,7 +509,7 @@ message GetMobilityConfigRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetMobilityConfigResponse {
|
message GetMobilityConfigResponse {
|
||||||
map<string, ConfigOption> config = 1;
|
map<string, common.ConfigOption> config = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetMobilityConfigRequest {
|
message SetMobilityConfigRequest {
|
||||||
|
@ -633,7 +634,7 @@ message GetWlanConfigRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetWlanConfigResponse {
|
message GetWlanConfigResponse {
|
||||||
map<string, ConfigOption> config = 1;
|
map<string, common.ConfigOption> config = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetWlanConfigRequest {
|
message SetWlanConfigRequest {
|
||||||
|
@ -650,7 +651,7 @@ message GetEmaneConfigRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetEmaneConfigResponse {
|
message GetEmaneConfigResponse {
|
||||||
map<string, ConfigOption> config = 1;
|
map<string, common.ConfigOption> config = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetEmaneConfigRequest {
|
message SetEmaneConfigRequest {
|
||||||
|
@ -678,7 +679,7 @@ message GetEmaneModelConfigRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetEmaneModelConfigResponse {
|
message GetEmaneModelConfigResponse {
|
||||||
map<string, ConfigOption> config = 1;
|
map<string, common.ConfigOption> config = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetEmaneModelConfigRequest {
|
message SetEmaneModelConfigRequest {
|
||||||
|
@ -699,7 +700,7 @@ message GetEmaneModelConfigsResponse {
|
||||||
int32 node_id = 1;
|
int32 node_id = 1;
|
||||||
string model = 2;
|
string model = 2;
|
||||||
int32 interface = 3;
|
int32 interface = 3;
|
||||||
map<string, ConfigOption> config = 4;
|
map<string, common.ConfigOption> config = 4;
|
||||||
}
|
}
|
||||||
repeated ModelConfig configs = 1;
|
repeated ModelConfig configs = 1;
|
||||||
}
|
}
|
||||||
|
@ -917,16 +918,7 @@ message NodeServiceData {
|
||||||
}
|
}
|
||||||
|
|
||||||
message MappedConfig {
|
message MappedConfig {
|
||||||
map<string, ConfigOption> config = 1;
|
map<string, common.ConfigOption> config = 1;
|
||||||
}
|
|
||||||
|
|
||||||
message ConfigOption {
|
|
||||||
string label = 1;
|
|
||||||
string name = 2;
|
|
||||||
string value = 3;
|
|
||||||
int32 type = 4;
|
|
||||||
repeated string select = 5;
|
|
||||||
string group = 6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Session {
|
message Session {
|
||||||
|
|
Loading…
Reference in a new issue