From 888bb9cc8c68bf61fddc0ca08a69f764a4012121 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Andr=C3=A9?= <martin.andre@kvhasia.com>
Date: Fri, 20 Mar 2015 10:31:02 +0900
Subject: [PATCH] Move genenv.sh and start.sh to tools directory

Rename them `genenv` and `start`.
Have `genenv` create the openrc file in the top-level directory.

Add openrc and compose/openstack.env to gitignore, as well as *.img.

Change-Id: I5d8006e97efd77cf364215f55d5e585139ae273e
---
 .gitignore                        |  7 ++++++-
 compose/README.md                 |  4 ++--
 docs/developer-env.md             | 12 +++++++-----
 compose/genenv.sh => tools/genenv |  8 ++++++--
 compose/start.sh => tools/start   | 25 ++++++++++++-------------
 5 files changed, 33 insertions(+), 23 deletions(-)
 rename compose/genenv.sh => tools/genenv (94%)
 rename compose/start.sh => tools/start (76%)

diff --git a/.gitignore b/.gitignore
index 8dcc4f5b79..08d55d2110 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,13 @@
 *~
 [._]*.s[a-w][a-z]
 
-# Any qcow images created from get-image script
+# Any disk images
 *.qcow2
+*.img
 
 .tox/
 .buildconf
+
+# Files generated by tools/genenv
+openrc
+openstack.env
diff --git a/compose/README.md b/compose/README.md
index ba0ce74e57..a513f78a09 100644
--- a/compose/README.md
+++ b/compose/README.md
@@ -2,12 +2,12 @@ Docker compose
 ==============
 
 These scripts and docker compose files can be used to stand up a simple
-installation of openstack.  Running the 'genenv.sh' script creates an
+installation of openstack.  Running the 'tools/genenv' script creates an
 'openstack.env' suitable for running on a single host system as well as an
 'openrc' to allow access to the installation.
 
 Once you have run that you can either manually start the containers using the
-'docker-compose' command or try the 'start.sh' script which tries to start them
+'docker-compose' command or try the 'tools/start' script which tries to start them
 all in a reasonable order, waiting at key points for services to become
 available.  Once stood up you can issue the typical openstack commands to use
 the installation:
diff --git a/docs/developer-env.md b/docs/developer-env.md
index fe1916bb67..3d31aa5301 100644
--- a/docs/developer-env.md
+++ b/docs/developer-env.md
@@ -7,18 +7,18 @@ compose directory.
 To start, setup your environment variables.
 
     $ cd kolla
-    $ ./tools/genenv.sh
+    $ ./tools/genenv
 
-The `genenv.sh` script will create an openstack.env file
+The `genenv` script will create a compose/openstack.env file
 and an openrc file in your current directory. The openstack.env
 file contains all of your initialized environment variables, which
 you can edit for a different setup.
 
 Next, run the start script.
 
-    $ ./start.sh
+    $ ./tools/start
 
-The `start.sh` script is responsible for starting the containers
+The `start` script is responsible for starting the containers
 using `docker-compose -f <osp-service-container> up -d`.
 
 If you want to start a container set by hand use this template
@@ -36,7 +36,9 @@ If any of the containers exited you can check the logs by doing
     $ sudo docker logs <glance-api-container>
     $ docker-compose logs <glance-api-container>
 
-If you want to start a individual service like `glance-api` by hand, then use this template.  This is a good method to test and troubleshoot an individual container.
+If you want to start a individual service like `glance-api` by hand, then use
+this template.  This is a good method to test and troubleshoot an individual
+container.
 
     $ docker run --name glance-api -d \
              --net=host
diff --git a/compose/genenv.sh b/tools/genenv
similarity index 94%
rename from compose/genenv.sh
rename to tools/genenv
index dc1e52f801..91ac42cc43 100755
--- a/compose/genenv.sh
+++ b/tools/genenv
@@ -6,6 +6,10 @@
 #
 # It also creates a suitable 'openrc' for use with the installed system.
 
+# Move to top level directory
+REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')")
+cd "$(dirname "$REAL_PATH")/.."
+
 MY_IP=$(ip route get $(ip route | awk '$1 == "default" {print $3}') |
     awk '$4 == "src" {print $5}')
 
@@ -58,14 +62,14 @@ NOVA_PUBLIC_INTERFACE=$MY_DEV
 NOVA_FLAT_INTERFACE=$MY_DEV
 CONFIG_NETWORK=True
 
-cat > openrc <<EOF
+cat > ./openrc <<EOF
 export OS_AUTH_URL="http://${KEYSTONE_PUBLIC_SERVICE_HOST}:5000/v2.0"
 export OS_USERNAME=$ADMIN_TENANT_NAME
 export OS_PASSWORD=$PASSWORD
 export OS_TENANT_NAME=$ADMIN_TENANT_NAME
 EOF
 
-cat > openstack.env <<EOF
+cat > ./compose/openstack.env <<EOF
 ADMIN_TENANT_NAME=$ADMIN_TENANT_NAME
 CONFIG_NETWORK=$CONFIG_NETWORK
 DB_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
diff --git a/compose/start.sh b/tools/start
similarity index 76%
rename from compose/start.sh
rename to tools/start
index fde554fc3d..887ec8ab1d 100755
--- a/compose/start.sh
+++ b/tools/start
@@ -6,10 +6,9 @@
 # services are up.  You will also need these in order to interact with the
 # installation once started.
 
-if [[ $EUID -ne 0 ]]; then
-    echo "You must execute this script as root." 1>&2
-    exit 1
-fi
+# Move to top level directory
+REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')")
+cd "$(dirname "$REAL_PATH")/.."
 
 # Set SELinux to permissive
 setenforce permissive
@@ -27,30 +26,30 @@ MY_IP=$(ip route get $(ip route | awk '$1 == "default" {print $3}') |
     awk '$4 == "src" {print $5}')
 
 # Source openrc for commands
-source openrc
+source ./openrc
 
 echo Starting rabbitmq.
-docker-compose -f rabbitmq.yml up -d
+docker-compose -f ./compose/rabbitmq.yml up -d
 
 echo Starting mariadb.
-docker-compose -f mariadb.yml up -d
+docker-compose -f ./compose/mariadb.yml up -d
 
 echo Starting keystone.
-docker-compose -f keystone.yml up -d
+docker-compose -f ./compose/keystone.yml up -d
 
 echo Starting glance.
-docker-compose -f glance-api-registry.yml up -d
+docker-compose -f ./compose/glance-api-registry.yml up -d
 
 echo Starting nova.
-docker-compose -f nova-api-conductor-scheduler.yml up -d
+docker-compose -f ./compose/nova-api-conductor-scheduler.yml up -d
 
 echo Starting nova compute with nova networking.
-docker-compose -f nova-compute-network.yml up -d
+docker-compose -f ./compose/nova-compute-network.yml up -d
 
 IMAGE_URL=http://download.cirros-cloud.net/0.3.3/
 IMAGE=cirros-0.3.3-x86_64-disk.img
 if ! [ -f "$IMAGE" ]; then
-    curl -o $IMAGE $IMAGE_URL/$IMAGE
+    curl -o ./$IMAGE $IMAGE_URL/$IMAGE
 fi
 
 until keystone user-list | grep glance
@@ -62,7 +61,7 @@ done
 sleep 3
 
 echo Creating glance image.
-glance image-create --name cirros --is-public false --disk-format qcow2 --container-format bare --file $IMAGE
+glance image-create --name cirros --is-public false --disk-format qcow2 --container-format bare --file ./$IMAGE
 
 echo Example usage:
 echo