blob: 958d2af4f2f19d392e993d4bf60a4d7c6734f9f7 [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 Young8bdc2632011-09-22 08:00:44 +000076# Services
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060077keystone service-create --name=keystone \
78 --type=identity \
79 --description="Keystone Identity Service"
80
81keystone service-create --name=nova \
82 --type=compute \
83 --description="Nova Compute Service"
84NOVA_USER=$(get_id keystone user-create --name=nova \
85 --pass="$SERVICE_PASSWORD" \
86 --tenant_id $SERVICE_TENANT \
87 --email=nova@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060088keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060089 --user $NOVA_USER \
90 --role $ADMIN_ROLE
termiea96a4182012-01-09 22:13:29 -080091
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060092keystone service-create --name=ec2 \
93 --type=ec2 \
94 --description="EC2 Compatibility Layer"
termiea96a4182012-01-09 22:13:29 -080095
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060096keystone service-create --name=glance \
97 --type=image \
98 --description="Glance Image Service"
99GLANCE_USER=$(get_id keystone user-create --name=glance \
100 --pass="$SERVICE_PASSWORD" \
101 --tenant_id $SERVICE_TENANT \
102 --email=glance@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -0600103keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600104 --user $GLANCE_USER \
105 --role $ADMIN_ROLE
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +0000106
107if [[ "$ENABLED_SERVICES" =~ "n-vol" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600108 keystone service-create --name="nova-volume" \
109 --type=volume \
110 --description="Nova Volume Service"
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +0000111fi
112
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800113if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600114 keystone service-create --name=swift \
115 --type="object-store" \
116 --description="Swift Service"
117 SWIFT_USER=$(get_id keystone user-create --name=swift \
118 --pass="$SERVICE_PASSWORD" \
119 --tenant_id $SERVICE_TENANT \
120 --email=swift@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -0600121 keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600122 --user $SWIFT_USER \
123 --role $ADMIN_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800124fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600125
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800126if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600127 keystone service-create --name=quantum \
128 --type=network \
129 --description="Quantum Service"
130 QUANTUM_USER=$(get_id keystone user-create --name=quantum \
131 --pass="$SERVICE_PASSWORD" \
132 --tenant_id $SERVICE_TENANT \
133 --email=quantum@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -0600134 keystone user-role-add --tenant_id $SERVICE_TENANT \
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600135 --user $QUANTUM_USER \
136 --role $ADMIN_ROLE
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800137fi
Anthony Young8bdc2632011-09-22 08:00:44 +0000138
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000139# create ec2 creds and parse the secret and access key returned
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600140RESULT=$(keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER)
141ADMIN_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
142ADMIN_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000143
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600144RESULT=$(keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER)
145DEMO_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }')
146DEMO_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }')
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000147
148# write the secret and access to ec2rc
149cat > $DEVSTACK_DIR/ec2rc <<EOF
150ADMIN_ACCESS=$ADMIN_ACCESS
151ADMIN_SECRET=$ADMIN_SECRET
152DEMO_ACCESS=$DEMO_ACCESS
153DEMO_SECRET=$DEMO_SECRET
154EOF