From 4265e70fa9218498d058c4e81c73dab6265b54da Mon Sep 17 00:00:00 2001
From: Narinder Gupta <narinder.gupta@canonical.com>
Date: Fri, 29 Jul 2016 12:46:28 -0500
Subject: [PATCH] make script more robust.

Change-Id: Iacdf67344759401c67a0f69ade91f221d4dd5749
Signed-off-by: Narinder Gupta <narinder.gupta@canonical.com>
---
 juju/configure-juju-on-openstack | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/juju/configure-juju-on-openstack b/juju/configure-juju-on-openstack
index ff60d454..bd2efd61 100755
--- a/juju/configure-juju-on-openstack
+++ b/juju/configure-juju-on-openstack
@@ -27,10 +27,12 @@ set -ex
 echo "This command is run to launch the first instance on a new Orange box Openstack deployment"
 
 source ~/nova.rc
+associated=0
 
 #Create a floating IP for the instance
 if ( nova list | grep jumpserver2 >/dev/null )
 then
+    associated=1
     FLOAT_IP="$(nova list | grep jumpserver2 | awk '{ print $13 }')"
 else
     FLOAT_IP="$(openstack ip floating create ext-net -c ip -f value)"
@@ -49,8 +51,12 @@ do
     sleep 1
 done
 sleep 6
+
 #Associate the floating IP with the new instance
-nova floating-ip-associate jumpserver2 $FLOAT_IP || true
+if [ "$associated" -eq "0" ]; then
+   nova floating-ip-associate jumpserver2 $FLOAT_IP || true
+   sleep 90
+fi
 
 sleep 90
 
@@ -81,7 +87,7 @@ $SSH \
         $OS_REGION_NAME:
           endpoint: $OS_AUTH_URL
 ' > os-cloud.yaml"
-$SSH juju add-cloud openstack os-cloud.yaml
+$SSH juju add-cloud openstack os-cloud.yaml --replace
 
 #Output a juju cred file that works on this cloud
 $SSH \
@@ -94,7 +100,7 @@ $SSH \
       username: $OS_USERNAME
 ' > os-creds.yaml"
 
-$SSH "juju add-credential openstack -f os-creds.yaml"
+$SSH "juju add-credential openstack -f os-creds.yaml" --replace
 
 ## Creating images metadata
 $SSH mkdir -p juju-meta
-- 
2.16.6