Resolve "Add wrappers to implement features related to NFV Orchestrator"

Closes #234 (closed)

Merge request reports

Loading
+74 −0
Changes for manifests/osm_clientservice.yaml: 74 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: osm_clientservice
spec:
  selector:
    matchLabels:
      app: osm_clientservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: osm_clientservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/osm_client:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 30210
            - containerPort: 9192
          env:
            - name: OSM_ADDRESS
              value: "127.0.0.1"
            - name: LOG_LEVEL
              value: "INFO"
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30210"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30210"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: osm_clientservice
  labels:
    app: osm_clientservice
spec:
  type: ClusterIP
  selector:
    app: osm_clientservice
  ports:
    - name: grpc
      protocol: TCP
      port: 30210
      targetPort: 30210
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192

proto/osm_client.proto

0 → 100644
+71 −0
Changes for proto/osm_client.proto: 71 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 osmClient;

import "context.proto";

service OsmService {
  rpc NsiCreate   (CreateRequest)   returns(CreateResponse) {}
  rpc NsiList     (context.Empty)   returns(NsiListResponse) {}
  rpc NsiGet      (GetRequest)      returns(GetResponse) {}
  rpc NsiDelete   (DeleteRequest)   returns(DeleteResponse) {}
}

message CreateRequest {
  string nst_name = 1;
  string nsi_name = 2;
  string config = 3;
  string ssh_key = 4;
  string account = 5;
}

//OSM library doesn't return nsi ID, just an exception
message CreateResponse {
  bool succeded = 1;
  string errormessage = 2;
}

message NsiListResponse {
  repeated string id = 1;
}

message GetRequest {
  string id = 1;
}

message GetResponse {
  NsiObject nsi = 1;
}

message NsiObject {
  string nst_name = 1;
  string nsi_name = 2;
  string description = 3;
  string VimAccountId = 4;
  string Netslice_Subnet_id = 5;
  string Netslice_vld_ip = 6;
}

message DeleteRequest {
  string id = 1;
}

//OSM library doesn't return nsi ID, just an exception
message DeleteResponse {
  bool succeded = 1;
  string errormessage = 2;
}
+2 −0
Changes for src/common/Constants.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class ServiceNameEnum(Enum):
    ANALYTICS              = 'analytics'
    ANALYTICSBACKEND       = 'analytics-backend'
    QOSPROFILE             = 'qos-profile'
    OSMCLIENT              = 'osm-client'

    # Used for test and debugging only
    DLT_GATEWAY    = 'dltgateway'
@@ -112,6 +113,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.ANALYTICS              .value : 30080,
    ServiceNameEnum.ANALYTICSBACKEND       .value : 30090,
    ServiceNameEnum.AUTOMATION             .value : 30200,
    ServiceNameEnum.OSMCLIENT              .value : 30210,

    # Used for test and debugging only
    ServiceNameEnum.DLT_GATEWAY   .value : 50051,
+80 −0
Changes for src/osm_client/client/OsmClient.py: 80 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.osm_client_pb2_grpc import OsmServiceStub
from common.proto.osm_client_pb2 import CreateRequest, CreateResponse, NsiListResponse, GetRequest, GetResponse, DeleteRequest, DeleteResponse
from common.proto.context_pb2 import (Empty)
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string

from osmclient import client
from osmclient.common.exceptions import ClientException


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 OsmClient:
    def __init__(self, host=None, port=None):
        if not host: host = get_service_host(ServiceNameEnum.OSMCLIENT)
        if not port: port = get_service_port_grpc(ServiceNameEnum.OSMCLIENT)
        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 = OsmServiceStub(self.channel)

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

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

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

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

    @RETRY_DECORATOR
    def NsiDelete(self, request : DeleteRequest) -> DeleteResponse:
        LOGGER.debug('NsiDelete request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.NsiDelete(request)
        LOGGER.debug('NsiDelete result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
+14 −0
Changes for src/osm_client/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