Add OpenStack Containers 70/50570/8
authorMarcus G K Williams <marcus.williams@intel.com>
Tue, 17 Jan 2017 17:57:04 +0000 (09:57 -0800)
committerJamo Luhrsen <jluhrsen@redhat.com>
Wed, 15 Feb 2017 22:31:29 +0000 (22:31 +0000)
Add OpenStack compute containers
for the purposes of
testing and developement.

Change-Id: I1b5717c2ed3665dae887b9ba15cf39d97aebeea0
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Co-Authored-By: Matt Welch <matt.welch@intel.com>
docker/openstack/compute/.dockerignore [new file with mode: 0644]
docker/openstack/compute/.gitignore [new file with mode: 0644]
docker/openstack/compute/Dockerfile [new file with mode: 0644]
docker/openstack/compute/build_compute.sh [new file with mode: 0755]
docker/openstack/compute/local.conf [new file with mode: 0644]
docker/openstack/compute/run_compute.sh [new file with mode: 0755]
docker/openstack/compute/start.sh [new file with mode: 0755]

diff --git a/docker/openstack/compute/.dockerignore b/docker/openstack/compute/.dockerignore
new file mode 100644 (file)
index 0000000..397680e
--- /dev/null
@@ -0,0 +1,3 @@
+logs
+history
+*.history
diff --git a/docker/openstack/compute/.gitignore b/docker/openstack/compute/.gitignore
new file mode 100644 (file)
index 0000000..b899373
--- /dev/null
@@ -0,0 +1,4 @@
+logs
+history
+*.history
+testing
diff --git a/docker/openstack/compute/Dockerfile b/docker/openstack/compute/Dockerfile
new file mode 100644 (file)
index 0000000..5b0452d
--- /dev/null
@@ -0,0 +1,37 @@
+FROM        ubuntu:14.04
+MAINTAINER  OpenDaylight Integration Project Team <integration-dev@lists.opendaylight.org>
+
+ENV     PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
+        DEBIAN_FRONTEND=noninteractive
+
+# Install devstack dependencies
+RUN     apt-get update && apt-get install -y --no-install-recommends \
+        git \
+        openssh-server \
+        ca-certificates \
+        openvswitch-common \
+        openvswitch-switch \
+        dbus && \
+        rm -rf /var/lib/apt/lists/*
+
+# Add stack user
+RUN     groupadd stack && \
+        useradd -g stack -s /bin/bash -m stack && \
+        echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
+
+# Get devstack
+USER    stack
+RUN     git clone https://git.openstack.org/openstack-dev/devstack /home/stack/devstack
+
+# Copy and chown local.conf to stack
+COPY    local.conf /home/stack/local.conf
+RUN     sudo chown stack:stack /home/stack/local.conf
+
+# Copy start.sh and chown to stack
+COPY    start.sh /home/stack/start.sh
+RUN     sudo chown stack:stack /home/stack/start.sh && chmod 766 /home/stack/start.sh
+
+CMD     ["/home/stack/start.sh"]
+
+# vim: set ft=dockerfile sw=4 ts=4 :
+
diff --git a/docker/openstack/compute/build_compute.sh b/docker/openstack/compute/build_compute.sh
new file mode 100755 (executable)
index 0000000..d79269a
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+# file: build_compute.sh
+# info: builds a docker compute image
+IMAGE_BASE=s3p/compute
+IMAGE_TAG=v0.2
+if [ -n "$1" ] ; then
+    # use arg as image tag if supplied
+    IMAGE_TAG="$1"
+fi
+IMAGE_NAME=$IMAGE_BASE:$IMAGE_TAG
+DOCKERFILE=Dockerfile
+
+echo "Building $IMAGE_NAME from Dockerfile=$DOCKERFILE at $(date) ... "
+docker build -t ${IMAGE_NAME} -f ${DOCKERFILE} \
+    --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy .
+
+if [ $? = 0 ] ; then
+    PROXIES=""
+    if [ -n "$http_proxy" ] ; then
+        PROXIES="--env http_proxy=$http_proxy --env https_proxy=$https_proxy --env no_proxy=$no_proxy"
+    fi
+    echo -e "\nDocker image $IMAGE_NAME built successfully.\n"
+    docker images $IMAGE_NAME
+    echo -e "\nYou can launch it with the following example command:\n"
+    echo -e "  docker run -it --rm $PROXIES $IMAGE_NAME bash\n"
+else
+    echo "An error occurred during the build of $IMAGE_NAME"
+fi
+
diff --git a/docker/openstack/compute/local.conf b/docker/openstack/compute/local.conf
new file mode 100644 (file)
index 0000000..655d3c7
--- /dev/null
@@ -0,0 +1,57 @@
+[[local|localrc]]
+## Services ##
+## When using OpenDaylight for NetVirt, remove q-agt from ENABLED_SERVICES
+ENABLED_SERVICES=n-cpu,q-agt
+
+## Repository sources ##
+GIT_BASE=${GIT_BASE:-https://git.openstack.org}
+PIP_UPGRADE=True
+
+## logging configuration ##
+HOME=/opt/stack
+DEST=${HOME}
+DATA_DIR=${DEST}/data
+LOGDIR=${DEST}/logs
+SCREEN_LOGDIR=${LOGDIR}/screen-logs
+LOGFILE=${LOGDIR}/stack.sh.log
+LOG_COLOR=False
+VERBOSE=True
+
+## Passwords & authentication ##
+ADMIN_PASSWORD=secret
+MYSQL_PASSWORD=${ADMIN_PASSWORD}
+DATABASE_PASSWORD=${ADMIN_PASSWORD}
+RABBIT_PASSWORD=${ADMIN_PASSWORD}
+SERVICE_PASSWORD=${ADMIN_PASSWORD}
+HORIZON_PASSWORD=${ADMIN_PASSWORD}
+SERVICE_TOKEN_PASSWORD=${ADMIN_PASSWORD}
+SERVICE_TOKEN=111222333
+
+## Hosts & services configuration ##
+HOST_IP=172.17.0.5
+HOST_NAME=$(hostname)
+SERVICE_HOST=10.20.0.2
+SERVICE_HOST_NAME=${HOST_NAME}
+SERVICE_LISTEN_ADDRESS=${HOST_IP}
+SERVICE_LOCAL_HOST=${SERVICE_HOST}
+MYSQL_HOST=${SERVICE_HOST}
+RABBIT_HOST=${SERVICE_HOST}
+GLANCE_HOSTPORT=${SERVICE_HOST}:9292
+KEYSTONE_AUTH_HOST=${SERVICE_HOST}
+KEYSTONE_SERVICE_HOST=${SERVICE_HOST}
+
+## Network Configuration ##
+## When using OpenDaylight for NetVirt uncomment the following two lines
+#enable_plugin networking-odl http://git.openstack.org/openstack/networking-odl stable/newton
+#ODL_MODE=compute
+IP_VERSION=4
+
+# disable security groups TODO: determine impact
+Q_USE_SECGROUP=False
+
+## Nova configuration ##
+LIBVIRT_TYPE=qemu
+
+
+# vim: set ft=conf :
+
diff --git a/docker/openstack/compute/run_compute.sh b/docker/openstack/compute/run_compute.sh
new file mode 100755 (executable)
index 0000000..ea86f34
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+# file: ./run_compute.sh
+# info: spawns a docker compute image
+# dependencies: consumes proxy variables if defined in the local environment
+# + To connect to an OpenStack service node, it must first be running.
+# + Compute host image must also be available locally or in a registry.
+
+# image selection
+IMAGE_REPO="s3p/compute"
+IMAGE_VERSION="v0.2" # v0.2==Ubuntu 14.04
+IMAGE_NAME="${IMAGE_REPO}:${IMAGE_VERSION}"
+
+# image configuration
+HOST_ID=01
+COMP_ID=04
+NAME="compute-${HOST_ID}-${COMP_ID}"
+ODL_NETWORK=false
+# when running on a RHEL-derivative host, use "--security-opt seccomp=unconfined"
+CAPABILITIES="--privileged --cap-add ALL --security-opt apparmor=docker-unconfined "
+CGROUP_MOUNT=""
+MOUNTS="-v /dev:/dev -v /lib/modules:/lib/modules $CGROUP_MOUNT "
+STACK_PASS=${STACK_PASS:-stack}
+# default SERVICE_HOST, based on openstack. This may be overridden.
+SERV_HOST=${SERV_HOST:-10.20.0.2}
+# define _no_proxy based on the cluster topology
+_no_proxy=localhost,10.0.0.0/8,192.168.0.0/16,172.17.0.0/16,127.0.0.1,127.0.0.0/8,$SERV_HOST
+
+#if [ -n "$1" ] ; then
+#    echo "Command argument supplied, running \"$1\" in $NAME..."
+#    COMMAND="$1"
+#fi
+
+SERVICE_NODE_NAME="service-node"
+# check to see that service-node is running first and get its IP from Docker
+SERVICE_NODE_IP=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" service-node)
+if [ -z "$SERVICE_NODE_IP" ] ; then
+    echo "WARNING: no service node is available on overlay-net."
+    echo "You can launch the compute container, but it may not be able to connect to a service node."
+fi
+SERV_HOST=$SERVICE_NODE_IP
+docker run -dit --name ${NAME} --hostname ${NAME} \
+    --env http_proxy=$http_proxy --env https_proxy=$https_proxy \
+    --env no_proxy=$_no_proxy \
+    --env ODL_NETWORK=$ODL_NETWORK \
+    --env STACK_PASS=$STACK_PASS \
+    --env SERV_HOST=$SERV_HOST \
+    --env container=docker \
+    --net=overlay-net \
+    $MOUNTS \
+    $CAPABILITIES $IMAGE_NAME \
+    /bin/bash
+
+CONTAINER_SHORT_ID=$(docker ps -aqf "name=${NAME}")
+docker exec -it $CONTAINER_SHORT_ID /bin/bash
+
diff --git a/docker/openstack/compute/start.sh b/docker/openstack/compute/start.sh
new file mode 100755 (executable)
index 0000000..f8a15e6
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+# On docker run, Env Variables "STACK_PASS & SERV_HOST" should be set using -e
+#  example 'docker run -e "STACK_PASS=stack" -e "SERV_HOST=192.168.0.5" compute'
+# or overided below by uncommenting:
+#STACK_PASS="stack"
+# SERV_HOST="192.168.0.5"
+# ODL_NETWORK should be set in the 'docker run' script
+set -o nounset # throw an error if a variable is unset to prevent unexpected behaviors
+ODL_NETWORK=${ODL_NETWORK}
+DEVSTACK_HOME="/home/stack/devstack"
+CONF_PATH=$DEVSTACK_HOME/local.conf
+BRANCH_NAME=stable/newton
+TAG_NAME="origin/${BRANCH_NAME}"
+
+#Set Nameserver to google
+echo nameserver 8.8.8.8 | sudo tee -a /etc/resolv.conf
+
+# change the stack user password
+echo "stack:$STACK_PASS" | sudo chpasswd
+
+# get container IP
+ip=`/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1`
+
+# Start SSH Service
+# Centos7: sudo: service: command not found
+#sudo service ssh start
+
+# Start openvswitch
+# Centos7: sudo: service: command not found
+#sudo service openvswitch-switch start
+
+# set the correct branch in devstack
+cd $DEVSTACK_HOME
+git fetch
+git checkout -b ${BRANCH_NAME} -t ${TAG_NAME}
+
+# copy local.conf into devstack and customize, based on environment including:
+# ODL_NETWORK, ip, DEVSTACK_HOME, SERV_HOST
+cp /home/stack/local.conf $CONF_PATH
+
+# Configure local.conf
+# update the ip of this host & SERVICE_HOST
+sed -i "s/HOST_IP=.*/HOST_IP=${ip}/" $CONF_PATH
+sed -i "s/SERVICE_HOST=.*/SERVICE_HOST=$SERV_HOST/" $CONF_PATH
+# modify the local.conf according to ODL_NETWORK value
+echo "Preparing $CONF_PATH for ODL=$ODL_NETWORK"
+echo
+if [ "$ODL_NETWORK" = "false" ] ; then
+    # prepare local.conf to NOT use ODL networking (default to Neutron)
+    sed -i "s:^\(enable_plugin networking-odl\):#\1:g" $CONF_PATH
+    sed -i "s:^\(ODL_MODE=compute\):#\1:g" $CONF_PATH
+    sed -i "s:^\(ENABLED_SERVICES=\).*:\1n-cpu,q-agt:g" $CONF_PATH
+else
+    # prepare local.conf to use ODL networking
+    sed -i "s:^#\(enable_plugin networking-odl\):\1:g" $CONF_PATH
+    sed -i "s:^#\(ODL_MODE=compute\):\1:g" $CONF_PATH
+    sed -i "s:^\(ENABLED_SERVICES=\).*:\1n-cpu:g" $CONF_PATH
+fi
+
+$DEVSTACK_HOME/stack.sh
+