blob: 972c35ce727325b22849d4c80e68dda1e5522946 [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
Dean Troyercc6b4432013-04-08 15:38:03 -050040
Dean Troyer4237f592014-01-29 16:22:11 -060041# Tell Tempest this project is present
42TEMPEST_SERVICES+=,heat
43
44
Dean Troyercc6b4432013-04-08 15:38:03 -050045# Functions
46# ---------
Steve Bakerbfdad752012-08-18 09:00:42 +120047
48# cleanup_heat() - Remove residual data files, anything left over from previous
49# runs that a clean run would need to clean up
50function cleanup_heat() {
Steve Bakerc3249082013-04-09 13:41:47 +120051 sudo rm -rf $HEAT_AUTH_CACHE_DIR
Angus Salkeldf645a852013-08-26 10:13:36 +100052 sudo rm -rf $HEAT_ENV_DIR
Angus Salkeldfb71a272013-08-26 10:15:38 +100053 sudo rm -rf $HEAT_TEMPLATES_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +120054}
55
56# configure_heat() - Set config files, create data dirs, etc
57function configure_heat() {
58 setup_develop $HEAT_DIR
59
Steve Bakerbfdad752012-08-18 09:00:42 +120060 if [[ ! -d $HEAT_CONF_DIR ]]; then
61 sudo mkdir -p $HEAT_CONF_DIR
62 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010063 sudo chown $STACK_USER $HEAT_CONF_DIR
Angus Salkelda213e2c2013-08-30 10:48:46 +100064 # remove old config files
65 rm -f $HEAT_CONF_DIR/heat-*.conf
Steve Bakerbfdad752012-08-18 09:00:42 +120066
Steve Bakere61bc612014-01-27 15:21:29 +130067 HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +100068 HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000}
Steve Bakerbfdad752012-08-18 09:00:42 +120069 HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST}
70 HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001}
Steve Bakere61bc612014-01-27 15:21:29 +130071 HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$HOST_IP}
Angus Salkelde2790212012-09-11 11:24:09 +100072 HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003}
Steve Bakere61bc612014-01-27 15:21:29 +130073 HEAT_API_HOST=${HEAT_API_HOST:-$HOST_IP}
Steve Bakerbb421be2012-10-10 13:19:10 +130074 HEAT_API_PORT=${HEAT_API_PORT:-8004}
Steve Bakerd5cd79b2013-04-13 11:14:41 -070075 HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini
76 HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json
77
78 cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE
79 cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE
Angus Salkelda213e2c2013-08-30 10:48:46 +100080 cp $HEAT_DIR/etc/heat/heat.conf.sample $HEAT_CONF
Steve Bakerbfdad752012-08-18 09:00:42 +120081
Angus Salkelda213e2c2013-08-30 10:48:46 +100082 # common options
83 iniset_rpc_backend heat $HEAT_CONF DEFAULT
84 iniset $HEAT_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
85 iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
86 iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
Angus Salkelde2314382013-11-14 14:36:46 +110087 iniset $HEAT_CONF database connection `database_connection_url heat`
Angus Salkelda213e2c2013-08-30 10:48:46 +100088 iniset $HEAT_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
Steve Bakerbfdad752012-08-18 09:00:42 +120089
Angus Salkelda213e2c2013-08-30 10:48:46 +100090 # logging
91 iniset $HEAT_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
92 iniset $HEAT_CONF DEFAULT use_syslog $SYSLOG
Steve Baker556ffe42013-08-06 16:42:38 +120093 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
94 # Add color to logging output
Arata Notsu4897ff52013-10-09 18:49:32 +090095 setup_colorized_logging $HEAT_CONF DEFAULT tenant user
Steve Baker556ffe42013-08-06 16:42:38 +120096 fi
97
Angus Salkelda213e2c2013-08-30 10:48:46 +100098 # keystone authtoken
99 iniset $HEAT_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
100 iniset $HEAT_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
101 iniset $HEAT_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Vincent Hou21fe4e72013-11-21 03:10:27 -0500102 configure_API_version $HEAT_CONF $IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000103 iniset $HEAT_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA
Angus Salkelda213e2c2013-08-30 10:48:46 +1000104 iniset $HEAT_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
105 iniset $HEAT_CONF keystone_authtoken admin_user heat
106 iniset $HEAT_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Angus Salkelde1186552013-09-06 13:35:09 +1000107 iniset $HEAT_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR
Angus Salkelde2790212012-09-11 11:24:09 +1000108
Angus Salkelda213e2c2013-08-30 10:48:46 +1000109 # ec2authtoken
110 iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
111 iniset $HEAT_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
112
113 # paste_deploy
114 [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_CONF paste_deploy flavor standalone
115
116 # OpenStack API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000117 iniset $HEAT_CONF heat_api bind_port $HEAT_API_PORT
118
119 # Cloudformation API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000120 iniset $HEAT_CONF heat_api_cfn bind_port $HEAT_API_CFN_PORT
121
122 # Cloudwatch API
Angus Salkelda213e2c2013-08-30 10:48:46 +1000123 iniset $HEAT_CONF heat_api_cloudwatch bind_port $HEAT_API_CW_PORT
Angus Salkelde2790212012-09-11 11:24:09 +1000124
Angus Salkeldf645a852013-08-26 10:13:36 +1000125 # heat environment
126 sudo mkdir -p $HEAT_ENV_DIR
127 sudo chown $STACK_USER $HEAT_ENV_DIR
128 # copy the default environment
129 cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/
130
Angus Salkeldfb71a272013-08-26 10:15:38 +1000131 # heat template resources.
132 sudo mkdir -p $HEAT_TEMPLATES_DIR
133 sudo chown $STACK_USER $HEAT_TEMPLATES_DIR
134 # copy the default templates
135 cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/
136
Steve Bakerbfdad752012-08-18 09:00:42 +1200137}
138
139# init_heat() - Initialize database
140function init_heat() {
141
142 # (re)create heat database
Terry Wilson428af5a2012-11-01 16:12:39 -0400143 recreate_database heat utf8
Steve Bakerbfdad752012-08-18 09:00:42 +1200144
Steve Bakere3111322013-06-19 13:57:31 +1200145 $HEAT_DIR/bin/heat-manage db_sync
Steve Bakerc3249082013-04-09 13:41:47 +1200146 create_heat_cache_dir
147}
148
149# create_heat_cache_dir() - Part of the init_heat() process
150function create_heat_cache_dir() {
151 # Create cache dirs
Angus Salkelde1186552013-09-06 13:35:09 +1000152 sudo mkdir -p $HEAT_AUTH_CACHE_DIR
153 sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR
Steve Bakerbfdad752012-08-18 09:00:42 +1200154}
155
Steve Baker32761a42012-11-05 09:57:57 +1300156# install_heatclient() - Collect source and prepare
157function install_heatclient() {
158 git_clone $HEATCLIENT_REPO $HEATCLIENT_DIR $HEATCLIENT_BRANCH
Sean Dagued644e232013-07-25 15:34:48 -0400159 setup_develop $HEATCLIENT_DIR
Attila Fazekas8664ca52014-02-02 10:07:39 +0100160 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 +1300161}
162
Steve Bakerbfdad752012-08-18 09:00:42 +1200163# install_heat() - Collect source and prepare
164function install_heat() {
165 git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH
166}
167
168# start_heat() - Start running processes, including screen
169function start_heat() {
Angus Salkelda213e2c2013-08-30 10:48:46 +1000170 screen_it h-eng "cd $HEAT_DIR; bin/heat-engine --config-file=$HEAT_CONF"
171 screen_it h-api "cd $HEAT_DIR; bin/heat-api --config-file=$HEAT_CONF"
172 screen_it h-api-cfn "cd $HEAT_DIR; bin/heat-api-cfn --config-file=$HEAT_CONF"
173 screen_it h-api-cw "cd $HEAT_DIR; bin/heat-api-cloudwatch --config-file=$HEAT_CONF"
Steve Bakerbfdad752012-08-18 09:00:42 +1200174}
175
Dean Troyer699a29f2012-09-10 14:10:27 -0500176# stop_heat() - Stop running processes
Steve Bakerbfdad752012-08-18 09:00:42 +1200177function stop_heat() {
Kieran Spear70338292013-05-28 11:31:31 +1000178 # Kill the screen windows
179 for serv in h-eng h-api h-api-cfn h-api-cw; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500180 screen_stop $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500181 done
Steve Bakerbfdad752012-08-18 09:00:42 +1200182}
Dean Troyer7903b792012-09-13 17:16:12 -0500183
Steve Bakerd5cccad2013-07-19 10:34:24 +1200184function disk_image_create {
185 local elements_path=$1
186 local elements=$2
187 local arch=$3
188 local output=$TOP_DIR/files/$4
Sean Dague16dd8b32014-02-03 09:10:54 +0900189 if [[ -f "$output.qcow2" ]]; then
Steve Bakerd5cccad2013-07-19 10:34:24 +1200190 echo "Image file already exists: $output_file"
191 else
192 ELEMENTS_PATH=$elements_path disk-image-create \
193 $elements -a $arch -o $output
194 fi
195 # upload with fake URL so that image in $TOP_DIR/files is used
196 upload_image "http://localhost/$output.qcow2" $TOKEN
197}
Dean Troyercc6b4432013-04-08 15:38:03 -0500198
Steven Hardy33d1f862014-02-13 15:00:33 +0000199# create_heat_accounts() - Set up common required heat accounts
200# Note this is in addition to what is in files/keystone_data.sh
201function create_heat_accounts() {
202 # Note we have to pass token/endpoint here because the current endpoint and
203 # version negotiation in OSC means just --os-identity-api-version=3 won't work
204 KS_ENDPOINT_V3="$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v3"
Steven Hardy8e1a1ff2014-02-21 14:45:48 +0000205 D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
Steven Hardy33d1f862014-02-13 15:00:33 +0000206 --os-identity-api-version=3 domain create heat \
Steven Hardy8e1a1ff2014-02-21 14:45:48 +0000207 --description "Owns users and projects created by heat" \
208 | grep ' id ' | get_field 2)
209 iniset $HEAT_CONF DEFAULT stack_user_domain ${D_ID}
Steven Hardydd029da2014-02-24 18:09:10 +0000210
211 openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
212 --os-identity-api-version=3 user create --password $SERVICE_PASSWORD \
213 --domain $D_ID heat_domain_admin \
214 --description "Manages users and projects created by heat"
215 openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
216 --os-identity-api-version=3 role add \
Dean Troyer1755f682014-02-26 13:08:00 -0600217 --user heat_domain_admin --domain ${D_ID} admin
Steven Hardydd029da2014-02-24 18:09:10 +0000218 iniset $HEAT_CONF DEFAULT stack_domain_admin heat_domain_admin
219 iniset $HEAT_CONF DEFAULT stack_domain_admin_password $SERVICE_PASSWORD
Steven Hardy33d1f862014-02-13 15:00:33 +0000220}
221
Dean Troyer7903b792012-09-13 17:16:12 -0500222# Restore xtrace
223$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400224
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100225# Tell emacs to use shell-script-mode
226## Local variables:
227## mode: shell-script
228## End: