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 | # |
| 5 | # A set of EC2-compatible credentials is created for both admin and demo |
| 6 | # users and placed in $DEVSTACK_DIR/ec2rc. |
| 7 | # |
| 8 | # Tenant User Roles |
| 9 | # ------------------------------------------------------- |
| 10 | # admin admin admin |
| 11 | # service glance admin |
| 12 | # service nova admin |
| 13 | # service quantum admin # if enabled |
| 14 | # service swift admin # if enabled |
| 15 | # demo admin admin |
| 16 | # demo demo Member,sysadmin,netadmin |
| 17 | # invisible_to_admin demo Member |
| 18 | # |
| 19 | # Variables set before calling this script: |
| 20 | # SERVICE_TOKEN - aka admin_token in keystone.conf |
| 21 | # SERVICE_ENDPOINT - local Keystone admin endpoint |
| 22 | # SERVICE_TENANT_NAME - name of tenant containing service accounts |
| 23 | # ENABLED_SERVICES - stack.sh's list of services to start |
| 24 | # DEVSTACK_DIR - Top-level DevStack directory |
| 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 | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 33 | echo `$@ | awk '/ id / { print $4 }'` |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 36 | # Tenants |
| 37 | ADMIN_TENANT=$(get_id keystone tenant-create --name=admin) |
| 38 | SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME) |
| 39 | DEMO_TENANT=$(get_id keystone tenant-create --name=demo) |
| 40 | INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin) |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 41 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 42 | |
| 43 | # Users |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 44 | ADMIN_USER=$(get_id keystone user-create --name=admin \ |
| 45 | --pass="$ADMIN_PASSWORD" \ |
| 46 | --email=admin@example.com) |
| 47 | DEMO_USER=$(get_id keystone user-create --name=demo \ |
| 48 | --pass="$ADMIN_PASSWORD" \ |
| 49 | --email=demo@example.com) |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 50 | |
| 51 | # Roles |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 52 | ADMIN_ROLE=$(get_id keystone role-create --name=admin) |
| 53 | KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin) |
| 54 | KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin) |
| 55 | SYSADMIN_ROLE=$(get_id keystone role-create --name=sysadmin) |
| 56 | NETADMIN_ROLE=$(get_id keystone role-create --name=netadmin) |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 57 | |
| 58 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 59 | # Add Roles to Users in Tenants |
| 60 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 61 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT |
| 62 | keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT |
| 63 | keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 64 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 65 | # TODO(termie): these two might be dubious |
| 66 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 67 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 68 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 69 | |
| 70 | # The Member role is used by Horizon and Swift so we need to keep it: |
| 71 | MEMBER_ROLE=$(get_id keystone role-create --name=Member) |
| 72 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT |
| 73 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT |
| 74 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 75 | |
Anthony Young | 8bdc263 | 2011-09-22 08:00:44 +0000 | [diff] [blame] | 76 | # Services |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 77 | keystone service-create --name=keystone \ |
| 78 | --type=identity \ |
| 79 | --description="Keystone Identity Service" |
| 80 | |
| 81 | keystone service-create --name=nova \ |
| 82 | --type=compute \ |
| 83 | --description="Nova Compute Service" |
| 84 | NOVA_USER=$(get_id keystone user-create --name=nova \ |
| 85 | --pass="$SERVICE_PASSWORD" \ |
| 86 | --tenant_id $SERVICE_TENANT \ |
| 87 | --email=nova@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 88 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 89 | --user $NOVA_USER \ |
| 90 | --role $ADMIN_ROLE |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 91 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 92 | keystone service-create --name=ec2 \ |
| 93 | --type=ec2 \ |
| 94 | --description="EC2 Compatibility Layer" |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 95 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 96 | keystone service-create --name=glance \ |
| 97 | --type=image \ |
| 98 | --description="Glance Image Service" |
| 99 | GLANCE_USER=$(get_id keystone user-create --name=glance \ |
| 100 | --pass="$SERVICE_PASSWORD" \ |
| 101 | --tenant_id $SERVICE_TENANT \ |
| 102 | --email=glance@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 103 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 104 | --user $GLANCE_USER \ |
| 105 | --role $ADMIN_ROLE |
Vishvananda Ishaya | 5f9473e | 2012-02-24 01:57:07 +0000 | [diff] [blame] | 106 | |
| 107 | if [[ "$ENABLED_SERVICES" =~ "n-vol" ]]; then |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 108 | keystone service-create --name="nova-volume" \ |
| 109 | --type=volume \ |
| 110 | --description="Nova Volume Service" |
Vishvananda Ishaya | 5f9473e | 2012-02-24 01:57:07 +0000 | [diff] [blame] | 111 | fi |
| 112 | |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 113 | if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 114 | keystone service-create --name=swift \ |
| 115 | --type="object-store" \ |
| 116 | --description="Swift Service" |
| 117 | SWIFT_USER=$(get_id keystone user-create --name=swift \ |
| 118 | --pass="$SERVICE_PASSWORD" \ |
| 119 | --tenant_id $SERVICE_TENANT \ |
| 120 | --email=swift@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 121 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 122 | --user $SWIFT_USER \ |
| 123 | --role $ADMIN_ROLE |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 124 | fi |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 125 | |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 126 | if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 127 | keystone service-create --name=quantum \ |
| 128 | --type=network \ |
| 129 | --description="Quantum Service" |
| 130 | QUANTUM_USER=$(get_id keystone user-create --name=quantum \ |
| 131 | --pass="$SERVICE_PASSWORD" \ |
| 132 | --tenant_id $SERVICE_TENANT \ |
| 133 | --email=quantum@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 134 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 135 | --user $QUANTUM_USER \ |
| 136 | --role $ADMIN_ROLE |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 137 | fi |
Anthony Young | 8bdc263 | 2011-09-22 08:00:44 +0000 | [diff] [blame] | 138 | |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 139 | # create ec2 creds and parse the secret and access key returned |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 140 | RESULT=$(keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER) |
| 141 | ADMIN_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }') |
| 142 | ADMIN_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }') |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 143 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 144 | RESULT=$(keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER) |
| 145 | DEMO_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }') |
| 146 | DEMO_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }') |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 147 | |
| 148 | # write the secret and access to ec2rc |
| 149 | cat > $DEVSTACK_DIR/ec2rc <<EOF |
| 150 | ADMIN_ACCESS=$ADMIN_ACCESS |
| 151 | ADMIN_SECRET=$ADMIN_SECRET |
| 152 | DEMO_ACCESS=$DEMO_ACCESS |
| 153 | DEMO_SECRET=$DEMO_SECRET |
| 154 | EOF |