| 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 | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 8 | # service              swift      admin        # if enabled | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 9 | # service              heat       admin        # if enabled | 
|  | 10 | # service              ceilometer admin        # 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) | 
| Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 50 |  | 
| Dean Troyer | 671c16e | 2012-12-13 16:22:38 -0600 | [diff] [blame] | 51 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 52 | # Services | 
|  | 53 | # -------- | 
| termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 54 |  | 
| Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 55 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]] && [[ "$ENABLED_SERVICES" =~ "swift" ]]; then | 
|  | 56 | NOVA_USER=$(keystone user-list | awk "/ nova / { print \$2 }") | 
| Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 57 | # Nova needs ResellerAdmin role to download images when accessing | 
| guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 58 | # swift through the s3 api. | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 59 | keystone user-role-add \ | 
|  | 60 | --tenant_id $SERVICE_TENANT \ | 
|  | 61 | --user_id $NOVA_USER \ | 
|  | 62 | --role_id $RESELLER_ROLE | 
| Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 63 | fi | 
| Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 64 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 65 | # Heat | 
|  | 66 | if [[ "$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 Baker | 053a5f8 | 2012-12-11 17:08:48 +1300 | [diff] [blame] | 74 | # heat_stack_user role is for users created by Heat | 
|  | 75 | keystone role-create --name heat_stack_user | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 76 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
| Steve Baker | 36cf7ee | 2012-09-17 16:49:24 +1200 | [diff] [blame] | 77 | HEAT_CFN_SERVICE=$(get_id keystone service-create \ | 
| Steve Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 78 | --name=heat-cfn \ | 
|  | 79 | --type=cloudformation \ | 
|  | 80 | --description="Heat CloudFormation Service") | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 81 | keystone endpoint-create \ | 
|  | 82 | --region RegionOne \ | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 83 | --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 Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 87 | 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 Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 97 | fi | 
|  | 98 | fi | 
|  | 99 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 100 | # Glance | 
|  | 101 | if [[ "$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 Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 119 | --publicurl "http://$SERVICE_HOST:9292" \ | 
|  | 120 | --adminurl "http://$SERVICE_HOST:9292" \ | 
|  | 121 | --internalurl "http://$SERVICE_HOST:9292" | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 122 | fi | 
|  | 123 | fi | 
|  | 124 |  | 
|  | 125 | # Swift | 
|  | 126 | if [[ "$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 Baker | 8d6c9bc | 2012-09-11 10:05:14 +1200 | [diff] [blame] | 145 | --adminurl "http://$SERVICE_HOST:8080" \ | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 146 | --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" | 
|  | 147 | fi | 
|  | 148 | fi | 
|  | 149 |  | 
| Doug Hellmann | 4a2b1c6 | 2012-11-01 16:23:52 -0400 | [diff] [blame] | 150 | if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then | 
|  | 151 | CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \ | 
|  | 152 | --pass="$SERVICE_PASSWORD" \ | 
|  | 153 | --tenant_id $SERVICE_TENANT \ | 
|  | 154 | --email=ceilometer@example.com) | 
|  | 155 | keystone user-role-add --tenant_id $SERVICE_TENANT \ | 
|  | 156 | --user_id $CEILOMETER_USER \ | 
|  | 157 | --role_id $ADMIN_ROLE | 
| guillaume pernot | 901eed7 | 2012-11-29 08:44:58 +0100 | [diff] [blame] | 158 | # Ceilometer needs ResellerAdmin role to access swift account stats. | 
|  | 159 | keystone user-role-add --tenant_id $SERVICE_TENANT \ | 
|  | 160 | --user_id $CEILOMETER_USER \ | 
|  | 161 | --role_id $RESELLER_ROLE | 
| Julien Danjou | f36afe5 | 2012-10-04 18:00:10 +0200 | [diff] [blame] | 162 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 163 | CEILOMETER_SERVICE=$(get_id keystone service-create \ | 
|  | 164 | --name=ceilometer \ | 
|  | 165 | --type=metering \ | 
|  | 166 | --description="Ceilometer Service") | 
|  | 167 | keystone endpoint-create \ | 
|  | 168 | --region RegionOne \ | 
|  | 169 | --service_id $CEILOMETER_SERVICE \ | 
|  | 170 | --publicurl "http://$SERVICE_HOST:8777/" \ | 
|  | 171 | --adminurl "http://$SERVICE_HOST:8777/" \ | 
|  | 172 | --internalurl "http://$SERVICE_HOST:8777/" | 
|  | 173 | fi | 
|  | 174 | fi | 
|  | 175 |  | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 176 | # EC2 | 
|  | 177 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then | 
|  | 178 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 179 | EC2_SERVICE=$(get_id keystone service-create \ | 
|  | 180 | --name=ec2 \ | 
|  | 181 | --type=ec2 \ | 
|  | 182 | --description="EC2 Compatibility Layer") | 
|  | 183 | keystone endpoint-create \ | 
|  | 184 | --region RegionOne \ | 
|  | 185 | --service_id $EC2_SERVICE \ | 
|  | 186 | --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \ | 
|  | 187 | --adminurl "http://$SERVICE_HOST:8773/services/Admin" \ | 
|  | 188 | --internalurl "http://$SERVICE_HOST:8773/services/Cloud" | 
|  | 189 | fi | 
|  | 190 | fi | 
|  | 191 |  | 
|  | 192 | # S3 | 
|  | 193 | if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then | 
|  | 194 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 195 | S3_SERVICE=$(get_id keystone service-create \ | 
|  | 196 | --name=s3 \ | 
|  | 197 | --type=s3 \ | 
|  | 198 | --description="S3") | 
|  | 199 | keystone endpoint-create \ | 
|  | 200 | --region RegionOne \ | 
|  | 201 | --service_id $S3_SERVICE \ | 
|  | 202 | --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \ | 
|  | 203 | --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \ | 
|  | 204 | --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" | 
|  | 205 | fi | 
| Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 206 | fi | 
| Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 207 |  | 
|  | 208 | if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then | 
|  | 209 | # Tempest has some tests that validate various authorization checks | 
|  | 210 | # between two regular users in separate tenants | 
| Dean Troyer | 3f7c06f | 2012-04-03 17:19:36 -0500 | [diff] [blame] | 211 | ALT_DEMO_TENANT=$(get_id keystone tenant-create \ | 
|  | 212 | --name=alt_demo) | 
|  | 213 | ALT_DEMO_USER=$(get_id keystone user-create \ | 
|  | 214 | --name=alt_demo \ | 
|  | 215 | --pass="$ADMIN_PASSWORD" \ | 
|  | 216 | --email=alt_demo@example.com) | 
|  | 217 | keystone user-role-add \ | 
|  | 218 | --tenant_id $ALT_DEMO_TENANT \ | 
|  | 219 | --user_id $ALT_DEMO_USER \ | 
|  | 220 | --role_id $MEMBER_ROLE | 
| Jay Pipes | b297d2d | 2012-05-10 11:21:22 -0400 | [diff] [blame] | 221 | fi |