blob: 8b6fd7fc4b1ac91d9e68f95c337401b580f34f45 [file] [log] [blame]
Steve Bakerbfdad752012-08-18 09:00:42 +12001# lib/heat
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Heat** service
3
Steve Bakerbfdad752012-08-18 09:00:42 +12004# To enable, add the following to localrc
Kieran Spear70338292013-05-28 11:31:31 +10005# ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
Steve Bakerbfdad752012-08-18 09:00:42 +12006
7# Dependencies:
8# - functions
9
10# stack.sh
11# ---------
Dean Troyer6d04fd72012-12-21 11:03:37 -060012# install_heatclient
13# install_heat
14# configure_heatclient
15# configure_heat
16# init_heat
17# start_heat
18# stop_heat
19# cleanup_heat
Steve Bakerbfdad752012-08-18 09:00:42 +120020
Dean Troyer7903b792012-09-13 17:16:12 -050021# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
Steve Bakerbfdad752012-08-18 09:00:42 +120024
25
26# Defaults
27# --------
Dean Troyercc6b4432013-04-08 15:38:03 -050028
29# set up default directories
Steve Bakerbfdad752012-08-18 09:00:42 +120030HEAT_DIR=$DEST/heat
Steve Baker32761a42012-11-05 09:57:57 +130031HEATCLIENT_DIR=$DEST/python-heatclient
Steve Bakerc3249082013-04-09 13:41:47 +120032HEAT_AUTH_CACHE_DIR=${HEAT_AUTH_CACHE_DIR:-/var/cache/heat}
Steve Baker389b3a02013-08-01 10:44:09 +120033HEAT_STANDALONE=`trueorfalse False $HEAT_STANDALONE`
Angus Salkeldf645a852013-08-26 10:13:36 +100034HEAT_CONF_DIR=/etc/heat
35HEAT_ENV_DIR=$HEAT_CONF_DIR/environment.d
Angus Salkeldfb71a272013-08-26 10:15:38 +100036HEAT_TEMPLATES_DIR=$HEAT_CONF_DIR/templates
Dean Troyercc6b4432013-04-08 15:38:03 -050037
38# Functions
39# ---------
Steve Bakerbfdad752012-08-18 09:00:42 +120040
41# cleanup_heat() - Remove residual data files, anything left over from previous
42# runs that a clean run would need to clean up
43function cleanup_heat() {
Steve Bakerc3249082013-04-09 13:41:47 +120044 sudo rm -rf $HEAT_AUTH_CACHE_DIR
Angus Salkeldf645a852013-08-26 10:13:36 +100045 sudo rm -rf $HEAT_ENV_DIR
Angus Salkeldfb71a272013-08-26 10:15:38 +100046 sudo rm -rf $HEAT_TEMPLATES_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +120047}
48
49# configure_heat() - Set config files, create data dirs, etc
50function configure_heat() {
51 setup_develop $HEAT_DIR
52
Steve Bakerbfdad752012-08-18 09:00:42 +120053 if [[ ! -d $HEAT_CONF_DIR ]]; then
54 sudo mkdir -p $HEAT_CONF_DIR
55 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010056 sudo chown $STACK_USER $HEAT_CONF_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +120057
Angus Salkelde2790212012-09-11 11:24:09 +100058 HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$SERVICE_HOST}
59 HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000}
Steve Bakerbfdad752012-08-18 09:00:42 +120060 HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST}
61 HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001}
Angus Salkelde2790212012-09-11 11:24:09 +100062 HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$SERVICE_HOST}
63 HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003}
Steve Bakerbb421be2012-10-10 13:19:10 +130064 HEAT_API_HOST=${HEAT_API_HOST:-$SERVICE_HOST}
65 HEAT_API_PORT=${HEAT_API_PORT:-8004}
Steve Bakerd5cd79b2013-04-13 11:14:41 -070066 HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini
67 HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json
68
69 cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE
70 cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE
Steve Bakerbfdad752012-08-18 09:00:42 +120071
Dean Troyer6d04fd72012-12-21 11:03:37 -060072 # Cloudformation API
Angus Salkelde2790212012-09-11 11:24:09 +100073 HEAT_API_CFN_CONF=$HEAT_CONF_DIR/heat-api-cfn.conf
74 cp $HEAT_DIR/etc/heat/heat-api-cfn.conf $HEAT_API_CFN_CONF
Ben Nemec03997942013-08-10 09:56:16 -050075 iniset $HEAT_API_CFN_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Angus Salkelde2790212012-09-11 11:24:09 +100076 inicomment $HEAT_API_CFN_CONF DEFAULT log_file
77 iniset $HEAT_API_CFN_CONF DEFAULT use_syslog $SYSLOG
78 iniset $HEAT_API_CFN_CONF DEFAULT bind_host $HEAT_API_CFN_HOST
79 iniset $HEAT_API_CFN_CONF DEFAULT bind_port $HEAT_API_CFN_PORT
Steve Bakerc3249082013-04-09 13:41:47 +120080 iniset $HEAT_API_CFN_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
81 iniset $HEAT_API_CFN_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
82 iniset $HEAT_API_CFN_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
83 iniset $HEAT_API_CFN_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
84 iniset $HEAT_API_CFN_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
85 iniset $HEAT_API_CFN_CONF keystone_authtoken admin_user heat
86 iniset $HEAT_API_CFN_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
87 iniset $HEAT_API_CFN_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR/api-cfn
Steve Bakerfd1ebe72013-04-13 09:49:14 +100088 iniset $HEAT_API_CFN_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
89 iniset $HEAT_API_CFN_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
Steve Baker389b3a02013-08-01 10:44:09 +120090 [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_API_CFN_CONF paste_deploy flavor standalone
Steve Bakerbfdad752012-08-18 09:00:42 +120091
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090092 iniset_rpc_backend heat $HEAT_API_CFN_CONF DEFAULT
Steve Bakerbfdad752012-08-18 09:00:42 +120093
Dean Troyer6d04fd72012-12-21 11:03:37 -060094 # OpenStack API
Steve Bakerbb421be2012-10-10 13:19:10 +130095 HEAT_API_CONF=$HEAT_CONF_DIR/heat-api.conf
96 cp $HEAT_DIR/etc/heat/heat-api.conf $HEAT_API_CONF
Ben Nemec03997942013-08-10 09:56:16 -050097 iniset $HEAT_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Steve Bakerbb421be2012-10-10 13:19:10 +130098 inicomment $HEAT_API_CONF DEFAULT log_file
99 iniset $HEAT_API_CONF DEFAULT use_syslog $SYSLOG
100 iniset $HEAT_API_CONF DEFAULT bind_host $HEAT_API_HOST
101 iniset $HEAT_API_CONF DEFAULT bind_port $HEAT_API_PORT
Steve Bakerc3249082013-04-09 13:41:47 +1200102 iniset $HEAT_API_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
103 iniset $HEAT_API_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
104 iniset $HEAT_API_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
105 iniset $HEAT_API_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
106 iniset $HEAT_API_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
107 iniset $HEAT_API_CONF keystone_authtoken admin_user heat
108 iniset $HEAT_API_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
109 iniset $HEAT_API_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR/api
Steve Bakerfd1ebe72013-04-13 09:49:14 +1000110 iniset $HEAT_API_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
111 iniset $HEAT_API_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
Steve Baker389b3a02013-08-01 10:44:09 +1200112 [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_API_CONF paste_deploy flavor standalone
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900113 iniset_rpc_backend heat $HEAT_API_CONF DEFAULT
Steve Bakerbb421be2012-10-10 13:19:10 +1300114
Steve Bakerbb421be2012-10-10 13:19:10 +1300115
Angus Salkelde2790212012-09-11 11:24:09 +1000116 # engine
Steve Bakerbfdad752012-08-18 09:00:42 +1200117 HEAT_ENGINE_CONF=$HEAT_CONF_DIR/heat-engine.conf
Angus Salkelde2790212012-09-11 11:24:09 +1000118 cp $HEAT_DIR/etc/heat/heat-engine.conf $HEAT_ENGINE_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500119 iniset $HEAT_ENGINE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Steve Bakerbfdad752012-08-18 09:00:42 +1200120 inicomment $HEAT_ENGINE_CONF DEFAULT log_file
121 iniset $HEAT_ENGINE_CONF DEFAULT use_syslog $SYSLOG
122 iniset $HEAT_ENGINE_CONF DEFAULT bind_host $HEAT_ENGINE_HOST
123 iniset $HEAT_ENGINE_CONF DEFAULT bind_port $HEAT_ENGINE_PORT
Steve Bakerb592b292012-11-21 14:20:12 +1300124 iniset $HEAT_ENGINE_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
Steve Baker9ec34212012-12-11 14:18:02 +1300125 iniset $HEAT_ENGINE_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
Steve Bakerb592b292012-11-21 14:20:12 +1300126 iniset $HEAT_ENGINE_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
Attila Fazekas7e79d912013-03-03 12:23:04 +0100127 iniset $HEAT_ENGINE_CONF DEFAULT sql_connection `database_connection_url heat`
Steve Bakerbfdad752012-08-18 09:00:42 +1200128 iniset $HEAT_ENGINE_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
129
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900130 iniset_rpc_backend heat $HEAT_ENGINE_CONF DEFAULT
Steve Bakerbfdad752012-08-18 09:00:42 +1200131
Steve Baker556ffe42013-08-06 16:42:38 +1200132 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
133 # Add color to logging output
134 iniset $HEAT_ENGINE_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s%(color)s] %(instance)s%(color)s%(message)s"
135 iniset $HEAT_ENGINE_CONF DEFAULT logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
136 iniset $HEAT_ENGINE_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
137 iniset $HEAT_ENGINE_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s"
138 fi
139
Dean Troyer6d04fd72012-12-21 11:03:37 -0600140 # Cloudwatch API
Angus Salkelde2790212012-09-11 11:24:09 +1000141 HEAT_API_CW_CONF=$HEAT_CONF_DIR/heat-api-cloudwatch.conf
142 cp $HEAT_DIR/etc/heat/heat-api-cloudwatch.conf $HEAT_API_CW_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500143 iniset $HEAT_API_CW_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Angus Salkelde2790212012-09-11 11:24:09 +1000144 inicomment $HEAT_API_CW_CONF DEFAULT log_file
145 iniset $HEAT_API_CW_CONF DEFAULT use_syslog $SYSLOG
146 iniset $HEAT_API_CW_CONF DEFAULT bind_host $HEAT_API_CW_HOST
147 iniset $HEAT_API_CW_CONF DEFAULT bind_port $HEAT_API_CW_PORT
Steve Bakerc3249082013-04-09 13:41:47 +1200148 iniset $HEAT_API_CW_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
149 iniset $HEAT_API_CW_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
150 iniset $HEAT_API_CW_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
151 iniset $HEAT_API_CW_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
152 iniset $HEAT_API_CW_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
153 iniset $HEAT_API_CW_CONF keystone_authtoken admin_user heat
154 iniset $HEAT_API_CW_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
155 iniset $HEAT_API_CW_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR/api-cloudwatch
Steve Bakerfd1ebe72013-04-13 09:49:14 +1000156 iniset $HEAT_API_CW_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
157 iniset $HEAT_API_CW_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
Steve Baker389b3a02013-08-01 10:44:09 +1200158 [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_API_CW_CONF paste_deploy flavor standalone
Angus Salkelde2790212012-09-11 11:24:09 +1000159
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900160 iniset_rpc_backend heat $HEAT_API_CW_CONF DEFAULT
Angus Salkelde2790212012-09-11 11:24:09 +1000161
Angus Salkeldf645a852013-08-26 10:13:36 +1000162 # heat environment
163 sudo mkdir -p $HEAT_ENV_DIR
164 sudo chown $STACK_USER $HEAT_ENV_DIR
165 # copy the default environment
166 cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/
167
Angus Salkeldfb71a272013-08-26 10:15:38 +1000168 # heat template resources.
169 sudo mkdir -p $HEAT_TEMPLATES_DIR
170 sudo chown $STACK_USER $HEAT_TEMPLATES_DIR
171 # copy the default templates
172 cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/
173
Steve Bakerbfdad752012-08-18 09:00:42 +1200174}
175
176# init_heat() - Initialize database
177function init_heat() {
178
179 # (re)create heat database
Terry Wilson428af5a2012-11-01 16:12:39 -0400180 recreate_database heat utf8
Steve Bakerbfdad752012-08-18 09:00:42 +1200181
Steve Bakere3111322013-06-19 13:57:31 +1200182 $HEAT_DIR/bin/heat-manage db_sync
Steve Bakerc3249082013-04-09 13:41:47 +1200183 create_heat_cache_dir
184}
185
186# create_heat_cache_dir() - Part of the init_heat() process
187function create_heat_cache_dir() {
188 # Create cache dirs
189 sudo mkdir -p $HEAT_AUTH_CACHE_DIR/api
190 sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR/api
191 sudo mkdir -p $HEAT_AUTH_CACHE_DIR/api-cfn
192 sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR/api-cfn
193 sudo mkdir -p $HEAT_AUTH_CACHE_DIR/api-cloudwatch
194 sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR/api-cloudwatch
Steve Bakerbfdad752012-08-18 09:00:42 +1200195}
196
Steve Baker32761a42012-11-05 09:57:57 +1300197# install_heatclient() - Collect source and prepare
198function install_heatclient() {
199 git_clone $HEATCLIENT_REPO $HEATCLIENT_DIR $HEATCLIENT_BRANCH
Sean Dagued644e232013-07-25 15:34:48 -0400200 setup_develop $HEATCLIENT_DIR
Steve Baker32761a42012-11-05 09:57:57 +1300201}
202
Steve Bakerbfdad752012-08-18 09:00:42 +1200203# install_heat() - Collect source and prepare
204function install_heat() {
205 git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH
206}
207
208# start_heat() - Start running processes, including screen
209function start_heat() {
210 screen_it h-eng "cd $HEAT_DIR; bin/heat-engine --config-file=$HEAT_CONF_DIR/heat-engine.conf"
Steve Bakerbb421be2012-10-10 13:19:10 +1300211 screen_it h-api "cd $HEAT_DIR; bin/heat-api --config-dir=$HEAT_CONF_DIR/heat-api.conf"
Angus Salkelde2790212012-09-11 11:24:09 +1000212 screen_it h-api-cfn "cd $HEAT_DIR; bin/heat-api-cfn --config-dir=$HEAT_CONF_DIR/heat-api-cfn.conf"
213 screen_it h-api-cw "cd $HEAT_DIR; bin/heat-api-cloudwatch --config-dir=$HEAT_CONF_DIR/heat-api-cloudwatch.conf"
Steve Bakerbfdad752012-08-18 09:00:42 +1200214}
215
Dean Troyer699a29f2012-09-10 14:10:27 -0500216# stop_heat() - Stop running processes
Steve Bakerbfdad752012-08-18 09:00:42 +1200217function stop_heat() {
Kieran Spear70338292013-05-28 11:31:31 +1000218 # Kill the screen windows
219 for serv in h-eng h-api h-api-cfn h-api-cw; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500220 screen -S $SCREEN_NAME -p $serv -X kill
221 done
Steve Bakerbfdad752012-08-18 09:00:42 +1200222}
Dean Troyer7903b792012-09-13 17:16:12 -0500223
Steve Bakerd5cccad2013-07-19 10:34:24 +1200224function disk_image_create {
225 local elements_path=$1
226 local elements=$2
227 local arch=$3
228 local output=$TOP_DIR/files/$4
229 if [[ -f "$output.qcow2" ]];
230 then
231 echo "Image file already exists: $output_file"
232 else
233 ELEMENTS_PATH=$elements_path disk-image-create \
234 $elements -a $arch -o $output
235 fi
236 # upload with fake URL so that image in $TOP_DIR/files is used
237 upload_image "http://localhost/$output.qcow2" $TOKEN
238}
Dean Troyercc6b4432013-04-08 15:38:03 -0500239
Dean Troyer7903b792012-09-13 17:16:12 -0500240# Restore xtrace
241$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400242
243# Local variables:
244# mode: shell-script
245# End: