updated config service grpc to return default templates and config, added logic to check for local custom templates
This commit is contained in:
parent
7b5df11dc7
commit
a4f3abf27c
7 changed files with 51 additions and 54 deletions
|
@ -13,10 +13,10 @@ import netaddr
|
|||
from core import utils
|
||||
from core.api.grpc import core_pb2, core_pb2_grpc
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
GetConfigServiceDefaultsRequest,
|
||||
GetConfigServiceDefaultsResponse,
|
||||
GetConfigServicesRequest,
|
||||
GetConfigServicesResponse,
|
||||
GetConfigServiceTemplatesRequest,
|
||||
GetConfigServiceTemplatesResponse,
|
||||
GetNodeConfigServiceRequest,
|
||||
GetNodeConfigServiceResponse,
|
||||
GetNodeConfigServicesRequest,
|
||||
|
@ -1094,11 +1094,11 @@ class CoreGrpcClient:
|
|||
request = GetConfigServicesRequest()
|
||||
return self.stub.GetConfigServices(request)
|
||||
|
||||
def get_config_service_templates(
|
||||
def get_config_service_defaults(
|
||||
self, name: str
|
||||
) -> GetConfigServiceTemplatesResponse:
|
||||
request = GetConfigServiceTemplatesRequest(name=name)
|
||||
return self.stub.GetConfigServiceTemplates(request)
|
||||
) -> GetConfigServiceDefaultsResponse:
|
||||
request = GetConfigServiceDefaultsRequest(name=name)
|
||||
return self.stub.GetConfigServiceDefaults(request)
|
||||
|
||||
def get_node_config_service(
|
||||
self, session_id: int, node_id: int, name: str
|
||||
|
|
|
@ -13,10 +13,10 @@ from grpc import ServicerContext
|
|||
from core.api.grpc import core_pb2, core_pb2_grpc, grpcutils
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
ConfigService,
|
||||
GetConfigServiceDefaultsRequest,
|
||||
GetConfigServiceDefaultsResponse,
|
||||
GetConfigServicesRequest,
|
||||
GetConfigServicesResponse,
|
||||
GetConfigServiceTemplatesRequest,
|
||||
GetConfigServiceTemplatesResponse,
|
||||
GetNodeConfigServiceRequest,
|
||||
GetNodeConfigServiceResponse,
|
||||
GetNodeConfigServicesRequest,
|
||||
|
@ -1482,20 +1482,20 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
self.validate_service(request.name, context)
|
||||
service = node.config_services.get(request.name)
|
||||
if service:
|
||||
config = service.get_config()
|
||||
|
||||
config = service.render_config()
|
||||
else:
|
||||
service = self.coreemu.service_manager.get_service(request.name)
|
||||
config = {x.id: x.default for x in service.default_configs}
|
||||
return GetNodeConfigServiceResponse(config=config)
|
||||
|
||||
def GetConfigServiceTemplates(
|
||||
self, request: GetConfigServiceTemplatesRequest, context: ServicerContext
|
||||
) -> GetConfigServiceTemplatesResponse:
|
||||
def GetConfigServiceDefaults(
|
||||
self, request: GetConfigServiceDefaultsRequest, context: ServicerContext
|
||||
) -> GetConfigServiceDefaultsResponse:
|
||||
service_class = self.validate_service(request.name, context)
|
||||
service = service_class(None)
|
||||
templates = service.get_templates()
|
||||
return GetConfigServiceTemplatesResponse(templates=templates)
|
||||
config = service.render_config()
|
||||
return GetConfigServiceDefaultsResponse(templates=templates, config=config)
|
||||
|
||||
def GetNodeConfigServices(
|
||||
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
||||
|
|
|
@ -37,6 +37,7 @@ class ConfigService(abc.ABC):
|
|||
logging.info(templates_path)
|
||||
self.templates = TemplateLookup(directories=templates_path)
|
||||
self.config = {}
|
||||
self.custom_templates = {}
|
||||
configs = self.default_configs[:]
|
||||
self._define_config(configs)
|
||||
|
||||
|
@ -128,6 +129,9 @@ class ConfigService(abc.ABC):
|
|||
def data(self) -> Dict[str, Any]:
|
||||
return {}
|
||||
|
||||
def custom_template(self, name: str, template: str) -> None:
|
||||
self.custom_templates[name] = template
|
||||
|
||||
def get_text(self, name: str) -> str:
|
||||
raise CoreError(
|
||||
f"node({self.node.name} service({self.name}) unknown template({name})"
|
||||
|
@ -136,7 +140,10 @@ class ConfigService(abc.ABC):
|
|||
def get_templates(self) -> Dict[str, str]:
|
||||
templates = {}
|
||||
for name in self.files:
|
||||
if self.templates.has_template(name):
|
||||
if name in self.custom_templates:
|
||||
template = self.custom_templates[name]
|
||||
template = inspect.cleandoc(template)
|
||||
elif self.templates.has_template(name):
|
||||
template = self.templates.get_template(name).source
|
||||
else:
|
||||
template = self.get_text(name)
|
||||
|
@ -147,7 +154,11 @@ class ConfigService(abc.ABC):
|
|||
def create_files(self) -> None:
|
||||
data = self.data()
|
||||
for name in self.files:
|
||||
if self.templates.has_template(name):
|
||||
if name in self.custom_templates:
|
||||
text = self.custom_templates[name]
|
||||
text = inspect.cleandoc(text)
|
||||
self.render_text(name, text, data)
|
||||
elif self.templates.has_template(name):
|
||||
self.render_template(name, data)
|
||||
else:
|
||||
text = self.get_text(name)
|
||||
|
|
|
@ -90,6 +90,7 @@ class CoreClient:
|
|||
self.emane_model_configs = {}
|
||||
self.emane_config = None
|
||||
self.service_configs = {}
|
||||
self.config_service_configs = {}
|
||||
self.file_configs = {}
|
||||
self.mobility_players = {}
|
||||
self.handling_throughputs = None
|
||||
|
|
|
@ -30,8 +30,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.core = app.core
|
||||
self.node_id = node_id
|
||||
self.service_name = service_name
|
||||
self.service_configs = app.core.service_configs
|
||||
self.file_configs = app.core.file_configs
|
||||
self.service_configs = app.core.config_service_configs
|
||||
|
||||
self.radiovar = tk.IntVar()
|
||||
self.radiovar.set(2)
|
||||
|
@ -68,41 +67,26 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
def load(self):
|
||||
try:
|
||||
self.app.core.create_nodes_and_links()
|
||||
# default_config = self.app.core.get_node_service(
|
||||
# self.node_id, self.service_name
|
||||
# )
|
||||
# self.default_startup = default_config.startup[:]
|
||||
# self.default_validate = default_config.validate[:]
|
||||
# self.default_shutdown = default_config.shutdown[:]
|
||||
# custom_configs = self.service_configs
|
||||
# if (
|
||||
# self.node_id in custom_configs
|
||||
# and self.service_name in custom_configs[self.node_id]
|
||||
# ):
|
||||
# service_config = custom_configs[self.node_id][self.service_name]
|
||||
# else:
|
||||
# service_config = default_config
|
||||
service = self.core.config_services[self.service_name]
|
||||
self.dependencies = service.dependencies[:]
|
||||
self.executables = service.executables[:]
|
||||
self.filenames = service.files[:]
|
||||
self.startup_commands = service.startup[:]
|
||||
self.validation_commands = service.validate[:]
|
||||
self.shutdown_commands = service.shutdown[:]
|
||||
self.validation_mode = service.validation_mode
|
||||
self.validation_time = service.validation_timer
|
||||
self.validation_period.set(service.validation_period)
|
||||
|
||||
service_config = self.core.config_services[self.service_name]
|
||||
self.dependencies = service_config.dependencies[:]
|
||||
self.executables = service_config.executables[:]
|
||||
self.filenames = service_config.files[:]
|
||||
self.startup_commands = service_config.startup[:]
|
||||
self.validation_commands = service_config.validate[:]
|
||||
self.shutdown_commands = service_config.shutdown[:]
|
||||
self.validation_mode = service_config.validation_mode
|
||||
self.validation_time = service_config.validation_timer
|
||||
self.validation_period.set(service_config.validation_period)
|
||||
response = self.core.client.get_config_service_templates(self.service_name)
|
||||
response = self.core.client.get_config_service_defaults(self.service_name)
|
||||
self.original_service_files = response.templates
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
file_configs = self.file_configs
|
||||
if (
|
||||
self.node_id in file_configs
|
||||
and self.service_name in file_configs[self.node_id]
|
||||
):
|
||||
for file, data in file_configs[self.node_id][self.service_name].items():
|
||||
self.temp_service_files[file] = data
|
||||
|
||||
node_configs = self.service_configs.get(self.node_id, {})
|
||||
service_config = node_configs.get(self.service_name, {})
|
||||
custom_templates = service_config.get("templates", {})
|
||||
for file, data in custom_templates.items():
|
||||
self.temp_service_files[file] = data
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e)
|
||||
|
||||
|
@ -270,7 +254,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||
tab.grid(sticky="nsew")
|
||||
tab.columnconfigure(0, weight=1)
|
||||
self.notebook.add(tab, text="Configuration", sticky="nsew")
|
||||
self.notebook.add(tab, text="Validation", sticky="nsew")
|
||||
|
||||
frame = ttk.Frame(tab)
|
||||
frame.grid(sticky="ew", pady=PADY)
|
||||
|
|
|
@ -33,12 +33,13 @@ message GetConfigServicesResponse {
|
|||
repeated ConfigService services = 1;
|
||||
}
|
||||
|
||||
message GetConfigServiceTemplatesRequest {
|
||||
message GetConfigServiceDefaultsRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message GetConfigServiceTemplatesResponse {
|
||||
message GetConfigServiceDefaultsResponse {
|
||||
map<string, string> templates = 1;
|
||||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message GetNodeConfigServiceRequest {
|
||||
|
|
|
@ -107,7 +107,7 @@ service CoreApi {
|
|||
// config services
|
||||
rpc GetConfigServices (configservices.GetConfigServicesRequest) returns (configservices.GetConfigServicesResponse) {
|
||||
}
|
||||
rpc GetConfigServiceTemplates (configservices.GetConfigServiceTemplatesRequest) returns (configservices.GetConfigServiceTemplatesResponse) {
|
||||
rpc GetConfigServiceDefaults (configservices.GetConfigServiceDefaultsRequest) returns (configservices.GetConfigServiceDefaultsResponse) {
|
||||
}
|
||||
rpc GetNodeConfigService (configservices.GetNodeConfigServiceRequest) returns (configservices.GetNodeConfigServiceResponse) {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue