added modes to config services that allows them to decide sets of configurations
This commit is contained in:
parent
1ca3b0e3f4
commit
0ea2f73a80
8 changed files with 64 additions and 18 deletions
|
@ -10,7 +10,13 @@ from typing import Type
|
|||
import grpc
|
||||
from grpc import ServicerContext
|
||||
|
||||
from core.api.grpc import common_pb2, core_pb2, core_pb2_grpc, grpcutils
|
||||
from core.api.grpc import (
|
||||
common_pb2,
|
||||
configservices_pb2,
|
||||
core_pb2,
|
||||
core_pb2_grpc,
|
||||
grpcutils,
|
||||
)
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
ConfigService,
|
||||
GetConfigServiceDefaultsRequest,
|
||||
|
@ -1514,7 +1520,13 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
group="Settings",
|
||||
)
|
||||
config[configuration.id] = config_option
|
||||
return GetConfigServiceDefaultsResponse(templates=templates, config=config)
|
||||
modes = []
|
||||
for name, mode_config in service.modes.items():
|
||||
mode = configservices_pb2.ConfigMode(name=name, config=mode_config)
|
||||
modes.append(mode)
|
||||
return GetConfigServiceDefaultsResponse(
|
||||
templates=templates, config=config, modes=modes
|
||||
)
|
||||
|
||||
def GetNodeConfigServices(
|
||||
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
||||
|
|
|
@ -66,6 +66,11 @@ class ConfigService(abc.ABC):
|
|||
def default_configs(self) -> List[Configuration]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def modes(self) -> Dict[str, Dict[str, str]]:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def executables(self) -> List[str]:
|
||||
|
|
|
@ -15,3 +15,4 @@ class VpnClient(ConfigService):
|
|||
shutdown = ["killall openvpn"]
|
||||
validation_mode = ConfigServiceMode.BLOCKING
|
||||
default_configs = []
|
||||
modes = {}
|
||||
|
|
|
@ -20,6 +20,7 @@ class DefaultRoute(ConfigService):
|
|||
shutdown = []
|
||||
validation_mode = ConfigServiceMode.BLOCKING
|
||||
default_configs = []
|
||||
modes = {}
|
||||
|
||||
def data(self) -> Dict[str, Any]:
|
||||
addresses = []
|
||||
|
@ -45,6 +46,7 @@ class IpForwardService(ConfigService):
|
|||
shutdown = []
|
||||
validation_mode = ConfigServiceMode.BLOCKING
|
||||
default_configs = []
|
||||
modes = {}
|
||||
|
||||
def data(self) -> Dict[str, Any]:
|
||||
devnames = []
|
||||
|
|
|
@ -19,6 +19,11 @@ class SimpleService(ConfigService):
|
|||
Configuration(_id="value2", _type=ConfigDataTypes.STRING, label="Value 2"),
|
||||
Configuration(_id="value3", _type=ConfigDataTypes.STRING, label="Value 3"),
|
||||
]
|
||||
modes = {
|
||||
"mode1": {"value1": "m1", "value2": "m1", "value3": "m1"},
|
||||
"mode2": {"value1": "m2", "value2": "m2", "value3": "m2"},
|
||||
"mode3": {"value1": "m3", "value2": "m3", "value3": "m3"},
|
||||
}
|
||||
|
||||
def get_text(self, name: str) -> str:
|
||||
if name == "test1.sh":
|
||||
|
|
|
@ -11,7 +11,6 @@ import grpc
|
|||
from core.api.grpc import core_pb2
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||
|
||||
|
@ -47,11 +46,12 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.validation_mode = None
|
||||
self.validation_time = None
|
||||
self.validation_period = tk.StringVar()
|
||||
self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16)
|
||||
self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16)
|
||||
self.modes = []
|
||||
self.mode_configs = {}
|
||||
|
||||
self.notebook = None
|
||||
self.templates_combobox = None
|
||||
self.modes_combobox = None
|
||||
self.startup_commands_listbox = None
|
||||
self.shutdown_commands_listbox = None
|
||||
self.validate_commands_listbox = None
|
||||
|
@ -87,6 +87,9 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.original_service_files = response.templates
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
|
||||
self.modes = sorted(x.name for x in response.modes)
|
||||
self.mode_configs = {x.name: x.config for x in response.modes}
|
||||
|
||||
node_configs = self.service_configs.get(self.node_id, {})
|
||||
service_config = node_configs.get(self.service_name, {})
|
||||
|
||||
|
@ -166,10 +169,24 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
tab.grid(sticky="nsew")
|
||||
tab.columnconfigure(0, weight=1)
|
||||
self.notebook.add(tab, text="Configuration")
|
||||
|
||||
if self.modes:
|
||||
frame = ttk.Frame(tab)
|
||||
frame.grid(sticky="ew", pady=PADY)
|
||||
frame.columnconfigure(1, weight=1)
|
||||
label = ttk.Label(frame, text="Modes")
|
||||
label.grid(row=0, column=0, padx=PADX)
|
||||
self.modes_combobox = ttk.Combobox(
|
||||
frame, values=self.modes, state="readonly"
|
||||
)
|
||||
self.modes_combobox.bind("<<ComboboxSelected>>", self.handle_mode_changed)
|
||||
self.modes_combobox.grid(row=0, column=1, sticky="ew", pady=PADY)
|
||||
|
||||
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)
|
||||
tab.rowconfigure(self.config_frame.grid_info()["row"], weight=1)
|
||||
|
||||
def draw_tab_startstop(self):
|
||||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||
|
@ -314,6 +331,12 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.template_text.text.delete(1.0, "end")
|
||||
self.template_text.text.insert("end", self.temp_service_files[template])
|
||||
|
||||
def handle_mode_changed(self, event: tk.Event):
|
||||
mode = self.modes_combobox.get()
|
||||
config = self.mode_configs[mode]
|
||||
logging.info("mode config: %s", config)
|
||||
self.config_frame.set_values(config)
|
||||
|
||||
def update_template_file_data(self, event: tk.Event):
|
||||
scrolledtext = event.widget
|
||||
template = self.templates_combobox.get()
|
||||
|
@ -345,16 +368,8 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.template_text.text.delete(1.0, "end")
|
||||
self.template_text.text.insert("end", self.temp_service_files[filename])
|
||||
if self.config_frame:
|
||||
self.config_frame.set_values(self.default_config)
|
||||
self.startup_commands_listbox.delete(0, tk.END)
|
||||
self.validate_commands_listbox.delete(0, tk.END)
|
||||
self.shutdown_commands_listbox.delete(0, tk.END)
|
||||
for cmd in self.default_startup:
|
||||
self.startup_commands_listbox.insert(tk.END, cmd)
|
||||
for cmd in self.default_validate:
|
||||
self.validate_commands_listbox.insert(tk.END, cmd)
|
||||
for cmd in self.default_shutdown:
|
||||
self.shutdown_commands_listbox.insert(tk.END, cmd)
|
||||
defaults = {x.id: x.value for x in self.default_config.values()}
|
||||
self.config_frame.set_values(defaults)
|
||||
|
||||
def click_copy(self):
|
||||
pass
|
||||
|
|
|
@ -184,10 +184,10 @@ class ConfigFrame(ttk.Notebook):
|
|||
|
||||
return {x: self.config[x].value for x in self.config}
|
||||
|
||||
def set_values(self, config: Dict[str, common_pb2.ConfigOption]) -> None:
|
||||
for name, option in config.items():
|
||||
def set_values(self, config: Dict[str, str]) -> None:
|
||||
for name, data in config.items():
|
||||
value = self.values[name]
|
||||
value.set(option.value)
|
||||
value.set(data)
|
||||
|
||||
|
||||
class ListboxScroll(ttk.Frame):
|
||||
|
|
|
@ -34,6 +34,11 @@ message ConfigService {
|
|||
float validation_period = 12;
|
||||
}
|
||||
|
||||
message ConfigMode {
|
||||
string name = 1;
|
||||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message GetConfigServicesRequest {
|
||||
int32 session_id = 1;
|
||||
}
|
||||
|
@ -49,6 +54,7 @@ message GetConfigServiceDefaultsRequest {
|
|||
message GetConfigServiceDefaultsResponse {
|
||||
map<string, string> templates = 1;
|
||||
map<string, common.ConfigOption> config = 2;
|
||||
repeated ConfigMode modes = 3;
|
||||
}
|
||||
|
||||
message GetNodeConfigServiceRequest {
|
||||
|
|
Loading…
Add table
Reference in a new issue