Merge "Fix Compass4nfv workspace permissions"
[releng.git] / utils / fetch_os_creds.sh
index 856f69a..458bbda 100755 (executable)
@@ -7,7 +7,9 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-
+set -o errexit
+set -o nounset
+set -o pipefail
 
 usage() {
     echo "usage: $0 [-v] -d <destination> -i <installer_type> -a <installer_ip>" >&2
@@ -121,6 +123,14 @@ if [ "$installer_type" == "fuel" ]; then
     # but sometimes the output of endpoint-list is like this: http://172.30.9.70:8004/v1/%(tenant_id)s
     # Fuel virtual need a fix
 
+    #convert to v3 URL
+    auth_url=$(cat $dest_path|grep AUTH_URL)
+    if [[ -z `echo $auth_url |grep v3` ]]; then
+        auth_url=$(echo $auth_url |sed "s|'$|v3&|")
+    fi
+    sed -i '/AUTH_URL/d' $dest_path
+    echo $auth_url >> $dest_path
+
 elif [ "$installer_type" == "apex" ]; then
     verify_connectivity $installer_ip
 
@@ -130,13 +140,13 @@ elif [ "$installer_type" == "apex" ]; then
     if [ -f /root/.ssh/id_rsa ]; then
         chmod 600 /root/.ssh/id_rsa
     fi
-    sudo scp $ssh_options root@$installer_ip:/home/stack/overcloudrc $dest_path
+    sudo scp $ssh_options root@$installer_ip:/home/stack/overcloudrc.v3 $dest_path
 
 elif [ "$installer_type" == "compass" ]; then
     verify_connectivity $installer_ip
     controller_ip=$(sshpass -p'root' ssh 2>/dev/null $ssh_options root@${installer_ip} \
         'mysql -ucompass -pcompass -Dcompass -e"select *  from cluster;"' \
-        | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"host[1-5]\"/) {print $(i+1);break;}}'  \
+        | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"127.0.0.1\"/) {print $(i+2);break;}}'  \
         | grep -oP "\d+.\d+.\d+.\d+")
 
     if [ -z $controller_ip ]; then
@@ -149,8 +159,8 @@ elif [ "$installer_type" == "compass" ]; then
     sshpass -p root scp 2>/dev/null $ssh_options root@${installer_ip}:~/admin-openrc.sh $dest_path &> /dev/null
 
     info "This file contains the mgmt keystone API, we need the public one for our rc file"
-    grep "OS_AUTH_URL.*v2" $dest_path > /dev/null 2>&1
-    if [ $?  -eq 0 ] ; then
+
+    if grep "OS_AUTH_URL.*v2" $dest_path > /dev/null 2>&1 ; then
         public_ip=$(sshpass -p root ssh $ssh_options root@${installer_ip} \
             "ssh ${controller_ip} 'source /opt/admin-openrc.sh; openstack endpoint show identity '" \
             | grep publicurl | awk '{print $4}')
@@ -193,6 +203,17 @@ elif [ "$installer_type" == "foreman" ]; then
         'source keystonerc_admin;keystone endpoint-list'" \
         | grep $admin_ip | sed 's/ /\n/g' | grep ^http | head -1) &> /dev/null
 
+elif [ "$installer_type" == "daisy" ]; then
+    verify_connectivity $installer_ip
+    cluster=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
+            "source ~/daisyrc_admin; daisy cluster-list"|grep active|head -1|awk -F "|" '{print $3}') &> /dev/null
+    if [ -z $cluster ]; then
+        echo "No active cluster detected in daisy"
+        exit 1
+    fi
+
+    sshpass -p r00tme scp 2>/dev/null $ssh_options root@${installer_ip}:/etc/kolla/admin-openrc.sh $dest_path &> /dev/null
+
 else
     error "Installer $installer is not supported by this script"
 fi
@@ -204,5 +225,3 @@ fi
 
 echo "-------- Credentials: --------"
 cat $dest_path
-
-exit 0