Commit e7f0f77f authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch...

Merge branch 'feat/232-add-ztp-server-that-provide-a-zero-touch-provisioning-to-whiteboxes' into 'develop'

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

See merge request !329
parents 6bdd4ce7 3a185647
Loading
Loading
Loading
Loading
+77 −0
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
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;
}
+5 −2
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
+20 −0
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.

from werkzeug.security import generate_password_hash

# REST-API users
RESTAPI_USERS = {   # TODO: implement a database of credentials and permissions
    'admin': generate_password_hash('admin'),
}
+72 −0
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.

FROM python:3.9-slim

# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
    apt-get --yes --quiet --quiet install wget g++ git build-essential cmake libpcre2-dev python3-dev python3-cffi && \
    rm -rf /var/lib/apt/lists/*

# Set Python to show logs as they occur
ENV PYTHONUNBUFFERED=0

# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
    chmod +x /bin/grpc_health_probe

# Get generic Python packages
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade setuptools wheel
RUN python3 -m pip install --upgrade pip-tools

# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt

# Add common files into working directory
WORKDIR /var/teraflow/common
COPY src/common/. ./
RUN rm -rf proto

# Create proto sub-folder, copy .proto files, and generate Python code
RUN mkdir -p /var/teraflow/common/proto
WORKDIR /var/teraflow/common/proto
RUN touch __init__.py
COPY proto/*.proto ./
RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto
RUN rm *.proto
RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \;

# Create component sub-folders, get specific Python packages
RUN mkdir -p /var/teraflow/ztp_server
WORKDIR /var/teraflow/ztp_server
COPY src/ztp_server/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN python3 -m pip install -r requirements.txt

# Add component files into working directory
WORKDIR /var/teraflow
COPY src/ztp_server/. ztp_server/

#ToDo Implement Test
#RUN mkdir -p /var/teraflow/tests/tools
#COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/

# Start the service
ENTRYPOINT ["python", "-m", "ztp_server.service"]
Loading