Skip to content

Commit 0bd2410

Browse files
author
Dean Troyer
committed
Move all EC2 cred creation to eucarc
* Remove credential creation from files/keystone_data.sh * Remove EC2 cert setup from openrc * Remove sourcing of ec2rc from stackrc * Collect the above in eucarc * Allow rc files to be sourced from other directories; based on Chmouel's 4881 proposal but is simpler and doesn't actually change the directory * Create S3 endpoint * Get EC2 and S3 endpoints from Keystone service catalog * Add EC2 credential checks to exercises/client-env.sh * exercises/bundle.sh and exercises/euca.sh use eucarc Updates: * remove readlink -f to stay bash 3 compatible * use service catalog * create S3 endpoint Fixes bug 949528 Change-Id: I58caea8cecbbd10661779bc2d150d241f4a5822e
1 parent 09cafcb commit 0bd2410

File tree

9 files changed

+103
-74
lines changed

9 files changed

+103
-74
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ We also provide an environment file that you can use to interact with your cloud
4141
. openrc
4242
# list instances
4343
nova list
44+
45+
If the EC2 API is your cup-o-tea, you can create credentials and use euca2ools:
46+
47+
# source eucarc to generate EC2 credentials and set up the environment
48+
. eucarc
4449
# list instances using ec2 api
4550
euca-describe-instances
4651

eucarc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+

exercises/bundle.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ set -o xtrace
1818
# Settings
1919
# ========
2020

21-
# Use openrc + stackrc + localrc for settings
22-
pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
21+
# Keep track of the current directory
22+
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
23+
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
2324

2425
# Import common functions
25-
source ./functions
26+
source $TOP_DIR/functions
2627

27-
# Import configuration
28-
source ./openrc
28+
# Import EC2 configuration
29+
source $TOP_DIR/eucarc
2930

3031
# Remove old certificates
31-
rm -f cacert.pem
32-
rm -f cert.pem
33-
rm -f pk.pem
32+
rm -f $TOP_DIR/cacert.pem
33+
rm -f $TOP_DIR/cert.pem
34+
rm -f $TOP_DIR/pk.pem
3435

3536
# Get Certificates
36-
nova x509-get-root-cert
37-
nova x509-create-cert
38-
popd >/dev/null
37+
nova x509-get-root-cert $TOP_DIR/cacert.pem
38+
nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem
3939

4040
# Max time to wait for image to be registered
4141
REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}

exercises/client-env.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ VERIFY=${1:-""}
1212
# Settings
1313
# ========
1414

15-
# Use openrc + stackrc + localrc for settings
16-
pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
15+
# Keep track of the current directory
16+
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
17+
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
1718

1819
# Import common functions
19-
source ./functions
20+
source $TOP_DIR/functions
2021

2122
# Import configuration
22-
source ./openrc
23-
popd >/dev/null
23+
source $TOP_DIR/openrc
2424

2525
# Unset all of the known NOVA_ vars
2626
unset NOVA_API_KEY
@@ -53,7 +53,7 @@ if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
5353
STATUS_KEYSTONE="Skipped"
5454
else
5555
echo -e "\nTest Keystone"
56-
if keystone service-list; then
56+
if keystone catalog --service identity; then
5757
STATUS_KEYSTONE="Succeeded"
5858
else
5959
STATUS_KEYSTONE="Failed"
@@ -68,14 +68,31 @@ fi
6868
if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
6969
if [[ "$SKIP_EXERCISES" =~ "n-api" ]] ; then
7070
STATUS_NOVA="Skipped"
71+
STATUS_EC2="Skipped"
7172
else
73+
# Test OSAPI
7274
echo -e "\nTest Nova"
7375
if nova flavor-list; then
7476
STATUS_NOVA="Succeeded"
7577
else
7678
STATUS_NOVA="Failed"
7779
RETURN=1
7880
fi
81+
82+
# Test EC2 API
83+
echo -e "\nTest EC2"
84+
# Get EC2 creds
85+
source $TOP_DIR/eucarc
86+
87+
if euca-describe-images; then
88+
STATUS_EC2="Succeeded"
89+
else
90+
STATUS_EC2="Failed"
91+
RETURN=1
92+
fi
93+
94+
# Clean up side effects
95+
unset NOVA_VERSION
7996
fi
8097
fi
8198

@@ -125,6 +142,7 @@ function report() {
125142
echo -e "\n"
126143
report "Keystone" $STATUS_KEYSTONE
127144
report "Nova" $STATUS_NOVA
145+
report "EC2" $STATUS_EC2
128146
report "Glance" $STATUS_GLANCE
129147
report "Swift" $STATUS_SWIFT
130148

exercises/euca.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ set -o xtrace
1818
# Settings
1919
# ========
2020

21-
# Use openrc + stackrc + localrc for settings
22-
pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
21+
# Keep track of the current directory
22+
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
23+
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
2324

2425
# Import common functions
25-
source ./functions
26+
source $TOP_DIR/functions
2627

27-
# Import configuration
28-
source ./openrc
29-
popd >/dev/null
28+
# Import EC2 configuration
29+
source $TOP_DIR/eucarc
3030

3131
# Max time to wait while vm goes from build to active state
3232
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}

files/default_catalog.templates

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ catalog.RegionOne.ec2.internalURL = http://%SERVICE_HOST%:8773/services/Cloud
2424
catalog.RegionOne.ec2.name = 'EC2 Service'
2525

2626

27+
catalog.RegionOne.s3.publicURL = http://%SERVICE_HOST%:3333
28+
catalog.RegionOne.s3.adminURL = http://%SERVICE_HOST%:3333
29+
catalog.RegionOne.s3.internalURL = http://%SERVICE_HOST%:3333
30+
catalog.RegionOne.s3.name = 'S3 Service'
31+
32+
2733
catalog.RegionOne.image.publicURL = http://%SERVICE_HOST%:9292/v1
2834
catalog.RegionOne.image.adminURL = http://%SERVICE_HOST%:9292/v1
2935
catalog.RegionOne.image.internalURL = http://%SERVICE_HOST%:9292/v1

files/keystone_data.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#
33
# Initial data for Keystone using python-keystoneclient
44
#
5-
# A set of EC2-compatible credentials is created for both admin and demo
6-
# users and placed in $DEVSTACK_DIR/ec2rc.
7-
#
85
# Tenant User Roles
96
# -------------------------------------------------------
107
# admin admin admin
@@ -48,6 +45,7 @@ DEMO_USER=$(get_id keystone user-create --name=demo \
4845
--pass="$ADMIN_PASSWORD" \
4946
--email=demo@example.com)
5047

48+
5149
# Roles
5250
ADMIN_ROLE=$(get_id keystone role-create --name=admin)
5351
KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
@@ -135,20 +133,3 @@ if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
135133
--user $QUANTUM_USER \
136134
--role $ADMIN_ROLE
137135
fi
138-
139-
# create ec2 creds and parse the secret and access key returned
140-
RESULT=$(keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER)
141-
ADMIN_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
142-
ADMIN_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
143-
144-
RESULT=$(keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER)
145-
DEMO_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
146-
DEMO_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
147-
148-
# write the secret and access to ec2rc
149-
cat > $DEVSTACK_DIR/ec2rc <<EOF
150-
ADMIN_ACCESS=$ADMIN_ACCESS
151-
ADMIN_SECRET=$ADMIN_SECRET
152-
DEMO_ACCESS=$DEMO_ACCESS
153-
DEMO_SECRET=$DEMO_SECRET
154-
EOF

openrc

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ if [[ -n "$2" ]]; then
1717
TENANT=$2
1818
fi
1919

20+
# Find the other rc files
21+
RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd)
22+
2023
# Load local configuration
21-
source ./stackrc
24+
source $RC_DIR/stackrc
2225

2326
# The introduction of Keystone to the OpenStack ecosystem has standardized the
2427
# term **tenant** as the entity that owns resources. In some places references
@@ -59,30 +62,8 @@ export NOVA_VERSION=${NOVA_VERSION:-1.1}
5962
# In the future this will change names:
6063
export COMPUTE_API_VERSION=${COMPUTE_API_VERSION:-$NOVA_VERSION}
6164

62-
# Set the ec2 url so euca2ools works
63-
export EC2_URL=${EC2_URL:-http://$SERVICE_HOST:8773/services/Cloud}
64-
65-
# Access key is set in the initial keystone data to be the same as username
66-
export EC2_ACCESS_KEY=${DEMO_ACCESS}
67-
68-
# Secret key is set in the initial keystone data to the admin password
69-
export EC2_SECRET_KEY=${DEMO_SECRET}
70-
71-
# Euca2ools Certificate stuff for uploading bundles
72-
# See exercises/bundle.sh to see how to get certs using nova cli
73-
NOVARC=$(readlink -f "${BASH_SOURCE:-${0}}" 2>/dev/null) ||
74-
NOVARC=$(python -c 'import os,sys; print os.path.abspath(os.path.realpath(sys.argv[1]))' "${BASH_SOURCE:-${0}}")
75-
NOVA_KEY_DIR=${NOVARC%/*}
76-
export S3_URL=http://$SERVICE_HOST:3333
77-
export EC2_USER_ID=42 # nova does not use user id, but bundling requires it
78-
export EC2_PRIVATE_KEY=${NOVA_KEY_DIR}/pk.pem
79-
export EC2_CERT=${NOVA_KEY_DIR}/cert.pem
80-
export NOVA_CERT=${NOVA_KEY_DIR}/cacert.pem
81-
export EUCALYPTUS_CERT=${NOVA_CERT} # euca-bundle-image seems to require this set
82-
alias ec2-bundle-image="ec2-bundle-image --cert ${EC2_CERT} --privatekey ${EC2_PRIVATE_KEY} --user 42 --ec2cert ${NOVA_CERT}"
83-
alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_KEY} --url ${S3_URL} --ec2cert ${NOVA_CERT}"
84-
8565
# set log level to DEBUG (helps debug issues)
66+
# export KEYSTONECLIENT_DEBUG=1
8667
# export NOVACLIENT_DEBUG=1
8768

8869
# Max time till the vm is bootable

stackrc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Find the other rc files
2+
RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd)
3+
14
# compute service
25
NOVA_REPO=https://github.com/openstack/nova.git
36
NOVA_BRANCH=master
@@ -76,12 +79,7 @@ case "$LIBVIRT_TYPE" in
7679
IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-uec.tar.gz";;
7780
esac
7881

79-
# use stored ec2 env variables
80-
if [ -f ./ec2rc ]; then
81-
source ./ec2rc
82-
fi
83-
8482
# allow local overrides of env variables
85-
if [ -f ./localrc ]; then
86-
source ./localrc
83+
if [ -f $RC_DIR/localrc ]; then
84+
source $RC_DIR/localrc
8785
fi

0 commit comments

Comments
 (0)