blob: 17e8c59eb6881d36884c162d9b64b87aa7d36159 [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
10# service cinder admin # if enabled
11# service heat admin # if enabled
12# service ceilometer admin # if enabled
Jay Pipesb297d2d2012-05-10 11:21:22 -040013# Tempest Only:
14# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060015#
16# Variables set before calling this script:
17# SERVICE_TOKEN - aka admin_token in keystone.conf
18# SERVICE_ENDPOINT - local Keystone admin endpoint
19# SERVICE_TENANT_NAME - name of tenant containing service accounts
Dean Troyer3f7c06f2012-04-03 17:19:36 -050020# SERVICE_HOST - host used for endpoint creation
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060021# ENABLED_SERVICES - stack.sh's list of services to start
22# DEVSTACK_DIR - Top-level DevStack directory
Dean Troyer3f7c06f2012-04-03 17:19:36 -050023# KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation
24
25# Defaults
26# --------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060027
28ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
29SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000030export SERVICE_TOKEN=$SERVICE_TOKEN
31export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060032SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000033
34function get_id () {
Dean Troyer3f7c06f2012-04-03 17:19:36 -050035 echo `"$@" | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000036}
37
Dean Troyerd835de82012-11-29 17:11:35 -060038# Lookups
39SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
40ADMIN_ROLE=$(keystone role-list | awk "/ admin / { 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 Troyer3f7c06f2012-04-03 17:19:36 -050052# Services
53# --------
termiea96a4182012-01-09 22:13:29 -080054
Dean Troyera0dce262012-12-11 16:52:37 -060055if [[ "$ENABLED_SERVICES" =~ "n-api" ]] && [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
56 NOVA_USER=$(keystone user-list | awk "/ nova / { print \$2 }")
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000057 # Nova needs ResellerAdmin role to download images when accessing
guillaume pernot901eed72012-11-29 08:44:58 +010058 # swift through the s3 api.
Dean Troyer3f7c06f2012-04-03 17:19:36 -050059 keystone user-role-add \
60 --tenant_id $SERVICE_TENANT \
61 --user_id $NOVA_USER \
62 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -080063fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060064
Steve Bakerbfdad752012-08-18 09:00:42 +120065# Heat
66if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
67 HEAT_USER=$(get_id keystone user-create --name=heat \
68 --pass="$SERVICE_PASSWORD" \
69 --tenant_id $SERVICE_TENANT \
70 --email=heat@example.com)
71 keystone user-role-add --tenant_id $SERVICE_TENANT \
72 --user_id $HEAT_USER \
73 --role_id $ADMIN_ROLE
Steve Baker053a5f82012-12-11 17:08:48 +130074 # heat_stack_user role is for users created by Heat
75 keystone role-create --name heat_stack_user
Steve Bakerbfdad752012-08-18 09:00:42 +120076 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +120077 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +130078 --name=heat-cfn \
79 --type=cloudformation \
80 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +120081 keystone endpoint-create \
82 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +100083 --service_id $HEAT_CFN_SERVICE \
84 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
85 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
86 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +130087 HEAT_SERVICE=$(get_id keystone service-create \
88 --name=heat \
89 --type=orchestration \
90 --description="Heat Service")
91 keystone endpoint-create \
92 --region RegionOne \
93 --service_id $HEAT_SERVICE \
94 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
95 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
96 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +120097 fi
98fi
99
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500100# Glance
101if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
102 GLANCE_USER=$(get_id keystone user-create \
103 --name=glance \
104 --pass="$SERVICE_PASSWORD" \
105 --tenant_id $SERVICE_TENANT \
106 --email=glance@example.com)
107 keystone user-role-add \
108 --tenant_id $SERVICE_TENANT \
109 --user_id $GLANCE_USER \
110 --role_id $ADMIN_ROLE
111 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
112 GLANCE_SERVICE=$(get_id keystone service-create \
113 --name=glance \
114 --type=image \
115 --description="Glance Image Service")
116 keystone endpoint-create \
117 --region RegionOne \
118 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200119 --publicurl "http://$SERVICE_HOST:9292" \
120 --adminurl "http://$SERVICE_HOST:9292" \
121 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500122 fi
123fi
124
125# Swift
126if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
127 SWIFT_USER=$(get_id keystone user-create \
128 --name=swift \
129 --pass="$SERVICE_PASSWORD" \
130 --tenant_id $SERVICE_TENANT \
131 --email=swift@example.com)
132 keystone user-role-add \
133 --tenant_id $SERVICE_TENANT \
134 --user_id $SWIFT_USER \
135 --role_id $ADMIN_ROLE
136 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
137 SWIFT_SERVICE=$(get_id keystone service-create \
138 --name=swift \
139 --type="object-store" \
140 --description="Swift Service")
141 keystone endpoint-create \
142 --region RegionOne \
143 --service_id $SWIFT_SERVICE \
144 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200145 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500146 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
147 fi
148fi
149
150if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
151 QUANTUM_USER=$(get_id keystone user-create \
152 --name=quantum \
153 --pass="$SERVICE_PASSWORD" \
154 --tenant_id $SERVICE_TENANT \
155 --email=quantum@example.com)
156 keystone user-role-add \
157 --tenant_id $SERVICE_TENANT \
158 --user_id $QUANTUM_USER \
159 --role_id $ADMIN_ROLE
160 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
161 QUANTUM_SERVICE=$(get_id keystone service-create \
162 --name=quantum \
163 --type=network \
164 --description="Quantum Service")
165 keystone endpoint-create \
166 --region RegionOne \
167 --service_id $QUANTUM_SERVICE \
168 --publicurl "http://$SERVICE_HOST:9696/" \
169 --adminurl "http://$SERVICE_HOST:9696/" \
170 --internalurl "http://$SERVICE_HOST:9696/"
171 fi
172fi
173
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400174if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
175 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
176 --pass="$SERVICE_PASSWORD" \
177 --tenant_id $SERVICE_TENANT \
178 --email=ceilometer@example.com)
179 keystone user-role-add --tenant_id $SERVICE_TENANT \
180 --user_id $CEILOMETER_USER \
181 --role_id $ADMIN_ROLE
guillaume pernot901eed72012-11-29 08:44:58 +0100182 # Ceilometer needs ResellerAdmin role to access swift account stats.
183 keystone user-role-add --tenant_id $SERVICE_TENANT \
184 --user_id $CEILOMETER_USER \
185 --role_id $RESELLER_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200186 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
187 CEILOMETER_SERVICE=$(get_id keystone service-create \
188 --name=ceilometer \
189 --type=metering \
190 --description="Ceilometer Service")
191 keystone endpoint-create \
192 --region RegionOne \
193 --service_id $CEILOMETER_SERVICE \
194 --publicurl "http://$SERVICE_HOST:8777/" \
195 --adminurl "http://$SERVICE_HOST:8777/" \
196 --internalurl "http://$SERVICE_HOST:8777/"
197 fi
198fi
199
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500200# EC2
201if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
202 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
203 EC2_SERVICE=$(get_id keystone service-create \
204 --name=ec2 \
205 --type=ec2 \
206 --description="EC2 Compatibility Layer")
207 keystone endpoint-create \
208 --region RegionOne \
209 --service_id $EC2_SERVICE \
210 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
211 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
212 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
213 fi
214fi
215
216# S3
217if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
218 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
219 S3_SERVICE=$(get_id keystone service-create \
220 --name=s3 \
221 --type=s3 \
222 --description="S3")
223 keystone endpoint-create \
224 --region RegionOne \
225 --service_id $S3_SERVICE \
226 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
227 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
228 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
229 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800230fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400231
232if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
233 # Tempest has some tests that validate various authorization checks
234 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500235 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
236 --name=alt_demo)
237 ALT_DEMO_USER=$(get_id keystone user-create \
238 --name=alt_demo \
239 --pass="$ADMIN_PASSWORD" \
240 --email=alt_demo@example.com)
241 keystone user-role-add \
242 --tenant_id $ALT_DEMO_TENANT \
243 --user_id $ALT_DEMO_USER \
244 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400245fi
Dean Troyer67787e62012-05-02 11:48:15 -0500246
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000247if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500248 CINDER_USER=$(get_id keystone user-create --name=cinder \
249 --pass="$SERVICE_PASSWORD" \
250 --tenant_id $SERVICE_TENANT \
251 --email=cinder@example.com)
252 keystone user-role-add --tenant_id $SERVICE_TENANT \
253 --user_id $CINDER_USER \
254 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700255 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
256 CINDER_SERVICE=$(get_id keystone service-create \
257 --name=cinder \
258 --type=volume \
259 --description="Cinder Service")
260 keystone endpoint-create \
261 --region RegionOne \
262 --service_id $CINDER_SERVICE \
263 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
264 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
265 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
266 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500267fi