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

Second Draft

parent 5a155f4b
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!329Resolve "Add ZTP server that provide a zero touch provisioning to whiteboxes"
...@@ -15,9 +15,27 @@ ...@@ -15,9 +15,27 @@
syntax = "proto3"; syntax = "proto3";
package ztpServer; package ztpServer;
import "context.proto"; //import "context.proto";
service ZtpServerService { service ZtpServerService {
rpc GetProvisioningScript (context.ProvisioningScriptName ) returns (context.ProvisioningScript ) {} rpc GetProvisioningScript (ProvisioningScriptName ) returns (ProvisioningScript ) {}
rpc GetZtpProvisioning (context.ZtpFileName ) returns (context.ZtpFile ) {} 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 @@ ...@@ -15,7 +15,7 @@
import grpc, logging import grpc, logging
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc 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 ( from common.proto.context_pb2 import (
ZtpFileName, ZtpFile, ProvisioningScriptName, ProvisioningScript) ZtpFileName, ZtpFile, ProvisioningScriptName, ProvisioningScript)
from common.tools.client.RetryDecorator import retry, delay_exponential from common.tools.client.RetryDecorator import retry, delay_exponential
...@@ -39,7 +39,7 @@ class ZtpClient: ...@@ -39,7 +39,7 @@ class ZtpClient:
def connect(self): def connect(self):
self.channel = grpc.insecure_channel(self.endpoint) self.channel = grpc.insecure_channel(self.endpoint)
self.stub = ztpServerServiceStub(self.channel) #TODO self.stub = ztpServerServiceStub(self.channel)
def close(self): def close(self):
if self.channel is not None: self.channel.close() if self.channel is not None: self.channel.close()
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
from common.Settings import get_service_port_grpc 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 common.tools.service.GenericGrpcService import GenericGrpcService
from ztp_server.service.ZtpServerServiceServicerImpl import ZtpServerServiceServicerImpl from ztp_server.service.ZtpServerServiceServicerImpl import ZtpServerServiceServicerImpl
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # 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.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import ( from common.proto.context_pb2 import (
ZtpFileName, ZtpFile, ProvisioningScriptName, ProvisioningScript) 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__) LOGGER = logging.getLogger(__name__)
...@@ -29,12 +29,25 @@ class ZtpServerServiceServicerImpl(ztpServerServiceServicer): ...@@ -29,12 +29,25 @@ class ZtpServerServiceServicerImpl(ztpServerServiceServicer):
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetZtpProvisioning(self, request : ProvisioningScriptName, context : grpc.ServicerContext) -> ProvisioningScript: def GetZtpProvisioning(self, request : ProvisioningScriptName, context : grpc.ServicerContext) -> ProvisioningScript:
LOGGER.warning('NOT IMPLEMENTED') try:
return ProvisioningScript() 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) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetZtpProvisioning(self, request : ZtpFileName, context : grpc.ServicerContext) -> ZtpFile: def GetZtpProvisioning(self, request : ZtpFileName, context : grpc.ServicerContext) -> ZtpFile:
LOGGER.warning('NOT IMPLEMENTED') try:
return ZtpFile() 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 ( ...@@ -21,6 +21,7 @@ from common.Settings import (
) )
from .ZtpServerService import ZtpServerService from .ZtpServerService import ZtpServerService
from .rest_server.RestServer import RestServer from .rest_server.RestServer import RestServer
from .rest_server.ztpServer_plugins.tfs_api import register_tfs_api
from .context_subscription import register_context_subscription 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