Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 2 | # Tenants |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 3 | export SERVICE_TOKEN=$SERVICE_TOKEN |
| 4 | export SERVICE_ENDPOINT=$SERVICE_ENDPOINT |
| 5 | |
| 6 | function get_id () { |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 7 | echo `$@ | grep ' id ' | awk '{print $4}'` |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 8 | } |
| 9 | |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 10 | # Detect if the keystone cli binary has the command names changed |
| 11 | # in https://review.openstack.org/4375 |
| 12 | # FIXME(dtroyer): Remove the keystone client command checking |
| 13 | # after a suitable transition period. add-user-role |
| 14 | # and ec2-create-credentials were renamed |
| 15 | if keystone help | grep -q user-role-add; then |
| 16 | KEYSTONE_COMMAND_4375=1 |
| 17 | fi |
| 18 | |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 19 | ADMIN_TENANT=`get_id keystone tenant-create --name=admin` |
| 20 | DEMO_TENANT=`get_id keystone tenant-create --name=demo` |
| 21 | INVIS_TENANT=`get_id keystone tenant-create --name=invisible_to_admin` |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 22 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 23 | |
| 24 | # Users |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 25 | ADMIN_USER=`get_id keystone user-create \ |
| 26 | --name=admin \ |
| 27 | --pass="$ADMIN_PASSWORD" \ |
| 28 | --email=admin@example.com` |
| 29 | DEMO_USER=`get_id keystone user-create \ |
| 30 | --name=demo \ |
| 31 | --pass="$ADMIN_PASSWORD" \ |
| 32 | --email=admin@example.com` |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 33 | |
| 34 | # Roles |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 35 | ADMIN_ROLE=`get_id keystone role-create --name=admin` |
| 36 | MEMBER_ROLE=`get_id keystone role-create --name=Member` |
| 37 | KEYSTONEADMIN_ROLE=`get_id keystone role-create --name=KeystoneAdmin` |
| 38 | KEYSTONESERVICE_ROLE=`get_id keystone role-create --name=KeystoneServiceAdmin` |
| 39 | SYSADMIN_ROLE=`get_id keystone role-create --name=sysadmin` |
| 40 | NETADMIN_ROLE=`get_id keystone role-create --name=netadmin` |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 41 | |
| 42 | |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 43 | if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then |
| 44 | # Add Roles to Users in Tenants |
| 45 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 46 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT |
| 47 | keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT |
| 48 | keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT |
| 49 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT |
| 50 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 51 | |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 52 | # TODO(termie): these two might be dubious |
| 53 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 54 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT |
| 55 | else |
| 56 | ### compat |
| 57 | # Add Roles to Users in Tenants |
| 58 | keystone add-user-role $ADMIN_USER $ADMIN_ROLE $ADMIN_TENANT |
| 59 | keystone add-user-role $DEMO_USER $MEMBER_ROLE $DEMO_TENANT |
| 60 | keystone add-user-role $DEMO_USER $SYSADMIN_ROLE $DEMO_TENANT |
| 61 | keystone add-user-role $DEMO_USER $NETADMIN_ROLE $DEMO_TENANT |
| 62 | keystone add-user-role $DEMO_USER $MEMBER_ROLE $INVIS_TENANT |
| 63 | keystone add-user-role $ADMIN_USER $ADMIN_ROLE $DEMO_TENANT |
| 64 | |
| 65 | # TODO(termie): these two might be dubious |
| 66 | keystone add-user-role $ADMIN_USER $KEYSTONEADMIN_ROLE $ADMIN_TENANT |
| 67 | keystone add-user-role $ADMIN_USER $KEYSTONESERVICE_ROLE $ADMIN_TENANT |
| 68 | ### |
| 69 | fi |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 70 | |
Anthony Young | 8bdc263 | 2011-09-22 08:00:44 +0000 | [diff] [blame] | 71 | # Services |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 72 | keystone service-create \ |
| 73 | --name=nova \ |
| 74 | --type=compute \ |
| 75 | --description="Nova Compute Service" |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 76 | |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 77 | keystone service-create \ |
| 78 | --name=ec2 \ |
| 79 | --type=ec2 \ |
| 80 | --description="EC2 Compatibility Layer" |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 81 | |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 82 | keystone service-create \ |
| 83 | --name=glance \ |
| 84 | --type=image \ |
| 85 | --description="Glance Image Service" |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 86 | |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 87 | keystone service-create \ |
| 88 | --name=keystone \ |
| 89 | --type=identity \ |
| 90 | --description="Keystone Identity Service" |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 91 | if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 92 | keystone service-create \ |
| 93 | --name=swift \ |
| 94 | --type="object-store" \ |
| 95 | --description="Swift Service" |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 96 | fi |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 97 | if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then |
| 98 | keystone service-create \ |
| 99 | --name=quantum \ |
| 100 | --type=network \ |
| 101 | --description="Quantum Service" |
| 102 | fi |
Anthony Young | 8bdc263 | 2011-09-22 08:00:44 +0000 | [diff] [blame] | 103 | |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 104 | # create ec2 creds and parse the secret and access key returned |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 105 | if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then |
| 106 | RESULT=`keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER` |
| 107 | else |
| 108 | RESULT=`keystone ec2-create-credentials --tenant_id=$ADMIN_TENANT --user_id=$ADMIN_USER` |
| 109 | fi |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 110 | echo `$@ | grep id | awk '{print $4}'` |
| 111 | ADMIN_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'` |
| 112 | ADMIN_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'` |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 113 | |
| 114 | |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 115 | if [[ -n "$KEYSTONE_COMMAND_4375" ]]; then |
| 116 | RESULT=`keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER` |
| 117 | else |
| 118 | RESULT=`keystone ec2-create-credentials --tenant_id=$DEMO_TENANT --user_id=$DEMO_USER` |
| 119 | fi |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 120 | DEMO_ACCESS=`echo "$RESULT" | grep access | awk '{print $4}'` |
| 121 | DEMO_SECRET=`echo "$RESULT" | grep secret | awk '{print $4}'` |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 122 | |
| 123 | # write the secret and access to ec2rc |
| 124 | cat > $DEVSTACK_DIR/ec2rc <<EOF |
| 125 | ADMIN_ACCESS=$ADMIN_ACCESS |
| 126 | ADMIN_SECRET=$ADMIN_SECRET |
| 127 | DEMO_ACCESS=$DEMO_ACCESS |
| 128 | DEMO_SECRET=$DEMO_SECRET |
| 129 | EOF |