| Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
 | 2 | # | 
 | 3 | # source eucarc [username] [tenantname] | 
 | 4 | # | 
 | 5 | # Create EC2 credentials for the current user as defined by OS_TENANT_NAME:OS_USERNAME | 
 | 6 | # Optionally set the tenant/username via openrc | 
 | 7 |  | 
 | 8 | if [[ -n "$1" ]]; then | 
 | 9 |     USERNAME=$1 | 
 | 10 | fi | 
 | 11 | if [[ -n "$2" ]]; then | 
 | 12 |     TENANT=$2 | 
 | 13 | fi | 
 | 14 |  | 
 | 15 | # Find the other rc files | 
 | 16 | RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd) | 
 | 17 |  | 
 | 18 | # Get user configuration | 
 | 19 | source $RC_DIR/openrc | 
 | 20 |  | 
 | 21 | # Set the ec2 url so euca2ools works | 
 | 22 | export EC2_URL=$(keystone catalog --service ec2 | awk '/ publicURL / { print $4 }') | 
 | 23 |  | 
 | 24 | # Create EC2 credentials for the current user | 
 | 25 | CREDS=$(keystone ec2-credentials-create) | 
 | 26 | export EC2_ACCESS_KEY=$(echo "$CREDS" | awk '/ access / { print $4 }') | 
 | 27 | export EC2_SECRET_KEY=$(echo "$CREDS" | awk '/ secret / { print $4 }') | 
 | 28 |  | 
 | 29 | # Euca2ools Certificate stuff for uploading bundles | 
 | 30 | # See exercises/bundle.sh to see how to get certs using nova cli | 
 | 31 | NOVA_KEY_DIR=${NOVA_KEY_DIR:-$RC_DIR} | 
 | 32 | export S3_URL=$(keystone catalog --service s3 | awk '/ publicURL / { print $4 }') | 
 | 33 | export EC2_USER_ID=42 # nova does not use user id, but bundling requires it | 
 | 34 | export EC2_PRIVATE_KEY=${NOVA_KEY_DIR}/pk.pem | 
 | 35 | export EC2_CERT=${NOVA_KEY_DIR}/cert.pem | 
 | 36 | export NOVA_CERT=${NOVA_KEY_DIR}/cacert.pem | 
 | 37 | export EUCALYPTUS_CERT=${NOVA_CERT} # euca-bundle-image seems to require this set | 
 | 38 | alias ec2-bundle-image="ec2-bundle-image --cert ${EC2_CERT} --privatekey ${EC2_PRIVATE_KEY} --user ${EC2_USER_ID} --ec2cert ${NOVA_CERT}" | 
 | 39 | alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_KEY} --url ${S3_URL} --ec2cert ${NOVA_CERT}" | 
 | 40 |  |