Adding grpc library 32/9232/2
authorlloretgalleg <illoret@indra.es>
Tue, 30 Jun 2020 11:26:48 +0000 (11:26 +0000)
committerlloretgalleg <illoret@indra.es>
Tue, 30 Jun 2020 13:36:14 +0000 (13:36 +0000)
Change-Id: I8577bf19b895f543518ff1eacb28aa1c757391b1
Signed-off-by: lloretgalleg <illoret@indra.es>
Dockerfile.local
debian/python3-osm-lcm.postinst
osm_lcm/frontend_grpc.py [new file with mode: 0644]
osm_lcm/frontend_pb2.py [new file with mode: 0644]
requirements.txt
setup.py
stdeb.cfg
tox.ini

index a64bf4c..d02aee2 100644 (file)
@@ -49,6 +49,8 @@ RUN git -C /app clone https://osm.etsi.org/gerrit/osm/common.git \
     && python3 -m pip install -e /app/common
     #  python3-pymongo python3-yaml pycrypto aiokafka
 
+RUN python3 -m pip install grpcio-tools grpclib
+
 RUN mkdir -p /app/storage/kafka && mkdir -p /app/log
 
 
index f66671f..4ee0a2e 100755 (executable)
@@ -22,6 +22,7 @@ echo "POST INSTALL OSM-LCM"
 # echo "Installing python dependencies via pip..."
 # python3 -m pip install -U pip
 # python3 -m pip install --user aiokafka
+python3 -m pip install grpcio-tools grpclib
 
 #Creation of log folder
 mkdir -p /var/log/osm
diff --git a/osm_lcm/frontend_grpc.py b/osm_lcm/frontend_grpc.py
new file mode 100644 (file)
index 0000000..c1dd60d
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+##
+# Copyright 2018 Telefonica S.A.
+#
+# 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.
+##
+# Generated by the Protocol Buffers compiler. DO NOT EDIT!
+# source: osm_lcm/frontend.proto
+# plugin: grpclib.plugin.main
+import abc
+import typing
+
+import grpclib.const
+import grpclib.client
+if typing.TYPE_CHECKING:
+    import grpclib.server
+
+import osm_lcm.frontend_pb2
+
+
+class FrontendExecutorBase(abc.ABC):
+
+    @abc.abstractmethod
+    async def RunPrimitive(self, stream: 'grpclib.server.Stream[osm_lcm.frontend_pb2.PrimitiveRequest, osm_lcm.frontend_pb2.PrimitiveReply]') -> None:
+        pass
+
+    @abc.abstractmethod
+    async def GetSshKey(self, stream: 'grpclib.server.Stream[osm_lcm.frontend_pb2.SshKeyRequest, osm_lcm.frontend_pb2.SshKeyReply]') -> None:
+        pass
+
+    def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
+        return {
+            '/osm_lcm.FrontendExecutor/RunPrimitive': grpclib.const.Handler(
+                self.RunPrimitive,
+                grpclib.const.Cardinality.UNARY_STREAM,
+                osm_lcm.frontend_pb2.PrimitiveRequest,
+                osm_lcm.frontend_pb2.PrimitiveReply,
+            ),
+            '/osm_lcm.FrontendExecutor/GetSshKey': grpclib.const.Handler(
+                self.GetSshKey,
+                grpclib.const.Cardinality.UNARY_UNARY,
+                osm_lcm.frontend_pb2.SshKeyRequest,
+                osm_lcm.frontend_pb2.SshKeyReply,
+            ),
+        }
+
+
+class FrontendExecutorStub:
+
+    def __init__(self, channel: grpclib.client.Channel) -> None:
+        self.RunPrimitive = grpclib.client.UnaryStreamMethod(
+            channel,
+            '/osm_lcm.FrontendExecutor/RunPrimitive',
+            osm_lcm.frontend_pb2.PrimitiveRequest,
+            osm_lcm.frontend_pb2.PrimitiveReply,
+        )
+        self.GetSshKey = grpclib.client.UnaryUnaryMethod(
+            channel,
+            '/osm_lcm.FrontendExecutor/GetSshKey',
+            osm_lcm.frontend_pb2.SshKeyRequest,
+            osm_lcm.frontend_pb2.SshKeyReply,
+        )
diff --git a/osm_lcm/frontend_pb2.py b/osm_lcm/frontend_pb2.py
new file mode 100644 (file)
index 0000000..0c24c73
--- /dev/null
@@ -0,0 +1,250 @@
+# -*- coding: utf-8 -*-
+##
+# Copyright 2020 Telefonica Investigacion y Desarrollo, S.A.U.
+#
+# 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.
+#
+##
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: osm_lcm/frontend.proto
+
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import symbol_database as _symbol_database
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+  name='osm_lcm/frontend.proto',
+  package='osm_lcm',
+  syntax='proto3',
+  serialized_options=b'\n\027com.etsi.osm.lcm.osm_lcmB\014GrpcExecutorP\001\242\002\003OEE',
+  serialized_pb=b'\n\x15osm_lcm/frontend.proto\x12\x06osm_lcm\"<\n\x10PrimitiveRequest\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0e\n\x06params\x18\x03 \x01(\t\":\n\x0ePrimitiveReply\x12\x0e\n\x06status\x18\x01 \x01(\t\x12\x18\n\x10\x64\x65tailed_message\x18\x02 \x01(\t\"\x0f\n\rSshKeyRequest\"\x1e\n\x0bSshKeyReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\x93\x01\n\x10\x46rontendExecutor\x12\x44\n\x0cRunPrimitive\x12\x18.osm_lcm.PrimitiveRequest\x1a\x16.osm_lcm.PrimitiveReply\"\x00\x30\x01\x12\x39\n\tGetSshKey\x12\x15.osm_lcm.SshKeyRequest\x1a\x13.osm_lcm.SshKeyReply\"\x00\x42/\n\x17\x63om.etsi.osm.lcm.osm_lcmB\x0cGrpcExecutorP\x01\xa2\x02\x03OEEb\x06proto3'
+)
+
+
+
+
+_PRIMITIVEREQUEST = _descriptor.Descriptor(
+  name='PrimitiveRequest',
+  full_name='osm_lcm.PrimitiveRequest',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='id', full_name='osm_lcm.PrimitiveRequest.id', index=0,
+      number=1, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='name', full_name='osm_lcm.PrimitiveRequest.name', index=1,
+      number=2, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='params', full_name='osm_lcm.PrimitiveRequest.params', index=2,
+      number=3, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  serialized_options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=33,
+  serialized_end=93,
+)
+
+
+_PRIMITIVEREPLY = _descriptor.Descriptor(
+  name='PrimitiveReply',
+  full_name='osm_lcm.PrimitiveReply',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='status', full_name='osm_lcm.PrimitiveReply.status', index=0,
+      number=1, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+    _descriptor.FieldDescriptor(
+      name='detailed_message', full_name='osm_lcm.PrimitiveReply.detailed_message', index=1,
+      number=2, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  serialized_options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=95,
+  serialized_end=153,
+)
+
+
+_SSHKEYREQUEST = _descriptor.Descriptor(
+  name='SshKeyRequest',
+  full_name='osm_lcm.SshKeyRequest',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  serialized_options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=155,
+  serialized_end=170,
+)
+
+
+_SSHKEYREPLY = _descriptor.Descriptor(
+  name='SshKeyReply',
+  full_name='osm_lcm.SshKeyReply',
+  filename=None,
+  file=DESCRIPTOR,
+  containing_type=None,
+  fields=[
+    _descriptor.FieldDescriptor(
+      name='message', full_name='osm_lcm.SshKeyReply.message', index=0,
+      number=1, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=b"".decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      serialized_options=None, file=DESCRIPTOR),
+  ],
+  extensions=[
+  ],
+  nested_types=[],
+  enum_types=[
+  ],
+  serialized_options=None,
+  is_extendable=False,
+  syntax='proto3',
+  extension_ranges=[],
+  oneofs=[
+  ],
+  serialized_start=172,
+  serialized_end=202,
+)
+
+DESCRIPTOR.message_types_by_name['PrimitiveRequest'] = _PRIMITIVEREQUEST
+DESCRIPTOR.message_types_by_name['PrimitiveReply'] = _PRIMITIVEREPLY
+DESCRIPTOR.message_types_by_name['SshKeyRequest'] = _SSHKEYREQUEST
+DESCRIPTOR.message_types_by_name['SshKeyReply'] = _SSHKEYREPLY
+_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+
+PrimitiveRequest = _reflection.GeneratedProtocolMessageType('PrimitiveRequest', (_message.Message,), {
+  'DESCRIPTOR' : _PRIMITIVEREQUEST,
+  '__module__' : 'osm_lcm.frontend_pb2'
+  # @@protoc_insertion_point(class_scope:osm_lcm.PrimitiveRequest)
+  })
+_sym_db.RegisterMessage(PrimitiveRequest)
+
+PrimitiveReply = _reflection.GeneratedProtocolMessageType('PrimitiveReply', (_message.Message,), {
+  'DESCRIPTOR' : _PRIMITIVEREPLY,
+  '__module__' : 'osm_lcm.frontend_pb2'
+  # @@protoc_insertion_point(class_scope:osm_lcm.PrimitiveReply)
+  })
+_sym_db.RegisterMessage(PrimitiveReply)
+
+SshKeyRequest = _reflection.GeneratedProtocolMessageType('SshKeyRequest', (_message.Message,), {
+  'DESCRIPTOR' : _SSHKEYREQUEST,
+  '__module__' : 'osm_lcm.frontend_pb2'
+  # @@protoc_insertion_point(class_scope:osm_lcm.SshKeyRequest)
+  })
+_sym_db.RegisterMessage(SshKeyRequest)
+
+SshKeyReply = _reflection.GeneratedProtocolMessageType('SshKeyReply', (_message.Message,), {
+  'DESCRIPTOR' : _SSHKEYREPLY,
+  '__module__' : 'osm_lcm.frontend_pb2'
+  # @@protoc_insertion_point(class_scope:osm_lcm.SshKeyReply)
+  })
+_sym_db.RegisterMessage(SshKeyReply)
+
+
+DESCRIPTOR._options = None
+
+_FRONTENDEXECUTOR = _descriptor.ServiceDescriptor(
+  name='FrontendExecutor',
+  full_name='osm_lcm.FrontendExecutor',
+  file=DESCRIPTOR,
+  index=0,
+  serialized_options=None,
+  serialized_start=205,
+  serialized_end=352,
+  methods=[
+  _descriptor.MethodDescriptor(
+    name='RunPrimitive',
+    full_name='osm_lcm.FrontendExecutor.RunPrimitive',
+    index=0,
+    containing_service=None,
+    input_type=_PRIMITIVEREQUEST,
+    output_type=_PRIMITIVEREPLY,
+    serialized_options=None,
+  ),
+  _descriptor.MethodDescriptor(
+    name='GetSshKey',
+    full_name='osm_lcm.FrontendExecutor.GetSshKey',
+    index=1,
+    containing_service=None,
+    input_type=_SSHKEYREQUEST,
+    output_type=_SSHKEYREPLY,
+    serialized_options=None,
+  ),
+])
+_sym_db.RegisterServiceDescriptor(_FRONTENDEXECUTOR)
+
+DESCRIPTOR.services_by_name['FrontendExecutor'] = _FRONTENDEXECUTOR
+
+# @@protoc_insertion_point(module_scope)
index a1b035b..32a09a9 100644 (file)
@@ -15,5 +15,8 @@
 pyyaml
 aiohttp>=2.3.10
 jinja2
+grpcio-tools
+grpclib
 git+https://osm.etsi.org/gerrit/osm/common.git#egg=osm-common
 git+https://osm.etsi.org/gerrit/osm/N2VC.git#egg=n2vc
+
index 9ba333b..aa83fd6 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -56,6 +56,8 @@ setup(
         'osm-common',
         'n2vc',
         'jinja2',
+        'grpcio-tools',
+        'grpclib',
         # TODO this is version installed by 'apt python3-aiohttp' on Ubuntu Sserver 14.04
         # version installed by pip 3.3.2 is not compatible. Code should be migrated to this version and use pip3
     ],
index 36d1fb0..3e222e5 100644 (file)
--- a/stdeb.cfg
+++ b/stdeb.cfg
@@ -1,3 +1,20 @@
+##
+# Copyright 2020 Telefonica Investigacion y Desarrollo, S.A.U.
+#
+# 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.
+#
+##
 [DEFAULT]
 X-Python3-Version : >= 3.5
-Depends3: python3-osm-common, python3-n2vc, python3-yaml, python3-aiohttp, python3-jinja2
+Depends3: python3-osm-common, python3-n2vc, python3-yaml, python3-aiohttp, python3-jinja2, python3-pip
diff --git a/tox.ini b/tox.ini
index de33e96..24b770f 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -27,7 +27,8 @@ commands=python3 -m unittest discover -v
 basepython = python3
 deps = flake8
 commands = flake8 osm_lcm --max-line-length 120 \
-    --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp --ignore W291,W293,E226,W504
+    --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp,frontend_grpc.py,frontend_pb2.py \
+    --ignore W291,W293,E226,W504
 
 [testenv:unittest]
 basepython = python3