blob: 71a8e5efa8f852b7a990e640dda8cab60fd37c9c [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#
Doug Hellmann4a2b1c62012-11-01 16:23:52 -04005# Tenant User Roles
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +00006# ------------------------------------------------------------------
Doug Hellmann4a2b1c62012-11-01 16:23:52 -04007# service glance admin
Doug Hellmann4a2b1c62012-11-01 16:23:52 -04008# service quantum admin # if enabled
9# service swift admin # if enabled
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040010# service heat admin # if enabled
11# service ceilometer admin # if enabled
Jay Pipesb297d2d2012-05-10 11:21:22 -040012# Tempest Only:
13# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060014#
15# Variables set before calling this script:
16# SERVICE_TOKEN - aka admin_token in keystone.conf
17# SERVICE_ENDPOINT - local Keystone admin endpoint
18# SERVICE_TENANT_NAME - name of tenant containing service accounts
Dean Troyer3f7c06f2012-04-03 17:19:36 -050019# SERVICE_HOST - host used for endpoint creation
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060020# ENABLED_SERVICES - stack.sh's list of services to start
21# DEVSTACK_DIR - Top-level DevStack directory
Dean Troyer3f7c06f2012-04-03 17:19:36 -050022# KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation
23
24# Defaults
25# --------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060026
27ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
28SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000029export SERVICE_TOKEN=$SERVICE_TOKEN
30export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060031SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000032
33function get_id () {
Dean Troyer3f7c06f2012-04-03 17:19:36 -050034 echo `"$@" | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000035}
36
Dean Troyerd835de82012-11-29 17:11:35 -060037# Lookups
38SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
39ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
Dean Troyer671c16e2012-12-13 16:22:38 -060040MEMBER_ROLE=$(keystone role-list | awk "/ Member / { print \$2 }")
Jesse Andrews73e27b82011-09-12 17:55:00 -070041
Dean Troyer0bd24102012-03-08 00:33:54 -060042
Jesse Andrews73e27b82011-09-12 17:55:00 -070043# Roles
Dean Troyer3f7c06f2012-04-03 17:19:36 -050044# -----
45
guillaume pernot901eed72012-11-29 08:44:58 +010046# The ResellerAdmin role is used by Nova and Ceilometer so we need to keep it.
47# The admin role in swift allows a user to act as an admin for their tenant,
48# but ResellerAdmin is needed for a user to act as any tenant. The name of this
49# role is also configurable in swift-proxy.conf
50RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
Jesse Andrews73e27b82011-09-12 17:55:00 -070051
Dean Troyer671c16e2012-12-13 16:22:38 -060052
Dean Troyer3f7c06f2012-04-03 17:19:36 -050053# Services
54# --------
termiea96a4182012-01-09 22:13:29 -080055
Dean Troyera0dce262012-12-11 16:52:37 -060056if [[ "$ENABLED_SERVICES" =~ "n-api" ]] && [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
57 NOVA_USER=$(keystone user-list | awk "/ nova / { print \$2 }")
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000058 # Nova needs ResellerAdmin role to download images when accessing
guillaume pernot901eed72012-11-29 08:44:58 +010059 # swift through the s3 api.
Dean Troyer3f7c06f2012-04-03 17:19:36 -050060 keystone user-role-add \
61 --tenant_id $SERVICE_TENANT \
62 --user_id $NOVA_USER \
63 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -080064fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060065
Steve Bakerbfdad752012-08-18 09:00:42 +120066# Heat
67if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
68 HEAT_USER=$(get_id keystone user-create --name=heat \
69 --pass="$SERVICE_PASSWORD" \
70 --tenant_id $SERVICE_TENANT \
71 --email=heat@example.com)
72 keystone user-role-add --tenant_id $SERVICE_TENANT \
73 --user_id $HEAT_USER \
74 --role_id $ADMIN_ROLE
Steve Baker053a5f82012-12-11 17:08:48 +130075 # heat_stack_user role is for users created by Heat
76 keystone role-create --name heat_stack_user
Steve Bakerbfdad752012-08-18 09:00:42 +120077 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +120078 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +130079 --name=heat-cfn \
80 --type=cloudformation \
81 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +120082 keystone endpoint-create \
83 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +100084 --service_id $HEAT_CFN_SERVICE \
85 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
86 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
87 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +130088 HEAT_SERVICE=$(get_id keystone service-create \
89 --name=heat \
90 --type=orchestration \
91 --description="Heat Service")
92 keystone endpoint-create \
93 --region RegionOne \
94 --service_id $HEAT_SERVICE \
95 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
96 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
97 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +120098 fi
99fi
100
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500101# Glance
102if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
103 GLANCE_USER=$(get_id keystone user-create \
104 --name=glance \
105 --pass="$SERVICE_PASSWORD" \
106 --tenant_id $SERVICE_TENANT \
107 --email=glance@example.com)
108 keystone user-role-add \
109 --tenant_id $SERVICE_TENANT \
110 --user_id $GLANCE_USER \
111 --role_id $ADMIN_ROLE
112 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
113 GLANCE_SERVICE=$(get_id keystone service-create \
114 --name=glance \
115 --type=image \
116 --description="Glance Image Service")
117 keystone endpoint-create \
118 --region RegionOne \
119 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200120 --publicurl "http://$SERVICE_HOST:9292" \
121 --adminurl "http://$SERVICE_HOST:9292" \
122 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500123 fi
124fi
125
126# Swift
127if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
128 SWIFT_USER=$(get_id keystone user-create \
129 --name=swift \
130 --pass="$SERVICE_PASSWORD" \
131 --tenant_id $SERVICE_TENANT \
132 --email=swift@example.com)
133 keystone user-role-add \
134 --tenant_id $SERVICE_TENANT \
135 --user_id $SWIFT_USER \
136 --role_id $ADMIN_ROLE
137 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
138 SWIFT_SERVICE=$(get_id keystone service-create \
139 --name=swift \
140 --type="object-store" \
141 --description="Swift Service")
142 keystone endpoint-create \
143 --region RegionOne \
144 --service_id $SWIFT_SERVICE \
145 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200146 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500147 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
148 fi
149fi
150
151if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
152 QUANTUM_USER=$(get_id keystone user-create \
153 --name=quantum \
154 --pass="$SERVICE_PASSWORD" \
155 --tenant_id $SERVICE_TENANT \
156 --email=quantum@example.com)
157 keystone user-role-add \
158 --tenant_id $SERVICE_TENANT \
159 --user_id $QUANTUM_USER \
160 --role_id $ADMIN_ROLE
161 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
162 QUANTUM_SERVICE=$(get_id keystone service-create \
163 --name=quantum \
164 --type=network \
165 --description="Quantum Service")
166 keystone endpoint-create \
167 --region RegionOne \
168 --service_id $QUANTUM_SERVICE \
169 --publicurl "http://$SERVICE_HOST:9696/" \
170 --adminurl "http://$SERVICE_HOST:9696/" \
171 --internalurl "http://$SERVICE_HOST:9696/"
172 fi
173fi
174
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400175if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
176 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
177 --pass="$SERVICE_PASSWORD" \
178 --tenant_id $SERVICE_TENANT \
179 --email=ceilometer@example.com)
180 keystone user-role-add --tenant_id $SERVICE_TENANT \
181 --user_id $CEILOMETER_USER \
182 --role_id $ADMIN_ROLE
guillaume pernot901eed72012-11-29 08:44:58 +0100183 # Ceilometer needs ResellerAdmin role to access swift account stats.
184 keystone user-role-add --tenant_id $SERVICE_TENANT \
185 --user_id $CEILOMETER_USER \
186 --role_id $RESELLER_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200187 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
188 CEILOMETER_SERVICE=$(get_id keystone service-create \
189 --name=ceilometer \
190 --type=metering \
191 --description="Ceilometer Service")
192 keystone endpoint-create \
193 --region RegionOne \
194 --service_id $CEILOMETER_SERVICE \
195 --publicurl "http://$SERVICE_HOST:8777/" \
196 --adminurl "http://$SERVICE_HOST:8777/" \
197 --internalurl "http://$SERVICE_HOST:8777/"
198 fi
199fi
200
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500201# EC2
202if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
203 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
204 EC2_SERVICE=$(get_id keystone service-create \
205 --name=ec2 \
206 --type=ec2 \
207 --description="EC2 Compatibility Layer")
208 keystone endpoint-create \
209 --region RegionOne \
210 --service_id $EC2_SERVICE \
211 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
212 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
213 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
214 fi
215fi
216
217# S3
218if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
219 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
220 S3_SERVICE=$(get_id keystone service-create \
221 --name=s3 \
222 --type=s3 \
223 --description="S3")
224 keystone endpoint-create \
225 --region RegionOne \
226 --service_id $S3_SERVICE \
227 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
228 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
229 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
230 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800231fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400232
233if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
234 # Tempest has some tests that validate various authorization checks
235 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500236 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
237 --name=alt_demo)
238 ALT_DEMO_USER=$(get_id keystone user-create \
239 --name=alt_demo \
240 --pass="$ADMIN_PASSWORD" \
241 --email=alt_demo@example.com)
242 keystone user-role-add \
243 --tenant_id $ALT_DEMO_TENANT \
244 --user_id $ALT_DEMO_USER \
245 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400246fi