blob: f6ad780bb981130638d5316dd4cd88b0820dad02 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyer67787e62012-05-02 11:48:15 -05003# lib/cinder
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Install and start **Cinder** volume service
Dean Troyer67787e62012-05-02 11:48:15 -05005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
Dean Troyer67787e62012-05-02 11:48:15 -05008# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01009# - DEST, DATA_DIR, STACK_USER must be defined
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010010# - SERVICE_{TENANT_NAME|PASSWORD} must be defined
11# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -050012
13# stack.sh
14# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_cinder
16# - configure_cinder
17# - init_cinder
18# - start_cinder
19# - stop_cinder
20# - cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050021
Dean Troyer7903b792012-09-13 17:16:12 -050022# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110023_XTRACE_CINDER=$(set +o | grep xtrace)
Dean Troyer7903b792012-09-13 17:16:12 -050024set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050025
26
27# Defaults
28# --------
29
Mate Lakatb2fdafe2012-11-20 15:52:21 +000030# set up default driver
31CINDER_DRIVER=${CINDER_DRIVER:-default}
john-griffithd0860cc2014-01-23 11:31:10 -070032CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins
Dean Troyer09718332014-07-03 10:46:57 -050033CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends
john-griffithd0860cc2014-01-23 11:31:10 -070034
35# grab plugin config if specified via cinder_driver
36if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
37 source $CINDER_PLUGINS/$CINDER_DRIVER
38fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +000039
Dean Troyer67787e62012-05-02 11:48:15 -050040# set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050041GITDIR["python-cinderclient"]=$DEST/python-cinderclient
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +030042GITDIR["python-brick-cinderclient-ext"]=$DEST/python-brick-cinderclient-ext
Dean Troyer67787e62012-05-02 11:48:15 -050043CINDER_DIR=$DEST/cinder
Dean Troyer6aaad5f2015-02-18 07:09:04 -060044
45# Cinder virtual environment
46if [[ ${USE_VENV} = True ]]; then
47 PROJECT_VENV["cinder"]=${CINDER_DIR}.venv
48 CINDER_BIN_DIR=${PROJECT_VENV["cinder"]}/bin
49else
50 CINDER_BIN_DIR=$(get_python_exec_prefix)
51fi
52
Dean Troyer50ac7922012-09-13 14:02:01 -050053CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060054CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
55
Dean Troyer50ac7922012-09-13 14:02:01 -050056CINDER_CONF_DIR=/etc/cinder
57CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060058CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050059
Dean Troyer560346b2012-12-13 17:05:24 -060060# Public facing bits
Rob Crittenden18d47782014-03-19 17:47:42 -040061if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
62 CINDER_SERVICE_PROTOCOL="https"
63fi
Dean Troyer560346b2012-12-13 17:05:24 -060064CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
65CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
66CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
67CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -040068CINDER_SERVICE_LISTEN_ADDRESS=${CINDER_SERVICE_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Dean Troyer560346b2012-12-13 17:05:24 -060069
John Griffithce8e6f62015-05-12 17:28:59 -060070# What type of LVM device should Cinder use for LVM backend
Matt Riedemannb6cbf922016-11-21 21:10:49 -050071# Defaults to default, which is thick, the other valid choice
72# is thin, which as the name implies utilizes lvm thin provisioning.
73# Thinly provisioned LVM volumes may be more efficient when using the Cinder
74# image cache, but there are also known race failures with volume snapshots
75# and thinly provisioned LVM volumes, see bug 1642111 for details.
76CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-default}
Dean Troyer09718332014-07-03 10:46:57 -050077
Dean Troyer09718332014-07-03 10:46:57 -050078# Default backends
79# The backend format is type:name where type is one of the supported backend
80# types (lvm, nfs, etc) and name is the identifier used in the Cinder
81# configuration and for the volume type name. Multiple backends are
82# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -060083# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
84# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
85CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -050086
87
Dean Troyerb7490da2013-03-18 16:07:56 -050088# Should cinder perform secure deletion of volumes?
Joe D'Andreadfcc3872015-04-29 15:39:17 -040089# Defaults to zero. Can also be set to none or shred.
90# This was previously CINDER_SECURE_DELETE (True or False).
91# Equivalents using CINDER_VOLUME_CLEAR are zero and none, respectively.
92# Set to none to avoid this bug when testing:
Dean Troyerb7490da2013-03-18 16:07:56 -050093# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
Joe D'Andreadfcc3872015-04-29 15:39:17 -040094if [[ -n $CINDER_SECURE_DELETE ]]; then
95 CINDER_SECURE_DELETE=$(trueorfalse True CINDER_SECURE_DELETE)
96 if [[ $CINDER_SECURE_DELETE == "False" ]]; then
97 CINDER_VOLUME_CLEAR_DEFAULT="none"
98 fi
Sean Dague72ad9422015-10-07 11:51:40 -040099 deprecated "Configure secure Cinder volume deletion using CINDER_VOLUME_CLEAR instead of CINDER_SECURE_DELETE."
Joe D'Andreadfcc3872015-04-29 15:39:17 -0400100fi
101CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
102CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -0500103
Sean Daguef35ff722013-05-16 16:31:12 -0400104# Cinder reports allocations back to the scheduler on periodic intervals
105# it turns out we can get an "out of space" issue when we run tests too
106# quickly just because cinder didn't realize we'd freed up resources.
107# Make this configurable so that devstack-gate/tempest can set it to
108# less than the 60 second default
109# https://bugs.launchpad.net/cinder/+bug/1180976
110CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
111
Attila Fazekasc70605d2015-01-26 15:44:47 +0100112CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
113
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300114# Toggle for deploying Cinder under HTTPD + mod_wsgi
115CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-False}
Dean Troyercc6b4432013-04-08 15:38:03 -0500116
Dean Troyer09718332014-07-03 10:46:57 -0500117# Source the enabled backends
118if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
119 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500120 be_type=${be%%:*}
121 be_name=${be##*:}
122 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
123 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500124 fi
125 done
126fi
127
git-harryafc14232015-01-08 17:37:40 +0000128# Change the default nova_catalog_info and nova_catalog_admin_info values in
129# cinder so that the service name cinder is searching for matches that set for
130# nova in keystone.
131CINDER_NOVA_CATALOG_INFO=${CINDER_NOVA_CATALOG_INFO:-compute:nova:publicURL}
132CINDER_NOVA_CATALOG_ADMIN_INFO=${CINDER_NOVA_CATALOG_ADMIN_INFO:-compute:nova:adminURL}
133
Patrick Eastdddb2c72016-05-03 17:34:00 -0700134# Environment variables to configure the image-volume cache
135CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
136
137# For limits, if left unset, it will use cinder defaults of 0 for unlimited
138CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
139CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
140
141# Configure which cinder backends will have the image-volume cache, this takes the same
142# form as the CINDER_ENABLED_BACKENDS config option. By default it will
143# enable the cache for all cinder backends.
144CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500145
Dean Troyercc6b4432013-04-08 15:38:03 -0500146# Functions
147# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600148
149# Test if any Cinder services are enabled
150# is_cinder_enabled
151function is_cinder_enabled {
152 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
153 return 1
154}
155
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300156# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
157function _cinder_cleanup_apache_wsgi {
158 sudo rm -f $(apache_site_config_for osapi-volume)
159}
160
Dean Troyer67787e62012-05-02 11:48:15 -0500161# cleanup_cinder() - Remove residual data files, anything left over from previous
162# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100163function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500164 # ensure the volume group is cleared up because fails might
165 # leave dead volumes in the group
Attila Fazekasc70605d2015-01-26 15:44:47 +0100166 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100167 local targets
168 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100169 if [ $? -ne 0 ]; then
170 # If tgt driver isn't running this won't work obviously
171 # So check the response and restart if need be
172 echo "tgtd seems to be in a bad state, restarting..."
173 if is_ubuntu; then
174 restart_service tgt
175 else
176 restart_service tgtd
177 fi
178 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500179 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500180
Attila Fazekasc70605d2015-01-26 15:44:47 +0100181 if [[ -n "$targets" ]]; then
182 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
183 for i in "${iqn_list[@]}"; do
184 echo removing iSCSI target: $i
185 sudo tgt-admin --delete $i
186 done
187 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500188
Attila Fazekasc70605d2015-01-26 15:44:47 +0100189 if is_ubuntu; then
190 stop_service tgt
191 else
192 stop_service tgtd
193 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500194 else
Attila Fazekasc70605d2015-01-26 15:44:47 +0100195 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Sean Dague252f2f52012-12-20 16:41:57 -0500196 fi
197
Dean Troyer09718332014-07-03 10:46:57 -0500198 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500199 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500200 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500201 be_type=${be%%:*}
202 be_name=${be##*:}
203 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
204 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500205 fi
206 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100207 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300208
209 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
210 _cinder_cleanup_apache_wsgi
211 fi
212}
213
214# _cinder_config_apache_wsgi() - Set WSGI config files
215function _cinder_config_apache_wsgi {
Ian Wienandada886d2015-10-07 14:06:26 +1100216 local cinder_apache_conf
217 cinder_apache_conf=$(apache_site_config_for osapi-volume)
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300218 local cinder_ssl=""
219 local cinder_certfile=""
220 local cinder_keyfile=""
221 local cinder_api_port=$CINDER_SERVICE_PORT
222 local venv_path=""
223
224 if is_ssl_enabled_service c-api; then
225 cinder_ssl="SSLEngine On"
226 cinder_certfile="SSLCertificateFile $CINDER_SSL_CERT"
227 cinder_keyfile="SSLCertificateKeyFile $CINDER_SSL_KEY"
228 fi
229 if [[ ${USE_VENV} = True ]]; then
230 venv_path="python-path=${PROJECT_VENV["cinder"]}/lib/python2.7/site-packages"
231 fi
232
233 # copy proxy vhost file
234 sudo cp $FILES/apache-cinder-api.template $cinder_apache_conf
235 sudo sed -e "
236 s|%PUBLICPORT%|$cinder_api_port|g;
237 s|%APACHE_NAME%|$APACHE_NAME|g;
238 s|%APIWORKERS%|$API_WORKERS|g
239 s|%CINDER_BIN_DIR%|$CINDER_BIN_DIR|g;
240 s|%SSLENGINE%|$cinder_ssl|g;
241 s|%SSLCERTFILE%|$cinder_certfile|g;
242 s|%SSLKEYFILE%|$cinder_keyfile|g;
243 s|%USER%|$STACK_USER|g;
244 s|%VIRTUALENV%|$venv_path|g
245 " -i $cinder_apache_conf
Dean Troyer67787e62012-05-02 11:48:15 -0500246}
247
Thierry Carrez63e17842014-01-10 14:23:03 +0100248# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100249function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500250 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100251
252 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
253
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800254 rm -f $CINDER_CONF
255
Ian Wienandc6782412015-05-14 10:01:53 +1000256 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600257
Dean Troyer67787e62012-05-02 11:48:15 -0500258 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400259
260 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
261 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
262 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000263 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400264 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
265 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
266 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
267 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500268
Brant Knudson05952372014-09-19 17:22:22 -0500269 configure_auth_token_middleware $CINDER_CONF cinder $CINDER_AUTH_CACHE_DIR
Dan Prince82dea7c2013-10-16 18:57:15 -0400270
git-harryafc14232015-01-08 17:37:40 +0000271 iniset $CINDER_CONF DEFAULT nova_catalog_info $CINDER_NOVA_CATALOG_INFO
272 iniset $CINDER_CONF DEFAULT nova_catalog_admin_info $CINDER_NOVA_CATALOG_ADMIN_INFO
273
Dean Troyer67787e62012-05-02 11:48:15 -0500274 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500275 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer09718332014-07-03 10:46:57 -0500276
Attila Fazekasc70605d2015-01-26 15:44:47 +0100277 iniset $CINDER_CONF DEFAULT iscsi_helper "$CINDER_ISCSI_HELPER"
Joe Gordon23d6d502015-03-06 15:24:22 -0800278 iniset $CINDER_CONF database connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500279 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800280 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500281 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Brian Haley180f5eb2015-06-16 13:14:31 -0400282 iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
Dean Troyer50ac7922012-09-13 14:02:01 -0500283 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Joe Gordon23d6d502015-03-06 15:24:22 -0800284 iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400285 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
Michał Dulko9ee14262016-06-03 15:34:50 +0200286 iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
John Griffith4e823ff2012-07-20 13:18:17 -0600287
Ethan Lynn679f3952015-03-09 23:45:18 +0800288 iniset $CINDER_CONF DEFAULT os_region_name "$REGION_NAME"
289
Dean Troyer09718332014-07-03 10:46:57 -0500290 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500291 local enabled_backends=""
292 local default_name=""
293 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500294 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500295 be_type=${be%%:*}
296 be_name=${be##*:}
297 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
298 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500299 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500300 if [[ -z "$default_name" ]]; then
301 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500302 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500303 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500304 done
305 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700306 if [[ -n "$default_name" ]]; then
307 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500308 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700309 configure_cinder_image_volume_cache
Dean Troyer09718332014-07-03 10:46:57 -0500310 fi
311
Attila Fazekas29834742014-03-09 18:36:42 +0100312 if is_service_enabled swift; then
Falk Reimann22f747b2015-08-28 12:40:19 +0200313 iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_"
Attila Fazekas29834742014-03-09 18:36:42 +0100314 fi
315
Gordon Chung2bfbc772013-08-09 10:55:12 -0400316 if is_service_enabled ceilometer; then
Wanlong Gaocf04a9a2016-01-16 17:46:35 +0800317 iniset $CINDER_CONF oslo_messaging_notifications driver "messaging"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400318 fi
319
Dean Troyer560346b2012-12-13 17:05:24 -0600320 if is_service_enabled tls-proxy; then
321 # Set the service port for a proxy to take the original
322 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400323 iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
Gregory Haynes4b49e402016-08-31 18:19:51 -0700324 iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
Dean Troyer560346b2012-12-13 17:05:24 -0600325 fi
326
Dean Troyer4d3049e2012-11-06 20:38:14 -0600327 if [ "$SYSLOG" != "False" ]; then
328 iniset $CINDER_CONF DEFAULT use_syslog True
329 fi
330
Brant Knudson2dd110c2015-03-14 12:39:14 -0500331 iniset_rpc_backend cinder $CINDER_CONF
Gary Kottonf71bf192012-08-06 11:15:36 -0400332
Matt Riedemanncdcdeb62015-10-29 09:48:17 -0700333 iniset $CINDER_CONF DEFAULT volume_clear $CINDER_VOLUME_CLEAR
James E. Blair213c4162012-11-06 09:38:36 +0100334
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700335 # Format logging
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300336 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700337 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
John Griffith95b994d2015-04-18 11:20:15 -0600338 else
339 # Set req-id, project-name and resource in log format
340 iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(project_name)s] %(resource)s%(message)s"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000341 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000342
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300343 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
344 _cinder_config_apache_wsgi
345 fi
346
john-griffithd0860cc2014-01-23 11:31:10 -0700347 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
348 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000349 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000350
Dean Troyer05bd7b82014-09-16 17:25:33 -0500351 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400352
353 iniset $CINDER_CONF DEFAULT glance_api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
354 if is_ssl_enabled_service glance || is_service_enabled tls-proxy; then
355 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400356 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400357 fi
358
Flavio Percoco22c695f2016-05-11 12:49:07 -0500359 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
360 iniset $CINDER_CONF DEFAULT glance_api_version 2
361 fi
362
Rob Crittenden18d47782014-03-19 17:47:42 -0400363 # Register SSL certificates if provided
364 if is_ssl_enabled_service cinder; then
365 ensure_certificates CINDER
366
367 iniset $CINDER_CONF DEFAULT ssl_cert_file "$CINDER_SSL_CERT"
368 iniset $CINDER_CONF DEFAULT ssl_key_file "$CINDER_SSL_KEY"
369 fi
370
Jordan Pittier38bee182015-05-11 16:51:10 +0200371 # Set os_privileged_user credentials (used for os-assisted-snapshots)
372 iniset $CINDER_CONF DEFAULT os_privileged_user_name nova
373 iniset $CINDER_CONF DEFAULT os_privileged_user_password "$SERVICE_PASSWORD"
Sean Dague7580a0c2016-02-17 06:23:36 -0500374 iniset $CINDER_CONF DEFAULT os_privileged_user_tenant "$SERVICE_PROJECT_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400375 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Dean Troyer67787e62012-05-02 11:48:15 -0500376}
377
Dean Troyer671c16e2012-12-13 16:22:38 -0600378# create_cinder_accounts() - Set up common required cinder accounts
379
380# Tenant User Roles
381# ------------------------------------------------------------------
382# service cinder admin # if enabled
383
384# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100385function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600386
Dean Troyer671c16e2012-12-13 16:22:38 -0600387 # Cinder
388 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100389
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100390 create_service_user "cinder"
Bartosz Górski0abde392014-02-28 14:15:19 +0100391
Sean Dague985e9582016-02-10 07:25:24 -0500392 get_or_create_service "cinder" "volume" "Cinder Volume Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000393 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500394 "volume" \
395 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400396 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s" \
397 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s" \
398 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s"
Bartosz Górski0abde392014-02-28 14:15:19 +0100399
Sean Dague985e9582016-02-10 07:25:24 -0500400 get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000401 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500402 "volumev2" \
403 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400404 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s" \
405 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s" \
406 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
Alex Meade06c7a442016-04-01 13:18:32 -0400407
408 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000409 get_or_create_endpoint \
Alex Meade06c7a442016-04-01 13:18:32 -0400410 "volumev3" \
411 "$REGION_NAME" \
412 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s" \
413 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s" \
414 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
Patrick Eastdddb2c72016-05-03 17:34:00 -0700415
416 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600417 fi
418}
419
Dean Troyerf03bafe2013-02-12 10:58:28 -0600420# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100421function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600422 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500423 sudo install -d -o $STACK_USER $CINDER_AUTH_CACHE_DIR
Dean Troyerf03bafe2013-02-12 10:58:28 -0600424 rm -f $CINDER_AUTH_CACHE_DIR/*
425}
426
Dean Troyer67787e62012-05-02 11:48:15 -0500427# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100428function init_cinder {
Terry Wilson428af5a2012-11-01 16:12:39 -0400429 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600430 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200431 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500432
Dean Troyerf03bafe2013-02-12 10:58:28 -0600433 # Migrate cinder database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000434 $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500435 fi
436
Dean Troyer09718332014-07-03 10:46:57 -0500437 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500438 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500439 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500440 be_type=${be%%:*}
441 be_name=${be##*:}
442 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
Maru Newbyc070a3d2015-01-27 17:44:44 +0000443 # Always init the default volume group for lvm.
444 if [[ "$be_type" == "lvm" ]]; then
445 init_default_lvm_volume_group
446 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500447 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200448 fi
Dean Troyer09718332014-07-03 10:46:57 -0500449 done
Dean Troyer67787e62012-05-02 11:48:15 -0500450 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500451
Dean Troyer09718332014-07-03 10:46:57 -0500452 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyerf03bafe2013-02-12 10:58:28 -0600453 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500454}
455
456# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100457function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500458 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400459 setup_develop $CINDER_DIR
Attila Fazekasc70605d2015-01-26 15:44:47 +0100460 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
461 if is_fedora; then
462 install_package scsi-target-utils
463 else
464 install_package tgt
465 fi
466 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300467
468 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
469 install_apache_wsgi
470 if is_ssl_enabled_service "c-api"; then
471 enable_mod_ssl
472 fi
473 fi
Dean Troyer253a1a32013-04-01 18:23:22 -0500474}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400475
Dean Troyer253a1a32013-04-01 18:23:22 -0500476# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100477function install_cinderclient {
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +0300478 if use_library_from_git "python-brick-cinderclient-ext"; then
479 git_clone_by_name "python-brick-cinderclient-ext"
480 setup_dev_lib "python-brick-cinderclient-ext"
481 fi
482
Sean Daguee08ab102014-11-13 17:09:28 -0500483 if use_library_from_git "python-cinderclient"; then
484 git_clone_by_name "python-cinderclient"
485 setup_dev_lib "python-cinderclient"
486 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100487 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500488}
489
Steve Baker18225d92013-04-14 12:48:41 -0700490# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100491function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700492 if [[ ! -d /etc/tgt/stack.d/ ]]; then
493 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
Jordan Pittiera263e7d2016-01-07 19:40:44 +0100494 fi
495 if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
Steve Baker18225d92013-04-14 12:48:41 -0700496 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100497 fi
498}
499
Dean Troyer67787e62012-05-02 11:48:15 -0500500# start_cinder() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100501function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400502 local service_port=$CINDER_SERVICE_PORT
503 local service_protocol=$CINDER_SERVICE_PROTOCOL
504 if is_service_enabled tls-proxy; then
505 service_port=$CINDER_SERVICE_PORT_INT
506 service_protocol="http"
507 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100508 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
509 if is_service_enabled c-vol; then
510 # Delete any old stack.conf
511 sudo rm -f /etc/tgt/conf.d/stack.conf
512 _configure_tgt_for_config_d
513 if is_ubuntu; then
514 sudo service tgt restart
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200515 elif is_suse; then
516 # NOTE(dmllr): workaround restart bug
517 # https://bugzilla.suse.com/show_bug.cgi?id=934642
518 stop_service tgtd
519 start_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100520 else
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200521 restart_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100522 fi
523 # NOTE(gfidente): ensure tgtd is running in debug mode
524 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500525 fi
526 fi
527
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300528 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
529 enable_apache_site osapi-volume
530 restart_apache_server
531 tail_log c-api /var/log/$APACHE_NAME/c-api.log
532 else
533 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
534 echo "Waiting for Cinder API to start..."
535 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
536 die $LINENO "c-api did not start"
537 fi
Dean Troyer09718332014-07-03 10:46:57 -0500538 fi
539
Dean Troyer3159a822014-08-27 14:13:58 -0500540 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
541 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
542 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600543
544 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
545 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
546 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600547
548 # Start proxies if enabled
549 if is_service_enabled c-api && is_service_enabled tls-proxy; then
Gregory Haynes4b49e402016-08-31 18:19:51 -0700550 start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
Dean Troyer560346b2012-12-13 17:05:24 -0600551 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500552}
553
Dean Troyer699a29f2012-09-10 14:10:27 -0500554# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100555function stop_cinder {
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300556 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
557 disable_apache_site osapi-volume
558 restart_apache_server
559 else
560 stop_process c-api
561 fi
562
Dean Troyer699a29f2012-09-10 14:10:27 -0500563 # Kill the cinder screen windows
Dean Troyere8a35ac2014-07-25 12:37:41 -0500564 local serv
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300565 for serv in c-bak c-sch c-vol; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100566 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500567 done
Dean Troyer67787e62012-05-02 11:48:15 -0500568}
Dean Troyer7903b792012-09-13 17:16:12 -0500569
Dean Troyer09718332014-07-03 10:46:57 -0500570# create_volume_types() - Create Cinder's configured volume types
571function create_volume_types {
572 # Create volume types
573 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Jamie Lennox494f7cd2015-05-29 08:33:03 +0000574 local be be_name
Dean Troyer09718332014-07-03 10:46:57 -0500575 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500576 be_name=${be##*:}
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300577 openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500578 done
579 fi
580}
581
582# Compatibility for Grenade
583
584function create_cinder_volume_group {
585 # During a transition period Grenade needs to have this function defined
586 # It is effectively a no-op in the Grenade 'target' use case
587 :
588}
589
Patrick Eastdddb2c72016-05-03 17:34:00 -0700590function configure_cinder_internal_tenant {
591 # Re-use the Cinder service account for simplicity.
592 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
593 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
594}
595
596function configure_cinder_image_volume_cache {
597 # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
598 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
599 # be the backend specific configuration stanza in cinder.conf.
600 for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
601 local be_name=${be##*:}
602
603 iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
604
605 if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
606 iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
607 fi
608
609 if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
610 iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
611 fi
612 done
613}
614
Dean Troyercc6b4432013-04-08 15:38:03 -0500615
Dean Troyer7903b792012-09-13 17:16:12 -0500616# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100617$_XTRACE_CINDER
Sean Dague584d90e2013-03-29 14:34:53 -0400618
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100619# Tell emacs to use shell-script-mode
620## Local variables:
621## mode: shell-script
622## End: