blob: c8e68dd67a638eb5e5de584467a1de1cc2d126c1 [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
96 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +120097 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +130098 --name=heat-cfn \
99 --type=cloudformation \
100 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +1200101 keystone endpoint-create \
102 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +1000103 --service_id $HEAT_CFN_SERVICE \
104 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
105 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
106 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +1300107 HEAT_SERVICE=$(get_id keystone service-create \
108 --name=heat \
109 --type=orchestration \
110 --description="Heat Service")
111 keystone endpoint-create \
112 --region RegionOne \
113 --service_id $HEAT_SERVICE \
114 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
115 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
116 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +1200117 fi
118fi
119
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500120# Glance
121if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
122 GLANCE_USER=$(get_id keystone user-create \
123 --name=glance \
124 --pass="$SERVICE_PASSWORD" \
125 --tenant_id $SERVICE_TENANT \
126 --email=glance@example.com)
127 keystone user-role-add \
128 --tenant_id $SERVICE_TENANT \
129 --user_id $GLANCE_USER \
130 --role_id $ADMIN_ROLE
131 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
132 GLANCE_SERVICE=$(get_id keystone service-create \
133 --name=glance \
134 --type=image \
135 --description="Glance Image Service")
136 keystone endpoint-create \
137 --region RegionOne \
138 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200139 --publicurl "http://$SERVICE_HOST:9292" \
140 --adminurl "http://$SERVICE_HOST:9292" \
141 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500142 fi
143fi
144
145# Swift
146if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
147 SWIFT_USER=$(get_id keystone user-create \
148 --name=swift \
149 --pass="$SERVICE_PASSWORD" \
150 --tenant_id $SERVICE_TENANT \
151 --email=swift@example.com)
152 keystone user-role-add \
153 --tenant_id $SERVICE_TENANT \
154 --user_id $SWIFT_USER \
155 --role_id $ADMIN_ROLE
156 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
157 SWIFT_SERVICE=$(get_id keystone service-create \
158 --name=swift \
159 --type="object-store" \
160 --description="Swift Service")
161 keystone endpoint-create \
162 --region RegionOne \
163 --service_id $SWIFT_SERVICE \
164 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200165 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500166 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
167 fi
168fi
169
170if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
171 QUANTUM_USER=$(get_id keystone user-create \
172 --name=quantum \
173 --pass="$SERVICE_PASSWORD" \
174 --tenant_id $SERVICE_TENANT \
175 --email=quantum@example.com)
176 keystone user-role-add \
177 --tenant_id $SERVICE_TENANT \
178 --user_id $QUANTUM_USER \
179 --role_id $ADMIN_ROLE
180 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
181 QUANTUM_SERVICE=$(get_id keystone service-create \
182 --name=quantum \
183 --type=network \
184 --description="Quantum Service")
185 keystone endpoint-create \
186 --region RegionOne \
187 --service_id $QUANTUM_SERVICE \
188 --publicurl "http://$SERVICE_HOST:9696/" \
189 --adminurl "http://$SERVICE_HOST:9696/" \
190 --internalurl "http://$SERVICE_HOST:9696/"
191 fi
192fi
193
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400194if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
195 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
196 --pass="$SERVICE_PASSWORD" \
197 --tenant_id $SERVICE_TENANT \
198 --email=ceilometer@example.com)
199 keystone user-role-add --tenant_id $SERVICE_TENANT \
200 --user_id $CEILOMETER_USER \
201 --role_id $ADMIN_ROLE
guillaume pernot901eed72012-11-29 08:44:58 +0100202 # Ceilometer needs ResellerAdmin role to access swift account stats.
203 keystone user-role-add --tenant_id $SERVICE_TENANT \
204 --user_id $CEILOMETER_USER \
205 --role_id $RESELLER_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200206 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
207 CEILOMETER_SERVICE=$(get_id keystone service-create \
208 --name=ceilometer \
209 --type=metering \
210 --description="Ceilometer Service")
211 keystone endpoint-create \
212 --region RegionOne \
213 --service_id $CEILOMETER_SERVICE \
214 --publicurl "http://$SERVICE_HOST:8777/" \
215 --adminurl "http://$SERVICE_HOST:8777/" \
216 --internalurl "http://$SERVICE_HOST:8777/"
217 fi
218fi
219
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500220# EC2
221if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
222 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
223 EC2_SERVICE=$(get_id keystone service-create \
224 --name=ec2 \
225 --type=ec2 \
226 --description="EC2 Compatibility Layer")
227 keystone endpoint-create \
228 --region RegionOne \
229 --service_id $EC2_SERVICE \
230 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
231 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
232 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
233 fi
234fi
235
236# S3
237if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
238 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
239 S3_SERVICE=$(get_id keystone service-create \
240 --name=s3 \
241 --type=s3 \
242 --description="S3")
243 keystone endpoint-create \
244 --region RegionOne \
245 --service_id $S3_SERVICE \
246 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
247 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
248 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
249 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800250fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400251
252if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
253 # Tempest has some tests that validate various authorization checks
254 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500255 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
256 --name=alt_demo)
257 ALT_DEMO_USER=$(get_id keystone user-create \
258 --name=alt_demo \
259 --pass="$ADMIN_PASSWORD" \
260 --email=alt_demo@example.com)
261 keystone user-role-add \
262 --tenant_id $ALT_DEMO_TENANT \
263 --user_id $ALT_DEMO_USER \
264 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400265fi
Dean Troyer67787e62012-05-02 11:48:15 -0500266
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000267if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500268 CINDER_USER=$(get_id keystone user-create --name=cinder \
269 --pass="$SERVICE_PASSWORD" \
270 --tenant_id $SERVICE_TENANT \
271 --email=cinder@example.com)
272 keystone user-role-add --tenant_id $SERVICE_TENANT \
273 --user_id $CINDER_USER \
274 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700275 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
276 CINDER_SERVICE=$(get_id keystone service-create \
277 --name=cinder \
278 --type=volume \
279 --description="Cinder Service")
280 keystone endpoint-create \
281 --region RegionOne \
282 --service_id $CINDER_SERVICE \
283 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
284 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
285 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
286 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500287fi