summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml2
-rw-r--r--vio/assembly.xml8
-rw-r--r--vio/docker/Dockerfile27
-rwxr-xr-xvio/docker/build_image.sh34
-rwxr-xr-xvio/docker/docker-entrypoint.sh41
-rwxr-xr-xvio/docker/instance-config.sh29
-rwxr-xr-xvio/docker/instance-init.sh9
-rwxr-xr-xvio/docker/instance-run.sh11
-rw-r--r--vio/pom.xml10
-rwxr-xr-xvio/run.sh29
-rw-r--r--vio/version.properties13
-rw-r--r--vio/vio/swagger/views/proxyplugin/identity/views.py18
12 files changed, 208 insertions, 23 deletions
diff --git a/pom.xml b/pom.xml
index 6770969..263afcf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<groupId>org.onap.multicloud.openstack.vmware</groupId>
<artifactId>multicloud-vio</artifactId>
<version>1.0.0-SNAPSHOT</version>
- <name>multicloud/openstack/vmware</name>
+ <name>multicloud-openstack-vmware</name>
<packaging>pom</packaging>
<modules>
diff --git a/vio/assembly.xml b/vio/assembly.xml
index c59ad59..5df8abe 100644
--- a/vio/assembly.xml
+++ b/vio/assembly.xml
@@ -38,6 +38,14 @@
<include>*.txt</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>docker</directory>
+ <outputDirectory>/docker</outputDirectory>
+ <includes>
+ <include>*.sh</include>
+ <include>Dockerfile</include>
+ </includes>
+ </fileSet>
<fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
diff --git a/vio/docker/Dockerfile b/vio/docker/Dockerfile
new file mode 100644
index 0000000..7d2e84f
--- /dev/null
+++ b/vio/docker/Dockerfile
@@ -0,0 +1,27 @@
+FROM python:2
+
+ENV MSB_ADDR "127.0.0.1"
+ENV MSB_PORT "80"
+ENV AAI_ADDR "aai.api.simpledemo.openecomp.org"
+ENV AAI_PORT "8443"
+ENV AAI_SCHEMA_VERSION "v11"
+ENV AAI_USERNAME "AAI"
+ENV AAI_PASSWORD "AAI"
+
+EXPOSE 9004
+
+RUN apt-get update && \
+ apt-get install -y unzip && \
+ apt-get install -y curl && \
+ apt-get install -y wget
+
+
+RUN cd /opt/ && \
+ wget -q -O multicloud-vio.zip 'https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.openstack.vmware&a=multicloud-vio&v=LATEST&e=zip' && \
+ unzip multicloud-vio.zip && \
+ rm -rf multicloud-vio.zip && \
+ pip install -r vio/requirements.txt
+
+
+WORKDIR /opt
+ENTRYPOINT vio/docker/docker-entrypoint.sh
diff --git a/vio/docker/build_image.sh b/vio/docker/build_image.sh
new file mode 100755
index 0000000..b1e691b
--- /dev/null
+++ b/vio/docker/build_image.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+DIRNAME=`dirname $0`
+DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd`
+echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}"
+cd ${DOCKER_BUILD_DIR}
+
+BUILD_ARGS="--no-cache"
+ORG="onap"
+VERSION="1.0.0-SNAPSHOT"
+PROJECT="multicloud"
+IMAGE="vio"
+DOCKER_REPOSITORY="nexus3.onap.org:10003"
+IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}"
+
+if [ $HTTP_PROXY ]; then
+ BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
+fi
+if [ $HTTPS_PROXY ]; then
+ BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
+fi
+
+function build_image {
+ echo "Start build docker image: ${IMAGE_NAME}"
+ docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:${VERSION} -t ${IMAGE_NAME}:latest .
+}
+
+function push_image {
+ echo "Start push docker image: ${IMAGE_NAME}"
+ docker push ${IMAGE_NAME}:${VERSION}
+ docker push ${IMAGE_NAME}:latest
+}
+
+build_image
+push_image
diff --git a/vio/docker/docker-entrypoint.sh b/vio/docker/docker-entrypoint.sh
new file mode 100755
index 0000000..6c9d3e3
--- /dev/null
+++ b/vio/docker/docker-entrypoint.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+
+if [ -z "$SERVICE_IP" ]; then
+ export SERVICE_IP=`hostname -i`
+fi
+echo
+echo Environment Variables:
+echo "SERVICE_IP=$SERVICE_IP"
+
+if [ -z "$MSB_ADDR" ]; then
+ echo "Missing required variable MSB_ADDR: Microservices Service Bus address <ip>:<port>"
+ exit 1
+fi
+echo "MSB_ADDR=$MSB_ADDR"
+echo
+
+# Wait for MSB initialization
+echo Wait for MSB initialization
+for i in {1..20}; do
+ curl -sS -m 1 $MSB_ADDR > /dev/null && break
+ sleep $i
+done
+
+echo
+
+# Configure service based on docker environment variables
+vio/docker/instance-config.sh
+
+
+# Perform one-time config
+if [ ! -e init.log ]; then
+
+ # microservice-specific one-time initialization
+ vio/docker/instance-init.sh
+
+ date > init.log
+fi
+
+# Start the microservice
+vio/docker/instance-run.sh
diff --git a/vio/docker/instance-config.sh b/vio/docker/instance-config.sh
new file mode 100755
index 0000000..221cac9
--- /dev/null
+++ b/vio/docker/instance-config.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+# Configure MSB IP address
+MSB_IP=`echo $MSB_ADDR | cut -d: -f 1`
+MSB_PORT=`echo $MSB_ADDR | cut -d: -f 2`
+sed -i "s|MSB_SERVICE_IP.*|MSB_SERVICE_IP = '$MSB_IP'|" vio/vio/pub/config/config.py
+sed -i "s|MSB_SERVICE_PORT.*|MSB_SERVICE_PORT = '$MSB_PORT'|" vio/vio/pub/config/config.py
+sed -i "s|DB_NAME.*|DB_NAME = 'inventory'|" vio/vio/pub/config/config.py
+sed -i "s|DB_USER.*|DB_USER = 'inventory'|" vio/vio/pub/config/config.py
+sed -i "s|DB_PASSWD.*|DB_PASSWD = 'inventory'|" vio/vio/pub/config/config.py
+sed -i "s|\"ip\": \".*\"|\"ip\": \"$SERVICE_IP\"|" vio/vio/pub/config/config.py
+
+# Configure MYSQL
+if [ -z "$MYSQL_ADDR" ]; then
+ export MYSQL_IP=`hostname -i`
+ export MYSQL_PORT=3306
+ export MYSQL_ADDR=$MYSQL_IP:$MYSQL_PORT
+else
+ MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
+ MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
+fi
+echo "MYSQL_ADDR=$MYSQL_ADDR"
+sed -i "s|DB_IP.*|DB_IP = '$MYSQL_IP'|" vio/vio/pub/config/config.py
+sed -i "s|DB_PORT.*|DB_PORT = $MYSQL_PORT|" vio/vio/pub/config/config.py
+
+cat vio/vio/pub/config/config.py
+
+sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/run.sh
+sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/stop.sh \ No newline at end of file
diff --git a/vio/docker/instance-init.sh b/vio/docker/instance-init.sh
new file mode 100755
index 0000000..f7e0e0e
--- /dev/null
+++ b/vio/docker/instance-init.sh
@@ -0,0 +1,9 @@
+#!/bin/bash -v
+
+# Initialize DB schema
+#./bin/initDB.sh root rootpass 3306 127.0.0.1
+
+# Install python requirements
+cd /opt/vio
+./initialize.sh
+cd /opt
diff --git a/vio/docker/instance-run.sh b/vio/docker/instance-run.sh
new file mode 100755
index 0000000..2393c5d
--- /dev/null
+++ b/vio/docker/instance-run.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -v
+
+redis-server &
+
+cd ./vio
+./run.sh
+
+while [ ! -f logs/runtime_vio.log ]; do
+ sleep 1
+done
+tail -F logs/runtime_vio.log
diff --git a/vio/pom.xml b/vio/pom.xml
index a3bda08..dd05ffe 100644
--- a/vio/pom.xml
+++ b/vio/pom.xml
@@ -12,7 +12,9 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
@@ -22,10 +24,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.multicloud.openstack.vmware</groupId>
<artifactId>multicloud-vio</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
- <name>multicloud/openstack/vmware</name>
- <description>multiclouddriver for vio</description>
+ <name>multicloud/opentack/vmware</name>
+ <description>multicloud vio</description>
<build>
<plugins>
<plugin>
diff --git a/vio/run.sh b/vio/run.sh
index aa2701f..9abbc85 100755
--- a/vio/run.sh
+++ b/vio/run.sh
@@ -1,14 +1,17 @@
#!/bin/bash
-# Copyright (c) 2017 VMware, Inc.
-#
-# 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.
-
-nohup python manage.py runserver 127.0.0.1:9004 > /dev/null &
+
+sed -i "s/MSB_SERVICE_IP =.*/MSB_SERVICE_IP = \"${MSB_ADDR}\"/g" vio/pub/config/config.py
+sed -i "s/MSB_SERVICE_PORT =.*/MSB_SERVICE_PORT = \"${MSB_PORT}\"/g" vio/pub/config/config.py
+sed -i "s/AAI_ADDR =.*/AAI_ADDR = \"${AAI_ADDR}\"/g" vio/pub/config/config.py
+sed -i "s/AAI_PORT =.*/AAI_PORT = \"${AAI_PORT}\"/g" vio/pub/config/config.py
+sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/g" vio/pub/config/config.py
+sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" vio/pub/config/config.py
+sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" vio/pub/config/config.py
+
+nohup python manage.py runserver 0.0.0.0:9004 2>&1 &
+
+while [ ! -f logs/runtime_vio.log ]; do
+ sleep 1
+done
+
+tail -F logs/runtime_vio.log
diff --git a/vio/version.properties b/vio/version.properties
new file mode 100644
index 0000000..5128787
--- /dev/null
+++ b/vio/version.properties
@@ -0,0 +1,13 @@
+# Versioning variables
+# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... )
+# because they are used in Jenkins, whose plug-in doesn't support
+
+major=1
+minor=0
+patch=0
+
+base_version=${major}.${minor}.${patch}
+
+# Release must be completed with git revision # in Jenkins
+release_version=${base_version}
+snapshot_version=${base_version}-SNAPSHOT
diff --git a/vio/vio/swagger/views/proxyplugin/identity/views.py b/vio/vio/swagger/views/proxyplugin/identity/views.py
index 0ce6312..cee11e7 100644
--- a/vio/vio/swagger/views/proxyplugin/identity/views.py
+++ b/vio/vio/swagger/views/proxyplugin/identity/views.py
@@ -93,9 +93,14 @@ class TokenView(BaseClient):
logger.info("vimid(%(vimid)s) get keystone url %(url)s ",
{"vimid": vimid, "url": keystoneURL})
try:
- res = requests.get(url=keystoneURL).json()
- res['version']['links'][0]['href'] = "http://" + \
- MSB_ADDRESS + "/multicloud-vio/v0/" + vimid + "/identity/v3"
+ res = requests.get(url=keystoneURL, verify=False)
+ if res.status_code != status.HTTP_200_OK:
+ return Response(data={"error": res.content},
+ status=res.status_code)
+ res = res.json()
+ res['version']['links'][0]['href'] = \
+ "http://" + MSB_ADDRESS + "/multicloud-vio/v0/" \
+ + vimid + "/identity/v3"
except Exception as e:
logging.exception("error %s" % e)
@@ -143,8 +148,11 @@ class TokenView(BaseClient):
{"vimid": vimid, "url": url})
try:
- res = requests.post(url=url, data=json.dumps(
- create_req), headers=headers)
+ res = requests.post(url=url, data=json.dumps(create_req),
+ headers=headers, verify=False)
+ if res.status_code != status.HTTP_201_CREATED:
+ return Response(data={"error": res.content},
+ status=res.status_code)
tokenInfo = res.json()
resHeader = dict(res.headers)
except Exception as e: