Commit 62f538ca authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent 6b28735c
Loading
Loading
Loading
Loading
+31 −29
Changes for manifests/spine_leafservice.yaml: 31 added lines, 29 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# 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.
@@ -32,22 +32,22 @@ spec:
          image: labs.etsi.org:5050/tfs/controller/spine_leaf:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 10095
            - containerPort: 30240
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          startupProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:10095"]
              command: ["/bin/grpc_health_probe", "-addr=:30240"]
            failureThreshold: 30
            periodSeconds: 1
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:10095"]
              command: ["/bin/grpc_health_probe", "-addr=:30240"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:10095"]
              command: ["/bin/grpc_health_probe", "-addr=:30240"]
          resources:
            requests:
              cpu: 250m
@@ -69,31 +69,33 @@ spec:
  ports:
    - name: grpc
      protocol: TCP
      port: 10095
      targetPort: 10095
      port: 30240
      targetPort: 30240
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: spine-leafservice-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: spine-leafservice
  minReplicas: 1
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80
  #behavior:
  #  scaleDown:
  #    stabilizationWindowSeconds: 30

# TODO: Cannot be auto-scaled until a proper database is implemented.
#---
#apiVersion: autoscaling/v2
#kind: HorizontalPodAutoscaler
#metadata:
#  name: spine-leafservice-hpa
#spec:
#  scaleTargetRef:
#    apiVersion: apps/v1
#    kind: Deployment
#    name: spine-leafservice
#  minReplicas: 1
#  maxReplicas: 20
#  metrics:
#    - type: Resource
#      resource:
#        name: cpu
#        target:
#          type: Utilization
#          averageUtilization: 80
#  #behavior:
#  #  scaleDown:
#  #    stabilizationWindowSeconds: 30
+2 −2
Changes for proto/spine_leaf.proto: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
// Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// 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.
@@ -14,7 +14,7 @@


syntax = "proto3";
package spineleaf;
package spine_leaf;

service SpineLeaf {
  rpc DefineSpineLeafFabric(FabricSettings           ) returns (FabricDefinitionResponse) {}
+3 −3
Changes for src/logical_resources/Dockerfile: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.9-slim
FROM python:3.13-slim

# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
@@ -35,7 +35,7 @@ RUN python3 -m pip install --upgrade 'pip-tools==7.3.0'
# 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
COPY common_requirements_py313.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

@@ -57,7 +57,7 @@ RUN find . -type f -exec sed -i -E 's/^(import\ .*)_pb2/from . \1_pb2/g' {} \;
RUN mkdir -p /var/teraflow/logical_resources
WORKDIR /var/teraflow/logical_resources
COPY src/logical_resources/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in /var/teraflow/common_requirements.in
RUN python3 -m pip install -r requirements.txt

# Add component files into working directory
+10 −9
Changes for src/logical_resources/client/LogicalResourcesClient.py: 10 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@ import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.logical_resources_pb2 import (
    Empty,
    ConfigParameters, Empty, FabricId, ResourceList, ResourceReservation,
    ResourceTypeQuery, Response, Success, TypedResourceList, Value
)
from common.proto.logical_resources_pb2_grpc import LogicalResourcesStub
from common.tools.client.RetryDecorator import retry, delay_exponential
@@ -48,14 +49,14 @@ class LogicalResourcesClient:
        self.stub = None

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

    @RETRY_DECORATOR
    def GetAvailableResources(self, request=None):
    def GetAvailableResources(self, request : Empty = None) -> ResourceList:
        if request is None:
            request = Empty()
        LOGGER.debug('GetAvailableResources request: {:s}'.format(grpc_message_to_json_string(request)))
@@ -64,28 +65,28 @@ class LogicalResourcesClient:
        return response

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

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

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

    @RETRY_DECORATOR
    def GetReservedResources(self, request=None):
    def GetReservedResources(self, request : Empty = None) -> ResourceList:
        if request is None:
            request = Empty()
        LOGGER.debug('GetReservedResources request: {:s}'.format(grpc_message_to_json_string(request)))
@@ -94,14 +95,14 @@ class LogicalResourcesClient:
        return response

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

    @RETRY_DECORATOR
    def GetResourcesByType(self, request):
    def GetResourcesByType(self, request : ResourceTypeQuery) -> TypedResourceList:
        LOGGER.debug('GetResourcesByType request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetResourcesByType(request)
        LOGGER.debug('GetResourcesByType result: {:s}'.format(grpc_message_to_json_string(response)))
+1 −1
Changes for src/logical_resources/service/__main__.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ from .LogicalResourcesService import LogicalResourcesService
TERMINATE = threading.Event()

LOG_LEVEL = get_log_level()
logging.basicConfig(level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s")
logging.basicConfig(level=LOG_LEVEL, format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s')
LOGGER = logging.getLogger(__name__)


Loading