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 |
Joe Gordon | 1216b9f | 2013-06-04 18:55:06 +0000 | [diff] [blame^] | 8 | # service swift service # if enabled |
| 9 | # service heat service # if enabled |
| 10 | # service ceilometer service # if enabled |
Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 11 | # Tempest Only: |
| 12 | # alt_demo alt_demo Member |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 13 | # |
| 14 | # Variables set before calling this script: |
| 15 | # SERVICE_TOKEN - aka admin_token in keystone.conf |
| 16 | # SERVICE_ENDPOINT - local Keystone admin endpoint |
| 17 | # SERVICE_TENANT_NAME - name of tenant containing service accounts |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 18 | # SERVICE_HOST - host used for endpoint creation |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 19 | # ENABLED_SERVICES - stack.sh's list of services to start |
| 20 | # DEVSTACK_DIR - Top-level DevStack directory |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 21 | # KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation |
| 22 | |
| 23 | # Defaults |
| 24 | # -------- |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 25 | |
| 26 | ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete} |
| 27 | SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD} |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 28 | export SERVICE_TOKEN=$SERVICE_TOKEN |
| 29 | export SERVICE_ENDPOINT=$SERVICE_ENDPOINT |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 30 | SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service} |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 31 | |
| 32 | function get_id () { |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 33 | echo `"$@" | awk '/ id / { print $4 }'` |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Dean Troyer | d835de8 | 2012-11-29 17:11:35 -0600 | [diff] [blame] | 36 | # Lookups |
| 37 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 38 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
Dean Troyer | 671c16e | 2012-12-13 16:22:38 -0600 | [diff] [blame] | 39 | MEMBER_ROLE=$(keystone role-list | awk "/ Member / { print \$2 }") |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 40 | |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 41 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 42 | # Roles |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 43 | # ----- |
| 44 | |
guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 45 | # The ResellerAdmin role is used by Nova and Ceilometer so we need to keep it. |
| 46 | # The admin role in swift allows a user to act as an admin for their tenant, |
| 47 | # but ResellerAdmin is needed for a user to act as any tenant. The name of this |
| 48 | # role is also configurable in swift-proxy.conf |
| 49 | RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin) |
Joe Gordon | 1216b9f | 2013-06-04 18:55:06 +0000 | [diff] [blame^] | 50 | # Service role, so service users do not have to be admins |
| 51 | SERVICE_ROLE=$(get_id keystone role-create --name=service) |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 52 | |
Dean Troyer | 671c16e | 2012-12-13 16:22:38 -0600 | [diff] [blame] | 53 | |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 54 | # Services |
| 55 | # -------- |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 56 | |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 57 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]] && [[ "$ENABLED_SERVICES" =~ "s-proxy" || "$ENABLED_SERVICES" =~ "swift" ]]; then |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 58 | NOVA_USER=$(keystone user-list | awk "/ nova / { print \$2 }") |
Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 59 | # Nova needs ResellerAdmin role to download images when accessing |
guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 60 | # swift through the s3 api. |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 61 | keystone user-role-add \ |
| 62 | --tenant_id $SERVICE_TENANT \ |
| 63 | --user_id $NOVA_USER \ |
| 64 | --role_id $RESELLER_ROLE |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 65 | fi |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 66 | |
Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 67 | # Heat |
| 68 | if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then |
| 69 | HEAT_USER=$(get_id keystone user-create --name=heat \ |
| 70 | --pass="$SERVICE_PASSWORD" \ |
| 71 | --tenant_id $SERVICE_TENANT \ |
| 72 | --email=heat@example.com) |
| 73 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
| 74 | --user_id $HEAT_USER \ |
Joe Gordon | 1216b9f | 2013-06-04 18:55:06 +0000 | [diff] [blame^] | 75 | --role_id $SERVICE_ROLE |
Steve Baker | 053a5f8 | 2012-12-11 17:08:48 +1300 | [diff] [blame] | 76 | # heat_stack_user role is for users created by Heat |
| 77 | keystone role-create --name heat_stack_user |
Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 78 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Steve Baker | 36cf7ee | 2012-09-17 16:49:24 +1200 | [diff] [blame] | 79 | HEAT_CFN_SERVICE=$(get_id keystone service-create \ |
Steve Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 80 | --name=heat-cfn \ |
| 81 | --type=cloudformation \ |
| 82 | --description="Heat CloudFormation Service") |
Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 83 | keystone endpoint-create \ |
| 84 | --region RegionOne \ |
Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 85 | --service_id $HEAT_CFN_SERVICE \ |
| 86 | --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \ |
| 87 | --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \ |
| 88 | --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" |
Steve Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 89 | HEAT_SERVICE=$(get_id keystone service-create \ |
| 90 | --name=heat \ |
| 91 | --type=orchestration \ |
| 92 | --description="Heat Service") |
| 93 | keystone endpoint-create \ |
| 94 | --region RegionOne \ |
| 95 | --service_id $HEAT_SERVICE \ |
| 96 | --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \ |
| 97 | --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \ |
| 98 | --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" |
Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 99 | fi |
| 100 | fi |
| 101 | |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 102 | # Glance |
| 103 | if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then |
| 104 | GLANCE_USER=$(get_id keystone user-create \ |
| 105 | --name=glance \ |
| 106 | --pass="$SERVICE_PASSWORD" \ |
| 107 | --tenant_id $SERVICE_TENANT \ |
| 108 | --email=glance@example.com) |
| 109 | keystone user-role-add \ |
| 110 | --tenant_id $SERVICE_TENANT \ |
| 111 | --user_id $GLANCE_USER \ |
| 112 | --role_id $ADMIN_ROLE |
| 113 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 114 | GLANCE_SERVICE=$(get_id keystone service-create \ |
| 115 | --name=glance \ |
| 116 | --type=image \ |
| 117 | --description="Glance Image Service") |
| 118 | keystone endpoint-create \ |
| 119 | --region RegionOne \ |
| 120 | --service_id $GLANCE_SERVICE \ |
Steve Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 121 | --publicurl "http://$SERVICE_HOST:9292" \ |
| 122 | --adminurl "http://$SERVICE_HOST:9292" \ |
| 123 | --internalurl "http://$SERVICE_HOST:9292" |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 124 | fi |
| 125 | fi |
| 126 | |
| 127 | # Swift |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 128 | |
| 129 | if [[ "$ENABLED_SERVICES" =~ "swift" || "$ENABLED_SERVICES" =~ "s-proxy" ]]; then |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 130 | SWIFT_USER=$(get_id keystone user-create \ |
| 131 | --name=swift \ |
| 132 | --pass="$SERVICE_PASSWORD" \ |
| 133 | --tenant_id $SERVICE_TENANT \ |
| 134 | --email=swift@example.com) |
| 135 | keystone user-role-add \ |
| 136 | --tenant_id $SERVICE_TENANT \ |
| 137 | --user_id $SWIFT_USER \ |
Joe Gordon | 1216b9f | 2013-06-04 18:55:06 +0000 | [diff] [blame^] | 138 | --role_id $SERVICE_ROLE |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 139 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 140 | SWIFT_SERVICE=$(get_id keystone service-create \ |
| 141 | --name=swift \ |
| 142 | --type="object-store" \ |
| 143 | --description="Swift Service") |
| 144 | keystone endpoint-create \ |
| 145 | --region RegionOne \ |
| 146 | --service_id $SWIFT_SERVICE \ |
| 147 | --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \ |
Steve Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 148 | --adminurl "http://$SERVICE_HOST:8080" \ |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 149 | --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" |
| 150 | fi |
| 151 | fi |
| 152 | |
Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 153 | if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then |
| 154 | CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \ |
| 155 | --pass="$SERVICE_PASSWORD" \ |
| 156 | --tenant_id $SERVICE_TENANT \ |
| 157 | --email=ceilometer@example.com) |
| 158 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
| 159 | --user_id $CEILOMETER_USER \ |
Joe Gordon | 1216b9f | 2013-06-04 18:55:06 +0000 | [diff] [blame^] | 160 | --role_id $SERVICE_ROLE |
guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 161 | # Ceilometer needs ResellerAdmin role to access swift account stats. |
| 162 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
| 163 | --user_id $CEILOMETER_USER \ |
| 164 | --role_id $RESELLER_ROLE |
Julien Danjou | f36afe5 | 2012-10-04 18:00:10 +0200 | [diff] [blame] | 165 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 166 | CEILOMETER_SERVICE=$(get_id keystone service-create \ |
| 167 | --name=ceilometer \ |
| 168 | --type=metering \ |
| 169 | --description="Ceilometer Service") |
| 170 | keystone endpoint-create \ |
| 171 | --region RegionOne \ |
| 172 | --service_id $CEILOMETER_SERVICE \ |
Eoghan Glynn | 21ddaac | 2013-03-05 12:40:59 +0000 | [diff] [blame] | 173 | --publicurl "http://$SERVICE_HOST:8777" \ |
| 174 | --adminurl "http://$SERVICE_HOST:8777" \ |
| 175 | --internalurl "http://$SERVICE_HOST:8777" |
Julien Danjou | f36afe5 | 2012-10-04 18:00:10 +0200 | [diff] [blame] | 176 | fi |
| 177 | fi |
| 178 | |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 179 | # EC2 |
| 180 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then |
| 181 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 182 | EC2_SERVICE=$(get_id keystone service-create \ |
| 183 | --name=ec2 \ |
| 184 | --type=ec2 \ |
| 185 | --description="EC2 Compatibility Layer") |
| 186 | keystone endpoint-create \ |
| 187 | --region RegionOne \ |
| 188 | --service_id $EC2_SERVICE \ |
| 189 | --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \ |
| 190 | --adminurl "http://$SERVICE_HOST:8773/services/Admin" \ |
| 191 | --internalurl "http://$SERVICE_HOST:8773/services/Cloud" |
| 192 | fi |
| 193 | fi |
| 194 | |
| 195 | # S3 |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 196 | if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift3" ]]; then |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 197 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 198 | S3_SERVICE=$(get_id keystone service-create \ |
| 199 | --name=s3 \ |
| 200 | --type=s3 \ |
| 201 | --description="S3") |
| 202 | keystone endpoint-create \ |
| 203 | --region RegionOne \ |
| 204 | --service_id $S3_SERVICE \ |
| 205 | --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \ |
| 206 | --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \ |
| 207 | --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" |
| 208 | fi |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 209 | fi |
Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 210 | |
| 211 | if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then |
| 212 | # Tempest has some tests that validate various authorization checks |
| 213 | # between two regular users in separate tenants |
Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 214 | ALT_DEMO_TENANT=$(get_id keystone tenant-create \ |
| 215 | --name=alt_demo) |
| 216 | ALT_DEMO_USER=$(get_id keystone user-create \ |
| 217 | --name=alt_demo \ |
| 218 | --pass="$ADMIN_PASSWORD" \ |
| 219 | --email=alt_demo@example.com) |
| 220 | keystone user-role-add \ |
| 221 | --tenant_id $ALT_DEMO_TENANT \ |
| 222 | --user_id $ALT_DEMO_USER \ |
| 223 | --role_id $MEMBER_ROLE |
Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 224 | fi |