blob: c9aa7d74419283a030d780cfff3da5ee1d55240f [file] [log] [blame]
Jesse Andrews73e27b82011-09-12 17:55:00 -07001#!/bin/bash
Dean Troyerb7d1fbb2012-03-02 08:43:09 -06002#
3# Initial data for Keystone using python-keystoneclient
4#
5# A set of EC2-compatible credentials is created for both admin and demo
6# users and placed in $DEVSTACK_DIR/ec2rc.
7#
8# Tenant User Roles
9# -------------------------------------------------------
10# admin admin admin
11# service glance admin
12# service nova admin
13# service quantum admin # if enabled
14# service swift admin # if enabled
15# demo admin admin
16# demo demo Member,sysadmin,netadmin
17# invisible_to_admin demo Member
18#
19# Variables set before calling this script:
20# SERVICE_TOKEN - aka admin_token in keystone.conf
21# SERVICE_ENDPOINT - local Keystone admin endpoint
22# SERVICE_TENANT_NAME - name of tenant containing service accounts
23# ENABLED_SERVICES - stack.sh's list of services to start
24# DEVSTACK_DIR - Top-level DevStack directory
25
26ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
27SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000028export SERVICE_TOKEN=$SERVICE_TOKEN
29export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060030SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000031
32function get_id () {
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060033 echo `$@ | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000034}
35
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060036# Tenants
37ADMIN_TENANT=$(get_id keystone tenant-create --name=admin)
38SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME)
39DEMO_TENANT=$(get_id keystone tenant-create --name=demo)
40INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin)
termiea96a4182012-01-09 22:13:29 -080041
Jesse Andrews73e27b82011-09-12 17:55:00 -070042
43# Users
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060044ADMIN_USER=$(get_id keystone user-create --name=admin \
45 --pass="$ADMIN_PASSWORD" \
46 --email=admin@example.com)
47DEMO_USER=$(get_id keystone user-create --name=demo \
48 --pass="$ADMIN_PASSWORD" \
49 --email=demo@example.com)
Jesse Andrews73e27b82011-09-12 17:55:00 -070050
51# Roles
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060052ADMIN_ROLE=$(get_id keystone role-create --name=admin)
53KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
54KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin)
55SYSADMIN_ROLE=$(get_id keystone role-create --name=sysadmin)
56NETADMIN_ROLE=$(get_id keystone role-create --name=netadmin)
termiea96a4182012-01-09 22:13:29 -080057
58
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060059# Add Roles to Users in Tenants
60keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT
61keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT
62keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT
63keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT
termiea96a4182012-01-09 22:13:29 -080064
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060065# TODO(termie): these two might be dubious
66keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
67keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
Dean Troyerf4565c42012-02-23 11:21:10 -060068
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060069
70# The Member role is used by Horizon and Swift so we need to keep it:
71MEMBER_ROLE=$(get_id keystone role-create --name=Member)
72keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT
73keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT
74
Jesse Andrews73e27b82011-09-12 17:55:00 -070075
Anthony Younge2d139b2012-03-09 15:47:28 -080076# Configure service users/roles
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060077NOVA_USER=$(get_id keystone user-create --name=nova \
78 --pass="$SERVICE_PASSWORD" \
79 --tenant_id $SERVICE_TENANT \
80 --email=nova@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060081keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060082 --user $NOVA_USER \
83 --role $ADMIN_ROLE
termiea96a4182012-01-09 22:13:29 -080084
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060085GLANCE_USER=$(get_id keystone user-create --name=glance \
86 --pass="$SERVICE_PASSWORD" \
87 --tenant_id $SERVICE_TENANT \
88 --email=glance@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060089keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060090 --user $GLANCE_USER \
91 --role $ADMIN_ROLE
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +000092
Jesse Andrews9c7c9082011-11-23 10:10:53 -080093if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060094 SWIFT_USER=$(get_id keystone user-create --name=swift \
95 --pass="$SERVICE_PASSWORD" \
96 --tenant_id $SERVICE_TENANT \
97 --email=swift@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060098 keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060099 --user $SWIFT_USER \
100 --role $ADMIN_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800101fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600102
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800103if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600104 QUANTUM_USER=$(get_id keystone user-create --name=quantum \
105 --pass="$SERVICE_PASSWORD" \
106 --tenant_id $SERVICE_TENANT \
107 --email=quantum@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -0600108 keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600109 --user $QUANTUM_USER \
110 --role $ADMIN_ROLE
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800111fi
Anthony Young8bdc2632011-09-22 08:00:44 +0000112
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000113# create ec2 creds and parse the secret and access key returned
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600114RESULT=$(keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER)
115ADMIN_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
116ADMIN_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000117
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600118RESULT=$(keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER)
119DEMO_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
120DEMO_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000121
122# write the secret and access to ec2rc
123cat > $DEVSTACK_DIR/ec2rc <<EOF
124ADMIN_ACCESS=$ADMIN_ACCESS
125ADMIN_SECRET=$ADMIN_SECRET
126DEMO_ACCESS=$DEMO_ACCESS
127DEMO_SECRET=$DEMO_SECRET
128EOF