| Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 1 | #!/bin/bash | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 2 | # | 
|  | 3 | # Initial data for Keystone using python-keystoneclient | 
|  | 4 | # | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 5 | # Tenant               User       Roles | 
| Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 6 | # ------------------------------------------------------------------ | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 7 | # 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 Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 14 | # Tempest Only: | 
|  | 15 | # alt_demo             alt_demo  Member | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 16 | # | 
|  | 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 Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 21 | # SERVICE_HOST - host used for endpoint creation | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 22 | # ENABLED_SERVICES - stack.sh's list of services to start | 
|  | 23 | # DEVSTACK_DIR - Top-level DevStack directory | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 24 | # KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation | 
|  | 25 |  | 
|  | 26 | # Defaults | 
|  | 27 | # -------- | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 28 |  | 
|  | 29 | ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete} | 
|  | 30 | SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD} | 
| Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 31 | export SERVICE_TOKEN=$SERVICE_TOKEN | 
|  | 32 | export SERVICE_ENDPOINT=$SERVICE_ENDPOINT | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 33 | SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service} | 
| Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 34 |  | 
|  | 35 | function get_id () { | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 36 | echo `"$@" | awk '/ id / { print $4 }'` | 
| Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
| Dean Troyer | d835de8 | 2012-11-29 17:11:35 -0600 | [diff] [blame] | 39 | # Lookups | 
|  | 40 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") | 
|  | 41 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") | 
| Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 42 |  | 
| Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 43 |  | 
| Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 44 | # Roles | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 45 | # ----- | 
|  | 46 |  | 
| guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 47 | # 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 | 
|  | 51 | RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin) | 
| Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 52 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 53 | # Services | 
|  | 54 | # -------- | 
| termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 55 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 56 | # Nova | 
| Akihiro MOTOKI | 766ae34 | 2012-11-22 20:04:02 +0900 | [diff] [blame] | 57 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 58 | 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 Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 75 | --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 Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 78 | fi | 
| Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 79 | # Nova needs ResellerAdmin role to download images when accessing | 
| guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 80 | # swift through the s3 api. | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 81 | keystone user-role-add \ | 
|  | 82 | --tenant_id $SERVICE_TENANT \ | 
|  | 83 | --user_id $NOVA_USER \ | 
|  | 84 | --role_id $RESELLER_ROLE | 
| Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 85 | fi | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 86 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 87 | # Heat | 
|  | 88 | if [[ "$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 Baker | 36cf7ee | 2012-09-17 16:49:24 +1200 | [diff] [blame] | 97 | HEAT_CFN_SERVICE=$(get_id keystone service-create \ | 
| Steve Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 98 | --name=heat-cfn \ | 
|  | 99 | --type=cloudformation \ | 
|  | 100 | --description="Heat CloudFormation Service") | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 101 | keystone endpoint-create \ | 
|  | 102 | --region RegionOne \ | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 103 | --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 Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 107 | 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 Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 117 | fi | 
|  | 118 | fi | 
|  | 119 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 120 | # Glance | 
|  | 121 | if [[ "$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 Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 139 | --publicurl "http://$SERVICE_HOST:9292" \ | 
|  | 140 | --adminurl "http://$SERVICE_HOST:9292" \ | 
|  | 141 | --internalurl "http://$SERVICE_HOST:9292" | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 142 | fi | 
|  | 143 | fi | 
|  | 144 |  | 
|  | 145 | # Swift | 
|  | 146 | if [[ "$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 Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 165 | --adminurl "http://$SERVICE_HOST:8080" \ | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 166 | --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" | 
|  | 167 | fi | 
|  | 168 | fi | 
|  | 169 |  | 
|  | 170 | if [[ "$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 | 
|  | 192 | fi | 
|  | 193 |  | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 194 | if [[ "$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 pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 202 | # 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 Danjou | f36afe5 | 2012-10-04 18:00:10 +0200 | [diff] [blame] | 206 | 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 | 
|  | 218 | fi | 
|  | 219 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 220 | # EC2 | 
|  | 221 | if [[ "$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 | 
|  | 234 | fi | 
|  | 235 |  | 
|  | 236 | # S3 | 
|  | 237 | if [[ "$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 Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 250 | fi | 
| Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 251 |  | 
|  | 252 | if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then | 
|  | 253 | # Tempest has some tests that validate various authorization checks | 
|  | 254 | # between two regular users in separate tenants | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 255 | 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 Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 265 | fi | 
| Dean Troyer | 67787e6 | 2012-05-02 11:48:15 -0500 | [diff] [blame] | 266 |  | 
| Chmouel Boudjnah | d55509d | 2012-07-20 15:00:02 +0000 | [diff] [blame] | 267 | if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then | 
| Dean Troyer | 67787e6 | 2012-05-02 11:48:15 -0500 | [diff] [blame] | 268 | 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 Young | 1cdf5fa | 2012-07-03 13:57:39 -0700 | [diff] [blame] | 275 | 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 Troyer | 67787e6 | 2012-05-02 11:48:15 -0500 | [diff] [blame] | 287 | fi |