Resolve "Add ZTP server that provide a zero touch provisioning to whiteboxes"

Closes #232 (closed)

Merge request reports

Loading
+77 −0
Changes for manifests/ztp_server.yaml: 77 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ztp_serverservice
spec:
  selector:
    matchLabels:
      app: ztp_serverservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: ztp_serverservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/ztp_server:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8005
            - containerPort: 5051
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5051"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5051"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: ztp_serverservice
  labels:
    app: ztp_serverservice
spec:
  type: ClusterIP
  selector:
    app: ztp_serverservice
  ports:
    - name: http
      protocol: TCP
      port: 8005
      targetPort: 8005
    - name: grpc
      protocol: TCP
      port: 5051
      targetPort: 5051
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192

proto/ztp_server.proto

0 → 100755
+41 −0
Changes for proto/ztp_server.proto: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
// Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";
package ztpServer;

//import "context.proto";

service ZtpServerService {
  rpc GetProvisioningScript     (ProvisioningScriptName         ) returns (ProvisioningScript       ) {}
  rpc GetZtpProvisioning        (ZtpFileName                    ) returns (ZtpFile                  ) {}
}


// Define the request message for both methods
message ProvisioningScriptName {
  string scriptname = 1;
}

message ZtpFileName {
  string filename = 1;
}

message ProvisioningScript {
  string script = 1;
}

message ZtpFile {
  string json = 1;
}
+3 −0
Changes for src/common/Constants.py: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class ServiceNameEnum(Enum):
    SERVICE                = 'service'
    SLICE                  = 'slice'
    ZTP                    = 'ztp'
    ZTP_SERVER             = 'ztp-server'
    POLICY                 = 'policy'
    MONITORING             = 'monitoring'
    DLT                    = 'dlt'
@@ -85,6 +86,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.SERVICE                .value :  3030,
    ServiceNameEnum.SLICE                  .value :  4040,
    ServiceNameEnum.ZTP                    .value :  5050,
    ServiceNameEnum.ZTP_SERVER             .value :  5051,
    ServiceNameEnum.POLICY                 .value :  6060,
    ServiceNameEnum.MONITORING             .value :  7070,
    ServiceNameEnum.DLT                    .value :  8080,
@@ -124,6 +126,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
DEFAULT_SERVICE_HTTP_PORTS = {
    ServiceNameEnum.NBI  .value      : 8080,
    ServiceNameEnum.WEBUI.value      : 8004,
    ServiceNameEnum.ZTP_SERVER.value : 8005,
}

# Default HTTP/REST-API service base URLs
+60 −0
Changes for src/ztp_server/client/ZtpClient.py: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.ztp_server_pb2_grpc import ZtpServerServiceStub
from common.proto.ztp_server_pb2 import ProvisioningScriptName, ProvisioningScript, ZtpFileName, ZtpFile
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string

LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')

class ZtpClient:
    def __init__(self, host=None, port=None):
        if not host: host = get_service_host(ServiceNameEnum.ZTP_SERVER)
        if not port: port = get_service_port_grpc(ServiceNameEnum.ZTP_SERVER)
        self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
        LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
        self.channel = None
        self.stub = None
        self.connect()
        LOGGER.debug('Channel created')

    def connect(self):
        self.channel = grpc.insecure_channel(self.endpoint)
        self.stub = ZtpServerServiceStub(self.channel)

    def close(self):
        if self.channel is not None: self.channel.close()
        self.channel = None
        self.stub = None

    @RETRY_DECORATOR
    def GetProvisioningScript(self, request : ProvisioningScriptName) -> ProvisioningScript:
        LOGGER.debug('GetProvisioningScript request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetProvisioningScript(request)
        LOGGER.debug('GetProvisioningScript result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetZtpProvisioning(self, request : ZtpFileName) -> ZtpFile:
        LOGGER.debug('GetZtpProvisioning request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetZtpProvisioning(request)
        LOGGER.debug('GetZtpProvisioning result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
+14 −0
Changes for src/ztp_server/client/__init__.py: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading