Resolve "(CTTC) Implement NBI Connector NOS ZTP"

Closes #328 (closed)

Edited by Lluis Gifre Renom

Merge request reports

Loading
+7 −0
Changes for manifests/nginx_ingress_http.yaml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -128,3 +128,10 @@ spec:
                name: nbiservice
                port:
                  number: 8080
          - path: /()(ztp-api/.*)
            pathType: Prefix
            backend:
              service:
                name: nbiservice
                port:
                  number: 8080
+6 −6
Changes for manifests/ztp_serverservice.yaml: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -15,16 +15,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ztp_serverservice
  name: ztp-serverservice
spec:
  selector:
    matchLabels:
      app: ztp_serverservice
      app: ztp-serverservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: ztp_serverservice
        app: ztp-serverservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
@@ -55,13 +55,13 @@ spec:
apiVersion: v1
kind: Service
metadata:
  name: ztp_serverservice
  name: ztp-serverservice
  labels:
    app: ztp_serverservice
    app: ztp-serverservice
spec:
  type: ClusterIP
  selector:
    app: ztp_serverservice
    app: ztp-serverservice
  ports:
    - name: http
      protocol: TCP
+28 −0
Changes for scripts/show_logs_ztp_server.sh : 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2026 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.

########################################################################################################################
# Define your deployment settings here
########################################################################################################################

# If not already set, set the name of the Kubernetes namespace to deploy to.
export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"}

########################################################################################################################
# Automated steps start here
########################################################################################################################

kubectl -n ${TFS_K8S_NAMESPACE:-tfs} logs deploy/ztp-serverservice -c server
+50 −0
Changes for src/nbi/service/ztp_api/Resources.py: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 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 os
import logging
import requests
from flask import Response
from flask_restful import Resource
from common.proto.ztp_server_pb2 import ProvisioningScriptName
from ztp_server.client.ZtpClient import ZtpClient

LOGGER = logging.getLogger(__name__)

# REST to ztp-server (for files)
ZTP_HTTP_BASE = os.getenv("ZTP_SERVER_HTTP_BASE", "http://ztp-serverservice:8005").rstrip("/")
ZTP_HTTP_USER = os.getenv("ZTP_SERVER_HTTP_USER", "admin")
ZTP_HTTP_PASS = os.getenv("ZTP_SERVER_HTTP_PASS", "admin")


class ZtpProvisioning(Resource):
    def get(self, filename: str):
        url = f"{ZTP_HTTP_BASE}/provisioning/{filename}"
        r = requests.get(url, auth=(ZTP_HTTP_USER, ZTP_HTTP_PASS), timeout=10)
        return Response(
            r.content,
            status=r.status_code,
            mimetype=r.headers.get("Content-Type", "application/json"),
        )

class ZtpScript(Resource):
    def __init__(self) -> None:
        super().__init__()
        self.ztp_client = ZtpClient()

    def get(self, scriptname: str):
        resp = self.ztp_client.GetProvisioningScript(
            ProvisioningScriptName(scriptname=scriptname)
        )
        return Response(resp.script, mimetype="text/plain")
+36 −0
Changes for src/nbi/service/ztp_api/__init__.py: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 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 logging
from nbi.service.NbiApplication import NbiApplication
from .Resources import ZtpProvisioning, ZtpScript

LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

ENDPOINT_PREFIX = 'ztp_api.'
URL_PREFIX = '/ztp-api'

_RESOURCES = [
    ('api.provisioning', ZtpProvisioning, '/provisioning/<path:filename>'),
    ('api.script',       ZtpScript,       '/script/<string:scriptname>'),
]

RESOURCES = [
    (ENDPOINT_PREFIX + endpoint_name, resource_class, URL_PREFIX + resource_url)
    for endpoint_name, resource_class, resource_url in _RESOURCES
]

def register_ztp_api(nbi_app : NbiApplication):
    nbi_app.add_rest_api_resources(RESOURCES)
Loading
Loading