grpc: combined get services and get config services into new get config call, that can be used to get all daemon configuration information
This commit is contained in:
parent
42dc56c56b
commit
8108db545a
8 changed files with 66 additions and 115 deletions
|
@ -23,10 +23,9 @@ from core.api.grpc import (
|
|||
)
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
GetConfigServiceDefaultsRequest,
|
||||
GetConfigServicesRequest,
|
||||
GetNodeConfigServiceRequest,
|
||||
)
|
||||
from core.api.grpc.core_pb2 import ExecuteScriptRequest
|
||||
from core.api.grpc.core_pb2 import ExecuteScriptRequest, GetConfigRequest
|
||||
from core.api.grpc.emane_pb2 import (
|
||||
EmaneLinkRequest,
|
||||
GetEmaneConfigRequest,
|
||||
|
@ -46,7 +45,6 @@ from core.api.grpc.services_pb2 import (
|
|||
GetNodeServiceFileRequest,
|
||||
GetNodeServiceRequest,
|
||||
GetServiceDefaultsRequest,
|
||||
GetServicesRequest,
|
||||
ServiceActionRequest,
|
||||
ServiceDefaults,
|
||||
SetServiceDefaultsRequest,
|
||||
|
@ -814,19 +812,15 @@ class CoreGrpcClient:
|
|||
response = self.stub.MobilityAction(request)
|
||||
return response.result
|
||||
|
||||
def get_services(self) -> List[wrappers.Service]:
|
||||
def get_config(self) -> wrappers.CoreConfig:
|
||||
"""
|
||||
Get all currently loaded services.
|
||||
Retrieve the current core configuration values.
|
||||
|
||||
:return: list of services, name and groups only
|
||||
:return: core configuration
|
||||
"""
|
||||
request = GetServicesRequest()
|
||||
response = self.stub.GetServices(request)
|
||||
services = []
|
||||
for service_proto in response.services:
|
||||
service = wrappers.Service.from_proto(service_proto)
|
||||
services.append(service)
|
||||
return services
|
||||
request = GetConfigRequest()
|
||||
response = self.stub.GetConfig(request)
|
||||
return wrappers.CoreConfig.from_proto(response)
|
||||
|
||||
def get_service_defaults(self, session_id: int) -> List[wrappers.ServiceDefault]:
|
||||
"""
|
||||
|
@ -1086,20 +1080,6 @@ class CoreGrpcClient:
|
|||
response = self.stub.GetInterfaces(request)
|
||||
return list(response.ifaces)
|
||||
|
||||
def get_config_services(self) -> List[wrappers.ConfigService]:
|
||||
"""
|
||||
Retrieve all known config services.
|
||||
|
||||
:return: list of config services
|
||||
"""
|
||||
request = GetConfigServicesRequest()
|
||||
response = self.stub.GetConfigServices(request)
|
||||
services = []
|
||||
for service_proto in response.services:
|
||||
service = wrappers.ConfigService.from_proto(service_proto)
|
||||
services.append(service)
|
||||
return services
|
||||
|
||||
def get_config_service_defaults(self, name: str) -> wrappers.ConfigServiceDefaults:
|
||||
"""
|
||||
Retrieves config service default values.
|
||||
|
|
|
@ -24,8 +24,6 @@ from core.api.grpc.configservices_pb2 import (
|
|||
ConfigService,
|
||||
GetConfigServiceDefaultsRequest,
|
||||
GetConfigServiceDefaultsResponse,
|
||||
GetConfigServicesRequest,
|
||||
GetConfigServicesResponse,
|
||||
GetNodeConfigServiceRequest,
|
||||
GetNodeConfigServiceResponse,
|
||||
)
|
||||
|
@ -66,8 +64,6 @@ from core.api.grpc.services_pb2 import (
|
|||
GetNodeServiceResponse,
|
||||
GetServiceDefaultsRequest,
|
||||
GetServiceDefaultsResponse,
|
||||
GetServicesRequest,
|
||||
GetServicesResponse,
|
||||
Service,
|
||||
ServiceAction,
|
||||
ServiceActionRequest,
|
||||
|
@ -190,6 +186,35 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
context.abort(grpc.StatusCode.NOT_FOUND, f"unknown service {name}")
|
||||
return service
|
||||
|
||||
def GetConfig(
|
||||
self, request: core_pb2.GetConfigRequest, context: ServicerContext
|
||||
) -> core_pb2.GetConfigResponse:
|
||||
services = []
|
||||
for name in ServiceManager.services:
|
||||
service = ServiceManager.services[name]
|
||||
service_proto = Service(group=service.group, name=service.name)
|
||||
services.append(service_proto)
|
||||
config_services = []
|
||||
for service in self.coreemu.service_manager.services.values():
|
||||
service_proto = ConfigService(
|
||||
name=service.name,
|
||||
group=service.group,
|
||||
executables=service.executables,
|
||||
dependencies=service.dependencies,
|
||||
directories=service.directories,
|
||||
files=service.files,
|
||||
startup=service.startup,
|
||||
validate=service.validate,
|
||||
shutdown=service.shutdown,
|
||||
validation_mode=service.validation_mode.value,
|
||||
validation_timer=service.validation_timer,
|
||||
validation_period=service.validation_period,
|
||||
)
|
||||
config_services.append(service_proto)
|
||||
return core_pb2.GetConfigResponse(
|
||||
services=services, config_services=config_services
|
||||
)
|
||||
|
||||
def StartSession(
|
||||
self, request: core_pb2.StartSessionRequest, context: ServicerContext
|
||||
) -> core_pb2.StartSessionResponse:
|
||||
|
@ -954,24 +979,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
result = False
|
||||
return MobilityActionResponse(result=result)
|
||||
|
||||
def GetServices(
|
||||
self, request: GetServicesRequest, context: ServicerContext
|
||||
) -> GetServicesResponse:
|
||||
"""
|
||||
Retrieve all the services that are running
|
||||
|
||||
:param request: get-service request
|
||||
:param context: context object
|
||||
:return: get-services response
|
||||
"""
|
||||
logger.debug("get services: %s", request)
|
||||
services = []
|
||||
for name in ServiceManager.services:
|
||||
service = ServiceManager.services[name]
|
||||
service_proto = Service(group=service.group, name=service.name)
|
||||
services.append(service_proto)
|
||||
return GetServicesResponse(services=services)
|
||||
|
||||
def GetServiceDefaults(
|
||||
self, request: GetServiceDefaultsRequest, context: ServicerContext
|
||||
) -> GetServiceDefaultsResponse:
|
||||
|
@ -1318,35 +1325,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
else:
|
||||
return EmaneLinkResponse(result=False)
|
||||
|
||||
def GetConfigServices(
|
||||
self, request: GetConfigServicesRequest, context: ServicerContext
|
||||
) -> GetConfigServicesResponse:
|
||||
"""
|
||||
Gets all currently known configuration services.
|
||||
|
||||
:param request: get config services request
|
||||
:param context: grpc context
|
||||
:return: get config services response
|
||||
"""
|
||||
services = []
|
||||
for service in self.coreemu.service_manager.services.values():
|
||||
service_proto = ConfigService(
|
||||
name=service.name,
|
||||
group=service.group,
|
||||
executables=service.executables,
|
||||
dependencies=service.dependencies,
|
||||
directories=service.directories,
|
||||
files=service.files,
|
||||
startup=service.startup,
|
||||
validate=service.validate,
|
||||
shutdown=service.shutdown,
|
||||
validation_mode=service.validation_mode.value,
|
||||
validation_timer=service.validation_timer,
|
||||
validation_period=service.validation_period,
|
||||
)
|
||||
services.append(service_proto)
|
||||
return GetConfigServicesResponse(services=services)
|
||||
|
||||
def GetNodeConfigService(
|
||||
self, request: GetNodeConfigServiceRequest, context: ServicerContext
|
||||
) -> GetNodeConfigServiceResponse:
|
||||
|
|
|
@ -175,7 +175,7 @@ class ConfigServiceDefaults:
|
|||
|
||||
@classmethod
|
||||
def from_proto(
|
||||
cls, proto: configservices_pb2.GetConfigServicesResponse
|
||||
cls, proto: configservices_pb2.GetConfigServiceDefaultsResponse
|
||||
) -> "ConfigServiceDefaults":
|
||||
config = ConfigOption.from_dict(proto.config)
|
||||
modes = {x.name: dict(x.config) for x in proto.modes}
|
||||
|
@ -886,6 +886,18 @@ class Session:
|
|||
self.options[key] = option
|
||||
|
||||
|
||||
@dataclass
|
||||
class CoreConfig:
|
||||
services: List[Service] = field(default_factory=list)
|
||||
config_services: List[ConfigService] = field(default_factory=list)
|
||||
|
||||
@classmethod
|
||||
def from_proto(cls, proto: core_pb2.GetConfigResponse) -> "CoreConfig":
|
||||
services = [Service.from_proto(x) for x in proto.services]
|
||||
config_services = [ConfigService.from_proto(x) for x in proto.config_services]
|
||||
return CoreConfig(services=services, config_services=config_services)
|
||||
|
||||
|
||||
@dataclass
|
||||
class LinkEvent:
|
||||
message_type: MessageType
|
||||
|
|
|
@ -389,12 +389,12 @@ class CoreClient:
|
|||
"""
|
||||
try:
|
||||
self.client.connect()
|
||||
# get all available services
|
||||
for service in self.client.get_services():
|
||||
# get current core configurations services/config services
|
||||
core_config = self.client.get_config()
|
||||
for service in core_config.services:
|
||||
group_services = self.services.setdefault(service.group, set())
|
||||
group_services.add(service.name)
|
||||
# get config service informations
|
||||
for service in self.client.get_config_services():
|
||||
for service in core_config.config_services:
|
||||
self.config_services[service.name] = service
|
||||
group_services = self.config_services_groups.setdefault(
|
||||
service.group, set()
|
||||
|
|
|
@ -39,14 +39,6 @@ message ConfigMode {
|
|||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message GetConfigServicesRequest {
|
||||
int32 session_id = 1;
|
||||
}
|
||||
|
||||
message GetConfigServicesResponse {
|
||||
repeated ConfigService services = 1;
|
||||
}
|
||||
|
||||
message GetConfigServiceDefaultsRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ service CoreApi {
|
|||
}
|
||||
|
||||
// service rpc
|
||||
rpc GetServiceDefaults (services.GetServiceDefaultsRequest) returns (services.GetServiceDefaultsResponse) {
|
||||
}
|
||||
rpc SetServiceDefaults (services.SetServiceDefaultsRequest) returns (services.SetServiceDefaultsResponse) {
|
||||
}
|
||||
rpc GetNodeService (services.GetNodeServiceRequest) returns (services.GetNodeServiceResponse) {
|
||||
|
@ -127,15 +129,21 @@ service CoreApi {
|
|||
// globals
|
||||
rpc GetEmaneModels (emane.GetEmaneModelsRequest) returns (emane.GetEmaneModelsResponse) {
|
||||
}
|
||||
rpc GetConfigServices (configservices.GetConfigServicesRequest) returns (configservices.GetConfigServicesResponse) {
|
||||
}
|
||||
rpc GetServices (services.GetServicesRequest) returns (services.GetServicesResponse) {
|
||||
}
|
||||
rpc GetServiceDefaults (services.GetServiceDefaultsRequest) returns (services.GetServiceDefaultsResponse) {
|
||||
rpc GetConfig (GetConfigRequest) returns (GetConfigResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
// rpc request/response messages
|
||||
message GetConfigRequest {
|
||||
}
|
||||
|
||||
message GetConfigResponse {
|
||||
repeated services.Service services = 1;
|
||||
repeated configservices.ConfigService config_services = 2;
|
||||
repeated string emane_models = 3;
|
||||
}
|
||||
|
||||
|
||||
message StartSessionRequest {
|
||||
int32 session_id = 1;
|
||||
repeated Node nodes = 2;
|
||||
|
|
|
@ -66,14 +66,6 @@ message NodeServiceConfig {
|
|||
map<string, string> files = 4;
|
||||
}
|
||||
|
||||
message GetServicesRequest {
|
||||
|
||||
}
|
||||
|
||||
message GetServicesResponse {
|
||||
repeated Service services = 1;
|
||||
}
|
||||
|
||||
message GetServiceDefaultsRequest {
|
||||
int32 session_id = 1;
|
||||
}
|
||||
|
|
|
@ -670,17 +670,6 @@ class TestGrpcw:
|
|||
# then
|
||||
assert result is True
|
||||
|
||||
def test_get_services(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
services = client.get_services()
|
||||
|
||||
# then
|
||||
assert len(services) > 0
|
||||
|
||||
def test_get_service_defaults(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
|
|
Loading…
Reference in a new issue