blob: c4a49cd99285ce776f4ca8b04e6ab4ae6a70d46a [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
Patrick Eastdddb2c72016-05-03 17:34:00 -070071# Defaults to thin. For thick provisioning change to 'default'
72CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-thin}
Dean Troyer09718332014-07-03 10:46:57 -050073
Dean Troyer09718332014-07-03 10:46:57 -050074# Default backends
75# The backend format is type:name where type is one of the supported backend
76# types (lvm, nfs, etc) and name is the identifier used in the Cinder
77# configuration and for the volume type name. Multiple backends are
78# comma-separated.
Dean Troyer311f4872014-12-18 16:31:34 -060079# The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
80# CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
81CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
Dean Troyer09718332014-07-03 10:46:57 -050082
83
Dean Troyerb7490da2013-03-18 16:07:56 -050084# Should cinder perform secure deletion of volumes?
Joe D'Andreadfcc3872015-04-29 15:39:17 -040085# Defaults to zero. Can also be set to none or shred.
86# This was previously CINDER_SECURE_DELETE (True or False).
87# Equivalents using CINDER_VOLUME_CLEAR are zero and none, respectively.
88# Set to none to avoid this bug when testing:
Dean Troyerb7490da2013-03-18 16:07:56 -050089# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
Joe D'Andreadfcc3872015-04-29 15:39:17 -040090if [[ -n $CINDER_SECURE_DELETE ]]; then
91 CINDER_SECURE_DELETE=$(trueorfalse True CINDER_SECURE_DELETE)
92 if [[ $CINDER_SECURE_DELETE == "False" ]]; then
93 CINDER_VOLUME_CLEAR_DEFAULT="none"
94 fi
Sean Dague72ad9422015-10-07 11:51:40 -040095 deprecated "Configure secure Cinder volume deletion using CINDER_VOLUME_CLEAR instead of CINDER_SECURE_DELETE."
Joe D'Andreadfcc3872015-04-29 15:39:17 -040096fi
97CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
98CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -050099
Sean Daguef35ff722013-05-16 16:31:12 -0400100# Cinder reports allocations back to the scheduler on periodic intervals
101# it turns out we can get an "out of space" issue when we run tests too
102# quickly just because cinder didn't realize we'd freed up resources.
103# Make this configurable so that devstack-gate/tempest can set it to
104# less than the 60 second default
105# https://bugs.launchpad.net/cinder/+bug/1180976
106CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
107
Attila Fazekasc70605d2015-01-26 15:44:47 +0100108CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
109
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300110# Toggle for deploying Cinder under HTTPD + mod_wsgi
111CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-False}
Dean Troyercc6b4432013-04-08 15:38:03 -0500112
Dean Troyer09718332014-07-03 10:46:57 -0500113# Source the enabled backends
114if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
115 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500116 be_type=${be%%:*}
117 be_name=${be##*:}
118 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
119 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500120 fi
121 done
122fi
123
git-harryafc14232015-01-08 17:37:40 +0000124# Change the default nova_catalog_info and nova_catalog_admin_info values in
125# cinder so that the service name cinder is searching for matches that set for
126# nova in keystone.
127CINDER_NOVA_CATALOG_INFO=${CINDER_NOVA_CATALOG_INFO:-compute:nova:publicURL}
128CINDER_NOVA_CATALOG_ADMIN_INFO=${CINDER_NOVA_CATALOG_ADMIN_INFO:-compute:nova:adminURL}
129
Patrick Eastdddb2c72016-05-03 17:34:00 -0700130# Environment variables to configure the image-volume cache
131CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
132
133# For limits, if left unset, it will use cinder defaults of 0 for unlimited
134CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
135CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
136
137# Configure which cinder backends will have the image-volume cache, this takes the same
138# form as the CINDER_ENABLED_BACKENDS config option. By default it will
139# enable the cache for all cinder backends.
140CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500141
Dean Troyercc6b4432013-04-08 15:38:03 -0500142# Functions
143# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600144
145# Test if any Cinder services are enabled
146# is_cinder_enabled
147function is_cinder_enabled {
148 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
149 return 1
150}
151
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300152# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
153function _cinder_cleanup_apache_wsgi {
154 sudo rm -f $(apache_site_config_for osapi-volume)
155}
156
Dean Troyer67787e62012-05-02 11:48:15 -0500157# cleanup_cinder() - Remove residual data files, anything left over from previous
158# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100159function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500160 # ensure the volume group is cleared up because fails might
161 # leave dead volumes in the group
Attila Fazekasc70605d2015-01-26 15:44:47 +0100162 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100163 local targets
164 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100165 if [ $? -ne 0 ]; then
166 # If tgt driver isn't running this won't work obviously
167 # So check the response and restart if need be
168 echo "tgtd seems to be in a bad state, restarting..."
169 if is_ubuntu; then
170 restart_service tgt
171 else
172 restart_service tgtd
173 fi
174 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500175 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500176
Attila Fazekasc70605d2015-01-26 15:44:47 +0100177 if [[ -n "$targets" ]]; then
178 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
179 for i in "${iqn_list[@]}"; do
180 echo removing iSCSI target: $i
181 sudo tgt-admin --delete $i
182 done
183 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500184
Attila Fazekasc70605d2015-01-26 15:44:47 +0100185 if is_ubuntu; then
186 stop_service tgt
187 else
188 stop_service tgtd
189 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500190 else
Attila Fazekasc70605d2015-01-26 15:44:47 +0100191 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Sean Dague252f2f52012-12-20 16:41:57 -0500192 fi
193
Dean Troyer09718332014-07-03 10:46:57 -0500194 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500195 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500196 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500197 be_type=${be%%:*}
198 be_name=${be##*:}
199 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
200 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500201 fi
202 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100203 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300204
205 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
206 _cinder_cleanup_apache_wsgi
207 fi
208}
209
210# _cinder_config_apache_wsgi() - Set WSGI config files
211function _cinder_config_apache_wsgi {
Ian Wienandada886d2015-10-07 14:06:26 +1100212 local cinder_apache_conf
213 cinder_apache_conf=$(apache_site_config_for osapi-volume)
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300214 local cinder_ssl=""
215 local cinder_certfile=""
216 local cinder_keyfile=""
217 local cinder_api_port=$CINDER_SERVICE_PORT
218 local venv_path=""
219
220 if is_ssl_enabled_service c-api; then
221 cinder_ssl="SSLEngine On"
222 cinder_certfile="SSLCertificateFile $CINDER_SSL_CERT"
223 cinder_keyfile="SSLCertificateKeyFile $CINDER_SSL_KEY"
224 fi
225 if [[ ${USE_VENV} = True ]]; then
226 venv_path="python-path=${PROJECT_VENV["cinder"]}/lib/python2.7/site-packages"
227 fi
228
229 # copy proxy vhost file
230 sudo cp $FILES/apache-cinder-api.template $cinder_apache_conf
231 sudo sed -e "
232 s|%PUBLICPORT%|$cinder_api_port|g;
233 s|%APACHE_NAME%|$APACHE_NAME|g;
234 s|%APIWORKERS%|$API_WORKERS|g
235 s|%CINDER_BIN_DIR%|$CINDER_BIN_DIR|g;
236 s|%SSLENGINE%|$cinder_ssl|g;
237 s|%SSLCERTFILE%|$cinder_certfile|g;
238 s|%SSLKEYFILE%|$cinder_keyfile|g;
239 s|%USER%|$STACK_USER|g;
240 s|%VIRTUALENV%|$venv_path|g
241 " -i $cinder_apache_conf
Dean Troyer67787e62012-05-02 11:48:15 -0500242}
243
Thierry Carrez63e17842014-01-10 14:23:03 +0100244# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100245function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500246 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100247
248 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
249
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800250 rm -f $CINDER_CONF
251
Ian Wienandc6782412015-05-14 10:01:53 +1000252 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600253
Dean Troyer67787e62012-05-02 11:48:15 -0500254 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400255
256 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
257 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
258 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000259 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400260 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
261 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
262 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
263 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500264
Brant Knudson05952372014-09-19 17:22:22 -0500265 configure_auth_token_middleware $CINDER_CONF cinder $CINDER_AUTH_CACHE_DIR
Dan Prince82dea7c2013-10-16 18:57:15 -0400266
git-harryafc14232015-01-08 17:37:40 +0000267 iniset $CINDER_CONF DEFAULT nova_catalog_info $CINDER_NOVA_CATALOG_INFO
268 iniset $CINDER_CONF DEFAULT nova_catalog_admin_info $CINDER_NOVA_CATALOG_ADMIN_INFO
269
Dean Troyer67787e62012-05-02 11:48:15 -0500270 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500271 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer09718332014-07-03 10:46:57 -0500272
Attila Fazekasc70605d2015-01-26 15:44:47 +0100273 iniset $CINDER_CONF DEFAULT iscsi_helper "$CINDER_ISCSI_HELPER"
Joe Gordon23d6d502015-03-06 15:24:22 -0800274 iniset $CINDER_CONF database connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500275 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800276 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500277 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Brian Haley180f5eb2015-06-16 13:14:31 -0400278 iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
Dean Troyer50ac7922012-09-13 14:02:01 -0500279 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Joe Gordon23d6d502015-03-06 15:24:22 -0800280 iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400281 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
Michał Dulko9ee14262016-06-03 15:34:50 +0200282 iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
John Griffith4e823ff2012-07-20 13:18:17 -0600283
Ethan Lynn679f3952015-03-09 23:45:18 +0800284 iniset $CINDER_CONF DEFAULT os_region_name "$REGION_NAME"
285
Dean Troyer09718332014-07-03 10:46:57 -0500286 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500287 local enabled_backends=""
288 local default_name=""
289 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500290 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500291 be_type=${be%%:*}
292 be_name=${be##*:}
293 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
294 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500295 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500296 if [[ -z "$default_name" ]]; then
297 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500298 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500299 enabled_backends+=$be_name,
Dean Troyer09718332014-07-03 10:46:57 -0500300 done
301 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700302 if [[ -n "$default_name" ]]; then
303 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500304 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700305 configure_cinder_image_volume_cache
Dean Troyer09718332014-07-03 10:46:57 -0500306 fi
307
Attila Fazekas29834742014-03-09 18:36:42 +0100308 if is_service_enabled swift; then
Falk Reimann22f747b2015-08-28 12:40:19 +0200309 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 +0100310 fi
311
Gordon Chung2bfbc772013-08-09 10:55:12 -0400312 if is_service_enabled ceilometer; then
Wanlong Gaocf04a9a2016-01-16 17:46:35 +0800313 iniset $CINDER_CONF oslo_messaging_notifications driver "messaging"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400314 fi
315
Dean Troyer560346b2012-12-13 17:05:24 -0600316 if is_service_enabled tls-proxy; then
317 # Set the service port for a proxy to take the original
318 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400319 iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
Gregory Haynes4b49e402016-08-31 18:19:51 -0700320 iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
Dean Troyer560346b2012-12-13 17:05:24 -0600321 fi
322
Dean Troyer4d3049e2012-11-06 20:38:14 -0600323 if [ "$SYSLOG" != "False" ]; then
324 iniset $CINDER_CONF DEFAULT use_syslog True
325 fi
326
Brant Knudson2dd110c2015-03-14 12:39:14 -0500327 iniset_rpc_backend cinder $CINDER_CONF
Gary Kottonf71bf192012-08-06 11:15:36 -0400328
Matt Riedemanncdcdeb62015-10-29 09:48:17 -0700329 iniset $CINDER_CONF DEFAULT volume_clear $CINDER_VOLUME_CLEAR
James E. Blair213c4162012-11-06 09:38:36 +0100330
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700331 # Format logging
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300332 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700333 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
John Griffith95b994d2015-04-18 11:20:15 -0600334 else
335 # Set req-id, project-name and resource in log format
336 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 +0000337 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000338
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300339 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
340 _cinder_config_apache_wsgi
341 fi
342
john-griffithd0860cc2014-01-23 11:31:10 -0700343 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
344 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000345 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000346
Dean Troyer05bd7b82014-09-16 17:25:33 -0500347 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400348
349 iniset $CINDER_CONF DEFAULT glance_api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
350 if is_ssl_enabled_service glance || is_service_enabled tls-proxy; then
351 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400352 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400353 fi
354
Flavio Percoco22c695f2016-05-11 12:49:07 -0500355 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
356 iniset $CINDER_CONF DEFAULT glance_api_version 2
357 fi
358
Rob Crittenden18d47782014-03-19 17:47:42 -0400359 # Register SSL certificates if provided
360 if is_ssl_enabled_service cinder; then
361 ensure_certificates CINDER
362
363 iniset $CINDER_CONF DEFAULT ssl_cert_file "$CINDER_SSL_CERT"
364 iniset $CINDER_CONF DEFAULT ssl_key_file "$CINDER_SSL_KEY"
365 fi
366
Jordan Pittier38bee182015-05-11 16:51:10 +0200367 # Set os_privileged_user credentials (used for os-assisted-snapshots)
368 iniset $CINDER_CONF DEFAULT os_privileged_user_name nova
369 iniset $CINDER_CONF DEFAULT os_privileged_user_password "$SERVICE_PASSWORD"
Sean Dague7580a0c2016-02-17 06:23:36 -0500370 iniset $CINDER_CONF DEFAULT os_privileged_user_tenant "$SERVICE_PROJECT_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400371 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Dean Troyer67787e62012-05-02 11:48:15 -0500372}
373
Dean Troyer671c16e2012-12-13 16:22:38 -0600374# create_cinder_accounts() - Set up common required cinder accounts
375
376# Tenant User Roles
377# ------------------------------------------------------------------
378# service cinder admin # if enabled
379
380# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100381function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600382
Dean Troyer671c16e2012-12-13 16:22:38 -0600383 # Cinder
384 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100385
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100386 create_service_user "cinder"
Bartosz Górski0abde392014-02-28 14:15:19 +0100387
Sean Dague985e9582016-02-10 07:25:24 -0500388 get_or_create_service "cinder" "volume" "Cinder Volume Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000389 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500390 "volume" \
391 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400392 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s" \
393 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s" \
394 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s"
Bartosz Górski0abde392014-02-28 14:15:19 +0100395
Sean Dague985e9582016-02-10 07:25:24 -0500396 get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000397 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500398 "volumev2" \
399 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400400 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s" \
401 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s" \
402 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
Alex Meade06c7a442016-04-01 13:18:32 -0400403
404 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000405 get_or_create_endpoint \
Alex Meade06c7a442016-04-01 13:18:32 -0400406 "volumev3" \
407 "$REGION_NAME" \
408 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s" \
409 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s" \
410 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
Patrick Eastdddb2c72016-05-03 17:34:00 -0700411
412 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600413 fi
414}
415
Dean Troyerf03bafe2013-02-12 10:58:28 -0600416# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100417function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600418 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500419 sudo install -d -o $STACK_USER $CINDER_AUTH_CACHE_DIR
Dean Troyerf03bafe2013-02-12 10:58:28 -0600420 rm -f $CINDER_AUTH_CACHE_DIR/*
421}
422
Dean Troyer67787e62012-05-02 11:48:15 -0500423# init_cinder() - Initialize database and volume group
Dean Troyere8a35ac2014-07-25 12:37:41 -0500424# Uses global ``NOVA_ENABLED_APIS``
Ian Wienandaee18c72014-02-21 15:35:08 +1100425function init_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500426 # Force nova volumes off
427 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
428
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: