Skip to content
Snippets Groups Projects
Commit a431db9a authored by Manuel Angel Jimenez Quesada's avatar Manuel Angel Jimenez Quesada
Browse files

Add DockerFile to osm_client MicroServices

Solve imports typo
parent 2a85e17a
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!319Resolve "Add wrappers to implement features related to NFV Orchestrator"
# 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.10.16-slim
# Install dependencies
RUN apt-get --yes --quiet --quiet update
RUN apt-get --yes --quiet --quiet install wget g++ git build-essential cmake make git \
libpcre2-dev python3-dev python3-pip python3-cffi curl software-properties-common && \
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
RUN mkdir -p /var/teraflow/osm_client
WORKDIR /var/teraflow/osm_client
ENV OSM_CLIENT_VERSION=v16.0
RUN python3 -m pip install -r "https://osm.etsi.org/gitweb/?p=osm/IM.git;a=blob_plain;f=requirements.txt;hb=${OSM_CLIENT_VERSION}"
RUN python3 -m pip install "git+https://osm.etsi.org/gerrit/osm/IM.git@${OSM_CLIENT_VERSION}#egg=osm-im" --upgrade
#Clone OsmCLient code
RUN git clone https://osm.etsi.org/gerrit/osm/osmclient
RUN git -C osmclient checkout ${OSM_CLIENT_VERSION}
# Install osmClient using pip
RUN python3 -m pip install -r osmclient/requirements.txt
RUN python3 -m pip install ./osmclient
# Add component files into working directory
WORKDIR /var/teraflow
COPY src/osm_client/. osm_client/
# Start the service
ENTRYPOINT ["python", "-m", "osm_client.service"]
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import grpc, logging import grpc, logging
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc from common.Settings import get_service_host, get_service_port_grpc
from common.proto.osm_client_pb2_grpc import osmClientServiceStub from common.proto.osm_client_pb2_grpc import OsmServiceStub
from common.proto.context_pb2 import (Empty) from common.proto.context_pb2 import (Empty)
from common.tools.client.RetryDecorator import retry, delay_exponential from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.grpc.Tools import grpc_message_to_json_string
...@@ -43,7 +43,7 @@ class OsmClient: ...@@ -43,7 +43,7 @@ class OsmClient:
def connect(self): def connect(self):
self.channel = grpc.insecure_channel(self.endpoint) self.channel = grpc.insecure_channel(self.endpoint)
self.stub = osmClientServiceStub(self.channel) self.stub = OsmServiceStub(self.channel)
def close(self): def close(self):
if self.channel is not None: self.channel.close() if self.channel is not None: self.channel.close()
......
...@@ -18,10 +18,6 @@ from common.proto.osm_client_pb2_grpc import add_OsmServiceServicer_to_server ...@@ -18,10 +18,6 @@ from common.proto.osm_client_pb2_grpc import add_OsmServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService from common.tools.service.GenericGrpcService import GenericGrpcService
from osm_client.service.OsmClientServiceServicerImpl import OsmClientServiceServicerImpl from osm_client.service.OsmClientServiceServicerImpl import OsmClientServiceServicerImpl
from osmclient import client
from osmclient.common.exceptions import ClientException
class OsmClientService(GenericGrpcService): class OsmClientService(GenericGrpcService):
def __init__(self, cls_name: str = __name__) -> None: def __init__(self, cls_name: str = __name__) -> None:
port = get_service_port_grpc(ServiceNameEnum.OSMCLIENT) port = get_service_port_grpc(ServiceNameEnum.OSMCLIENT)
......
...@@ -17,7 +17,7 @@ from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_m ...@@ -17,7 +17,7 @@ from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_m
from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.grpc.Tools import grpc_message_to_json_string
from common.proto.context_pb2 import (Empty) from common.proto.context_pb2 import (Empty)
from common.proto.osm_client_pb2 import CreateRequest, CreateResponse, NsiListResponse, GetRequest, GetResponse, DeleteRequest, DeleteResponse from common.proto.osm_client_pb2 import CreateRequest, CreateResponse, NsiListResponse, GetRequest, GetResponse, DeleteRequest, DeleteResponse
from common.proto.osm_client_pb2_grpc import osmCLientServiceServicer from common.proto.osm_client_pb2_grpc import OsmServiceServicer
from osmclient import client from osmclient import client
from osmclient.common.exceptions import ClientException from osmclient.common.exceptions import ClientException
from osm_client.Config import OSM_ADDRESS from osm_client.Config import OSM_ADDRESS
...@@ -26,7 +26,7 @@ LOGGER = logging.getLogger(__name__) ...@@ -26,7 +26,7 @@ LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('OSMCLIENT', 'RPC') METRICS_POOL = MetricsPool('OSMCLIENT', 'RPC')
class OsmClientServiceServicerImpl(osmCLientServiceServicer): class OsmClientServiceServicerImpl(OsmServiceServicer):
def __init__(self): def __init__(self):
LOGGER.info('Creating Servicer...') LOGGER.info('Creating Servicer...')
self.myclient = client.Client(host=OSM_ADDRESS, sol005=True) self.myclient = client.Client(host=OSM_ADDRESS, sol005=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment