blob: a7cf3813a13ba90b4837dd91071eec45d5879f36 [file] [log] [blame]
Mate Lakat45ea0812013-09-25 10:00:29 +01001# 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
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
Steve Bakerbfdad752012-08-18 09:00:42 +12007
8# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01009#
Steve Bakerbfdad752012-08-18 09:00:42 +120010# - functions
11
12# stack.sh
13# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010014# - install_heatclient
15# - install_heat
16# - configure_heatclient
17# - configure_heat
18# - init_heat
19# - start_heat
20# - stop_heat
21# - cleanup_heat
Steve Bakerbfdad752012-08-18 09:00:42 +120022
Dean Troyer7903b792012-09-13 17:16:12 -050023# Save trace setting
24XTRACE=$(set +o | grep xtrace)
25set +o xtrace
Steve Bakerbfdad752012-08-18 09:00:42 +120026
27
28# Defaults
29# --------
Dean Troyercc6b4432013-04-08 15:38:03 -050030
31# set up default directories
Steve Bakerbfdad752012-08-18 09:00:42 +120032HEAT_DIR=$DEST/heat
Steve Baker32761a42012-11-05 09:57:57 +130033HEATCLIENT_DIR=$DEST/python-heatclient
Steve Bakerc3249082013-04-09 13:41:47 +120034HEAT_AUTH_CACHE_DIR=${HEAT_AUTH_CACHE_DIR:-/var/cache/heat}
Steve Baker389b3a02013-08-01 10:44:09 +120035HEAT_STANDALONE=`trueorfalse False $HEAT_STANDALONE`
Angus Salkeldf645a852013-08-26 10:13:36 +100036HEAT_CONF_DIR=/etc/heat
Angus Salkelda213e2c2013-08-30 10:48:46 +100037HEAT_CONF=$HEAT_CONF_DIR/heat.conf
Angus Salkeldf645a852013-08-26 10:13:36 +100038HEAT_ENV_DIR=$HEAT_CONF_DIR/environment.d
Angus Salkeldfb71a272013-08-26 10:15:38 +100039HEAT_TEMPLATES_DIR=$HEAT_CONF_DIR/templates
Steve Baker16aca8a2014-03-11 14:01:57 +130040HEAT_STACK_DOMAIN=`trueorfalse True $HEAT_STACK_DOMAIN`
Dean Troyercc6b4432013-04-08 15:38:03 -050041
Dean Troyer4237f592014-01-29 16:22:11 -060042# Tell Tempest this project is present
43TEMPEST_SERVICES+=,heat
44
45
Dean Troyercc6b4432013-04-08 15:38:03 -050046# Functions
47# ---------
Steve Bakerbfdad752012-08-18 09:00:42 +120048
49# cleanup_heat() - Remove residual data files, anything left over from previous
50# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110051function cleanup_heat {
Steve Bakerc3249082013-04-09 13:41:47 +120052 sudo rm -rf $HEAT_AUTH_CACHE_DIR
Angus Salkeldf645a852013-08-26 10:13:36 +100053 sudo rm -rf $HEAT_ENV_DIR
Angus Salkeldfb71a272013-08-26 10:15:38 +100054 sudo rm -rf $HEAT_TEMPLATES_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +120055}
56
57# configure_heat() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110058function configure_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +120059 setup_develop $HEAT_DIR
60
Steve Bakerbfdad752012-08-18 09:00:42 +120061 if [[ ! -d $HEAT_CONF_DIR ]]; then
62 sudo mkdir -p $HEAT_CONF_DIR
63 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010064 sudo chown $STACK_USER $HEAT_CONF_DIR
Angus Salkelda213e2c2013-08-30 10:48:46 +100065 # remove old config files
66 rm -f $HEAT_CONF_DIR/heat-*.conf
Steve Bakerbfdad752012-08-18 09:00:42 +120067
Steve Bakere61bc612014-01-27 15:21:29 +130068 HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +100069 HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000}
Steve Bakerbfdad752012-08-18 09:00:42 +120070 HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST}
71 HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001}
Steve Bakere61bc612014-01-27 15:21:29 +130072 HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +100073 HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003}
Steve Bakere61bc612014-01-27 15:21:29 +130074 HEAT_API_HOST=${HEAT_API_HOST:-$HOST_IP}
Steve Bakerbb421be2012-10-10 13:19:10 +130075 HEAT_API_PORT=${HEAT_API_PORT:-8004}
Steve Bakerd5cd79b2013-04-13 11:14:41 -070076 HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini
77 HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json
78
79 cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE
80 cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE
Angus Salkelda213e2c2013-08-30 10:48:46 +100081 cp $HEAT_DIR/etc/heat/heat.conf.sample $HEAT_CONF
Steve Bakerbfdad752012-08-18 09:00:42 +120082
Angus Salkelda213e2c2013-08-30 10:48:46 +100083 # common options
84 iniset_rpc_backend heat $HEAT_CONF DEFAULT
85 iniset $HEAT_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
86 iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
87 iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
Angus Salkelde2314382013-11-14 14:36:46 +110088 iniset $HEAT_CONF database connection `database_connection_url heat`
Angus Salkelda213e2c2013-08-30 10:48:46 +100089 iniset $HEAT_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
Steve Bakerbfdad752012-08-18 09:00:42 +120090
Angus Salkelda213e2c2013-08-30 10:48:46 +100091 # logging
92 iniset $HEAT_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
93 iniset $HEAT_CONF DEFAULT use_syslog $SYSLOG
Steve Baker556ffe42013-08-06 16:42:38 +120094 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
95 # Add color to logging output
Arata Notsu4897ff52013-10-09 18:49:32 +090096 setup_colorized_logging $HEAT_CONF DEFAULT tenant user
Steve Baker556ffe42013-08-06 16:42:38 +120097 fi
98
Angus Salkelda213e2c2013-08-30 10:48:46 +100099 # keystone authtoken
100 iniset $HEAT_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
101 iniset $HEAT_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
102 iniset $HEAT_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Vincent Hou21fe4e72013-11-21 03:10:27 -0500103 configure_API_version $HEAT_CONF $IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000104 iniset $HEAT_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA
Angus Salkelda213e2c2013-08-30 10:48:46 +1000105 iniset $HEAT_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
106 iniset $HEAT_CONF keystone_authtoken admin_user heat
107 iniset $HEAT_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Angus Salkelde1186552013-09-06 13:35:09 +1000108 iniset $HEAT_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR
Angus Salkelde2790212012-09-11 11:24:09 +1000109
Angus Salkelda213e2c2013-08-30 10:48:46 +1000110 # ec2authtoken
111 iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
112 iniset $HEAT_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
113
114 # paste_deploy
115 [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_CONF paste_deploy flavor standalone
116
117 # OpenStack API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000118 iniset $HEAT_CONF heat_api bind_port $HEAT_API_PORT
119
120 # Cloudformation API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000121 iniset $HEAT_CONF heat_api_cfn bind_port $HEAT_API_CFN_PORT
122
123 # Cloudwatch API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000124 iniset $HEAT_CONF heat_api_cloudwatch bind_port $HEAT_API_CW_PORT
Angus Salkelde2790212012-09-11 11:24:09 +1000125
Angus Salkeldf645a852013-08-26 10:13:36 +1000126 # heat environment
127 sudo mkdir -p $HEAT_ENV_DIR
128 sudo chown $STACK_USER $HEAT_ENV_DIR
129 # copy the default environment
130 cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/
131
Angus Salkeldfb71a272013-08-26 10:15:38 +1000132 # heat template resources.
133 sudo mkdir -p $HEAT_TEMPLATES_DIR
134 sudo chown $STACK_USER $HEAT_TEMPLATES_DIR
135 # copy the default templates
136 cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/
137
Steve Bakerbfdad752012-08-18 09:00:42 +1200138}
139
140# init_heat() - Initialize database
Ian Wienandaee18c72014-02-21 15:35:08 +1100141function init_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200142
143 # (re)create heat database
Terry Wilson428af5a2012-11-01 16:12:39 -0400144 recreate_database heat utf8
Steve Bakerbfdad752012-08-18 09:00:42 +1200145
Steve Bakere3111322013-06-19 13:57:31 +1200146 $HEAT_DIR/bin/heat-manage db_sync
Steve Bakerc3249082013-04-09 13:41:47 +1200147 create_heat_cache_dir
148}
149
150# create_heat_cache_dir() - Part of the init_heat() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100151function create_heat_cache_dir {
Steve Bakerc3249082013-04-09 13:41:47 +1200152 # Create cache dirs
Angus Salkelde1186552013-09-06 13:35:09 +1000153 sudo mkdir -p $HEAT_AUTH_CACHE_DIR
154 sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +1200155}
156
Steve Baker32761a42012-11-05 09:57:57 +1300157# install_heatclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100158function install_heatclient {
Steve Baker32761a42012-11-05 09:57:57 +1300159 git_clone $HEATCLIENT_REPO $HEATCLIENT_DIR $HEATCLIENT_BRANCH
Sean Dagued644e232013-07-25 15:34:48 -0400160 setup_develop $HEATCLIENT_DIR
Attila Fazekas8664ca52014-02-02 10:07:39 +0100161 sudo install -D -m 0644 -o $STACK_USER {$HEATCLIENT_DIR/tools/,/etc/bash_completion.d/}heat.bash_completion
Steve Baker32761a42012-11-05 09:57:57 +1300162}
163
Steve Bakerbfdad752012-08-18 09:00:42 +1200164# install_heat() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100165function install_heat {
Steve Bakerbfdad752012-08-18 09:00:42 +1200166 git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH
167}
168
169# start_heat() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100170function start_heat {
Angus Salkelda213e2c2013-08-30 10:48:46 +1000171 screen_it h-eng "cd $HEAT_DIR; bin/heat-engine --config-file=$HEAT_CONF"
172 screen_it h-api "cd $HEAT_DIR; bin/heat-api --config-file=$HEAT_CONF"
173 screen_it h-api-cfn "cd $HEAT_DIR; bin/heat-api-cfn --config-file=$HEAT_CONF"
174 screen_it h-api-cw "cd $HEAT_DIR; bin/heat-api-cloudwatch --config-file=$HEAT_CONF"
Steve Bakerbfdad752012-08-18 09:00:42 +1200175}
176
Dean Troyer699a29f2012-09-10 14:10:27 -0500177# stop_heat() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100178function stop_heat {
Kieran Spear70338292013-05-28 11:31:31 +1000179 # Kill the screen windows
180 for serv in h-eng h-api h-api-cfn h-api-cw; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500181 screen_stop $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500182 done
Steve Bakerbfdad752012-08-18 09:00:42 +1200183}
Dean Troyer7903b792012-09-13 17:16:12 -0500184
Steve Bakerd5cccad2013-07-19 10:34:24 +1200185function disk_image_create {
186 local elements_path=$1
187 local elements=$2
188 local arch=$3
189 local output=$TOP_DIR/files/$4
Sean Dague16dd8b32014-02-03 09:10:54 +0900190 if [[ -f "$output.qcow2" ]]; then
Steve Bakerd5cccad2013-07-19 10:34:24 +1200191 echo "Image file already exists: $output_file"
192 else
193 ELEMENTS_PATH=$elements_path disk-image-create \
194 $elements -a $arch -o $output
195 fi
196 # upload with fake URL so that image in $TOP_DIR/files is used
197 upload_image "http://localhost/$output.qcow2" $TOKEN
198}
Dean Troyercc6b4432013-04-08 15:38:03 -0500199
Steven Hardy33d1f862014-02-13 15:00:33 +0000200# create_heat_accounts() - Set up common required heat accounts
Ian Wienandaee18c72014-02-21 15:35:08 +1100201function create_heat_accounts {
Steven Hardy57d478d2014-02-28 16:37:43 +0000202 # migrated from files/keystone_data.sh
203 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
204 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
205
206 HEAT_USER=$(openstack user create \
207 heat \
208 --password "$SERVICE_PASSWORD" \
209 --project $SERVICE_TENANT \
210 --email heat@example.com \
211 | grep " id " | get_field 2)
212 openstack role add \
213 $ADMIN_ROLE \
214 --project $SERVICE_TENANT \
215 --user $HEAT_USER
216 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
217 HEAT_SERVICE=$(openstack service create \
218 heat \
219 --type=orchestration \
220 --description="Heat Orchestration Service" \
221 | grep " id " | get_field 2)
222 openstack endpoint create \
223 $HEAT_SERVICE \
224 --region RegionOne \
225 --publicurl "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
226 --adminurl "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
227 --internalurl "$SERVICE_PROTOCOL://$HEAT_API_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
228 HEAT_CFN_SERVICE=$(openstack service create \
229 heat \
230 --type=cloudformation \
231 --description="Heat CloudFormation Service" \
232 | grep " id " | get_field 2)
233 openstack endpoint create \
234 $HEAT_CFN_SERVICE \
235 --region RegionOne \
236 --publicurl "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
237 --adminurl "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1" \
238 --internalurl "$SERVICE_PROTOCOL://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1"
239 fi
240
241 # heat_stack_user role is for users created by Heat
242 openstack role create heat_stack_user
243
Steven Hardy2ca3bf12014-03-03 18:07:33 +0000244 # heat_stack_owner role is given to users who create Heat stacks,
245 # it's the default role used by heat to delegate to the heat service
246 # user (for performing deferred operations via trusts), see heat.conf
247 HEAT_OWNER_ROLE=$(openstack role create \
248 heat_stack_owner \
249 | grep " id " | get_field 2)
250
251 # Give the role to the demo and admin users so they can create stacks
252 # in either of the projects created by devstack
253 openstack role add $HEAT_OWNER_ROLE --project demo --user demo
254 openstack role add $HEAT_OWNER_ROLE --project demo --user admin
255 openstack role add $HEAT_OWNER_ROLE --project admin --user admin
256
Steve Baker16aca8a2014-03-11 14:01:57 +1300257 if [[ "$HEAT_STACK_DOMAIN" == "True" ]]; then
258 # Note we have to pass token/endpoint here because the current endpoint and
259 # version negotiation in OSC means just --os-identity-api-version=3 won't work
260 KS_ENDPOINT_V3="$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v3"
261 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
262 --os-identity-api-version=3 domain create heat \
263 --description "Owns users and projects created by heat" \
264 | grep ' id ' | get_field 2)
265 iniset $HEAT_CONF DEFAULT stack_user_domain ${D_ID}
Steven Hardydd029da2014-02-24 18:09:10 +0000266
Steve Baker16aca8a2014-03-11 14:01:57 +1300267 openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
268 --os-identity-api-version=3 user create --password $SERVICE_PASSWORD \
269 --domain $D_ID heat_domain_admin \
270 --description "Manages users and projects created by heat"
271 openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
272 --os-identity-api-version=3 role add \
273 --user heat_domain_admin --domain ${D_ID} admin
274 iniset $HEAT_CONF DEFAULT stack_domain_admin heat_domain_admin
275 iniset $HEAT_CONF DEFAULT stack_domain_admin_password $SERVICE_PASSWORD
276 fi
Steven Hardy33d1f862014-02-13 15:00:33 +0000277}
278
Dean Troyer7903b792012-09-13 17:16:12 -0500279# Restore xtrace
280$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400281
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100282# Tell emacs to use shell-script-mode
283## Local variables:
284## mode: shell-script
285## End: