| Mate Lakat | 45ea081 | 2013-09-25 10:00:29 +0100 | [diff] [blame] | 1 | # lib/heat | 
| Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Install and start **Heat** service | 
|  | 3 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 4 | # To enable, add the following to localrc | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # | 
|  | 6 | #   ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 7 |  | 
|  | 8 | # Dependencies: | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 9 | # | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 10 | # - functions | 
|  | 11 |  | 
|  | 12 | # stack.sh | 
|  | 13 | # --------- | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 14 | # - install_heatclient | 
|  | 15 | # - install_heat | 
|  | 16 | # - configure_heatclient | 
|  | 17 | # - configure_heat | 
|  | 18 | # - init_heat | 
|  | 19 | # - start_heat | 
|  | 20 | # - stop_heat | 
|  | 21 | # - cleanup_heat | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 22 |  | 
| Dean Troyer | 7903b79 | 2012-09-13 17:16:12 -0500 | [diff] [blame] | 23 | # Save trace setting | 
|  | 24 | XTRACE=$(set +o | grep xtrace) | 
|  | 25 | set +o xtrace | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 26 |  | 
|  | 27 |  | 
|  | 28 | # Defaults | 
|  | 29 | # -------- | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 30 |  | 
|  | 31 | # set up default directories | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 32 | HEAT_DIR=$DEST/heat | 
| Steve Baker | 32761a4 | 2012-11-05 09:57:57 +1300 | [diff] [blame] | 33 | HEATCLIENT_DIR=$DEST/python-heatclient | 
| Steve Baker | c324908 | 2013-04-09 13:41:47 +1200 | [diff] [blame] | 34 | HEAT_AUTH_CACHE_DIR=${HEAT_AUTH_CACHE_DIR:-/var/cache/heat} | 
| Steve Baker | 389b3a0 | 2013-08-01 10:44:09 +1200 | [diff] [blame] | 35 | HEAT_STANDALONE=`trueorfalse False $HEAT_STANDALONE` | 
| Angus Salkeld | f645a85 | 2013-08-26 10:13:36 +1000 | [diff] [blame] | 36 | HEAT_CONF_DIR=/etc/heat | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 37 | HEAT_CONF=$HEAT_CONF_DIR/heat.conf | 
| Angus Salkeld | f645a85 | 2013-08-26 10:13:36 +1000 | [diff] [blame] | 38 | HEAT_ENV_DIR=$HEAT_CONF_DIR/environment.d | 
| Angus Salkeld | fb71a27 | 2013-08-26 10:15:38 +1000 | [diff] [blame] | 39 | HEAT_TEMPLATES_DIR=$HEAT_CONF_DIR/templates | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 40 |  | 
|  | 41 | # Functions | 
|  | 42 | # --------- | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 43 |  | 
|  | 44 | # cleanup_heat() - Remove residual data files, anything left over from previous | 
|  | 45 | # runs that a clean run would need to clean up | 
|  | 46 | function cleanup_heat() { | 
| Steve Baker | c324908 | 2013-04-09 13:41:47 +1200 | [diff] [blame] | 47 | sudo rm -rf $HEAT_AUTH_CACHE_DIR | 
| Angus Salkeld | f645a85 | 2013-08-26 10:13:36 +1000 | [diff] [blame] | 48 | sudo rm -rf $HEAT_ENV_DIR | 
| Angus Salkeld | fb71a27 | 2013-08-26 10:15:38 +1000 | [diff] [blame] | 49 | sudo rm -rf $HEAT_TEMPLATES_DIR | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 50 | } | 
|  | 51 |  | 
|  | 52 | # configure_heat() - Set config files, create data dirs, etc | 
|  | 53 | function configure_heat() { | 
|  | 54 | setup_develop $HEAT_DIR | 
|  | 55 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 56 | if [[ ! -d $HEAT_CONF_DIR ]]; then | 
|  | 57 | sudo mkdir -p $HEAT_CONF_DIR | 
|  | 58 | fi | 
| Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 59 | sudo chown $STACK_USER $HEAT_CONF_DIR | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 60 | # remove old config files | 
|  | 61 | rm -f $HEAT_CONF_DIR/heat-*.conf | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 62 |  | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 63 | HEAT_API_CFN_HOST=${HEAT_API_CFN_HOST:-$SERVICE_HOST} | 
|  | 64 | HEAT_API_CFN_PORT=${HEAT_API_CFN_PORT:-8000} | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 65 | HEAT_ENGINE_HOST=${HEAT_ENGINE_HOST:-$SERVICE_HOST} | 
|  | 66 | HEAT_ENGINE_PORT=${HEAT_ENGINE_PORT:-8001} | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 67 | HEAT_API_CW_HOST=${HEAT_API_CW_HOST:-$SERVICE_HOST} | 
|  | 68 | HEAT_API_CW_PORT=${HEAT_API_CW_PORT:-8003} | 
| Steve Baker | bb421be | 2012-10-10 13:19:10 +1300 | [diff] [blame] | 69 | HEAT_API_HOST=${HEAT_API_HOST:-$SERVICE_HOST} | 
|  | 70 | HEAT_API_PORT=${HEAT_API_PORT:-8004} | 
| Steve Baker | d5cd79b | 2013-04-13 11:14:41 -0700 | [diff] [blame] | 71 | HEAT_API_PASTE_FILE=$HEAT_CONF_DIR/api-paste.ini | 
|  | 72 | HEAT_POLICY_FILE=$HEAT_CONF_DIR/policy.json | 
|  | 73 |  | 
|  | 74 | cp $HEAT_DIR/etc/heat/api-paste.ini $HEAT_API_PASTE_FILE | 
|  | 75 | cp $HEAT_DIR/etc/heat/policy.json $HEAT_POLICY_FILE | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 76 | cp $HEAT_DIR/etc/heat/heat.conf.sample $HEAT_CONF | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 77 |  | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 78 | # common options | 
|  | 79 | iniset_rpc_backend heat $HEAT_CONF DEFAULT | 
|  | 80 | iniset $HEAT_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT | 
|  | 81 | iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition | 
|  | 82 | iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT | 
| Angus Salkeld | e231438 | 2013-11-14 14:36:46 +1100 | [diff] [blame] | 83 | iniset $HEAT_CONF database connection `database_connection_url heat` | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 84 | iniset $HEAT_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random` | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 85 |  | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 86 | # logging | 
|  | 87 | iniset $HEAT_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL | 
|  | 88 | iniset $HEAT_CONF DEFAULT use_syslog $SYSLOG | 
| Steve Baker | 556ffe4 | 2013-08-06 16:42:38 +1200 | [diff] [blame] | 89 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then | 
|  | 90 | # Add color to logging output | 
| Arata Notsu | 4897ff5 | 2013-10-09 18:49:32 +0900 | [diff] [blame] | 91 | setup_colorized_logging $HEAT_CONF DEFAULT tenant user | 
| Steve Baker | 556ffe4 | 2013-08-06 16:42:38 +1200 | [diff] [blame] | 92 | fi | 
|  | 93 |  | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 94 | # keystone authtoken | 
|  | 95 | iniset $HEAT_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST | 
|  | 96 | iniset $HEAT_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT | 
|  | 97 | iniset $HEAT_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL | 
|  | 98 | iniset $HEAT_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0 | 
| Jamie Lennox | bd24a8d | 2013-09-20 16:26:42 +1000 | [diff] [blame^] | 99 | iniset $HEAT_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 100 | iniset $HEAT_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME | 
|  | 101 | iniset $HEAT_CONF keystone_authtoken admin_user heat | 
|  | 102 | iniset $HEAT_CONF keystone_authtoken admin_password $SERVICE_PASSWORD | 
| Angus Salkeld | e118655 | 2013-09-06 13:35:09 +1000 | [diff] [blame] | 103 | iniset $HEAT_CONF keystone_authtoken signing_dir $HEAT_AUTH_CACHE_DIR | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 104 |  | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 105 | # ec2authtoken | 
|  | 106 | iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0 | 
|  | 107 | iniset $HEAT_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens | 
|  | 108 |  | 
|  | 109 | # paste_deploy | 
|  | 110 | [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_CONF paste_deploy flavor standalone | 
|  | 111 |  | 
|  | 112 | # OpenStack API | 
|  | 113 | iniset $HEAT_CONF heat_api bind_host $HEAT_API_HOST | 
|  | 114 | iniset $HEAT_CONF heat_api bind_port $HEAT_API_PORT | 
|  | 115 |  | 
|  | 116 | # Cloudformation API | 
|  | 117 | iniset $HEAT_CONF heat_api_cfn bind_host $HEAT_API_CFN_HOST | 
|  | 118 | iniset $HEAT_CONF heat_api_cfn bind_port $HEAT_API_CFN_PORT | 
|  | 119 |  | 
|  | 120 | # Cloudwatch API | 
|  | 121 | iniset $HEAT_CONF heat_api_cloudwatch bind_host $HEAT_API_CW_HOST | 
|  | 122 | iniset $HEAT_CONF heat_api_cloudwatch bind_port $HEAT_API_CW_PORT | 
| Angus Salkeld | e279021 | 2012-09-11 11:24:09 +1000 | [diff] [blame] | 123 |  | 
| Angus Salkeld | f645a85 | 2013-08-26 10:13:36 +1000 | [diff] [blame] | 124 | # heat environment | 
|  | 125 | sudo mkdir -p $HEAT_ENV_DIR | 
|  | 126 | sudo chown $STACK_USER $HEAT_ENV_DIR | 
|  | 127 | # copy the default environment | 
|  | 128 | cp $HEAT_DIR/etc/heat/environment.d/* $HEAT_ENV_DIR/ | 
|  | 129 |  | 
| Angus Salkeld | fb71a27 | 2013-08-26 10:15:38 +1000 | [diff] [blame] | 130 | # heat template resources. | 
|  | 131 | sudo mkdir -p $HEAT_TEMPLATES_DIR | 
|  | 132 | sudo chown $STACK_USER $HEAT_TEMPLATES_DIR | 
|  | 133 | # copy the default templates | 
|  | 134 | cp $HEAT_DIR/etc/heat/templates/* $HEAT_TEMPLATES_DIR/ | 
|  | 135 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 136 | } | 
|  | 137 |  | 
|  | 138 | # init_heat() - Initialize database | 
|  | 139 | function init_heat() { | 
|  | 140 |  | 
|  | 141 | # (re)create heat database | 
| Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 142 | recreate_database heat utf8 | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 143 |  | 
| Steve Baker | e311132 | 2013-06-19 13:57:31 +1200 | [diff] [blame] | 144 | $HEAT_DIR/bin/heat-manage db_sync | 
| Steve Baker | c324908 | 2013-04-09 13:41:47 +1200 | [diff] [blame] | 145 | create_heat_cache_dir | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | # create_heat_cache_dir() - Part of the init_heat() process | 
|  | 149 | function create_heat_cache_dir() { | 
|  | 150 | # Create cache dirs | 
| Angus Salkeld | e118655 | 2013-09-06 13:35:09 +1000 | [diff] [blame] | 151 | sudo mkdir -p $HEAT_AUTH_CACHE_DIR | 
|  | 152 | sudo chown $STACK_USER $HEAT_AUTH_CACHE_DIR | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
| Steve Baker | 32761a4 | 2012-11-05 09:57:57 +1300 | [diff] [blame] | 155 | # install_heatclient() - Collect source and prepare | 
|  | 156 | function install_heatclient() { | 
|  | 157 | git_clone $HEATCLIENT_REPO $HEATCLIENT_DIR $HEATCLIENT_BRANCH | 
| Sean Dague | d644e23 | 2013-07-25 15:34:48 -0400 | [diff] [blame] | 158 | setup_develop $HEATCLIENT_DIR | 
| Steve Baker | 32761a4 | 2012-11-05 09:57:57 +1300 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 161 | # install_heat() - Collect source and prepare | 
|  | 162 | function install_heat() { | 
|  | 163 | git_clone $HEAT_REPO $HEAT_DIR $HEAT_BRANCH | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | # start_heat() - Start running processes, including screen | 
|  | 167 | function start_heat() { | 
| Angus Salkeld | a213e2c | 2013-08-30 10:48:46 +1000 | [diff] [blame] | 168 | screen_it h-eng "cd $HEAT_DIR; bin/heat-engine --config-file=$HEAT_CONF" | 
|  | 169 | screen_it h-api "cd $HEAT_DIR; bin/heat-api --config-file=$HEAT_CONF" | 
|  | 170 | screen_it h-api-cfn "cd $HEAT_DIR; bin/heat-api-cfn --config-file=$HEAT_CONF" | 
|  | 171 | screen_it h-api-cw "cd $HEAT_DIR; bin/heat-api-cloudwatch --config-file=$HEAT_CONF" | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| Dean Troyer | 699a29f | 2012-09-10 14:10:27 -0500 | [diff] [blame] | 174 | # stop_heat() - Stop running processes | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 175 | function stop_heat() { | 
| Kieran Spear | 7033829 | 2013-05-28 11:31:31 +1000 | [diff] [blame] | 176 | # Kill the screen windows | 
|  | 177 | for serv in h-eng h-api h-api-cfn h-api-cw; do | 
| Dean Troyer | 699a29f | 2012-09-10 14:10:27 -0500 | [diff] [blame] | 178 | screen -S $SCREEN_NAME -p $serv -X kill | 
|  | 179 | done | 
| Steve Baker | bfdad75 | 2012-08-18 09:00:42 +1200 | [diff] [blame] | 180 | } | 
| Dean Troyer | 7903b79 | 2012-09-13 17:16:12 -0500 | [diff] [blame] | 181 |  | 
| Steve Baker | d5cccad | 2013-07-19 10:34:24 +1200 | [diff] [blame] | 182 | function disk_image_create { | 
|  | 183 | local elements_path=$1 | 
|  | 184 | local elements=$2 | 
|  | 185 | local arch=$3 | 
|  | 186 | local output=$TOP_DIR/files/$4 | 
|  | 187 | if [[ -f "$output.qcow2" ]]; | 
|  | 188 | then | 
|  | 189 | echo "Image file already exists: $output_file" | 
|  | 190 | else | 
|  | 191 | ELEMENTS_PATH=$elements_path disk-image-create \ | 
|  | 192 | $elements -a $arch -o $output | 
|  | 193 | fi | 
|  | 194 | # upload with fake URL so that image in $TOP_DIR/files is used | 
|  | 195 | upload_image "http://localhost/$output.qcow2" $TOKEN | 
|  | 196 | } | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 197 |  | 
| Dean Troyer | 7903b79 | 2012-09-13 17:16:12 -0500 | [diff] [blame] | 198 | # Restore xtrace | 
|  | 199 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 200 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 201 | # Tell emacs to use shell-script-mode | 
|  | 202 | ## Local variables: | 
|  | 203 | ## mode: shell-script | 
|  | 204 | ## End: |