added grpc to get current config services for a node
This commit is contained in:
parent
a7764214d2
commit
0e6d1535db
4 changed files with 59 additions and 30 deletions
|
@ -13,12 +13,14 @@ import netaddr
|
|||
from core import utils
|
||||
from core.api.grpc import core_pb2, core_pb2_grpc
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
GetConfigServiceRequest,
|
||||
GetConfigServiceResponse,
|
||||
GetConfigServicesRequest,
|
||||
GetConfigServicesResponse,
|
||||
SetConfigServiceRequest,
|
||||
SetConfigServiceResponse,
|
||||
GetNodeConfigServiceRequest,
|
||||
GetNodeConfigServiceResponse,
|
||||
GetNodeConfigServicesRequest,
|
||||
GetNodeConfigServicesResponse,
|
||||
SetNodeConfigServiceRequest,
|
||||
SetNodeConfigServiceResponse,
|
||||
)
|
||||
|
||||
|
||||
|
@ -1090,21 +1092,27 @@ class CoreGrpcClient:
|
|||
request = GetConfigServicesRequest()
|
||||
return self.stub.GetConfigServices(request)
|
||||
|
||||
def get_config_service(
|
||||
def get_node_config_service(
|
||||
self, session_id: int, node_id: int, name: str
|
||||
) -> GetConfigServiceResponse:
|
||||
request = GetConfigServiceRequest(
|
||||
) -> GetNodeConfigServiceResponse:
|
||||
request = GetNodeConfigServiceRequest(
|
||||
session_id=session_id, node_id=node_id, name=name
|
||||
)
|
||||
return self.stub.GetConfigService(request)
|
||||
return self.stub.GetNodeConfigService(request)
|
||||
|
||||
def set_config_service(
|
||||
def get_node_config_services(
|
||||
self, session_id: int, node_id: int
|
||||
) -> GetNodeConfigServicesResponse:
|
||||
request = GetNodeConfigServicesRequest(session_id=session_id, node_id=node_id)
|
||||
return self.stub.GetNodeConfigServices(request)
|
||||
|
||||
def set_node_config_service(
|
||||
self, session_id: int, node_id: int, name: str, config: Dict[str, str]
|
||||
) -> SetConfigServiceResponse:
|
||||
request = SetConfigServiceRequest(
|
||||
) -> SetNodeConfigServiceResponse:
|
||||
request = SetNodeConfigServiceRequest(
|
||||
session_id=session_id, node_id=node_id, name=name, config=config
|
||||
)
|
||||
return self.stub.SetConfigService(request)
|
||||
return self.stub.SetNodeConfigService(request)
|
||||
|
||||
def connect(self) -> None:
|
||||
"""
|
||||
|
|
|
@ -12,12 +12,14 @@ from grpc import ServicerContext
|
|||
from core.api.grpc import core_pb2, core_pb2_grpc, grpcutils
|
||||
from core.api.grpc.configservices_pb2 import (
|
||||
ConfigService,
|
||||
GetConfigServiceRequest,
|
||||
GetConfigServiceResponse,
|
||||
GetConfigServicesRequest,
|
||||
GetConfigServicesResponse,
|
||||
SetConfigServiceRequest,
|
||||
SetConfigServiceResponse,
|
||||
GetNodeConfigServiceRequest,
|
||||
GetNodeConfigServiceResponse,
|
||||
GetNodeConfigServicesRequest,
|
||||
GetNodeConfigServicesResponse,
|
||||
SetNodeConfigServiceRequest,
|
||||
SetNodeConfigServiceResponse,
|
||||
)
|
||||
from core.api.grpc.events import EventStreamer
|
||||
from core.api.grpc.grpcutils import (
|
||||
|
@ -1464,9 +1466,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
services.append(service_proto)
|
||||
return GetConfigServicesResponse(services=services)
|
||||
|
||||
def GetConfigService(
|
||||
self, request: GetConfigServiceRequest, context: ServicerContext
|
||||
) -> GetConfigServiceResponse:
|
||||
def GetNodeConfigService(
|
||||
self, request: GetNodeConfigServiceRequest, context: ServicerContext
|
||||
) -> GetNodeConfigServiceResponse:
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context)
|
||||
self.validate_service(request.name, context)
|
||||
|
@ -1477,18 +1479,26 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
else:
|
||||
service = self.coreemu.service_manager.get_service(request.name)
|
||||
config = {x.id: x.default for x in service.default_configs}
|
||||
return GetConfigServiceResponse(config=config)
|
||||
return GetNodeConfigServiceResponse(config=config)
|
||||
|
||||
def SetConfigService(
|
||||
self, request: SetConfigServiceRequest, context: ServicerContext
|
||||
) -> SetConfigServiceResponse:
|
||||
def GetNodeConfigServices(
|
||||
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
||||
) -> GetNodeConfigServicesResponse:
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context)
|
||||
services = node.config_services.keys()
|
||||
return GetNodeConfigServicesResponse(services=services)
|
||||
|
||||
def SetNodeConfigService(
|
||||
self, request: SetNodeConfigServiceRequest, context: ServicerContext
|
||||
) -> SetNodeConfigServiceResponse:
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context)
|
||||
self.validate_service(request.name, context)
|
||||
service = node.config_services.get(request.name)
|
||||
if service:
|
||||
service.set_config(request.config)
|
||||
return SetConfigServiceResponse(result=True)
|
||||
return SetNodeConfigServiceResponse(result=True)
|
||||
else:
|
||||
context.abort(
|
||||
grpc.StatusCode.NOT_FOUND,
|
||||
|
|
|
@ -32,23 +32,32 @@ message GetConfigServicesResponse {
|
|||
repeated ConfigService services = 1;
|
||||
}
|
||||
|
||||
message GetConfigServiceRequest {
|
||||
message GetNodeConfigServiceRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
string name = 3;
|
||||
}
|
||||
|
||||
message GetConfigServiceResponse {
|
||||
message GetNodeConfigServiceResponse {
|
||||
map<string, string> config = 1;
|
||||
}
|
||||
|
||||
message SetConfigServiceRequest {
|
||||
message GetNodeConfigServicesRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
}
|
||||
|
||||
message GetNodeConfigServicesResponse {
|
||||
repeated string services = 1;
|
||||
}
|
||||
|
||||
message SetNodeConfigServiceRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
string name = 3;
|
||||
map<string, string> config = 4;
|
||||
}
|
||||
|
||||
message SetConfigServiceResponse {
|
||||
message SetNodeConfigServiceResponse {
|
||||
bool result = 1;
|
||||
}
|
||||
|
|
|
@ -107,9 +107,11 @@ service CoreApi {
|
|||
// config services
|
||||
rpc GetConfigServices (configservices.GetConfigServicesRequest) returns (configservices.GetConfigServicesResponse) {
|
||||
}
|
||||
rpc GetConfigService (configservices.GetConfigServiceRequest) returns (configservices.GetConfigServiceResponse) {
|
||||
rpc GetNodeConfigService (configservices.GetNodeConfigServiceRequest) returns (configservices.GetNodeConfigServiceResponse) {
|
||||
}
|
||||
rpc SetConfigService (configservices.SetConfigServiceRequest) returns (configservices.SetConfigServiceResponse) {
|
||||
rpc GetNodeConfigServices (configservices.GetNodeConfigServicesRequest) returns (configservices.GetNodeConfigServicesResponse) {
|
||||
}
|
||||
rpc SetNodeConfigService (configservices.SetNodeConfigServiceRequest) returns (configservices.SetNodeConfigServiceResponse) {
|
||||
}
|
||||
|
||||
// wlan rpc
|
||||
|
|
Loading…
Add table
Reference in a new issue