Add OpenStack support

This change allows the provisioning of an All-in-One OpenStack
deployment through ansible-kolla project. Given that it uses System D
this adds an exception to use Ubuntu Xenial release.

Change-Id: I57973a1b5cc331654fbabf7932ddcfef817afedf
Signed-off-by: Victor Morales <victor.morales@intel.com>
Issue-Id: INT-329
diff --git a/bootstrap/vagrant-onap/lib/commons b/bootstrap/vagrant-onap/lib/commons
index 1c45413..5d0c691 100755
--- a/bootstrap/vagrant-onap/lib/commons
+++ b/bootstrap/vagrant-onap/lib/commons
@@ -34,7 +34,7 @@
         *suse)
         ;;
         ubuntu|debian)
-            dpkg -s "$@" > /dev/null 2> /dev/null
+            dpkg -s "$@" > /dev/null
         ;;
         rhel|centos|fedora)
         ;;
diff --git a/bootstrap/vagrant-onap/lib/functions b/bootstrap/vagrant-onap/lib/functions
index cc90523..25fbba3 100755
--- a/bootstrap/vagrant-onap/lib/functions
+++ b/bootstrap/vagrant-onap/lib/functions
@@ -5,7 +5,8 @@
 source /var/onap/_onap_functions
 
 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
-export IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
+export NIC=$(ip route get 8.8.8.8 | awk '{ print $5; exit }')
+export IP_ADDRESS=$(ifconfig $NIC | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
 
 mvn_conf_file=/root/.m2/settings.xml
 git_src_folder=/opt
@@ -16,6 +17,14 @@
     resolvconf -u
 }
 
+# get_next_ip() - Function that provides the next ip
+function get_next_ip {
+    local ip=${1:-$IP_ADDRESS}
+    ip_hex=$(printf '%.2X%.2X%.2X%.2X\n' `echo $ip | sed -e 's/\./ /g'`)
+    next_ip_hex=$(printf %.8X `echo $(( 0x$ip_hex + 1 ))`)
+    echo $(printf '%d.%d.%d.%d\n' `echo $next_ip_hex | sed -r 's/(..)/0x\1 /g'`)
+}
+
 # _git_timed() - git can sometimes get itself infinitely stuck with transient network
 # errors or other issues with the remote end.  This wraps git in a
 # timeout/retry loop and is intended to watch over non-local git
@@ -142,7 +151,6 @@
     rm $docker_conf_backup
 
     echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock\"" >> $docker_conf
-    usermod -a -G docker vagrant
 }
 
 # install_nodejs() - Download and install NodeJS
@@ -165,17 +173,17 @@
 # _install_pip() - Install Python Package Manager
 function _install_pip {
     install_python
-    if [ ! -f /usr/local/bin/pip ]; then
+    if ! which pip; then
         curl -sL https://bootstrap.pypa.io/get-pip.py | python
     fi
 }
 
 # install_python_package() - Install a python module
 function install_python_package {
-    local python_package=$1
+    local python_packages=$@
 
     _install_pip
-    pip install $python_package
+    pip install $python_packages
 }
 
 # install_docker() - Download and install docker-engine
diff --git a/bootstrap/vagrant-onap/lib/openstack b/bootstrap/vagrant-onap/lib/openstack
new file mode 100755
index 0000000..6fe20d9
--- /dev/null
+++ b/bootstrap/vagrant-onap/lib/openstack
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+source /var/onap/functions
+
+# deploy_openstack() - Function that provisions an OpenStack deployment
+function deploy_openstack {
+    local network_id=${1:-"192.168.53.0"}
+    nic=$(ip route get $network_id | awk '{ print $4; exit }')
+    ip_address=$(ip route get $network_id | awk '{ print $6; exit }')
+    internal_vip_address=$(get_next_ip $ip_address)
+
+    install_docker
+    mkdir -p /etc/systemd/system/docker.service.d
+    tee /etc/systemd/system/docker.service.d/kolla.conf <<-'EOF'
+[Service]
+MountFlags=shared
+EOF
+    install_packages python-dev libffi-dev gcc libssl-dev python-selinux gcc
+
+    install_python_package ansible docker kolla-ansible python-openstackclient
+    source /etc/os-release || source /usr/lib/os-release
+    case ${ID,,} in
+        *suse)
+        ;;
+        ubuntu|debian)
+        service docker restart
+
+        cp -r /usr/local/share/kolla-ansible/etc_examples/kolla /etc/kolla/
+        cp /usr/local/share/kolla-ansible/ansible/inventory/* .
+        sed -i "s/#kolla_base_distro: \"centos\"/kolla_base_distro: \"ubuntu\"/g" /etc/kolla/globals.yml
+        ;;
+        rhel|centos|fedora)
+        systemctl daemon-reload
+        systemctl restart docker
+
+        cp -r /usr/share/kolla-ansible/etc_examples/kolla /etc/kolla/
+        cp /usr/share/kolla-ansible/ansible/inventory/* .
+        sed -i "s/#kolla_base_distro: \"centos\"/kolla_base_distro: \"centos\"/g" /etc/kolla/globals.yml
+        ;;
+    esac
+    kolla-genpwd
+    sed -i "s/#openstack_release: \"\"/openstack_release: \"master\"/g" /etc/kolla/globals.yml
+
+    sed -i "s/#network_interface: \"eth0\"/network_interface: \"$nic\"/g" /etc/kolla/globals.yml
+    sed -i "s/kolla_internal_vip_address: \"10.10.10.254\"/kolla_internal_vip_address: \"$internal_vip_address\"/g" /etc/kolla/globals.yml
+    sed -i "s/#api_interface: \"{{ network_interface }}\"/api_interface: \"{{ network_interface }}\"/g" /etc/kolla/globals.yml
+    echo "$ip_address $(hostname)" >> /etc/hosts
+
+    kolla-ansible pull -i all-in-one
+    kolla-ansible deploy -i all-in-one
+    kolla-ansible post-deploy
+    echo "source /etc/kolla/admin-openrc.sh" >> ${HOME}/.bashrc
+}