blob: a4f08e42e09aae88676dbbda31bd4cf6de4f538e [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
8# service nova admin, [ResellerAdmin (swift only)]
9# service quantum admin # if enabled
10# service swift admin # if enabled
11# service cinder admin # if enabled
12# service heat admin # if enabled
13# service ceilometer admin # if enabled
Jay Pipesb297d2d2012-05-10 11:21:22 -040014# Tempest Only:
15# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060016#
17# Variables set before calling this script:
18# SERVICE_TOKEN - aka admin_token in keystone.conf
19# SERVICE_ENDPOINT - local Keystone admin endpoint
20# SERVICE_TENANT_NAME - name of tenant containing service accounts
Dean Troyer3f7c06f2012-04-03 17:19:36 -050021# SERVICE_HOST - host used for endpoint creation
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060022# ENABLED_SERVICES - stack.sh's list of services to start
23# DEVSTACK_DIR - Top-level DevStack directory
Dean Troyer3f7c06f2012-04-03 17:19:36 -050024# KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation
25
26# Defaults
27# --------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060028
29ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
30SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000031export SERVICE_TOKEN=$SERVICE_TOKEN
32export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060033SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000034
35function get_id () {
Dean Troyer3f7c06f2012-04-03 17:19:36 -050036 echo `"$@" | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000037}
38
Dean Troyerd835de82012-11-29 17:11:35 -060039# Lookups
40SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
41ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
Jesse Andrews73e27b82011-09-12 17:55:00 -070042
Dean Troyer0bd24102012-03-08 00:33:54 -060043
Jesse Andrews73e27b82011-09-12 17:55:00 -070044# Roles
Dean Troyer3f7c06f2012-04-03 17:19:36 -050045# -----
46
guillaume pernot901eed72012-11-29 08:44:58 +010047# The ResellerAdmin role is used by Nova and Ceilometer so we need to keep it.
48# The admin role in swift allows a user to act as an admin for their tenant,
49# but ResellerAdmin is needed for a user to act as any tenant. The name of this
50# role is also configurable in swift-proxy.conf
51RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
Jesse Andrews73e27b82011-09-12 17:55:00 -070052
Dean Troyer3f7c06f2012-04-03 17:19:36 -050053# Services
54# --------
termiea96a4182012-01-09 22:13:29 -080055
Dean Troyer3f7c06f2012-04-03 17:19:36 -050056# Nova
Akihiro MOTOKI766ae342012-11-22 20:04:02 +090057if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Dean Troyer3f7c06f2012-04-03 17:19:36 -050058 NOVA_USER=$(get_id keystone user-create \
59 --name=nova \
60 --pass="$SERVICE_PASSWORD" \
61 --tenant_id $SERVICE_TENANT \
62 --email=nova@example.com)
63 keystone user-role-add \
64 --tenant_id $SERVICE_TENANT \
65 --user_id $NOVA_USER \
66 --role_id $ADMIN_ROLE
67 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
68 NOVA_SERVICE=$(get_id keystone service-create \
69 --name=nova \
70 --type=compute \
71 --description="Nova Compute Service")
72 keystone endpoint-create \
73 --region RegionOne \
74 --service_id $NOVA_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +120075 --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
76 --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
77 --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s"
Dean Troyer3f7c06f2012-04-03 17:19:36 -050078 fi
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000079 # Nova needs ResellerAdmin role to download images when accessing
guillaume pernot901eed72012-11-29 08:44:58 +010080 # swift through the s3 api.
Dean Troyer3f7c06f2012-04-03 17:19:36 -050081 keystone user-role-add \
82 --tenant_id $SERVICE_TENANT \
83 --user_id $NOVA_USER \
84 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -080085fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060086
Steve Bakerbfdad752012-08-18 09:00:42 +120087# Heat
88if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
89 HEAT_USER=$(get_id keystone user-create --name=heat \
90 --pass="$SERVICE_PASSWORD" \
91 --tenant_id $SERVICE_TENANT \
92 --email=heat@example.com)
93 keystone user-role-add --tenant_id $SERVICE_TENANT \
94 --user_id $HEAT_USER \
95 --role_id $ADMIN_ROLE
Steve Baker053a5f82012-12-11 17:08:48 +130096 # heat_stack_user role is for users created by Heat
97 keystone role-create --name heat_stack_user
Steve Bakerbfdad752012-08-18 09:00:42 +120098 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +120099 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +1300100 --name=heat-cfn \
101 --type=cloudformation \
102 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +1200103 keystone endpoint-create \
104 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +1000105 --service_id $HEAT_CFN_SERVICE \
106 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
107 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
108 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +1300109 HEAT_SERVICE=$(get_id keystone service-create \
110 --name=heat \
111 --type=orchestration \
112 --description="Heat Service")
113 keystone endpoint-create \
114 --region RegionOne \
115 --service_id $HEAT_SERVICE \
116 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
117 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
118 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +1200119 fi
120fi
121
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500122# Glance
123if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
124 GLANCE_USER=$(get_id keystone user-create \
125 --name=glance \
126 --pass="$SERVICE_PASSWORD" \
127 --tenant_id $SERVICE_TENANT \
128 --email=glance@example.com)
129 keystone user-role-add \
130 --tenant_id $SERVICE_TENANT \
131 --user_id $GLANCE_USER \
132 --role_id $ADMIN_ROLE
133 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
134 GLANCE_SERVICE=$(get_id keystone service-create \
135 --name=glance \
136 --type=image \
137 --description="Glance Image Service")
138 keystone endpoint-create \
139 --region RegionOne \
140 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200141 --publicurl "http://$SERVICE_HOST:9292" \
142 --adminurl "http://$SERVICE_HOST:9292" \
143 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500144 fi
145fi
146
147# Swift
148if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
149 SWIFT_USER=$(get_id keystone user-create \
150 --name=swift \
151 --pass="$SERVICE_PASSWORD" \
152 --tenant_id $SERVICE_TENANT \
153 --email=swift@example.com)
154 keystone user-role-add \
155 --tenant_id $SERVICE_TENANT \
156 --user_id $SWIFT_USER \
157 --role_id $ADMIN_ROLE
158 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
159 SWIFT_SERVICE=$(get_id keystone service-create \
160 --name=swift \
161 --type="object-store" \
162 --description="Swift Service")
163 keystone endpoint-create \
164 --region RegionOne \
165 --service_id $SWIFT_SERVICE \
166 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200167 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500168 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
169 fi
170fi
171
172if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
173 QUANTUM_USER=$(get_id keystone user-create \
174 --name=quantum \
175 --pass="$SERVICE_PASSWORD" \
176 --tenant_id $SERVICE_TENANT \
177 --email=quantum@example.com)
178 keystone user-role-add \
179 --tenant_id $SERVICE_TENANT \
180 --user_id $QUANTUM_USER \
181 --role_id $ADMIN_ROLE
182 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
183 QUANTUM_SERVICE=$(get_id keystone service-create \
184 --name=quantum \
185 --type=network \
186 --description="Quantum Service")
187 keystone endpoint-create \
188 --region RegionOne \
189 --service_id $QUANTUM_SERVICE \
190 --publicurl "http://$SERVICE_HOST:9696/" \
191 --adminurl "http://$SERVICE_HOST:9696/" \
192 --internalurl "http://$SERVICE_HOST:9696/"
193 fi
194fi
195
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400196if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
197 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
198 --pass="$SERVICE_PASSWORD" \
199 --tenant_id $SERVICE_TENANT \
200 --email=ceilometer@example.com)
201 keystone user-role-add --tenant_id $SERVICE_TENANT \
202 --user_id $CEILOMETER_USER \
203 --role_id $ADMIN_ROLE
guillaume pernot901eed72012-11-29 08:44:58 +0100204 # Ceilometer needs ResellerAdmin role to access swift account stats.
205 keystone user-role-add --tenant_id $SERVICE_TENANT \
206 --user_id $CEILOMETER_USER \
207 --role_id $RESELLER_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200208 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
209 CEILOMETER_SERVICE=$(get_id keystone service-create \
210 --name=ceilometer \
211 --type=metering \
212 --description="Ceilometer Service")
213 keystone endpoint-create \
214 --region RegionOne \
215 --service_id $CEILOMETER_SERVICE \
216 --publicurl "http://$SERVICE_HOST:8777/" \
217 --adminurl "http://$SERVICE_HOST:8777/" \
218 --internalurl "http://$SERVICE_HOST:8777/"
219 fi
220fi
221
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500222# EC2
223if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
224 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
225 EC2_SERVICE=$(get_id keystone service-create \
226 --name=ec2 \
227 --type=ec2 \
228 --description="EC2 Compatibility Layer")
229 keystone endpoint-create \
230 --region RegionOne \
231 --service_id $EC2_SERVICE \
232 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
233 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
234 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
235 fi
236fi
237
238# S3
239if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
240 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
241 S3_SERVICE=$(get_id keystone service-create \
242 --name=s3 \
243 --type=s3 \
244 --description="S3")
245 keystone endpoint-create \
246 --region RegionOne \
247 --service_id $S3_SERVICE \
248 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
249 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
250 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
251 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800252fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400253
254if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
255 # Tempest has some tests that validate various authorization checks
256 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500257 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
258 --name=alt_demo)
259 ALT_DEMO_USER=$(get_id keystone user-create \
260 --name=alt_demo \
261 --pass="$ADMIN_PASSWORD" \
262 --email=alt_demo@example.com)
263 keystone user-role-add \
264 --tenant_id $ALT_DEMO_TENANT \
265 --user_id $ALT_DEMO_USER \
266 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400267fi
Dean Troyer67787e62012-05-02 11:48:15 -0500268
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000269if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500270 CINDER_USER=$(get_id keystone user-create --name=cinder \
271 --pass="$SERVICE_PASSWORD" \
272 --tenant_id $SERVICE_TENANT \
273 --email=cinder@example.com)
274 keystone user-role-add --tenant_id $SERVICE_TENANT \
275 --user_id $CINDER_USER \
276 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700277 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
278 CINDER_SERVICE=$(get_id keystone service-create \
279 --name=cinder \
280 --type=volume \
281 --description="Cinder Service")
282 keystone endpoint-create \
283 --region RegionOne \
284 --service_id $CINDER_SERVICE \
285 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
286 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
287 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
288 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500289fi