VOL-1483 Update voltha-cli to use pyvoltha
Modifications done to use pyvoltha and voltha_protos libraries.
Change-Id: I2f6038fa9fce47459c68cc6e06ddc6bec3150cd6
diff --git a/python/Makefile b/python/Makefile
index 7a548e0..d7c4a1b 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -147,7 +147,15 @@
containers: base adapter_ponsim_olt adapter_ponsim_onu ofagent cli
base:
+ifdef LOCAL_PYVOLTHA
+ mkdir -p pyvoltha/dist
+ cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
+ mkdir -p voltha-protos/dist
+ cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
+ docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base_local .
+else
docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-base:${TAG} -f docker/Dockerfile.base .
+endif
adapter_ponsim_olt:
docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-ponsim-olt:${TAG} -f docker/Dockerfile.adapter_ponsim_olt .
@@ -198,6 +206,8 @@
rm -f ./protos/*_pb2_grpc.py
rm -f ./protos/*.desc
rm -f ./protos/*.proto
+ rm -rf pyvoltha
+ rm -rf voltha-protos
distclean: clean
rm -rf ${VENVDIR}
@@ -231,6 +241,15 @@
uname -s > ${VENVDIR}/.built; \
fi
+ifdef LOCAL_PYVOLTHA
+ mkdir -p pyvoltha/dist
+ cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
+ mkdir -p voltha-protos/dist
+ cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
+ . ${VENVDIR}/bin/activate && \
+ pip install pyvoltha/dist/*.tar.gz && \
+ pip install voltha-protos/dist/*.tar.gz
+endif
flake8: $(DIRS_FLAKE8)
diff --git a/python/cli/alarm_filters.py b/python/cli/alarm_filters.py
index ed2af32..57a782f 100644
--- a/python/cli/alarm_filters.py
+++ b/python/cli/alarm_filters.py
@@ -24,11 +24,9 @@
from google.protobuf.empty_pb2 import Empty
from table import print_pb_list_as_table
-from python.protos import third_party
-from python.protos import voltha_pb2
-from python.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha_protos import voltha_pb2
+from voltha_protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
-_ = third_party
class AlarmFiltersCli(Cmd):
diff --git a/python/cli/device.py b/python/cli/device.py
index 38ea835..484185f 100644
--- a/python/cli/device.py
+++ b/python/cli/device.py
@@ -24,10 +24,8 @@
from table import print_pb_as_table, print_pb_list_as_table
from utils import print_flows, pb2dict, enum2name
-from python.protos import third_party
-_ = third_party
-from python.protos import voltha_pb2, common_pb2
+from voltha_protos import voltha_pb2, common_pb2
import sys
import json
from google.protobuf.json_format import MessageToDict
diff --git a/python/cli/logical_device.py b/python/cli/logical_device.py
index cd991c6..187dd88 100644
--- a/python/cli/logical_device.py
+++ b/python/cli/logical_device.py
@@ -24,11 +24,9 @@
from table import print_pb_as_table, print_pb_list_as_table
from utils import pb2dict
from utils import print_flows, print_groups
-from python.protos import third_party
from google.protobuf.empty_pb2 import Empty
-_ = third_party
-from python.protos import voltha_pb2
+from voltha_protos import voltha_pb2
class LogicalDeviceCli(Cmd):
diff --git a/python/cli/main.py b/python/cli/main.py
index 0fc9b5b..0f5c618 100755
--- a/python/cli/main.py
+++ b/python/cli/main.py
@@ -33,12 +33,11 @@
from alarm_filters import AlarmFiltersCli
from logical_device import LogicalDeviceCli
from table import print_pb_list_as_table
-from python.common.openflow.utils import *
-from python.protos import third_party
-from python.protos import voltha_pb2
-from python.protos.openflow_13_pb2 import FlowTableUpdate, FlowGroupTableUpdate
+from pyvoltha.common.openflow.utils import *
+from voltha_protos import voltha_pb2
+from voltha_protos import voltha_pb2_grpc
+from voltha_protos.openflow_13_pb2 import FlowTableUpdate, FlowGroupTableUpdate
-_ = third_party
from python.cli.utils import pb2dict
defs = dict(
@@ -142,7 +141,7 @@
def get_stub(self):
if self.stub is None:
- self.stub = voltha_pb2.VolthaServiceStub(self.get_channel())
+ self.stub = voltha_pb2_grpc.VolthaServiceStub(self.get_channel())
# self.stub = \
# voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) \
# if self.global_request else \
diff --git a/python/cli/omci.py b/python/cli/omci.py
index d8b8334..95768c8 100644
--- a/python/cli/omci.py
+++ b/python/cli/omci.py
@@ -23,13 +23,11 @@
from datetime import datetime
from google.protobuf.empty_pb2 import Empty
from table import print_pb_list_as_table
-from python.protos import third_party
-from python.protos import voltha_pb2
-from python.protos.omci_mib_db_pb2 import MibDeviceData, MibClassData, \
+from voltha_protos import voltha_pb2
+from voltha_protos.omci_mib_db_pb2 import MibDeviceData, MibClassData, \
MibInstanceData
from os import linesep
-_ = third_party
class OmciCli(Cmd):
diff --git a/python/docker/Dockerfile.base_local b/python/docker/Dockerfile.base_local
new file mode 100644
index 0000000..b71627b
--- /dev/null
+++ b/python/docker/Dockerfile.base_local
@@ -0,0 +1,43 @@
+# Copyright 2016 the original author or authors.
+#
+# 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 ubuntu:xenial
+
+MAINTAINER Voltha Community <info@opennetworking.org>
+
+# Update to have latest images
+RUN apt-get update && \
+ apt-get install -y python python-pip openssl iproute2 libpcap-dev wget
+
+COPY requirements.txt /tmp/requirements.txt
+
+# pip install cython enum34 six && \
+# Install app dependencies
+RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \
+ dpkg -i *.deb && \
+ rm -f *.deb && \
+ apt-get update && \
+ apt-get install -y wget build-essential make gcc binutils python-dev libffi-dev libssl-dev git && \
+ pip install -r /tmp/requirements.txt
+
+# Install local pyvoltha
+COPY pyvoltha/dist /pyvoltha/dist
+RUN pip install /pyvoltha/dist/*.tar.gz
+
+# Install local voltha-protos
+COPY voltha-protos/dist /voltha-protos/dist
+RUN pip install /voltha-protos/dist/*.tar.gz
+
+RUN apt-get purge -y wget build-essential make gcc binutils python-dev libffi-dev libssl-dev git && \
+ apt-get autoremove -y
diff --git a/python/docker/Dockerfile.cli b/python/docker/Dockerfile.cli
index 2c4fd45..4e2d925 100644
--- a/python/docker/Dockerfile.cli
+++ b/python/docker/Dockerfile.cli
@@ -23,17 +23,10 @@
# Bundle app source
RUN mkdir /voltha && touch /voltha/__init__.py
ENV PYTHONPATH=/voltha
-COPY common /voltha/python/common/
COPY cli /voltha/python/cli
RUN touch /voltha/python/__init__.py
RUN touch /voltha/python/cli/__init__.py
-# Copy in the generated GRPC proto code
-COPY --from=protos /protos/voltha /voltha/python/protos
-COPY --from=protos /protos/google/api /voltha/python/protos/third_party/google/api
-COPY protos/third_party/__init__.py /voltha/python/protos/third_party
-RUN touch /voltha/python/protos/__init__.py
-RUN touch /voltha/python/protos/third_party/google/__init__.py
# Setup the voltha user
RUN useradd -b /home -d /home/voltha voltha -s /bin/bash
diff --git a/python/requirements.txt b/python/requirements.txt
index 56cb356..d6dd15d 100644
--- a/python/requirements.txt
+++ b/python/requirements.txt
@@ -28,7 +28,7 @@
pcapy==0.11.1
pep8==1.7.1
pep8-naming>=0.3.3
-protobuf==3.3.0
+protobuf==3.6.1
protobuf-to-dict==0.1.0
pyflakes==1.6.0
pylint==1.7.6
@@ -60,6 +60,8 @@
etcd3==0.7.0
pyparsing==2.2.0
packaging==17.1
+pyvoltha==0.1.7
+voltha-protos==0.1.0
# python-consul>=0.6.1 we need the pre-released version for now, because 0.6.1 does not
# yet support Twisted. Once this is released, it will be the 0.6.2 version