Last active
December 14, 2015 00:49
-
-
Save chmouel/5001515 to your computer and use it in GitHub Desktop.
Get storage url from keystone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
[[ $1 == "-s" ]] && { | |
SHORT=yes | |
shift | |
} | |
[[ $1 == "-c" ]] && { | |
CONTINUE=yes | |
shift | |
} | |
KEYSTONE_URL=${1:-localhost} | |
USER=${2:-admin:admin} | |
PASSWORD=${3:-ADMIN} | |
if [[ $KEYSTONE_URL != http* ]];then | |
KEYSTONE_URL="http://$KEYSTONE_URL:5000/v2.0/tokens" | |
elif [[ $KEYSTONE_URL != */tokens ]];then | |
KEYSTONE_URL="$KEYSTONE_URL/tokens" | |
fi | |
if [[ $USER == *:* ]];then | |
TENANT=${USER%%:*} | |
USER=${USER##*:} | |
else | |
TENANT=$USER | |
fi | |
#curl -s -d "{\"auth\": {\"passwordCredentials\": {\"username\": \"$1\", \"password\": \"$2\"}}}" -H 'Content-type: application/json' http://$3:5000/v2.0/tokens | python -m json.tool | |
curl -s -d "{\"auth\": {\"tenantName\": \"$TENANT\", \"passwordCredentials\": {\"username\": \"$USER\", \"password\": \"$PASSWORD\"}}}" -H 'Content-type: application/json' $KEYSTONE_URL >/tmp/.auth.json || { echo "Cannot conntect to ${KEYSTONE_URL}"; exit 1; } | |
[[ -z ${SHORT} ]] && echo "${KEYSTONE_URL}:" | |
grep -q 'access' /tmp/.auth.json || { | |
curl -v -d "{\"auth\": {\"tenantName\": \"$TENANT\", \"passwordCredentials\": {\"username\": \"$USER\", \"password\": \"$PASSWORD\"}}}" -H 'Content-type: application/json' $KEYSTONE_URL | |
echo | |
exit | |
} | |
python -mjson.tool < /tmp/.auth.json > /tmp/.pauth.json | |
TOKEN=$(python -c 'import sys, json; print json.load(sys.stdin)["access"]["token"]["id"]' < /tmp/.pauth.json) | |
URL=$( grep -B10 object-store /tmp/.pauth.json|grep internalURL|sed 's/.* "//;s/".*//'|tr -d '\r') | |
if [[ ${SHORT} ]];then | |
echo "TOKEN='${TOKEN}'" | |
echo "STORAGE_URL='${URL}'" | |
echo "KEYSTONE_URL='${KEYSTONE_URL}'" | |
exit | |
fi | |
cat /tmp/.pauth.json | |
echo "curl -H 'X-Auth-Token: ${TOKEN}' ${URL}" | |
[[ -n ${CONTINUE} ]] || exit | |
curl -v -H "X-Auth-Token: ${TOKEN}" ${URL} | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment