From 6fb0879ab761b23fe5c5a9feb25deb8453d2a5fe Mon Sep 17 00:00:00 2001
From: Kevin Carter <kevin.carter@rackspace.com>
Date: Fri, 7 Oct 2016 00:27:27 -0500
Subject: [PATCH] Updated deploy-osa section to setup more production like

This change simple makes the system deploy a network stack and create
various images in a more production like fashion.

Change-Id: Ib316d5fcab08aa31f2965175a4fb31f1d3566228
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
---
 multi-node-aio/deploy-osa.sh              |  12 +-
 multi-node-aio/openstack-service-setup.sh | 129 ++++++++++++++++++++++
 2 files changed, 134 insertions(+), 7 deletions(-)
 create mode 100644 multi-node-aio/openstack-service-setup.sh

diff --git a/multi-node-aio/deploy-osa.sh b/multi-node-aio/deploy-osa.sh
index 6ae77c04..937aaaff 100755
--- a/multi-node-aio/deploy-osa.sh
+++ b/multi-node-aio/deploy-osa.sh
@@ -106,12 +106,10 @@ pushd /opt/openstack-ansible
   bash ./scripts/run-playbooks.sh
 popd
 
+EXEC_DIR="$(pwd)"
 pushd /opt/openstack-ansible/playbooks
-# This is optional and only being done to give the cloud networks and an image.
-#  The tempest install will work out of the box because the deployment is setup
-#  already with all of the correct networks, devices, and other bits. If you want
-#  to test with tempest the OSA script will work out the box. Post deployment you
-#  can test with the following: `cd /opt/openstack-ansible; ./scripts/run-tempest.sh`
-openstack-ansible os-tempest-install.yml
+  if [[ -f "/usr/local/bin/openstack-ansible.rc" ]]; then
+    source /usr/local/bin/openstack-ansible.rc
+  fi
+  ansible -m script -a "${EXEC_DIR}/openstack-service-setup.sh" 'utility_all[0]'
 popd
-
diff --git a/multi-node-aio/openstack-service-setup.sh b/multi-node-aio/openstack-service-setup.sh
new file mode 100644
index 00000000..427ab0f0
--- /dev/null
+++ b/multi-node-aio/openstack-service-setup.sh
@@ -0,0 +1,129 @@
+#!/usr/bin/env bash
+
+# Load service variables
+source openrc
+
+# Neutron provider network setup
+neutron net-create GATEWAY_NET \
+    --router:external=True \
+    --provider:physical_network=flat \
+    --provider:network_type=flat
+
+neutron subnet-create GATEWAY_NET 172.29.248.0/22 \
+    --name GATEWAY_NET_SUBNET \
+    --gateway 172.29.248.1 \
+    --allocation-pool start=172.29.248.201,end=172.29.248.255 \
+    --dns-nameservers list=true 8.8.4.4 8.8.8.8
+
+# Neutron private network setup
+neutron net-create PRIVATE_NET \
+    --shared \
+    --router:external=True \
+    --provider:network_type=vxlan \
+    --provider:segmentation_id 101
+
+neutron subnet-create PRIVATE_NET 192.168.0.0/24 \
+    --name PRIVATE_NET_SUBNET
+
+# Neutron router setup
+ROUTER_ID=$(neutron router-create GATEWAY_NET_ROUTER | grep -w id | awk '{print $4}')
+neutron router-gateway-set \
+    ${ROUTER_ID} \
+    $(neutron net-list | awk '/GATEWAY_NET/ {print $2}')
+
+neutron router-interface-add \
+    ${ROUTER_ID} \
+    $(neutron subnet-list | awk '/PRIVATE_NET_SUBNET/ {print $2}')
+
+# Neutron security group setup
+for id in $(neutron security-group-list -f yaml | awk '/- id\:/ {print $3}'); do
+    # Allow ICMP
+    neutron security-group-rule-create --protocol icmp \
+                                       --direction ingress \
+                                       $id || true
+    # Allow all TCP
+    neutron security-group-rule-create --protocol tcp \
+                                       --port-range-min 1 \
+                                       --port-range-max 65535 \
+                                       --direction ingress \
+                                       $id || true
+    # Allow all UDP
+    neutron security-group-rule-create --protocol udp \
+                                       --port-range-min 1 \
+                                       --port-range-max 65535 -\
+                                       -direction ingress \
+                                       $id || true
+done
+
+# Create some default images
+wget http://uec-images.ubuntu.com/releases/14.04/release/ubuntu-14.04-server-cloudimg-amd64-disk1.img
+glance image-create --name 'Ubuntu 14.04 LTS' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file ubuntu-14.04-server-cloudimg-amd64-disk1.img
+rm ubuntu-14.04-server-cloudimg-amd64-disk1.img
+
+wget http://uec-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img
+glance image-create --name 'Ubuntu 16.04' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file ubuntu-16.04-server-cloudimg-amd64-disk1.img
+rm ubuntu-16.04-server-cloudimg-amd64-disk1.img
+
+wget http://dfw.mirror.rackspace.com/fedora/releases/24/CloudImages/x86_64/images/Fedora-Cloud-Base-24-1.2.x86_64.qcow2
+glance image-create --name 'Fedora 24' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file Fedora-Cloud-Base-24-1.2.x86_64.qcow2
+rm Fedora-Cloud-Base-24-1.2.x86_64.qcow2
+
+wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
+glance image-create --name 'CentOS 7' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file CentOS-7-x86_64-GenericCloud.qcow2
+rm CentOS-7-x86_64-GenericCloud.qcow2
+
+wget http://download.opensuse.org/repositories/Cloud:/Images:/Leap_42.1/images/openSUSE-Leap-42.1-OpenStack.x86_64-0.0.4-Build2.12.qcow2
+glance image-create --name 'OpenSuse Leap 42' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file openSUSE-Leap-42.1-OpenStack.x86_64-0.0.4-Build2.12.qcow2
+rm openSUSE-Leap-42.1-OpenStack.x86_64-0.0.4-Build2.12.qcow2
+
+wget http://cdimage.debian.org/cdimage/openstack/current/debian-8.6.0-openstack-amd64.qcow2
+glance image-create --name 'Debian 8.6.0' \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file debian-8.6.0-openstack-amd64.qcow2
+rm debian-8.6.0-openstack-amd64.qcow2
+
+wget http://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.qcow2
+glance image-create --name "Debian TESTING $(date +%m-%d-%y)" \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file debian-testing-openstack-amd64.qcow2
+rm debian-testing-openstack-amd64.qcow2
+
+wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
+glance image-create --name "Cirros-0.3.4" \
+                    --container-format bare \
+                    --disk-format qcow2 \
+                    --visibility public \
+                    --progress \
+                    --file cirros-0.3.4-x86_64-disk.img
+rm cirros-0.3.4-x86_64-disk.img