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 (
|
from core.api.grpc.configservices_pb2 import (
|
||||||
GetConfigServiceDefaultsRequest,
|
GetConfigServiceDefaultsRequest,
|
||||||
GetConfigServicesRequest,
|
|
||||||
GetNodeConfigServiceRequest,
|
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 (
|
from core.api.grpc.emane_pb2 import (
|
||||||
EmaneLinkRequest,
|
EmaneLinkRequest,
|
||||||
GetEmaneConfigRequest,
|
GetEmaneConfigRequest,
|
||||||
|
@ -46,7 +45,6 @@ from core.api.grpc.services_pb2 import (
|
||||||
GetNodeServiceFileRequest,
|
GetNodeServiceFileRequest,
|
||||||
GetNodeServiceRequest,
|
GetNodeServiceRequest,
|
||||||
GetServiceDefaultsRequest,
|
GetServiceDefaultsRequest,
|
||||||
GetServicesRequest,
|
|
||||||
ServiceActionRequest,
|
ServiceActionRequest,
|
||||||
ServiceDefaults,
|
ServiceDefaults,
|
||||||
SetServiceDefaultsRequest,
|
SetServiceDefaultsRequest,
|
||||||
|
@ -814,19 +812,15 @@ class CoreGrpcClient:
|
||||||
response = self.stub.MobilityAction(request)
|
response = self.stub.MobilityAction(request)
|
||||||
return response.result
|
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()
|
request = GetConfigRequest()
|
||||||
response = self.stub.GetServices(request)
|
response = self.stub.GetConfig(request)
|
||||||
services = []
|
return wrappers.CoreConfig.from_proto(response)
|
||||||
for service_proto in response.services:
|
|
||||||
service = wrappers.Service.from_proto(service_proto)
|
|
||||||
services.append(service)
|
|
||||||
return services
|
|
||||||
|
|
||||||
def get_service_defaults(self, session_id: int) -> List[wrappers.ServiceDefault]:
|
def get_service_defaults(self, session_id: int) -> List[wrappers.ServiceDefault]:
|
||||||
"""
|
"""
|
||||||
|
@ -1086,20 +1080,6 @@ class CoreGrpcClient:
|
||||||
response = self.stub.GetInterfaces(request)
|
response = self.stub.GetInterfaces(request)
|
||||||
return list(response.ifaces)
|
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:
|
def get_config_service_defaults(self, name: str) -> wrappers.ConfigServiceDefaults:
|
||||||
"""
|
"""
|
||||||
Retrieves config service default values.
|
Retrieves config service default values.
|
||||||
|
|
|
@ -24,8 +24,6 @@ from core.api.grpc.configservices_pb2 import (
|
||||||
ConfigService,
|
ConfigService,
|
||||||
GetConfigServiceDefaultsRequest,
|
GetConfigServiceDefaultsRequest,
|
||||||
GetConfigServiceDefaultsResponse,
|
GetConfigServiceDefaultsResponse,
|
||||||
GetConfigServicesRequest,
|
|
||||||
GetConfigServicesResponse,
|
|
||||||
GetNodeConfigServiceRequest,
|
GetNodeConfigServiceRequest,
|
||||||
GetNodeConfigServiceResponse,
|
GetNodeConfigServiceResponse,
|
||||||
)
|
)
|
||||||
|
@ -66,8 +64,6 @@ from core.api.grpc.services_pb2 import (
|
||||||
GetNodeServiceResponse,
|
GetNodeServiceResponse,
|
||||||
GetServiceDefaultsRequest,
|
GetServiceDefaultsRequest,
|
||||||
GetServiceDefaultsResponse,
|
GetServiceDefaultsResponse,
|
||||||
GetServicesRequest,
|
|
||||||
GetServicesResponse,
|
|
||||||
Service,
|
Service,
|
||||||
ServiceAction,
|
ServiceAction,
|
||||||
ServiceActionRequest,
|
ServiceActionRequest,
|
||||||
|
@ -190,6 +186,35 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
context.abort(grpc.StatusCode.NOT_FOUND, f"unknown service {name}")
|
context.abort(grpc.StatusCode.NOT_FOUND, f"unknown service {name}")
|
||||||
return service
|
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(
|
def StartSession(
|
||||||
self, request: core_pb2.StartSessionRequest, context: ServicerContext
|
self, request: core_pb2.StartSessionRequest, context: ServicerContext
|
||||||
) -> core_pb2.StartSessionResponse:
|
) -> core_pb2.StartSessionResponse:
|
||||||
|
@ -954,24 +979,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
result = False
|
result = False
|
||||||
return MobilityActionResponse(result=result)
|
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(
|
def GetServiceDefaults(
|
||||||
self, request: GetServiceDefaultsRequest, context: ServicerContext
|
self, request: GetServiceDefaultsRequest, context: ServicerContext
|
||||||
) -> GetServiceDefaultsResponse:
|
) -> GetServiceDefaultsResponse:
|
||||||
|
@ -1318,35 +1325,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
else:
|
else:
|
||||||
return EmaneLinkResponse(result=False)
|
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(
|
def GetNodeConfigService(
|
||||||
self, request: GetNodeConfigServiceRequest, context: ServicerContext
|
self, request: GetNodeConfigServiceRequest, context: ServicerContext
|
||||||
) -> GetNodeConfigServiceResponse:
|
) -> GetNodeConfigServiceResponse:
|
||||||
|
|
|
@ -175,7 +175,7 @@ class ConfigServiceDefaults:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_proto(
|
def from_proto(
|
||||||
cls, proto: configservices_pb2.GetConfigServicesResponse
|
cls, proto: configservices_pb2.GetConfigServiceDefaultsResponse
|
||||||
) -> "ConfigServiceDefaults":
|
) -> "ConfigServiceDefaults":
|
||||||
config = ConfigOption.from_dict(proto.config)
|
config = ConfigOption.from_dict(proto.config)
|
||||||
modes = {x.name: dict(x.config) for x in proto.modes}
|
modes = {x.name: dict(x.config) for x in proto.modes}
|
||||||
|
@ -886,6 +886,18 @@ class Session:
|
||||||
self.options[key] = option
|
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
|
@dataclass
|
||||||
class LinkEvent:
|
class LinkEvent:
|
||||||
message_type: MessageType
|
message_type: MessageType
|
||||||
|
|
|
@ -389,12 +389,12 @@ class CoreClient:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.client.connect()
|
self.client.connect()
|
||||||
# get all available services
|
# get current core configurations services/config services
|
||||||
for service in self.client.get_services():
|
core_config = self.client.get_config()
|
||||||
|
for service in core_config.services:
|
||||||
group_services = self.services.setdefault(service.group, set())
|
group_services = self.services.setdefault(service.group, set())
|
||||||
group_services.add(service.name)
|
group_services.add(service.name)
|
||||||
# get config service informations
|
for service in core_config.config_services:
|
||||||
for service in self.client.get_config_services():
|
|
||||||
self.config_services[service.name] = service
|
self.config_services[service.name] = service
|
||||||
group_services = self.config_services_groups.setdefault(
|
group_services = self.config_services_groups.setdefault(
|
||||||
service.group, set()
|
service.group, set()
|
||||||
|
|
|
@ -39,14 +39,6 @@ message ConfigMode {
|
||||||
map<string, string> config = 2;
|
map<string, string> config = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetConfigServicesRequest {
|
|
||||||
int32 session_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetConfigServicesResponse {
|
|
||||||
repeated ConfigService services = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetConfigServiceDefaultsRequest {
|
message GetConfigServiceDefaultsRequest {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ service CoreApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// service rpc
|
// service rpc
|
||||||
|
rpc GetServiceDefaults (services.GetServiceDefaultsRequest) returns (services.GetServiceDefaultsResponse) {
|
||||||
|
}
|
||||||
rpc SetServiceDefaults (services.SetServiceDefaultsRequest) returns (services.SetServiceDefaultsResponse) {
|
rpc SetServiceDefaults (services.SetServiceDefaultsRequest) returns (services.SetServiceDefaultsResponse) {
|
||||||
}
|
}
|
||||||
rpc GetNodeService (services.GetNodeServiceRequest) returns (services.GetNodeServiceResponse) {
|
rpc GetNodeService (services.GetNodeServiceRequest) returns (services.GetNodeServiceResponse) {
|
||||||
|
@ -127,15 +129,21 @@ service CoreApi {
|
||||||
// globals
|
// globals
|
||||||
rpc GetEmaneModels (emane.GetEmaneModelsRequest) returns (emane.GetEmaneModelsResponse) {
|
rpc GetEmaneModels (emane.GetEmaneModelsRequest) returns (emane.GetEmaneModelsResponse) {
|
||||||
}
|
}
|
||||||
rpc GetConfigServices (configservices.GetConfigServicesRequest) returns (configservices.GetConfigServicesResponse) {
|
rpc GetConfig (GetConfigRequest) returns (GetConfigResponse) {
|
||||||
}
|
|
||||||
rpc GetServices (services.GetServicesRequest) returns (services.GetServicesResponse) {
|
|
||||||
}
|
|
||||||
rpc GetServiceDefaults (services.GetServiceDefaultsRequest) returns (services.GetServiceDefaultsResponse) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rpc request/response messages
|
// 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 {
|
message StartSessionRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
repeated Node nodes = 2;
|
repeated Node nodes = 2;
|
||||||
|
|
|
@ -66,14 +66,6 @@ message NodeServiceConfig {
|
||||||
map<string, string> files = 4;
|
map<string, string> files = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetServicesRequest {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetServicesResponse {
|
|
||||||
repeated Service services = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetServiceDefaultsRequest {
|
message GetServiceDefaultsRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -670,17 +670,6 @@ class TestGrpcw:
|
||||||
# then
|
# then
|
||||||
assert result is True
|
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):
|
def test_get_service_defaults(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
|
Loading…
Reference in a new issue