blob: ed85aca03af8331f61aa94401e7413bc902a9b36 [file] [log] [blame]
Jesse Andrews73e27b82011-09-12 17:55:00 -07001#!/bin/bash
Jesse Andrews73e27b82011-09-12 17:55:00 -07002# Tenants
Vishvananda Ishayad1f52432012-02-09 03:50:57 +00003export SERVICE_TOKEN=$SERVICE_TOKEN
4export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
5
6function get_id () {
Dean Troyerf4565c42012-02-23 11:21:10 -06007 echo `$@ | grep ' id ' | awk '{print $4}'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +00008}
9
Dean Troyerf4565c42012-02-23 11:21:10 -060010# Detect if the keystone cli binary has the command names changed
11# in https://review.openstack.org/4375
12# FIXME(dtroyer): Remove the keystone client command checking
13# after a suitable transition period. add-user-role
14# and ec2-create-credentials were renamed
15if keystone help | grep -q user-role-add; then
16 KEYSTONE_COMMAND_4375=1
17fi
18
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000019ADMIN_TENANT=`get_id keystone tenant-create --name=admin`
20DEMO_TENANT=`get_id keystone tenant-create --name=demo`
21INVIS_TENANT=`get_id keystone tenant-create --name=invisible_to_admin`
termiea96a4182012-01-09 22:13:29 -080022
Jesse Andrews73e27b82011-09-12 17:55:00 -070023
24# Users
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000025ADMIN_USER=`get_id keystone user-create \
26 --name=admin \
27 --pass="$ADMIN_PASSWORD" \
28 --email=admin@example.com`
29DEMO_USER=`get_id keystone user-create \
30 --name=demo \
31 --pass="$ADMIN_PASSWORD" \
32 --email=admin@example.com`
Jesse Andrews73e27b82011-09-12 17:55:00 -070033
34# Roles
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000035ADMIN_ROLE=`get_id keystone role-create --name=admin`
36MEMBER_ROLE=`get_id keystone role-create --name=Member`
37KEYSTONEADMIN_ROLE=`get_id keystone role-create --name=KeystoneAdmin`
38KEYSTONESERVICE_ROLE=`get_id keystone role-create --name=KeystoneServiceAdmin`
39SYSADMIN_ROLE=`get_id keystone role-create --name=sysadmin`
40NETADMIN_ROLE=`get_id keystone role-create --name=netadmin`
termiea96a4182012-01-09 22:13:29 -080041
42
Dean Troyerf4565c42012-02-23 11:21:10 -060043if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
44 # Add Roles to Users in Tenants
45 keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT
46 keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT
47 keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT
48 keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT
49 keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT
50 keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT
termiea96a4182012-01-09 22:13:29 -080051
Dean Troyerf4565c42012-02-23 11:21:10 -060052 # TODO(termie): these two might be dubious
53 keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
54 keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
55else
56 ### compat
57 # Add Roles to Users in Tenants
58 keystone add-user-role $ADMIN_USER $ADMIN_ROLE $ADMIN_TENANT
59 keystone add-user-role $DEMO_USER $MEMBER_ROLE $DEMO_TENANT
60 keystone add-user-role $DEMO_USER $SYSADMIN_ROLE $DEMO_TENANT
61 keystone add-user-role $DEMO_USER $NETADMIN_ROLE $DEMO_TENANT
62 keystone add-user-role $DEMO_USER $MEMBER_ROLE $INVIS_TENANT
63 keystone add-user-role $ADMIN_USER $ADMIN_ROLE $DEMO_TENANT
64
65 # TODO(termie): these two might be dubious
66 keystone add-user-role $ADMIN_USER $KEYSTONEADMIN_ROLE $ADMIN_TENANT
67 keystone add-user-role $ADMIN_USER $KEYSTONESERVICE_ROLE $ADMIN_TENANT
68 ###
69fi
Jesse Andrews73e27b82011-09-12 17:55:00 -070070
Anthony Young8bdc2632011-09-22 08:00:44 +000071# Services
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000072keystone service-create \
73 --name=nova \
74 --type=compute \
75 --description="Nova Compute Service"
termiea96a4182012-01-09 22:13:29 -080076
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000077keystone service-create \
78 --name=ec2 \
79 --type=ec2 \
80 --description="EC2 Compatibility Layer"
termiea96a4182012-01-09 22:13:29 -080081
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000082keystone service-create \
83 --name=glance \
84 --type=image \
85 --description="Glance Image Service"
termiea96a4182012-01-09 22:13:29 -080086
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000087keystone service-create \
88 --name=keystone \
89 --type=identity \
90 --description="Keystone Identity Service"
Jesse Andrews9c7c9082011-11-23 10:10:53 -080091if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000092 keystone service-create \
93 --name=swift \
94 --type="object-store" \
95 --description="Swift Service"
Jesse Andrews9c7c9082011-11-23 10:10:53 -080096fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -080097if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
98 keystone service-create \
99 --name=quantum \
100 --type=network \
101 --description="Quantum Service"
102fi
Anthony Young8bdc2632011-09-22 08:00:44 +0000103
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000104# create ec2 creds and parse the secret and access key returned
Dean Troyerf4565c42012-02-23 11:21:10 -0600105if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
106 RESULT=`keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER`
107else
108 RESULT=`keystone ec2-create-credentials --tenant_id=$ADMIN_TENANT --user_id=$ADMIN_USER`
109fi
Vishvananda Ishayad1f52432012-02-09 03:50:57 +0000110 echo `$@ | grep id | awk '{print $4}'`
111ADMIN_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'`
112ADMIN_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'`
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000113
114
Dean Troyerf4565c42012-02-23 11:21:10 -0600115if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then
116 RESULT=`keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER`
117else
118 RESULT=`keystone ec2-create-credentials --tenant_id=$DEMO_TENANT --user_id=$DEMO_USER`
119fi
Vishvananda Ishayad1f52432012-02-09 03:50:57 +0000120DEMO_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'`
121DEMO_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'`
Vishvananda Ishaya658ac7a2012-02-06 22:56:37 +0000122
123# write the secret and access to ec2rc
124cat > $DEVSTACK_DIR/ec2rc <<EOF
125ADMIN_ACCESS=$ADMIN_ACCESS
126ADMIN_SECRET=$ADMIN_SECRET
127DEMO_ACCESS=$DEMO_ACCESS
128DEMO_SECRET=$DEMO_SECRET
129EOF