blob: 3666776317971d8d22a6d3a94e19c9a3a8c3b103 [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 Hardy2a688442015-12-08 13:26:29 +000059HEAT_SERVICE_USER=${HEAT_SERVICE_USER:-heat}
60HEAT_TRUSTEE_USER=${HEAT_TRUSTEE_USER:-$HEAT_SERVICE_USER}
61HEAT_TRUSTEE_PASSWORD=${HEAT_TRUSTEE_PASSWORD:-$SERVICE_PASSWORD}
62HEAT_TRUSTEE_DOMAIN=${HEAT_TRUSTEE_DOMAIN:-default}
Steven Hardy3163c172015-01-23 13:26:29 +000063
Sirushti Murugesan9e68af72015-06-16 23:25:17 +053064# Support entry points installation of console scripts
65HEAT_BIN_DIR=$(get_python_exec_prefix)
Dean Troyercc6b4432013-04-08 15:38:03 -050066
Steven Hardyf83cf932014-03-12 16:54:01 +000067# other default options
Steve Baker744c2af2014-12-16 12:00:40 +130068if [[ "$HEAT_STANDALONE" = "True" ]]; then
69 # for standalone, use defaults which require no service user
Ian Wienande82bac02015-08-25 14:29:08 +100070 HEAT_STACK_DOMAIN=$(trueorfalse False HEAT_STACK_DOMAIN)
Steve Baker744c2af2014-12-16 12:00:40 +130071 HEAT_DEFERRED_AUTH=${HEAT_DEFERRED_AUTH:-password}
Joe D'Andrea779d8672015-11-30 15:35:13 +000072 if [[ ${HEAT_DEFERRED_AUTH} != "password" ]]; then
73 # Heat does not support keystone trusts when deployed in
74 # standalone mode
75 die $LINENO \
76 'HEAT_DEFERRED_AUTH can only be set to "password" when HEAT_STANDALONE is True.'
77 fi
Steve Baker744c2af2014-12-16 12:00:40 +130078else
Ian Wienande82bac02015-08-25 14:29:08 +100079 HEAT_STACK_DOMAIN=$(trueorfalse True HEAT_STACK_DOMAIN)
Steven Hardy2a688442015-12-08 13:26:29 +000080 HEAT_DEFERRED_AUTH=${HEAT_DEFERRED_AUTH:-}
Steve Baker744c2af2014-12-16 12:00:40 +130081fi
Nicolas Simonds347dbac2015-01-21 13:40:42 -080082HEAT_PLUGIN_DIR=${HEAT_PLUGIN_DIR:-$DATA_DIR/heat/plugins}
83ENABLE_HEAT_PLUGINS=${ENABLE_HEAT_PLUGINS:-}
Steven Hardyf83cf932014-03-12 16:54:01 +000084
Dean Troyercc6b4432013-04-08 15:38:03 -050085# Functions
86# ---------
Steve Bakerbfdad752012-08-18 09:00:42 +120087
Sean Dague29870cc2014-03-14 14:32:01 -040088# Test if any Heat services are enabled
89# is_heat_enabled
90function is_heat_enabled {
91 [[ ,${ENABLED_SERVICES} =~ ,"h-" ]] && return 0
92 return 1
93}
94
Steve Bakerbfdad752012-08-18 09:00:42 +120095# cleanup_heat() - Remove residual data files, anything left over from previous
96# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110097function cleanup_heat {
Steve Bakerc3249082013-04-09 13:41:47 +120098 sudo rm -rf $HEAT_AUTH_CACHE_DIR
Angus Salkeldf645a852013-08-26 10:13:36 +100099 sudo rm -rf $HEAT_ENV_DIR
Angus Salkeldfb71a272013-08-26 10:15:38 +1000100 sudo rm -rf $HEAT_TEMPLATES_DIR
Steve Baker744c2af2014-12-16 12:00:40 +1300101 sudo rm -rf $HEAT_CONF_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +1200102}
103
104# configure_heat() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100105function configure_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200106
Dean Troyer8421c2b2015-03-16 13:52:19 -0500107 sudo install -d -o $STACK_USER $HEAT_CONF_DIR
Angus Salkelda213e2c2013-08-30 10:48:46 +1000108 # remove old config files
109 rm -f $HEAT_CONF_DIR/heat-*.conf
Steve Bakerbfdad752012-08-18 09:00:42 +1200110
Steve Bakere61bc612014-01-27 15:21:29 +1300111 HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +1000112 HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000}
Steve Bakerbfdad752012-08-18 09:00:42 +1200113 HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST}
114 HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001}
Steve Bakere61bc612014-01-27 15:21:29 +1300115 HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +1000116 HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003}
Steve Bakerd5cd79b2013-04-13 11:14:41 -0700117 HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini
118 HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json
119
120 cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE
121 cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE
Steve Bakerbfdad752012-08-18 09:00:42 +1200122
Angus Salkelda213e2c2013-08-30 10:48:46 +1000123 # common options
Brant Knudson2dd110c2015-03-14 12:39:14 -0500124 iniset_rpc_backend heat $HEAT_CONF
Angus Salkelda213e2c2013-08-30 10:48:46 +1000125 iniset $HEAT_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
126 iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
127 iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
Angus Salkelde2314382013-11-14 14:36:46 +1100128 iniset $HEAT_CONF database connection `database_connection_url heat`
Attila Fazekasf71b5002014-05-28 09:52:22 +0200129 iniset $HEAT_CONF DEFAULT auth_encryption_key $(generate_hex_string 16)
Steve Bakerbfdad752012-08-18 09:00:42 +1200130
Bartosz Górski0abde392014-02-28 14:15:19 +0100131 iniset $HEAT_CONF DEFAULT region_name_for_services "$REGION_NAME"
132
Angus Salkelda213e2c2013-08-30 10:48:46 +1000133 # logging
134 iniset $HEAT_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
135 iniset $HEAT_CONF DEFAULT use_syslog $SYSLOG
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400136 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$HEAT_USE_MOD_WSGI" == "False" ] ; then
Steve Baker556ffe42013-08-06 16:42:38 +1200137 # Add color to logging output
Arata Notsu4897ff52013-10-09 18:49:32 +0900138 setup_colorized_logging $HEAT_CONF DEFAULT tenant user
Steve Baker556ffe42013-08-06 16:42:38 +1200139 fi
140
Steven Hardy2a688442015-12-08 13:26:29 +0000141 if [ ! -z "$HEAT_DEFERRED_AUTH" ]; then
142 iniset $HEAT_CONF DEFAULT deferred_auth_method $HEAT_DEFERRED_AUTH
143 fi
Angus Salkeld93b906d2015-03-26 12:53:51 +1000144
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400145 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
146 _config_heat_apache_wsgi
147 fi
148
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
Steven Hardy2a688442015-12-08 13:26:29 +0000154 iniset $HEAT_CONF keystone_authtoken admin_user $HEAT_SERVICE_USER
Steve Baker744c2af2014-12-16 12:00:40 +1300155 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
Steven Hardy2a688442015-12-08 13:26:29 +0000161 # If HEAT_DEFERRED_AUTH is unset or explicitly set to trusts, configure
162 # the section for the client plugin associated with the trustee
163 if [ -z "$HEAT_DEFERRED_AUTH" -o "trusts" == "$HEAT_DEFERRED_AUTH" ]; then
164 iniset $HEAT_CONF trustee auth_plugin password
165 iniset $HEAT_CONF trustee auth_url $KEYSTONE_AUTH_URI
166 iniset $HEAT_CONF trustee username $HEAT_TRUSTEE_USER
167 iniset $HEAT_CONF trustee password $HEAT_TRUSTEE_PASSWORD
168 iniset $HEAT_CONF trustee user_domain_id $HEAT_TRUSTEE_DOMAIN
169 fi
170
171 # clients_keystone
172 iniset $HEAT_CONF clients_keystone auth_uri $KEYSTONE_AUTH_URI
173
Angus Salkelda213e2c2013-08-30 10:48:46 +1000174 # ec2authtoken
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000175 iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_URI/v2.0
Angus Salkelda213e2c2013-08-30 10:48:46 +1000176
Angus Salkelda213e2c2013-08-30 10:48:46 +1000177 # OpenStack API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000178 iniset $HEAT_CONF heat_api bind_port $HEAT_API_PORT
Davanum Srinivas905275e2015-01-24 19:21:34 -0500179 iniset $HEAT_CONF heat_api workers "$API_WORKERS"
Angus Salkelda213e2c2013-08-30 10:48:46 +1000180
181 # Cloudformation API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000182 iniset $HEAT_CONF heat_api_cfn bind_port $HEAT_API_CFN_PORT
183
184 # Cloudwatch API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000185 iniset $HEAT_CONF heat_api_cloudwatch bind_port $HEAT_API_CW_PORT
Angus Salkelde2790212012-09-11 11:24:09 +1000186
Rob Crittenden18d47782014-03-19 17:47:42 -0400187 if is_ssl_enabled_service "key" || is_service_enabled tls-proxy; then
188 iniset $HEAT_CONF clients_keystone ca_file $SSL_BUNDLE_FILE
189 fi
190
191 if is_ssl_enabled_service "nova" || is_service_enabled tls-proxy; then
192 iniset $HEAT_CONF clients_nova ca_file $SSL_BUNDLE_FILE
193 fi
194
195 if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
196 iniset $HEAT_CONF clients_cinder ca_file $SSL_BUNDLE_FILE
197 fi
198
Angus Salkeld826e4502015-01-07 17:52:05 +1000199 if [[ "$HEAT_ENABLE_ADOPT_ABANDON" = "True" ]]; then
200 iniset $HEAT_CONF DEFAULT enable_stack_adopt true
201 iniset $HEAT_CONF DEFAULT enable_stack_abandon true
202 fi
203
Dean Troyer8421c2b2015-03-16 13:52:19 -0500204 sudo install -d -o $STACK_USER $HEAT_ENV_DIR $HEAT_TEMPLATES_DIR
205
Angus Salkeldf645a852013-08-26 10:13:36 +1000206 # copy the default environment
207 cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/
208
Angus Salkeldfb71a272013-08-26 10:15:38 +1000209 # copy the default templates
210 cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/
211
Nicolas Simonds347dbac2015-01-21 13:40:42 -0800212 # Enable heat plugins.
213 # NOTE(nic): The symlink nonsense is necessary because when
214 # plugins are installed in "developer mode", the final component
215 # of their target directory is always "resources", which confuses
216 # Heat's plugin loader into believing that all plugins are named
217 # "resources", and therefore are all the same plugin; so it
218 # will only load one of them. Linking them all to a common
219 # location with unique names avoids that type of collision,
220 # while still allowing the plugins to be edited in-tree.
221 local err_count=0
222
223 if [ -n "$ENABLE_HEAT_PLUGINS" ]; then
224 mkdir -p $HEAT_PLUGIN_DIR
225 # Clean up cruft from any previous runs
226 rm -f $HEAT_PLUGIN_DIR/*
227 iniset $HEAT_CONF DEFAULT plugin_dirs $HEAT_PLUGIN_DIR
228 fi
229
230 for heat_plugin in $ENABLE_HEAT_PLUGINS; do
231 if [ -d $HEAT_DIR/contrib/$heat_plugin ]; then
232 setup_package $HEAT_DIR/contrib/$heat_plugin -e
233 ln -s $HEAT_DIR/contrib/$heat_plugin/$heat_plugin/resources $HEAT_PLUGIN_DIR/$heat_plugin
234 else
235 : # clear retval on the test so that we can roll up errors
236 err $LINENO "Requested Heat plugin(${heat_plugin}) not found."
237 err_count=$(($err_count + 1))
238 fi
239 done
240 [ $err_count -eq 0 ] || die $LINENO "$err_count of the requested Heat plugins could not be installed."
Steve Bakerbfdad752012-08-18 09:00:42 +1200241}
242
243# init_heat() - Initialize database
Ian Wienandaee18c72014-02-21 15:35:08 +1100244function init_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200245
246 # (re)create heat database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200247 recreate_database heat
Steve Bakerbfdad752012-08-18 09:00:42 +1200248
Sirushti Murugesan9e68af72015-06-16 23:25:17 +0530249 $HEAT_BIN_DIR/heat-manage db_sync
Steve Bakerc3249082013-04-09 13:41:47 +1200250 create_heat_cache_dir
251}
252
253# create_heat_cache_dir() - Part of the init_heat() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100254function create_heat_cache_dir {
Steve Bakerc3249082013-04-09 13:41:47 +1200255 # Create cache dirs
Dean Troyer8421c2b2015-03-16 13:52:19 -0500256 sudo install -d -o $STACK_USER $HEAT_AUTH_CACHE_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +1200257}
258
Steve Baker32761a42012-11-05 09:57:57 +1300259# install_heatclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100260function install_heatclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500261 if use_library_from_git "python-heatclient"; then
262 git_clone_by_name "python-heatclient"
263 setup_dev_lib "python-heatclient"
264 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 +0100265 fi
Steve Baker32761a42012-11-05 09:57:57 +1300266}
267
Steve Bakerbfdad752012-08-18 09:00:42 +1200268# install_heat() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100269function install_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200270 git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH
Sergey Krayneva38bc5b2014-12-16 04:25:11 -0500271 setup_develop $HEAT_DIR
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400272 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
273 install_apache_wsgi
274 fi
Steve Bakerbfdad752012-08-18 09:00:42 +1200275}
276
Steve Baker315971d2014-05-27 12:24:18 +1200277# install_heat_other() - Collect source and prepare
278function install_heat_other {
279 git_clone $HEAT_CFNTOOLS_REPO $HEAT_CFNTOOLS_DIR $HEAT_CFNTOOLS_BRANCH
280 git_clone $HEAT_TEMPLATES_REPO $HEAT_TEMPLATES_REPO_DIR $HEAT_TEMPLATES_BRANCH
Steve Baker16819952015-03-18 13:45:40 +1300281 git_clone $OAC_REPO $OAC_DIR $OAC_BRANCH
282 git_clone $OCC_REPO $OCC_DIR $OCC_BRANCH
283 git_clone $ORC_REPO $ORC_DIR $ORC_BRANCH
284 git_clone $DIB_UTILS_REPO $DIB_UTILS_DIR $DIB_UTILS_BRANCH
Steve Baker315971d2014-05-27 12:24:18 +1200285}
286
Steve Bakerbfdad752012-08-18 09:00:42 +1200287# start_heat() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100288function start_heat {
Sirushti Murugesan9e68af72015-06-16 23:25:17 +0530289 run_process h-eng "$HEAT_BIN_DIR/heat-engine --config-file=$HEAT_CONF"
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400290
291 # If the site is not enabled then we are in a grenade scenario
Ian Wienand5cdee8d2015-10-19 14:17:18 +1100292 local enabled_site_file
293 enabled_site_file=$(apache_site_config_for heat-api)
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400294 if [ -f ${enabled_site_file} ] && [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
295 enable_apache_site heat-api
296 enable_apache_site heat-api-cfn
297 enable_apache_site heat-api-cloudwatch
298 restart_apache_server
299 tail_log heat-api /var/log/$APACHE_NAME/heat-api.log
300 tail_log heat-api-cfn /var/log/$APACHE_NAME/heat-api-cfn.log
301 tail_log heat-api-cloudwatch /var/log/$APACHE_NAME/heat-api-cloudwatch.log
302 else
303 run_process h-api "$HEAT_BIN_DIR/heat-api --config-file=$HEAT_CONF"
304 run_process h-api-cfn "$HEAT_BIN_DIR/heat-api-cfn --config-file=$HEAT_CONF"
305 run_process h-api-cw "$HEAT_BIN_DIR/heat-api-cloudwatch --config-file=$HEAT_CONF"
306 fi
Steve Bakerbfdad752012-08-18 09:00:42 +1200307}
308
Dean Troyer699a29f2012-09-10 14:10:27 -0500309# stop_heat() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100310function stop_heat {
Kieran Spear70338292013-05-28 11:31:31 +1000311 # Kill the screen windows
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400312 stop_process h-eng
313
314 if [ "$HEAT_USE_MOD_WSGI" == "True" ]; then
315 disable_apache_site heat-api
316 disable_apache_site heat-api-cfn
317 disable_apache_site heat-api-cloudwatch
318 restart_apache_server
319 else
320 local serv
321 for serv in h-api h-api-cfn h-api-cw; do
322 stop_process $serv
323 done
324 fi
325
Steve Bakerbfdad752012-08-18 09:00:42 +1200326}
Dean Troyer7903b792012-09-13 17:16:12 -0500327
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400328# _cleanup_heat_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
329function _cleanup_heat_apache_wsgi {
330 sudo rm -f $(apache_site_config_for heat-api)
331 sudo rm -f $(apache_site_config_for heat-api-cfn)
332 sudo rm -f $(apache_site_config_for heat-api-cloudwatch)
333}
334
335# _config_heat_apache_wsgi() - Set WSGI config files of Heat
336function _config_heat_apache_wsgi {
337
Ian Wienand5cdee8d2015-10-19 14:17:18 +1100338 local heat_apache_conf
339 heat_apache_conf=$(apache_site_config_for heat-api)
340 local heat_cfn_apache_conf
341 heat_cfn_apache_conf=$(apache_site_config_for heat-api-cfn)
342 local heat_cloudwatch_apache_conf
343 heat_cloudwatch_apache_conf=$(apache_site_config_for heat-api-cloudwatch)
Oleksii Chuprykova6928102015-06-11 08:56:58 -0400344 local heat_ssl=""
345 local heat_certfile=""
346 local heat_keyfile=""
347 local heat_api_port=$HEAT_API_PORT
348 local heat_cfn_api_port=$HEAT_API_CFN_PORT
349 local heat_cw_api_port=$HEAT_API_CW_PORT
350 local venv_path=""
351
352 sudo cp $FILES/apache-heat-api.template $heat_apache_conf
353 sudo sed -e "
354 s|%PUBLICPORT%|$heat_api_port|g;
355 s|%APACHE_NAME%|$APACHE_NAME|g;
356 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
357 s|%SSLENGINE%|$heat_ssl|g;
358 s|%SSLCERTFILE%|$heat_certfile|g;
359 s|%SSLKEYFILE%|$heat_keyfile|g;
360 s|%USER%|$STACK_USER|g;
361 s|%VIRTUALENV%|$venv_path|g
362 " -i $heat_apache_conf
363
364 sudo cp $FILES/apache-heat-api-cfn.template $heat_cfn_apache_conf
365 sudo sed -e "
366 s|%PUBLICPORT%|$heat_cfn_api_port|g;
367 s|%APACHE_NAME%|$APACHE_NAME|g;
368 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
369 s|%SSLENGINE%|$heat_ssl|g;
370 s|%SSLCERTFILE%|$heat_certfile|g;
371 s|%SSLKEYFILE%|$heat_keyfile|g;
372 s|%USER%|$STACK_USER|g;
373 s|%VIRTUALENV%|$venv_path|g
374 " -i $heat_cfn_apache_conf
375
376 sudo cp $FILES/apache-heat-api-cloudwatch.template $heat_cloudwatch_apache_conf
377 sudo sed -e "
378 s|%PUBLICPORT%|$heat_cw_api_port|g;
379 s|%APACHE_NAME%|$APACHE_NAME|g;
380 s|%HEAT_BIN_DIR%|$HEAT_BIN_DIR|g;
381 s|%SSLENGINE%|$heat_ssl|g;
382 s|%SSLCERTFILE%|$heat_certfile|g;
383 s|%SSLKEYFILE%|$heat_keyfile|g;
384 s|%USER%|$STACK_USER|g;
385 s|%VIRTUALENV%|$venv_path|g
386 " -i $heat_cloudwatch_apache_conf
387}
388
389
Steven Hardy33d1f862014-02-13 15:00:33 +0000390# create_heat_accounts() - Set up common required heat accounts
Ian Wienandaee18c72014-02-21 15:35:08 +1100391function create_heat_accounts {
Steve Baker744c2af2014-12-16 12:00:40 +1300392 if [[ "$HEAT_STANDALONE" != "True" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100393
Steve Baker744c2af2014-12-16 12:00:40 +1300394 create_service_user "heat" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100395
Steve Baker744c2af2014-12-16 12:00:40 +1300396 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100397
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000398 get_or_create_service "heat" "orchestration" "Heat Orchestration Service"
399 get_or_create_endpoint "orchestration" \
Steve Baker744c2af2014-12-16 12:00:40 +1300400 "$REGION_NAME" \
401 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
402 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
403 "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
404
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000405 get_or_create_service "heat-cfn" "cloudformation" "Heat CloudFormation Service"
406 get_or_create_endpoint "cloudformation" \
Steve Baker744c2af2014-12-16 12:00:40 +1300407 "$REGION_NAME" \
408 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
409 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
410 "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1"
411 fi
412
413 # heat_stack_user role is for users created by Heat
414 get_or_create_role "heat_stack_user"
Steven Hardy57d478d2014-02-28 16:37:43 +0000415 fi
416
Steve Baker16aca8a2014-03-11 14:01:57 +1300417 if [[ "$HEAT_STACK_DOMAIN" == "True" ]]; then
418 # Note we have to pass token/endpoint here because the current endpoint and
419 # version negotiation in OSC means just --os-identity-api-version=3 won't work
Steve Martinellib74e01c2014-12-18 01:35:35 -0500420 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100421 --os-identity-api-version=3 domain list | grep ' heat ' | get_field 1)
422
423 if [[ -z "$D_ID" ]]; then
Steve Martinellib74e01c2014-12-18 01:35:35 -0500424 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100425 --os-identity-api-version=3 domain create heat \
426 --description "Owns users and projects created by heat" \
427 | grep ' id ' | get_field 2)
Sirushti Murugesan2f92c8d2014-10-09 14:35:38 +0530428 iniset $HEAT_CONF DEFAULT stack_user_domain_id ${D_ID}
Bartosz Górski0abde392014-02-28 14:15:19 +0100429
Steve Martinellib74e01c2014-12-18 01:35:35 -0500430 openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100431 --os-identity-api-version=3 user create --password $SERVICE_PASSWORD \
432 --domain $D_ID heat_domain_admin \
433 --description "Manages users and projects created by heat"
Steve Martinellib74e01c2014-12-18 01:35:35 -0500434 openstack --os-token $OS_TOKEN --os-url=$KEYSTONE_SERVICE_URI_V3 \
Bartosz Górski0abde392014-02-28 14:15:19 +0100435 --os-identity-api-version=3 role add \
436 --user heat_domain_admin --domain ${D_ID} admin
437 iniset $HEAT_CONF DEFAULT stack_domain_admin heat_domain_admin
438 iniset $HEAT_CONF DEFAULT stack_domain_admin_password $SERVICE_PASSWORD
439 fi
Steve Baker16aca8a2014-03-11 14:01:57 +1300440 fi
Steven Hardy33d1f862014-02-13 15:00:33 +0000441}
442
Steve Baker249e36d2015-03-05 14:01:45 +1300443# build_heat_pip_mirror() - Build a pip mirror containing heat agent projects
444function build_heat_pip_mirror {
Steve Baker16819952015-03-18 13:45:40 +1300445 local project_dirs="$OCC_DIR $OAC_DIR $ORC_DIR $HEAT_CFNTOOLS_DIR $DIB_UTILS_DIR"
Steve Baker249e36d2015-03-05 14:01:45 +1300446 local projpath proj package
Steve Baker2a6009c2014-05-05 16:13:39 +1200447
Steve Baker249e36d2015-03-05 14:01:45 +1300448 rm -rf $HEAT_PIP_REPO
449 mkdir -p $HEAT_PIP_REPO
Steve Baker2a6009c2014-05-05 16:13:39 +1200450
Steve Baker249e36d2015-03-05 14:01:45 +1300451 echo "<html><body>" > $HEAT_PIP_REPO/index.html
452 for projpath in $project_dirs; do
453 proj=$(basename $projpath)
454 mkdir -p $HEAT_PIP_REPO/$proj
455 pushd $projpath
456 rm -rf dist
457 python setup.py sdist
458 pushd dist
459 package=$(ls *)
460 mv $package $HEAT_PIP_REPO/$proj/$package
461 popd
462
463 echo "<html><body><a href=\"$package\">$package</a></body></html>" > $HEAT_PIP_REPO/$proj/index.html
464 echo "<a href=\"$proj\">$proj</a><br/>" >> $HEAT_PIP_REPO/index.html
465
466 popd
467 done
468
469 echo "</body></html>" >> $HEAT_PIP_REPO/index.html
470
Ian Wienandada886d2015-10-07 14:06:26 +1100471 local heat_pip_repo_apache_conf
472 heat_pip_repo_apache_conf=$(apache_site_config_for heat_pip_repo)
Steve Baker249e36d2015-03-05 14:01:45 +1300473
474 sudo cp $FILES/apache-heat-pip-repo.template $heat_pip_repo_apache_conf
475 sudo sed -e "
476 s|%HEAT_PIP_REPO%|$HEAT_PIP_REPO|g;
477 s|%HEAT_PIP_REPO_PORT%|$HEAT_PIP_REPO_PORT|g;
478 s|%APACHE_NAME%|$APACHE_NAME|g;
479 " -i $heat_pip_repo_apache_conf
480 enable_apache_site heat_pip_repo
481 restart_apache_server
Steve Baker11cf7b62015-03-27 09:08:53 +1300482 sudo iptables -I INPUT -d $HOST_IP -p tcp --dport $HEAT_PIP_REPO_PORT -j ACCEPT || true
Steve Baker2a6009c2014-05-05 16:13:39 +1200483}
484
Dean Troyer7903b792012-09-13 17:16:12 -0500485# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100486$_XTRACE_HEAT
Sean Dague584d90e2013-03-29 14:34:53 -0400487
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100488# Tell emacs to use shell-script-mode
489## Local variables:
490## mode: shell-script
491## End: