From 182bd73468eb7e3a69254bed25f12a91b18393d0 Mon Sep 17 00:00:00 2001 From: Mike Marchetti Date: Wed, 5 Sep 2018 09:52:42 -0400 Subject: [PATCH] Initial seed file for MDG dockerfiles Change-Id: I7426a709e1b531dd28c440e088b6f508e7cdefa0 Signed-off-by: Mike Marchetti --- docker/MON/Dockerfile | 53 ++++++++++++ docker/MON/scripts/requirements.txt | 39 +++++++++ docker/MON/scripts/runInstall.sh | 26 ++++++ docker/NBI/Dockerfile | 62 ++++++++++++++ docker/RO/Dockerfile | 47 ++++++++++ docker/RO/scripts/start.sh | 128 ++++++++++++++++++++++++++++ 6 files changed, 355 insertions(+) create mode 100644 docker/MON/Dockerfile create mode 100644 docker/MON/scripts/requirements.txt create mode 100755 docker/MON/scripts/runInstall.sh create mode 100644 docker/NBI/Dockerfile create mode 100644 docker/RO/Dockerfile create mode 100755 docker/RO/scripts/start.sh diff --git a/docker/MON/Dockerfile b/docker/MON/Dockerfile new file mode 100644 index 00000000..9ea5b3ef --- /dev/null +++ b/docker/MON/Dockerfile @@ -0,0 +1,53 @@ +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# 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. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## + +FROM ubuntu:16.04 + +LABEL authors="Guillermo Calvino" + +RUN apt-get update && apt-get -y install curl software-properties-common + +ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian +ARG RELEASE=ReleaseFOUR-daily +ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg +ARG REPOSITORY=testing + +RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add - +RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} MON IM common" && apt update + +RUN apt-get --yes update \ + && apt-get --yes install git python python-pip python3 python3-pip libmysqlclient-dev libssl-dev libffi-dev \ + && pip3 install pip==9.0.3 + +RUN apt-get --yes update && apt-get -y install python3-osm-common python3-osm-mon + +COPY scripts/ scripts/ + +RUN pip3 install -r scripts/requirements.txt + +# These ENV must be provided +# ENV BROKER_URI=kafka:9092 +# ENV OS_NOTIFIER_URI=:8662 + +EXPOSE 8662 + +CMD /bin/bash scripts/runInstall.sh diff --git a/docker/MON/scripts/requirements.txt b/docker/MON/scripts/requirements.txt new file mode 100644 index 00000000..28bb7197 --- /dev/null +++ b/docker/MON/scripts/requirements.txt @@ -0,0 +1,39 @@ +# Copyright 2017 Intel Research and Development Ireland Limited +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Intel Corporation + +# 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. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: prithiv.mohan@intel.com or adrian.hoban@intel.com +kafka==1.3.* +lxml==4.2.* +requests==2.18.* +logutils==0.3.* +cherrypy==14.0.* +jsmin==2.2.* +jsonschema==2.6.* +python-openstackclient==3.15.* +python-novaclient==10.1.* +python-keystoneclient==3.15.* +boto==2.48 +python-cloudwatchlogs-logging==0.0.3 +py-cloudwatch==0.0.1 +pyvcloud==19.1.1 +pyopenssl==17.5.* +six==1.11.* +bottle==0.12.* +peewee==3.1.* +pyyaml==3.* diff --git a/docker/MON/scripts/runInstall.sh b/docker/MON/scripts/runInstall.sh new file mode 100755 index 00000000..236aa3da --- /dev/null +++ b/docker/MON/scripts/runInstall.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# 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. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## +/bin/bash /mon/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh +python3 /usr/lib/python3/dist-packages/osm_mon/plugins/OpenStack/Aodh/notifier.py & +python3 ./usr/lib/python3/dist-packages/osm_mon/core/message_bus/common_consumer.py + diff --git a/docker/NBI/Dockerfile b/docker/NBI/Dockerfile new file mode 100644 index 00000000..44b24b24 --- /dev/null +++ b/docker/NBI/Dockerfile @@ -0,0 +1,62 @@ +# This creates osm/NBI docker from local NBI source code + +FROM ubuntu:16.04 + +RUN apt-get update && apt-get -y install curl software-properties-common + +ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian +ARG RELEASE=ReleaseFOUR-daily +ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg +ARG REPOSITORY=testing + +RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add - +RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} NBI IM common" && apt update + +RUN apt-get -y install python3-osm-nbi python3-osm-common python3-osm-im + +# Set the working directory to /app +WORKDIR /app/osm_nbi + +RUN apt-get update && apt-get install -y git python3 python3-jsonschema \ + python3-pymongo python3-yaml python3-pip \ + && pip3 install pip==9.0.3 \ + && pip3 install aiokafka cherrypy pyangbind \ + && mkdir -p /app/storage/kafka && mkdir -p /app/log + +EXPOSE 9999 + +LABEL Maintainer="alfonso.tiernosepulveda@telefonica.com" \ + Description="This implements a north bound interface for OSM" \ + Version="1.0" \ + Author="Alfonso Tierno" + +# Used for local storage +VOLUME /app/storage +# Used for logs +VOLUME /app/log + +# The following ENV can be added with "docker run -e xxx' to configure +# server +ENV OSMNBI_SOCKET_HOST 0.0.0.0 +ENV OSMNBI_SOCKET_PORT 9999 +# storage +ENV OSMNBI_STORAGE_PATH /app/storage +# database +ENV OSMNBI_DATABASE_DRIVER mongo +ENV OSMNBI_DATABASE_HOST mongo +ENV OSMNBI_DATABASE_PORT 27017 +# web +ENV OSMNBI_STATIC_DIR /usr/lib/python3/dist-packages/osm_nbi/html_public +# logs +ENV OSMNBI_LOG_FILE /app/log +ENV OSMNBI_LOG_LEVEL DEBUG +# message +ENV OSMNBI_MESSAGE_DRIVER kafka +ENV OSMNBI_MESSAGE_HOST kafka +ENV OSMNBI_MESSAGE_PORT 9092 +# logs +ENV OSMNBI_LOG_FILE /app/log/nbi.log +ENV OSMNBI_LOG_LEVEL DEBUG + +# Run app.py when the container launches +CMD ["python3", "/usr/lib/python3/dist-packages/osm_nbi/nbi.py"] diff --git a/docker/RO/Dockerfile b/docker/RO/Dockerfile new file mode 100644 index 00000000..e6d37632 --- /dev/null +++ b/docker/RO/Dockerfile @@ -0,0 +1,47 @@ +from ubuntu:xenial + +MAINTAINER Gennadiy Dubina ; Alfonso Tierno + +RUN apt-get update && apt-get -y install curl software-properties-common + +ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian +ARG RELEASE=ReleaseFOUR-daily +ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg +ARG REPOSITORY=testing + +RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add - +RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} RO IM common openvim" && apt update + +RUN apt-get update && apt-get install -y python-setuptools python-wheel mysql-client python-bitarray +RUN apt-get update && apt-get install -y python-osm-ro python-osm-im + +RUN mkdir -p /bin/RO + +COPY scripts/ /bin/RO + +VOLUME /opt/openmano/logs + +EXPOSE 9090 + +# Two mysql databases are needed (DB and DB_OVIM). Can be hosted on same or separated containers +# These ENV must be provided +ENV RO_DB_HOST="" +ENV RO_DB_OVIM_HOST="" + # if empty RO_DB_HOST is assumed + +# These ENV should be provided first time for creating database. It will create and init only if empty! +ENV RO_DB_ROOT_PASSWORD="" +ENV RO_DB_OVIM_ROOT_PASSWORD="" + # if empty RO_DB_ROOT_PASSWORD is assumed + +# These ENV can be provided, but default values are ok +ENV RO_DB_USER=mano +ENV RO_DB_OVIM_USER=mano +ENV RO_DB_PASSWORD=manopw +ENV RO_DB_OVIM_PASSWORD=manopw +ENV RO_DB_PORT=3306 +ENV RO_DB_OVIM_PORT=3306 +ENV RO_DB_NAME=mano_db +ENV RO_DB_OVIM_NAME=mano_vim_db + +CMD /bin/RO/start.sh diff --git a/docker/RO/scripts/start.sh b/docker/RO/scripts/start.sh new file mode 100755 index 00000000..1506e3a3 --- /dev/null +++ b/docker/RO/scripts/start.sh @@ -0,0 +1,128 @@ +#!/bin/bash + + +[ -z "$RO_DB_OVIM_HOST" ] && export RO_DB_OVIM_HOST="$RO_DB_HOST" +[ -z "$RO_DB_OVIM_ROOT_PASSWORD" ] && export RO_DB_OVIM_ROOT_PASSWORD="$RO_DB_ROOT_PASSWORD" + +function is_db_created() { + db_host=$1 + db_port=$2 + db_user=$3 + db_pswd=$4 + db_name=$5 + + RESULT=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -o $db_name` + if [ "$RESULT" == "$db_name" ]; then + + RESULT=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" "$db_name" | grep -v Wildcard | grep schema_version` + #TODO validate version + if [ -n "$RESULT" ]; then + echo " DB $db_name exists and inited" + return 0 + else + echo " DB $db_name exists BUT not inited" + return 1 + fi + fi + echo " DB $db_name does not exist" + return 1 +} + +function configure(){ + #Database parameters + #db_host: localhost + #db_user: mano + #db_passwd: manopw + #db_name: mano_db + # Database ovim parameters + #db_ovim_host: localhost # by default localhost + #db_ovim_user: mano # DB user + #db_ovim_passwd: manopw # DB password + #db_ovim_name: mano_vim_db # Name of the OVIM MANO DB + + + sed -i "s/^db_host:.*/db_host: $RO_DB_HOST/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_user:.*/db_user: $RO_DB_USER/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_passwd:.*/db_passwd: $RO_DB_PASSWORD/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_name:.*/db_name: $RO_DB_NAME/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_ovim_host:.*/db_ovim_host: $RO_DB_OVIM_HOST/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_ovim_user:.*/db_ovim_user: $RO_DB_OVIM_USER/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_ovim_passwd:.*/db_ovim_passwd: $RO_DB_OVIM_PASSWORD/" /etc/osm/openmanod.cfg || return 1 + sed -i "s/^db_ovim_name:.*/db_ovim_name: $RO_DB_OVIM_NAME/" /etc/osm/openmanod.cfg || return 1 + return 0 +} + +max_attempts=120 +function wait_db(){ + db_host=$1 + db_port=$2 + attempt=0 + echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} " + while ! mysqladmin ping -h"$db_host" -P"$db_port" --silent; do + #wait 120 sec + if [ $attempt -ge $max_attempts ]; then + echo + echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec" + return 1 + fi + attempt=$[$attempt+1] + echo -n "." + sleep 1 + done + return 0 +} + + +echo "1/4 Apply config" +configure || exit 1 + + +echo "2/4 Wait for db up" +wait_db "$RO_DB_HOST" "$RO_DB_PORT" || exit 1 +[ "$RO_DB_OVIM_HOST" = "$RO_DB_HOST" ] || wait_db "$RO_DB_OVIM_HOST" "$RO_DB_OVIM_PORT" || exit 1 + + +echo "3/4 Init database" +RO_PATH=`python -c 'import osm_ro; print(osm_ro.__path__[0])'` +echo "RO_PATH: $RO_PATH" +if ! is_db_created "$RO_DB_HOST" "$RO_DB_PORT" "$RO_DB_USER" "$RO_DB_PASSWORD" "$RO_DB_NAME" +then + if [ -n "$RO_DB_ROOT_PASSWORD" ] ; then + mysqladmin -h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" create "$RO_DB_NAME" + echo "CREATE USER '${RO_DB_USER}'@'%' IDENTIFIED BY '${RO_DB_PASSWORD}';" | + mysql -h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" || echo "user ${RO_DB_USER} already created?" + echo "GRANT ALL PRIVILEGES ON ${RO_DB_NAME}.* TO '${RO_DB_USER}'@'%';" | + mysql -h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" || echo "user ${RO_DB_USER} already granted?" + fi + ${RO_PATH}/database_utils/init_mano_db.sh -u "$RO_DB_USER" -p "$RO_DB_PASSWORD" -h "$RO_DB_HOST" \ + -P "${RO_DB_PORT}" -d "${RO_DB_NAME}" || exit 1 +else + echo " migrage database version" + ${RO_PATH}/database_utils/migrate_mano_db.sh -u "$RO_DB_USER" -p "$RO_DB_PASSWORD" -h "$RO_DB_HOST" \ + -P "$RO_DB_PORT" -d "$RO_DB_NAME" +fi + +OVIM_PATH=`python -c 'import lib_osm_openvim; print(lib_osm_openvim.__path__[0])'` +echo "OVIM_PATH: $OVIM_PATH" +if ! is_db_created "$RO_DB_OVIM_HOST" "$RO_DB_OVIM_PORT" "$RO_DB_OVIM_USER" "$RO_DB_OVIM_PASSWORD" "$RO_DB_OVIM_NAME" +then + if [ -n "$RO_DB_OVIM_ROOT_PASSWORD" ] ; then + mysqladmin -h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" create "$RO_DB_OVIM_NAME" + echo "CREATE USER '${RO_DB_OVIM_USER}'@'%' IDENTIFIED BY '${RO_DB_OVIM_PASSWORD}';" | + mysql -h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" || + echo "user ${RO_DB_OVIM_USER} already created?" + echo "GRANT ALL PRIVILEGES ON ${RO_DB_OVIM_NAME}.* TO '${RO_DB_OVIM_USER}'@'%';" | + mysql -h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" || + echo "user ${RO_DB_OVIM_USER} already granted?" + fi + ${OVIM_PATH}/database_utils/init_vim_db.sh -u "$RO_DB_OVIM_USER" -p "$RO_DB_OVIM_PASSWORD" -h "$RO_DB_OVIM_HOST" \ + -P "${RO_DB_OVIM_PORT}" -d "${RO_DB_OVIM_NAME}" || exit 1 +else + echo " migrage database version" + ${OVIM_PATH}/database_utils/migrate_vim_db.sh -u "$RO_DB_OVIM_USER" -p "$RO_DB_OVIM_PASSWORD" -h "$RO_DB_OVIM_HOST"\ + -P "$RO_DB_OVIM_PORT" -d "$RO_DB_OVIM_NAME" +fi + + +echo "4/4 Try to start" +/usr/bin/openmanod -c /etc/osm/openmanod.cfg --log-file=/var/log/osm/openmano.log --create-tenant=osm -- 2.25.1