blob: ac15cbd00ad76fd9b52ad0eef165df856ff5f32d [file] [log] [blame]
Dean Troyerd81a0272012-08-31 18:04:55 -05001# lib/keystone
2# Functions to control the configuration and operation of **Keystone**
3
4# Dependencies:
5# ``functions`` file
6# ``BASE_SQL_CONN``
7# ``SERVICE_HOST``
8# ``SERVICE_TOKEN``
9# ``S3_SERVICE_PORT`` (template backend only)
10
11
12# ``stack.sh`` calls the entry points in this order:
13#
14# install_keystone
15# configure_keystone
16# init_keystone
17# start_keystone
18# stop_keystone
19# cleanup_keystone
20
Dean Troyer7903b792012-09-13 17:16:12 -050021# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
Dean Troyerd81a0272012-08-31 18:04:55 -050024
25
26# Defaults
27# --------
28
29# <define global variables here that belong to this project>
30
31# Set up default directories
32KEYSTONE_DIR=$DEST/keystone
33KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
34KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
35
36KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
37
38# Select the backend for Keystopne's service catalog
Dean Troyerb80379c2012-09-10 18:30:37 -050039KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
Dean Troyerd81a0272012-08-31 18:04:55 -050040KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
41
42# Set Keystone interface configuration
43KEYSTONE_API_PORT=${KEYSTONE_API_PORT:-5000}
44KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
45KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
46KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-http}
47KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
48KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
49KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-http}
Doug Hellmann4de55e92012-10-26 12:24:28 -040050KEYSTONE_TOKEN_FORMAT=${KEYSTONE_TOKEN_FORMAT:-PKI}
Dean Troyerd81a0272012-08-31 18:04:55 -050051
52
53# Entry Points
54# ------------
55
56# cleanup_keystone() - Remove residual data files, anything left over from previous
57# runs that a clean run would need to clean up
58function cleanup_keystone() {
59 # kill instances (nova)
60 # delete image files (glance)
61 # This function intentionally left blank
62 :
63}
64
65# configure_keystoneclient() - Set config files, create data dirs, etc
66function configure_keystoneclient() {
67 setup_develop $KEYSTONECLIENT_DIR
68}
69
70# configure_keystone() - Set config files, create data dirs, etc
71function configure_keystone() {
72 setup_develop $KEYSTONE_DIR
73
74 if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
75 sudo mkdir -p $KEYSTONE_CONF_DIR
76 sudo chown `whoami` $KEYSTONE_CONF_DIR
77 fi
78
79 if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
80 cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
81 cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
82 fi
83
84 # Rewrite stock ``keystone.conf``
Terry Wilson428af5a2012-11-01 16:12:39 -040085 local dburl
86 database_connection_url dburl keystone
Dean Troyerd81a0272012-08-31 18:04:55 -050087 iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
Doug Hellmann4de55e92012-10-26 12:24:28 -040088 iniset $KEYSTONE_CONF signing token_format "$KEYSTONE_TOKEN_FORMAT"
Terry Wilson428af5a2012-11-01 16:12:39 -040089 iniset $KEYSTONE_CONF sql connection $dburl
Dean Troyerd81a0272012-08-31 18:04:55 -050090 iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
91 sed -e "
92 /^pipeline.*ec2_extension crud_/s|ec2_extension crud_extension|ec2_extension s3_extension crud_extension|;
93 " -i $KEYSTONE_CONF
94
95 # Append the S3 bits
96 iniset $KEYSTONE_CONF filter:s3_extension paste.filter_factory "keystone.contrib.s3:S3Extension.factory"
97
98 if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
99 # Configure ``keystone.conf`` to use sql
100 iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
101 inicomment $KEYSTONE_CONF catalog template_file
102 else
103 cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
104
105 # Add swift endpoints to service catalog if swift is enabled
106 if is_service_enabled swift; then
107 echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
108 echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
109 echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
110 echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
111 fi
112
113 # Add quantum endpoints to service catalog if quantum is enabled
114 if is_service_enabled quantum; then
115 echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
116 echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
117 echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
118 echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
119 fi
120
121 sudo sed -e "
122 s,%SERVICE_HOST%,$SERVICE_HOST,g;
123 s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
124 " -i $KEYSTONE_CATALOG
125
126 # Configure ``keystone.conf`` to use templates
127 iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
128 iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
129 fi
130
131 # Set up logging
132 LOGGING_ROOT="devel"
133 if [ "$SYSLOG" != "False" ]; then
134 LOGGING_ROOT="$LOGGING_ROOT,production"
135 fi
136 KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
137 cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
138 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
139 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
140
141}
142
143# init_keystone() - Initialize databases, etc.
144function init_keystone() {
145 # (Re)create keystone database
Terry Wilson428af5a2012-11-01 16:12:39 -0400146 recreate_database keystone utf8
Dean Troyerd81a0272012-08-31 18:04:55 -0500147
148 # Initialize keystone database
149 $KEYSTONE_DIR/bin/keystone-manage db_sync
150
151 # Set up certificates
152 $KEYSTONE_DIR/bin/keystone-manage pki_setup
153}
154
155# install_keystoneclient() - Collect source and prepare
156function install_keystoneclient() {
157 git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
158}
159
160# install_keystone() - Collect source and prepare
161function install_keystone() {
162 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
163}
164
165# start_keystone() - Start running processes, including screen
166function start_keystone() {
167 # Start Keystone in a screen window
168 screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
169}
170
171# stop_keystone() - Stop running processes
172function stop_keystone() {
173 # Kill the Keystone screen window
174 screen -S $SCREEN_NAME -p key -X kill
175}
Dean Troyer7903b792012-09-13 17:16:12 -0500176
177# Restore xtrace
178$XTRACE