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 import utils
|
||||||
from core.api.grpc import core_pb2, core_pb2_grpc
|
from core.api.grpc import core_pb2, core_pb2_grpc
|
||||||
from core.api.grpc.configservices_pb2 import (
|
from core.api.grpc.configservices_pb2 import (
|
||||||
GetConfigServiceRequest,
|
|
||||||
GetConfigServiceResponse,
|
|
||||||
GetConfigServicesRequest,
|
GetConfigServicesRequest,
|
||||||
GetConfigServicesResponse,
|
GetConfigServicesResponse,
|
||||||
SetConfigServiceRequest,
|
GetNodeConfigServiceRequest,
|
||||||
SetConfigServiceResponse,
|
GetNodeConfigServiceResponse,
|
||||||
|
GetNodeConfigServicesRequest,
|
||||||
|
GetNodeConfigServicesResponse,
|
||||||
|
SetNodeConfigServiceRequest,
|
||||||
|
SetNodeConfigServiceResponse,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1090,21 +1092,27 @@ class CoreGrpcClient:
|
||||||
request = GetConfigServicesRequest()
|
request = GetConfigServicesRequest()
|
||||||
return self.stub.GetConfigServices(request)
|
return self.stub.GetConfigServices(request)
|
||||||
|
|
||||||
def get_config_service(
|
def get_node_config_service(
|
||||||
self, session_id: int, node_id: int, name: str
|
self, session_id: int, node_id: int, name: str
|
||||||
) -> GetConfigServiceResponse:
|
) -> GetNodeConfigServiceResponse:
|
||||||
request = GetConfigServiceRequest(
|
request = GetNodeConfigServiceRequest(
|
||||||
session_id=session_id, node_id=node_id, name=name
|
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]
|
self, session_id: int, node_id: int, name: str, config: Dict[str, str]
|
||||||
) -> SetConfigServiceResponse:
|
) -> SetNodeConfigServiceResponse:
|
||||||
request = SetConfigServiceRequest(
|
request = SetNodeConfigServiceRequest(
|
||||||
session_id=session_id, node_id=node_id, name=name, config=config
|
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:
|
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 import core_pb2, core_pb2_grpc, grpcutils
|
||||||
from core.api.grpc.configservices_pb2 import (
|
from core.api.grpc.configservices_pb2 import (
|
||||||
ConfigService,
|
ConfigService,
|
||||||
GetConfigServiceRequest,
|
|
||||||
GetConfigServiceResponse,
|
|
||||||
GetConfigServicesRequest,
|
GetConfigServicesRequest,
|
||||||
GetConfigServicesResponse,
|
GetConfigServicesResponse,
|
||||||
SetConfigServiceRequest,
|
GetNodeConfigServiceRequest,
|
||||||
SetConfigServiceResponse,
|
GetNodeConfigServiceResponse,
|
||||||
|
GetNodeConfigServicesRequest,
|
||||||
|
GetNodeConfigServicesResponse,
|
||||||
|
SetNodeConfigServiceRequest,
|
||||||
|
SetNodeConfigServiceResponse,
|
||||||
)
|
)
|
||||||
from core.api.grpc.events import EventStreamer
|
from core.api.grpc.events import EventStreamer
|
||||||
from core.api.grpc.grpcutils import (
|
from core.api.grpc.grpcutils import (
|
||||||
|
@ -1464,9 +1466,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
services.append(service_proto)
|
services.append(service_proto)
|
||||||
return GetConfigServicesResponse(services=services)
|
return GetConfigServicesResponse(services=services)
|
||||||
|
|
||||||
def GetConfigService(
|
def GetNodeConfigService(
|
||||||
self, request: GetConfigServiceRequest, context: ServicerContext
|
self, request: GetNodeConfigServiceRequest, context: ServicerContext
|
||||||
) -> GetConfigServiceResponse:
|
) -> GetNodeConfigServiceResponse:
|
||||||
session = self.get_session(request.session_id, context)
|
session = self.get_session(request.session_id, context)
|
||||||
node = self.get_node(session, request.node_id, context)
|
node = self.get_node(session, request.node_id, context)
|
||||||
self.validate_service(request.name, context)
|
self.validate_service(request.name, context)
|
||||||
|
@ -1477,18 +1479,26 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
else:
|
else:
|
||||||
service = self.coreemu.service_manager.get_service(request.name)
|
service = self.coreemu.service_manager.get_service(request.name)
|
||||||
config = {x.id: x.default for x in service.default_configs}
|
config = {x.id: x.default for x in service.default_configs}
|
||||||
return GetConfigServiceResponse(config=config)
|
return GetNodeConfigServiceResponse(config=config)
|
||||||
|
|
||||||
def SetConfigService(
|
def GetNodeConfigServices(
|
||||||
self, request: SetConfigServiceRequest, context: ServicerContext
|
self, request: GetNodeConfigServicesRequest, context: ServicerContext
|
||||||
) -> SetConfigServiceResponse:
|
) -> 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)
|
session = self.get_session(request.session_id, context)
|
||||||
node = self.get_node(session, request.node_id, context)
|
node = self.get_node(session, request.node_id, context)
|
||||||
self.validate_service(request.name, context)
|
self.validate_service(request.name, context)
|
||||||
service = node.config_services.get(request.name)
|
service = node.config_services.get(request.name)
|
||||||
if service:
|
if service:
|
||||||
service.set_config(request.config)
|
service.set_config(request.config)
|
||||||
return SetConfigServiceResponse(result=True)
|
return SetNodeConfigServiceResponse(result=True)
|
||||||
else:
|
else:
|
||||||
context.abort(
|
context.abort(
|
||||||
grpc.StatusCode.NOT_FOUND,
|
grpc.StatusCode.NOT_FOUND,
|
||||||
|
|
|
@ -32,23 +32,32 @@ message GetConfigServicesResponse {
|
||||||
repeated ConfigService services = 1;
|
repeated ConfigService services = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetConfigServiceRequest {
|
message GetNodeConfigServiceRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string name = 3;
|
string name = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetConfigServiceResponse {
|
message GetNodeConfigServiceResponse {
|
||||||
map<string, string> config = 1;
|
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 session_id = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string name = 3;
|
string name = 3;
|
||||||
map<string, string> config = 4;
|
map<string, string> config = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetConfigServiceResponse {
|
message SetNodeConfigServiceResponse {
|
||||||
bool result = 1;
|
bool result = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,9 +107,11 @@ service CoreApi {
|
||||||
// config services
|
// config services
|
||||||
rpc GetConfigServices (configservices.GetConfigServicesRequest) returns (configservices.GetConfigServicesResponse) {
|
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
|
// wlan rpc
|
||||||
|
|
Loading…
Add table
Reference in a new issue