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
|
import grpc
|
||||||
from grpc import ServicerContext
|
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 (
|
from core.api.grpc.configservices_pb2 import (
|
||||||
ConfigService,
|
ConfigService,
|
||||||
GetConfigServiceDefaultsRequest,
|
GetConfigServiceDefaultsRequest,
|
||||||
|
@ -1514,7 +1520,13 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
group="Settings",
|
group="Settings",
|
||||||
)
|
)
|
||||||
config[configuration.id] = config_option
|
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(
|
def GetNodeConfigServices(
|
||||||
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
||||||
|
|
|
@ -66,6 +66,11 @@ class ConfigService(abc.ABC):
|
||||||
def default_configs(self) -> List[Configuration]:
|
def default_configs(self) -> List[Configuration]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abc.abstractmethod
|
||||||
|
def modes(self) -> Dict[str, Dict[str, str]]:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def executables(self) -> List[str]:
|
def executables(self) -> List[str]:
|
||||||
|
|
|
@ -15,3 +15,4 @@ class VpnClient(ConfigService):
|
||||||
shutdown = ["killall openvpn"]
|
shutdown = ["killall openvpn"]
|
||||||
validation_mode = ConfigServiceMode.BLOCKING
|
validation_mode = ConfigServiceMode.BLOCKING
|
||||||
default_configs = []
|
default_configs = []
|
||||||
|
modes = {}
|
||||||
|
|
|
@ -20,6 +20,7 @@ class DefaultRoute(ConfigService):
|
||||||
shutdown = []
|
shutdown = []
|
||||||
validation_mode = ConfigServiceMode.BLOCKING
|
validation_mode = ConfigServiceMode.BLOCKING
|
||||||
default_configs = []
|
default_configs = []
|
||||||
|
modes = {}
|
||||||
|
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
addresses = []
|
addresses = []
|
||||||
|
@ -45,6 +46,7 @@ class IpForwardService(ConfigService):
|
||||||
shutdown = []
|
shutdown = []
|
||||||
validation_mode = ConfigServiceMode.BLOCKING
|
validation_mode = ConfigServiceMode.BLOCKING
|
||||||
default_configs = []
|
default_configs = []
|
||||||
|
modes = {}
|
||||||
|
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
devnames = []
|
devnames = []
|
||||||
|
|
|
@ -19,6 +19,11 @@ class SimpleService(ConfigService):
|
||||||
Configuration(_id="value2", _type=ConfigDataTypes.STRING, label="Value 2"),
|
Configuration(_id="value2", _type=ConfigDataTypes.STRING, label="Value 2"),
|
||||||
Configuration(_id="value3", _type=ConfigDataTypes.STRING, label="Value 3"),
|
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:
|
def get_text(self, name: str) -> str:
|
||||||
if name == "test1.sh":
|
if name == "test1.sh":
|
||||||
|
|
|
@ -11,7 +11,6 @@ import grpc
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from core.gui.dialogs.dialog import Dialog
|
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.themes import FRAME_PAD, PADX, PADY
|
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||||
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||||
|
|
||||||
|
@ -47,11 +46,12 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
self.validation_mode = None
|
self.validation_mode = None
|
||||||
self.validation_time = None
|
self.validation_time = None
|
||||||
self.validation_period = tk.StringVar()
|
self.validation_period = tk.StringVar()
|
||||||
self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16)
|
self.modes = []
|
||||||
self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16)
|
self.mode_configs = {}
|
||||||
|
|
||||||
self.notebook = None
|
self.notebook = None
|
||||||
self.templates_combobox = None
|
self.templates_combobox = None
|
||||||
|
self.modes_combobox = None
|
||||||
self.startup_commands_listbox = None
|
self.startup_commands_listbox = None
|
||||||
self.shutdown_commands_listbox = None
|
self.shutdown_commands_listbox = None
|
||||||
self.validate_commands_listbox = None
|
self.validate_commands_listbox = None
|
||||||
|
@ -87,6 +87,9 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
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.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, {})
|
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, {})
|
||||||
|
|
||||||
|
@ -166,10 +169,24 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
tab.grid(sticky="nsew")
|
tab.grid(sticky="nsew")
|
||||||
tab.columnconfigure(0, weight=1)
|
tab.columnconfigure(0, weight=1)
|
||||||
self.notebook.add(tab, text="Configuration")
|
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)
|
logging.info("config service config: %s", self.config)
|
||||||
self.config_frame = ConfigFrame(tab, self.app, self.config)
|
self.config_frame = ConfigFrame(tab, self.app, self.config)
|
||||||
self.config_frame.draw_config()
|
self.config_frame.draw_config()
|
||||||
self.config_frame.grid(sticky="nsew", pady=PADY)
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
||||||
|
tab.rowconfigure(self.config_frame.grid_info()["row"], weight=1)
|
||||||
|
|
||||||
def draw_tab_startstop(self):
|
def draw_tab_startstop(self):
|
||||||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
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.delete(1.0, "end")
|
||||||
self.template_text.text.insert("end", self.temp_service_files[template])
|
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):
|
def update_template_file_data(self, event: tk.Event):
|
||||||
scrolledtext = event.widget
|
scrolledtext = event.widget
|
||||||
template = self.templates_combobox.get()
|
template = self.templates_combobox.get()
|
||||||
|
@ -345,16 +368,8 @@ class ConfigServiceConfigDialog(Dialog):
|
||||||
self.template_text.text.delete(1.0, "end")
|
self.template_text.text.delete(1.0, "end")
|
||||||
self.template_text.text.insert("end", self.temp_service_files[filename])
|
self.template_text.text.insert("end", self.temp_service_files[filename])
|
||||||
if self.config_frame:
|
if self.config_frame:
|
||||||
self.config_frame.set_values(self.default_config)
|
defaults = {x.id: x.value for x in self.default_config.values()}
|
||||||
self.startup_commands_listbox.delete(0, tk.END)
|
self.config_frame.set_values(defaults)
|
||||||
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)
|
|
||||||
|
|
||||||
def click_copy(self):
|
def click_copy(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -184,10 +184,10 @@ class ConfigFrame(ttk.Notebook):
|
||||||
|
|
||||||
return {x: self.config[x].value for x in self.config}
|
return {x: self.config[x].value for x in self.config}
|
||||||
|
|
||||||
def set_values(self, config: Dict[str, common_pb2.ConfigOption]) -> None:
|
def set_values(self, config: Dict[str, str]) -> None:
|
||||||
for name, option in config.items():
|
for name, data in config.items():
|
||||||
value = self.values[name]
|
value = self.values[name]
|
||||||
value.set(option.value)
|
value.set(data)
|
||||||
|
|
||||||
|
|
||||||
class ListboxScroll(ttk.Frame):
|
class ListboxScroll(ttk.Frame):
|
||||||
|
|
|
@ -34,6 +34,11 @@ message ConfigService {
|
||||||
float validation_period = 12;
|
float validation_period = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ConfigMode {
|
||||||
|
string name = 1;
|
||||||
|
map<string, string> config = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message GetConfigServicesRequest {
|
message GetConfigServicesRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +54,7 @@ message GetConfigServiceDefaultsRequest {
|
||||||
message GetConfigServiceDefaultsResponse {
|
message GetConfigServiceDefaultsResponse {
|
||||||
map<string, string> templates = 1;
|
map<string, string> templates = 1;
|
||||||
map<string, common.ConfigOption> config = 2;
|
map<string, common.ConfigOption> config = 2;
|
||||||
|
repeated ConfigMode modes = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetNodeConfigServiceRequest {
|
message GetNodeConfigServiceRequest {
|
||||||
|
|
Loading…
Add table
Reference in a new issue