blob: fdcf5bcaadcd553a854f28f54e8567db7c10ab05 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Mate Lakat45ea0812013-09-25 10:00:29 +01003# lib/heat
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Install and start **Heat** service
5
Steve Bakerbfdad752012-08-18 09:00:42 +12006# To enable, add the following to localrc
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
Steve Bakerbfdad752012-08-18 09:00:42 +12009
10# Dependencies:
Steve Baker249e36d2015-03-05 14:01:45 +130011# (none)
Steve Bakerbfdad752012-08-18 09:00:42 +120012
13# stack.sh
14# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_heatclient
16# - install_heat
17# - configure_heatclient
18# - configure_heat
Oleksii Chuprykova6928102015-06-11 08:56:58 -040019# - _config_heat_apache_wsgi
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010020# - init_heat
21# - start_heat
22# - stop_heat
23# - cleanup_heat
Steve Bakerbfdad752012-08-18 09:00:42 +120024
Dean Troyer7903b792012-09-13 17:16:12 -050025# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110026_XTRACE_HEAT=$(set +o | grep xtrace)
Dean Troyer7903b792012-09-13 17:16:12 -050027set +o xtrace
Steve Bakerbfdad752012-08-18 09:00:42 +120028
29
30# Defaults
31# --------
Dean Troyercc6b4432013-04-08 15:38:03 -050032
33# set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050034GITDIR["python-heatclient"]=$DEST/python-heatclient
Sean Dague5cb19062014-11-01 01:37:45 +010035
Oleksii Chuprykova6928102015-06-11 08:56:58 -040036# Toggle for deploying Heat-API under HTTPD + mod_wsgi
37HEAT_USE_MOD_WSGI=${HEAT_USE_MOD_WSGI:-False}
38
Steve Bakerbfdad752012-08-18 09:00:42 +120039HEAT_DIR=$DEST/heat
Steve Baker315971d2014-05-27 12:24:18 +120040HEAT_CFNTOOLS_DIR=$DEST/heat-cfntools
41HEAT_TEMPLATES_REPO_DIR=$DEST/heat-templates
Steve Baker249e36d2015-03-05 14:01:45 +130042OCC_DIR=$DEST/os-collect-config
Steve Baker16819952015-03-18 13:45:40 +130043DIB_UTILS_DIR=$DEST/dib-utils
Steve Baker249e36d2015-03-05 14:01:45 +130044ORC_DIR=$DEST/os-refresh-config
45OAC_DIR=$DEST/os-apply-config
46
47HEAT_PIP_REPO=$DATA_DIR/heat-pip-repo
48HEAT_PIP_REPO_PORT=${HEAT_PIP_REPO_PORT:-8899}
49
Steve Bakerc3249082013-04-09 13:41:47 +120050HEAT_AUTH_CACHE_DIR=${HEAT_AUTH_CACHE_DIR:-/var/cache/heat}
Sean Dague53753292014-12-04 19:38:15 -050051HEAT_STANDALONE=$(trueorfalse False HEAT_STANDALONE)
52HEAT_ENABLE_ADOPT_ABANDON=$(trueorfalse False HEAT_ENABLE_ADOPT_ABANDON)
Angus Salkeldf645a852013-08-26 10:13:36 +100053HEAT_CONF_DIR=/etc/heat
Angus Salkelda213e2c2013-08-30 10:48:46 +100054HEAT_CONF=$HEAT_CONF_DIR/heat.conf
Angus Salkeldf645a852013-08-26 10:13:36 +100055HEAT_ENV_DIR=$HEAT_CONF_DIR/environment.d
Angus Salkeldfb71a272013-08-26 10:15:38 +100056HEAT_TEMPLATES_DIR=$HEAT_CONF_DIR/templates
Steve Bakere389aed2014-09-23 17:10:39 +120057HEAT_API_HOST=${HEAT_API_HOST:-$HOST_IP}
58HEAT_API_PORT=${HEAT_API_PORT:-8004}
Steven Hardy3163c172015-01-23 13:26:29 +000059
Sirushti Murugesan9e68af72015-06-16 23:25:17 +053060# Support entry points installation of console scripts
61HEAT_BIN_DIR=$(get_python_exec_prefix)
Dean Troyercc6b4432013-04-08 15:38:03 -050062
Steven Hardyf83cf932014-03-12 16:54:01 +000063# other default options
Steve Baker744c2af2014-12-16 12:00:40 +130064if [[ "$HEAT_STANDALONE" = "True" ]]; then
65 # for standalone, use defaults which require no service user
Ian Wienande82bac02015-08-25 14:29:08 +100066 HEAT_STACK_DOMAIN=$(trueorfalse False HEAT_STACK_DOMAIN)
Steve Baker744c2af2014-12-16 12:00:40 +130067 HEAT_DEFERRED_AUTH=${HEAT_DEFERRED_AUTH:-password}
Joe D'Andrea779d8672015-11-30 15:35:13 +000068 if [[ ${HEAT_DEFERRED_AUTH} != "password" ]]; then
69 # Heat does not support keystone trusts when deployed in
70 # standalone mode
71 die $LINENO \
72 'HEAT_DEFERRED_AUTH can only be set to "password" when HEAT_STANDALONE is True.'
73 fi
Steve Baker744c2af2014-12-16 12:00:40 +130074else
Ian Wienande82bac02015-08-25 14:29:08 +100075 HEAT_STACK_DOMAIN=$(trueorfalse True HEAT_STACK_DOMAIN)
Steve Baker744c2af2014-12-16 12:00:40 +130076 HEAT_DEFERRED_AUTH=${HEAT_DEFERRED_AUTH:-trusts}
77fi
Nicolas Simonds347dbac2015-01-21 13:40:42 -080078HEAT_PLUGIN_DIR=${HEAT_PLUGIN_DIR:-$DATA_DIR/heat/plugins}
79ENABLE_HEAT_PLUGINS=${ENABLE_HEAT_PLUGINS:-}
Steven Hardyf83cf932014-03-12 16:54:01 +000080
Dean Troyercc6b4432013-04-08 15:38:03 -050081# Functions
82# ---------
Steve Bakerbfdad752012-08-18 09:00:42 +120083
Sean Dague29870cc2014-03-14 14:32:01 -040084# Test if any Heat services are enabled
85# is_heat_enabled
86function is_heat_enabled {
87 [[ ,${ENABLED_SERVICES} =~ ,"h-" ]] && return 0
88 return 1
89}
90
Steve Bakerbfdad752012-08-18 09:00:42 +120091# cleanup_heat() - Remove residual data files, anything left over from previous
92# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110093function cleanup_heat {
Steve Bakerc3249082013-04-09 13:41:47 +120094 sudo rm -rf $HEAT_AUTH_CACHE_DIR
Angus Salkeldf645a852013-08-26 10:13:36 +100095 sudo rm -rf $HEAT_ENV_DIR
Angus Salkeldfb71a272013-08-26 10:15:38 +100096 sudo rm -rf $HEAT_TEMPLATES_DIR
Steve Baker744c2af2014-12-16 12:00:40 +130097 sudo rm -rf $HEAT_CONF_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +120098}
99
100# configure_heat() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100101function configure_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200102
Dean Troyer8421c2b2015-03-16 13:52:19 -0500103 sudo install -d -o $STACK_USER $HEAT_CONF_DIR
Angus Salkelda213e2c2013-08-30 10:48:46 +1000104 # remove old config files
105 rm -f $HEAT_CONF_DIR/heat-*.conf
Steve Bakerbfdad752012-08-18 09:00:42 +1200106
Steve Bakere61bc612014-01-27 15:21:29 +1300107 HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +1000108 HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000}
Steve Bakerbfdad752012-08-18 09:00:42 +1200109 HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST}
110 HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001}
Steve Bakere61bc612014-01-27 15:21:29 +1300111 HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +1000112 HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003}
Steve Bakerd5cd79b2013-04-13 11:14:41 -0700113 HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini
114 HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json
115
116 cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE
117 cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE
Steve Bakerbfdad752012-08-18 09:00:42 +1200118
Angus Salkelda213e2c2013-08-30 10:48:46 +1000119 # common options
Brant Knudson2dd110c2015-03-14 12:39:14 -0500120 iniset_rpc_backend heat $HEAT_CONF
Angus Salkelda213e2c2013-08-30 10:48:46 +1000121 iniset $HEAT_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
122 iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
123 iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
Angus Salkelde2314382013-11-14 14:36:46 +1100124 iniset $HEAT_CONF database connection `database_connection_url heat`
Attila Fazekasf71b5002014-05-28 09:52:22 +0200125 iniset $HEAT_CONF DEFAULT auth_encryption_key $(generate_hex_string 16)
Steve Bakerbfdad752012-08-18 09:00:42 +1200126
Bartosz Górski0abde392014-02-28 14:15:19 +0100127 iniset $HEAT_CONF DEFAULT region_name_for_services "$REGION_NAME"
128
Angus Salkelda213e2c2013-08-30 10:48:46 +1000129 # logging
130 iniset $HEAT_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
131 iniset $HEAT_CONF DEFAULT use_syslog $SYSLOG
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400132 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$HEAT_USE_MOD_WSGI" == "False" ] ; then
Steve Baker556ffe42013-08-06 16:42:38 +1200133 # Add color to logging output
Arata Notsu4897ff52013-10-09 18:49:32 +0900134 setup_colorized_logging $HEAT_CONF DEFAULT tenant user
Steve Baker556ffe42013-08-06 16:42:38 +1200135 fi
136
Angus Salkeld93b906d2015-03-26 12:53:51 +1000137 iniset $HEAT_CONF DEFAULT deferred_auth_method $HEAT_DEFERRED_AUTH
138
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400139 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
140 _config_heat_apache_wsgi
141 fi
142
Jamie Lennox78b77262014-12-19 12:56:01 +1000143 # NOTE(jamielennox): heat re-uses specific values from the
144 # keystone_authtoken middleware group and so currently fails when using the
145 # auth plugin setup. This should be fixed in heat. Heat is also the only
146 # service that requires the auth_uri to include a /v2.0. Remove this custom
147 # setup when bug #1300246 is resolved.
Jamie Lennox78b77262014-12-19 12:56:01 +1000148 iniset $HEAT_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_URI/v2.0
Steve Baker744c2af2014-12-16 12:00:40 +1300149 if [[ "$HEAT_STANDALONE" = "True" ]]; then
150 iniset $HEAT_CONF paste_deploy flavor standalone
151 iniset $HEAT_CONF clients_heat url "http://$HEAT_API_HOST:$HEAT_API_PORT/v1/%(tenant_id)s"
152 else
153 iniset $HEAT_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
154 iniset $HEAT_CONF keystone_authtoken admin_user heat
155 iniset $HEAT_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
156 iniset $HEAT_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
157 iniset $HEAT_CONF keystone_authtoken cafile $SSL_BUNDLE_FILE
158 iniset $HEAT_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR
159 fi
Angus Salkelde2790212012-09-11 11:24:09 +1000160
Angus Salkelda213e2c2013-08-30 10:48:46 +1000161 # ec2authtoken
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000162 iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_URI/v2.0
Angus Salkelda213e2c2013-08-30 10:48:46 +1000163
Angus Salkelda213e2c2013-08-30 10:48:46 +1000164 # OpenStack API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000165 iniset $HEAT_CONF heat_api bind_port $HEAT_API_PORT
Davanum Srinivas905275e2015-01-24 19:21:34 -0500166 iniset $HEAT_CONF heat_api workers "$API_WORKERS"
Angus Salkelda213e2c2013-08-30 10:48:46 +1000167
168 # Cloudformation API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000169 iniset $HEAT_CONF heat_api_cfn bind_port $HEAT_API_CFN_PORT
170
171 # Cloudwatch API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000172 iniset $HEAT_CONF heat_api_cloudwatch bind_port $HEAT_API_CW_PORT
Angus Salkelde2790212012-09-11 11:24:09 +1000173
Rob Crittenden18d47782014-03-19 17:47:42 -0400174 if is_ssl_enabled_service "key" || is_service_enabled tls-proxy; then
175 iniset $HEAT_CONF clients_keystone ca_file $SSL_BUNDLE_FILE
176 fi
177
178 if is_ssl_enabled_service "nova" || is_service_enabled tls-proxy; then
179 iniset $HEAT_CONF clients_nova ca_file $SSL_BUNDLE_FILE
180 fi
181
182 if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
183 iniset $HEAT_CONF clients_cinder ca_file $SSL_BUNDLE_FILE
184 fi
185
Angus Salkeld826e4502015-01-07 17:52:05 +1000186 if [[ "$HEAT_ENABLE_ADOPT_ABANDON" = "True" ]]; then
187 iniset $HEAT_CONF DEFAULT enable_stack_adopt true
188 iniset $HEAT_CONF DEFAULT enable_stack_abandon true
189 fi
190
Dean Troyer8421c2b2015-03-16 13:52:19 -0500191 sudo install -d -o $STACK_USER $HEAT_ENV_DIR $HEAT_TEMPLATES_DIR
192
Angus Salkeldf645a852013-08-26 10:13:36 +1000193 # copy the default environment
194 cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/
195
Angus Salkeldfb71a272013-08-26 10:15:38 +1000196 # copy the default templates
197 cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/
198
Nicolas Simonds347dbac2015-01-21 13:40:42 -0800199 # Enable heat plugins.
200 # NOTE(nic): The symlink nonsense is necessary because when
201 # plugins are installed in "developer mode", the final component
202 # of their target directory is always "resources", which confuses
203 # Heat's plugin loader into believing that all plugins are named
204 # "resources", and therefore are all the same plugin; so it
205 # will only load one of them. Linking them all to a common
206 # location with unique names avoids that type of collision,
207 # while still allowing the plugins to be edited in-tree.
208 local err_count=0
209
210 if [ -n "$ENABLE_HEAT_PLUGINS" ]; then
211 mkdir -p $HEAT_PLUGIN_DIR
212 # Clean up cruft from any previous runs
213 rm -f $HEAT_PLUGIN_DIR/*
214 iniset $HEAT_CONF DEFAULT plugin_dirs $HEAT_PLUGIN_DIR
215 fi
216
217 for heat_plugin in $ENABLE_HEAT_PLUGINS; do
218 if [ -d $HEAT_DIR/contrib/$heat_plugin ]; then
219 setup_package $HEAT_DIR/contrib/$heat_plugin -e
220 ln -s $HEAT_DIR/contrib/$heat_plugin/$heat_plugin/resources $HEAT_PLUGIN_DIR/$heat_plugin
221 else
222 : # clear retval on the test so that we can roll up errors
223 err $LINENO "Requested Heat plugin(${heat_plugin}) not found."
224 err_count=$(($err_count + 1))
225 fi
226 done
227 [ $err_count -eq 0 ] || die $LINENO "$err_count of the requested Heat plugins could not be installed."
Steve Bakerbfdad752012-08-18 09:00:42 +1200228}
229
230# init_heat() - Initialize database
Ian Wienandaee18c72014-02-21 15:35:08 +1100231function init_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200232
233 # (re)create heat database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200234 recreate_database heat
Steve Bakerbfdad752012-08-18 09:00:42 +1200235
Sirushti Murugesan9e68af72015-06-16 23:25:17 +0530236 $HEAT_BIN_DIR/heat-manage db_sync
Steve Bakerc3249082013-04-09 13:41:47 +1200237 create_heat_cache_dir
238}
239
240# create_heat_cache_dir() - Part of the init_heat() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100241function create_heat_cache_dir {
Steve Bakerc3249082013-04-09 13:41:47 +1200242 # Create cache dirs
Dean Troyer8421c2b2015-03-16 13:52:19 -0500243 sudo install -d -o $STACK_USER $HEAT_AUTH_CACHE_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +1200244}
245
Steve Baker32761a42012-11-05 09:57:57 +1300246# install_heatclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100247function install_heatclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500248 if use_library_from_git "python-heatclient"; then
249 git_clone_by_name "python-heatclient"
250 setup_dev_lib "python-heatclient"
251 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-heatclient"]}/tools/,/etc/bash_completion.d/}heat.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100252 fi
Steve Baker32761a42012-11-05 09:57:57 +1300253}
254
Steve Bakerbfdad752012-08-18 09:00:42 +1200255# install_heat() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100256function install_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200257 git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH
Sergey Krayneva38bc5b2014-12-16 04:25:11 -0500258 setup_develop $HEAT_DIR
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400259 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
260 install_apache_wsgi
261 fi
Steve Bakerbfdad752012-08-18 09:00:42 +1200262}
263
Steve Baker315971d2014-05-27 12:24:18 +1200264# install_heat_other() - Collect source and prepare
265function install_heat_other {
266 git_clone $HEAT_CFNTOOLS_REPO $HEAT_CFNTOOLS_DIR $HEAT_CFNTOOLS_BRANCH
267 git_clone $HEAT_TEMPLATES_REPO $HEAT_TEMPLATES_REPO_DIR $HEAT_TEMPLATES_BRANCH
Steve Baker16819952015-03-18 13:45:40 +1300268 git_clone $OAC_REPO $OAC_DIR $OAC_BRANCH
269 git_clone $OCC_REPO $OCC_DIR $OCC_BRANCH
270 git_clone $ORC_REPO $ORC_DIR $ORC_BRANCH
271 git_clone $DIB_UTILS_REPO $DIB_UTILS_DIR $DIB_UTILS_BRANCH
Steve Baker315971d2014-05-27 12:24:18 +1200272}
273
Steve Bakerbfdad752012-08-18 09:00:42 +1200274# start_heat() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100275function start_heat {
Sirushti Murugesan9e68af72015-06-16 23:25:17 +0530276 run_process h-eng "$HEAT_BIN_DIR/heat-engine --config-file=$HEAT_CONF"
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400277
278 # If the site is not enabled then we are in a grenade scenario
Ian Wienand5cdee8d2015-10-19 14:17:18 +1100279 local enabled_site_file
280 enabled_site_file=$(apache_site_config_for heat-api)
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400281 if [ -f ${enabled_site_file} ] && [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
282 enable_apache_site heat-api
283 enable_apache_site heat-api-cfn
284 enable_apache_site heat-api-cloudwatch
285 restart_apache_server
286 tail_log heat-api /var/log/$APACHE_NAME/heat-api.log
287 tail_log heat-api-cfn /var/log/$APACHE_NAME/heat-api-cfn.log
288 tail_log heat-api-cloudwatch /var/log/$APACHE_NAME/heat-api-cloudwatch.log
289 else
290 run_process h-api "$HEAT_BIN_DIR/heat-api --config-file=$HEAT_CONF"
291 run_process h-api-cfn "$HEAT_BIN_DIR/heat-api-cfn --config-file=$HEAT_CONF"
292 run_process h-api-cw "$HEAT_BIN_DIR/heat-api-cloudwatch --config-file=$HEAT_CONF"
293 fi
Steve Bakerbfdad752012-08-18 09:00:42 +1200294}
295
Dean Troyer699a29f2012-09-10 14:10:27 -0500296# stop_heat() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100297function stop_heat {
Kieran Spear70338292013-05-28 11:31:31 +1000298 # Kill the screen windows
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400299 stop_process h-eng
300
301 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
302 disable_apache_site heat-api
303 disable_apache_site heat-api-cfn
304 disable_apache_site heat-api-cloudwatch
305 restart_apache_server
306 else
307 local serv
308 for serv in h-api h-api-cfn h-api-cw; do
309 stop_process $serv
310 done
311 fi
312
Steve Bakerbfdad752012-08-18 09:00:42 +1200313}
Dean Troyer7903b792012-09-13 17:16:12 -0500314
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400315# _cleanup_heat_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
316function _cleanup_heat_apache_wsgi {
317 sudo rm -f $(apache_site_config_for heat-api)
318 sudo rm -f $(apache_site_config_for heat-api-cfn)
319 sudo rm -f $(apache_site_config_for heat-api-cloudwatch)
320}
321
322# _config_heat_apache_wsgi() - Set WSGI config files of Heat
323function _config_heat_apache_wsgi {
324
Ian Wienand5cdee8d2015-10-19 14:17:18 +1100325 local heat_apache_conf
326 heat_apache_conf=$(apache_site_config_for heat-api)
327 local heat_cfn_apache_conf
328 heat_cfn_apache_conf=$(apache_site_config_for heat-api-cfn)
329 local heat_cloudwatch_apache_conf
330 heat_cloudwatch_apache_conf=$(apache_site_config_for heat-api-cloudwatch)
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400331 local heat_ssl=""
332 local heat_certfile=""
333 local heat_keyfile=""
334 local heat_api_port=$HEAT_API_PORT
335 local heat_cfn_api_port=$HEAT_API_CFN_PORT
336 local heat_cw_api_port=$HEAT_API_CW_PORT
337 local venv_path=""
338
339 sudo cp $FILES/apache-heat-api.template $heat_apache_conf
340 sudo sed -e "
341 s|%PUBLICPORT%|$heat_api_port|g;
342 s|%APACHE_NAME%|$APACHE_NAME|g;
343 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
344 s|%SSLENGINE%|$heat_ssl|g;
345 s|%SSLCERTFILE%|$heat_certfile|g;
346 s|%SSLKEYFILE%|$heat_keyfile|g;
347 s|%USER%|$STACK_USER|g;
348 s|%VIRTUALENV%|$venv_path|g
349 " -i $heat_apache_conf
350
351 sudo cp $FILES/apache-heat-api-cfn.template $heat_cfn_apache_conf
352 sudo sed -e "
353 s|%PUBLICPORT%|$heat_cfn_api_port|g;
354 s|%APACHE_NAME%|$APACHE_NAME|g;
355 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
356 s|%SSLENGINE%|$heat_ssl|g;
357 s|%SSLCERTFILE%|$heat_certfile|g;
358 s|%SSLKEYFILE%|$heat_keyfile|g;
359 s|%USER%|$STACK_USER|g;
360 s|%VIRTUALENV%|$venv_path|g
361 " -i $heat_cfn_apache_conf
362
363 sudo cp $FILES/apache-heat-api-cloudwatch.template $heat_cloudwatch_apache_conf
364 sudo sed -e "
365 s|%PUBLICPORT%|$heat_cw_api_port|g;
366 s|%APACHE_NAME%|$APACHE_NAME|g;
367 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
368 s|%SSLENGINE%|$heat_ssl|g;
369 s|%SSLCERTFILE%|$heat_certfile|g;
370 s|%SSLKEYFILE%|$heat_keyfile|g;
371 s|%USER%|$STACK_USER|g;
372 s|%VIRTUALENV%|$venv_path|g
373 " -i $heat_cloudwatch_apache_conf
374}
375
376
Steven Hardy33d1f862014-02-13 15:00:33 +0000377# create_heat_accounts() - Set up common required heat accounts
Ian Wienandaee18c72014-02-21 15:35:08 +1100378function create_heat_accounts {
Steve Baker744c2af2014-12-16 12:00:40 +1300379 if [[ "$HEAT_STANDALONE" != "True" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100380
Steve Baker744c2af2014-12-16 12:00:40 +1300381 create_service_user "heat" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100382
Steve Baker744c2af2014-12-16 12:00:40 +1300383 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100384
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000385 get_or_create_service "heat" "orchestration" "Heat Orchestration Service"
386 get_or_create_endpoint "orchestration" \
Steve Baker744c2af2014-12-16 12:00:40 +1300387 "$REGION_NAME" \
388 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
389 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
390 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
391
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000392 get_or_create_service "heat-cfn" "cloudformation" "Heat CloudFormation Service"
393 get_or_create_endpoint "cloudformation" \
Steve Baker744c2af2014-12-16 12:00:40 +1300394 "$REGION_NAME" \
395 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
396 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
397 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1"
398 fi
399
400 # heat_stack_user role is for users created by Heat
401 get_or_create_role "heat_stack_user"
Steven Hardy57d478d2014-02-28 16:37:43 +0000402 fi
403
Steve Baker16aca8a2014-03-11 14:01:57 +1300404 if [[ "$HEAT_STACK_DOMAIN" == "True" ]]; then
405 # Note we have to pass token/endpoint here because the current endpoint and
406 # version negotiation in OSC means just --os-identity-api-version=3 won't work
Steve Martinellib74e01c2014-12-18 01:35:35 -0500407 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100408 --os-identity-api-version=3 domain list | grep ' heat ' | get_field 1)
409
410 if [[ -z "$D_ID" ]]; then
Steve Martinellib74e01c2014-12-18 01:35:35 -0500411 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100412 --os-identity-api-version=3 domain create heat \
413 --description "Owns users and projects created by heat" \
414 | grep ' id ' | get_field 2)
Sirushti Murugesan2f92c8d2014-10-09 14:35:38 +0530415 iniset $HEAT_CONF DEFAULT stack_user_domain_id ${D_ID}
Bartosz Górski0abde392014-02-28 14:15:19 +0100416
Steve Martinellib74e01c2014-12-18 01:35:35 -0500417 openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100418 --os-identity-api-version=3 user create --password $SERVICE_PASSWORD \
419 --domain $D_ID heat_domain_admin \
420 --description "Manages users and projects created by heat"
Steve Martinellib74e01c2014-12-18 01:35:35 -0500421 openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100422 --os-identity-api-version=3 role add \
423 --user heat_domain_admin --domain ${D_ID} admin
424 iniset $HEAT_CONF DEFAULT stack_domain_admin heat_domain_admin
425 iniset $HEAT_CONF DEFAULT stack_domain_admin_password $SERVICE_PASSWORD
426 fi
Steve Baker16aca8a2014-03-11 14:01:57 +1300427 fi
Steven Hardy33d1f862014-02-13 15:00:33 +0000428}
429
Steve Baker249e36d2015-03-05 14:01:45 +1300430# build_heat_pip_mirror() - Build a pip mirror containing heat agent projects
431function build_heat_pip_mirror {
Steve Baker16819952015-03-18 13:45:40 +1300432 local project_dirs="$OCC_DIR $OAC_DIR $ORC_DIR $HEAT_CFNTOOLS_DIR $DIB_UTILS_DIR"
Steve Baker249e36d2015-03-05 14:01:45 +1300433 local projpath proj package
Steve Baker2a6009c2014-05-05 16:13:39 +1200434
Steve Baker249e36d2015-03-05 14:01:45 +1300435 rm -rf $HEAT_PIP_REPO
436 mkdir -p $HEAT_PIP_REPO
Steve Baker2a6009c2014-05-05 16:13:39 +1200437
Steve Baker249e36d2015-03-05 14:01:45 +1300438 echo "<html><body>" > $HEAT_PIP_REPO/index.html
439 for projpath in $project_dirs; do
440 proj=$(basename $projpath)
441 mkdir -p $HEAT_PIP_REPO/$proj
442 pushd $projpath
443 rm -rf dist
444 python setup.py sdist
445 pushd dist
446 package=$(ls *)
447 mv $package $HEAT_PIP_REPO/$proj/$package
448 popd
449
450 echo "<html><body><a href=\"$package\">$package</a></body></html>" > $HEAT_PIP_REPO/$proj/index.html
451 echo "<a href=\"$proj\">$proj</a><br/>" >> $HEAT_PIP_REPO/index.html
452
453 popd
454 done
455
456 echo "</body></html>" >> $HEAT_PIP_REPO/index.html
457
Ian Wienandada886d2015-10-07 14:06:26 +1100458 local heat_pip_repo_apache_conf
459 heat_pip_repo_apache_conf=$(apache_site_config_for heat_pip_repo)
Steve Baker249e36d2015-03-05 14:01:45 +1300460
461 sudo cp $FILES/apache-heat-pip-repo.template $heat_pip_repo_apache_conf
462 sudo sed -e "
463 s|%HEAT_PIP_REPO%|$HEAT_PIP_REPO|g;
464 s|%HEAT_PIP_REPO_PORT%|$HEAT_PIP_REPO_PORT|g;
465 s|%APACHE_NAME%|$APACHE_NAME|g;
466 " -i $heat_pip_repo_apache_conf
467 enable_apache_site heat_pip_repo
468 restart_apache_server
Steve Baker11cf7b62015-03-27 09:08:53 +1300469 sudo iptables -I INPUT -d $HOST_IP -p tcp --dport $HEAT_PIP_REPO_PORT -j ACCEPT || true
Steve Baker2a6009c2014-05-05 16:13:39 +1200470}
471
Dean Troyer7903b792012-09-13 17:16:12 -0500472# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100473$_XTRACE_HEAT
Sean Dague584d90e2013-03-29 14:34:53 -0400474
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100475# Tell emacs to use shell-script-mode
476## Local variables:
477## mode: shell-script
478## End: