Skip to content
Snippets Groups Projects
Commit 11b4748c authored by Manuel Angel Jimenez Quesada's avatar Manuel Angel Jimenez Quesada
Browse files

Second Draft

parent c8b24867
No related branches found
No related tags found
1 merge request!329Resolve "Add ZTP server that provide a zero touch provisioning to whiteboxes"
......@@ -15,9 +15,27 @@
syntax = "proto3";
package ztpServer;
import "context.proto";
//import "context.proto";
service ZtpServerService {
rpc GetProvisioningScript (context.ProvisioningScriptName ) returns (context.ProvisioningScript ) {}
rpc GetZtpProvisioning (context.ZtpFileName ) returns (context.ZtpFile ) {}
rpc GetProvisioningScript (ProvisioningScriptName ) returns (ProvisioningScript ) {}
rpc GetZtpProvisioning (ZtpFileName ) returns (ZtpFile ) {}
}
// Define the request message for both methods
message ProvisioningScriptName {
string input = 1;
}
message ZtpFileName {
string input = 1;
}
message ProvisioningScript {
string script = 1;
}
message ZtpFile {
string json = 1;
}
......@@ -15,7 +15,7 @@
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.ztpServer_pb2_grpc import ztpServerServiceStub #TODO
from common.proto.ztp_server_pb2_grpc import ztpServerServiceStub
from common.proto.context_pb2 import (
ZtpFileName, ZtpFile, ProvisioningScriptName, ProvisioningScript)
from common.tools.client.RetryDecorator import retry, delay_exponential
......@@ -39,7 +39,7 @@ class ZtpClient:
def connect(self):
self.channel = grpc.insecure_channel(self.endpoint)
self.stub = ztpServerServiceStub(self.channel) #TODO
self.stub = ztpServerServiceStub(self.channel)
def close(self):
if self.channel is not None: self.channel.close()
......
......@@ -14,7 +14,7 @@
from common.Constants import ServiceNameEnum
from common.Settings import get_service_port_grpc
from common.proto.ztpServer_pb2_grpc import add_Ztp_ServerServiceServicer_to_server
from common.proto.ztp_server_pb2_grpc import add_Ztp_ServerServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService
from ztp_server.service.ZtpServerServiceServicerImpl import ZtpServerServiceServicerImpl
......
......@@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import grpc, logging
import grpc, logging, json
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import (
ZtpFileName, ZtpFile, ProvisioningScriptName, ProvisioningScript)
from common.proto.ztpServer_pb2_grpc import ztpServerServiceServicer
from common.proto.ztp_server_pb2_grpc import ztpServerServiceServicer
LOGGER = logging.getLogger(__name__)
......@@ -29,12 +29,25 @@ class ZtpServerServiceServicerImpl(ztpServerServiceServicer):
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetZtpProvisioning(self, request : ProvisioningScriptName, context : grpc.ServicerContext) -> ProvisioningScript:
LOGGER.warning('NOT IMPLEMENTED')
return ProvisioningScript()
try:
filePath = '../data/' + ProvisioningScriptName
with open(filePath, 'r') as provisioning_file:
provisioning_content = provisioning_file.read()
return ztpServerServiceServicer.ProvisioningScript(script=provisioning_content)
except FileNotFoundError:
context.set_code(grpc.StatusCode.NOT_FOUND)
context.set_details('File not found')
return ztpServerServiceServicer.ProvisioningScript()
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetZtpProvisioning(self, request : ZtpFileName, context : grpc.ServicerContext) -> ZtpFile:
LOGGER.warning('NOT IMPLEMENTED')
return ZtpFile()
try:
filePath = '../data/' + ZtpFileName
with open(filePath, 'r') as json_file:
json_content = json_file.read()
return ztpServerServiceServicer.ZtpFile(json=json_content)
except FileNotFoundError:
context.set_code(grpc.StatusCode.NOT_FOUND)
context.set_details('File not found')
return ztpServerServiceServicer.ZtpFile(json=json_content)
\ No newline at end of file
......@@ -21,6 +21,7 @@ from common.Settings import (
)
from .ZtpServerService import ZtpServerService
from .rest_server.RestServer import RestServer
from .rest_server.ztpServer_plugins.tfs_api import register_tfs_api
from .context_subscription import register_context_subscription
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment