devstack/eucarc
Peter Feiner 388e36c98b zsh openrc compatibility
Replacing $BASH_SOURCE with ${BASH_SOURCE:-$0} makes devstack zsh friendly: in
bash, $BASH_SOURCE is used per usual; in zsh, where $BASH_SOURCE isn't
defined, $0 is used, which, unlike in bash, evaluates to the current
source file.

Now you can source devstack's openrc from a zsh shell.

Tested with bash and zsh from directories other than the root devstack
directory.

Change-Id: Iab1a817b15d86144163b5094bb58f94b15c598a0
2013-10-25 12:00:06 -04:00

41 lines
1.5 KiB
Bash

#!/usr/bin/env bash
#
# source eucarc [username] [tenantname]
#
# Create EC2 credentials for the current user as defined by OS_TENANT_NAME:OS_USERNAME
# Optionally set the tenant/username via openrc
if [[ -n "$1" ]]; then
USERNAME=$1
fi
if [[ -n "$2" ]]; then
TENANT=$2
fi
# Find the other rc files
RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)
# Get user configuration
source $RC_DIR/openrc
# Set the ec2 url so euca2ools works
export EC2_URL=$(keystone catalog --service ec2 | awk '/ publicURL / { print $4 }')
# Create EC2 credentials for the current user
CREDS=$(keystone ec2-credentials-create)
export EC2_ACCESS_KEY=$(echo "$CREDS" | awk '/ access / { print $4 }')
export EC2_SECRET_KEY=$(echo "$CREDS" | awk '/ secret / { print $4 }')
# Euca2ools Certificate stuff for uploading bundles
# See exercises/bundle.sh to see how to get certs using nova cli
NOVA_KEY_DIR=${NOVA_KEY_DIR:-$RC_DIR}
export S3_URL=$(keystone catalog --service s3 | awk '/ publicURL / { print $4 }')
export EC2_USER_ID=42 # nova does not use user id, but bundling requires it
export EC2_PRIVATE_KEY=${NOVA_KEY_DIR}/pk.pem
export EC2_CERT=${NOVA_KEY_DIR}/cert.pem
export NOVA_CERT=${NOVA_KEY_DIR}/cacert.pem
export EUCALYPTUS_CERT=${NOVA_CERT} # euca-bundle-image seems to require this set
alias ec2-bundle-image="ec2-bundle-image --cert ${EC2_CERT} --privatekey ${EC2_PRIVATE_KEY} --user ${EC2_USER_ID} --ec2cert ${NOVA_CERT}"
alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_KEY} --url ${S3_URL} --ec2cert ${NOVA_CERT}"