blob: b585416f7a014000f9c164ec129045295ecaf6bc [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
Sean Daguef3b2f4c2017-04-13 10:11:48 -040061if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040062 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
Joe D'Andreadfcc3872015-04-29 15:39:17 -040087CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
88CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
Dean Troyerb7490da2013-03-18 16:07:56 -050089
Sean Daguef35ff722013-05-16 16:31:12 -040090# Cinder reports allocations back to the scheduler on periodic intervals
91# it turns out we can get an "out of space" issue when we run tests too
92# quickly just because cinder didn't realize we'd freed up resources.
93# Make this configurable so that devstack-gate/tempest can set it to
94# less than the 60 second default
95# https://bugs.launchpad.net/cinder/+bug/1180976
96CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
97
Ian Wienanda881b882017-04-19 15:42:34 +100098# Centos7 switched to using LIO and that's all that's supported,
99# although the tgt bits are in EPEL we don't want that for CI
100if is_fedora; then
101 CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-lioadm}
102 if [[ ${CINDER_ISCSI_HELPER} != "lioadm" ]]; then
103 die "lioadm is the only valid Cinder iscsi_helper config on this platform"
104 fi
105else
106 CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
107fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100108
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300109# Toggle for deploying Cinder under HTTPD + mod_wsgi
110CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-False}
Dean Troyercc6b4432013-04-08 15:38:03 -0500111
Dean Troyer09718332014-07-03 10:46:57 -0500112# Source the enabled backends
113if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
114 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500115 be_type=${be%%:*}
116 be_name=${be##*:}
117 if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
118 source $CINDER_BACKENDS/${be_type}
Dean Troyer09718332014-07-03 10:46:57 -0500119 fi
120 done
121fi
122
Patrick Eastdddb2c72016-05-03 17:34:00 -0700123# Environment variables to configure the image-volume cache
124CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
125
126# For limits, if left unset, it will use cinder defaults of 0 for unlimited
127CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
128CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
129
130# Configure which cinder backends will have the image-volume cache, this takes the same
131# form as the CINDER_ENABLED_BACKENDS config option. By default it will
132# enable the cache for all cinder backends.
133CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
Dean Troyer09718332014-07-03 10:46:57 -0500134
Dean Troyercc6b4432013-04-08 15:38:03 -0500135# Functions
136# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600137
138# Test if any Cinder services are enabled
139# is_cinder_enabled
140function is_cinder_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700141 [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600142 [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
143 return 1
144}
145
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300146# _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
147function _cinder_cleanup_apache_wsgi {
148 sudo rm -f $(apache_site_config_for osapi-volume)
149}
150
Dean Troyer67787e62012-05-02 11:48:15 -0500151# cleanup_cinder() - Remove residual data files, anything left over from previous
152# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100153function cleanup_cinder {
Sean Dague252f2f52012-12-20 16:41:57 -0500154 # ensure the volume group is cleared up because fails might
155 # leave dead volumes in the group
Attila Fazekasc70605d2015-01-26 15:44:47 +0100156 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100157 local targets
158 targets=$(sudo tgtadm --op show --mode target)
Attila Fazekasc70605d2015-01-26 15:44:47 +0100159 if [ $? -ne 0 ]; then
160 # If tgt driver isn't running this won't work obviously
161 # So check the response and restart if need be
162 echo "tgtd seems to be in a bad state, restarting..."
163 if is_ubuntu; then
164 restart_service tgt
165 else
166 restart_service tgtd
167 fi
168 targets=$(sudo tgtadm --op show --mode target)
Sean Dague252f2f52012-12-20 16:41:57 -0500169 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500170
Attila Fazekasc70605d2015-01-26 15:44:47 +0100171 if [[ -n "$targets" ]]; then
172 local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
173 for i in "${iqn_list[@]}"; do
174 echo removing iSCSI target: $i
175 sudo tgt-admin --delete $i
176 done
177 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500178
Attila Fazekasc70605d2015-01-26 15:44:47 +0100179 if is_ubuntu; then
180 stop_service tgt
181 else
182 stop_service tgtd
183 fi
Sean Dague252f2f52012-12-20 16:41:57 -0500184 else
Attila Fazekasc70605d2015-01-26 15:44:47 +0100185 sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
Sean Dague252f2f52012-12-20 16:41:57 -0500186 fi
187
Dean Troyer09718332014-07-03 10:46:57 -0500188 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500189 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500190 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500191 be_type=${be%%:*}
192 be_name=${be##*:}
193 if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
194 cleanup_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500195 fi
196 done
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100197 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300198
199 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
200 _cinder_cleanup_apache_wsgi
201 fi
202}
203
204# _cinder_config_apache_wsgi() - Set WSGI config files
205function _cinder_config_apache_wsgi {
Ian Wienandada886d2015-10-07 14:06:26 +1100206 local cinder_apache_conf
207 cinder_apache_conf=$(apache_site_config_for osapi-volume)
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300208 local cinder_ssl=""
209 local cinder_certfile=""
210 local cinder_keyfile=""
211 local cinder_api_port=$CINDER_SERVICE_PORT
212 local venv_path=""
213
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300214 if [[ ${USE_VENV} = True ]]; then
215 venv_path="python-path=${PROJECT_VENV["cinder"]}/lib/python2.7/site-packages"
216 fi
217
218 # copy proxy vhost file
219 sudo cp $FILES/apache-cinder-api.template $cinder_apache_conf
220 sudo sed -e "
221 s|%PUBLICPORT%|$cinder_api_port|g;
222 s|%APACHE_NAME%|$APACHE_NAME|g;
223 s|%APIWORKERS%|$API_WORKERS|g
224 s|%CINDER_BIN_DIR%|$CINDER_BIN_DIR|g;
225 s|%SSLENGINE%|$cinder_ssl|g;
226 s|%SSLCERTFILE%|$cinder_certfile|g;
227 s|%SSLKEYFILE%|$cinder_keyfile|g;
228 s|%USER%|$STACK_USER|g;
229 s|%VIRTUALENV%|$venv_path|g
230 " -i $cinder_apache_conf
Dean Troyer67787e62012-05-02 11:48:15 -0500231}
232
Thierry Carrez63e17842014-01-10 14:23:03 +0100233# configure_cinder() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100234function configure_cinder {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500235 sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
Thierry Carrez63e17842014-01-10 14:23:03 +0100236
237 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
238
Yalei Wangcecbd1f2015-01-05 17:05:47 +0800239 rm -f $CINDER_CONF
240
Ian Wienandc6782412015-05-14 10:01:53 +1000241 configure_rootwrap cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600242
TommyLike401de4d2017-05-04 17:56:22 +0800243 if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
244 cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
245 fi
246
Dean Troyer67787e62012-05-02 11:48:15 -0500247 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400248
249 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
250 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
251 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000252 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400253 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
254 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
255 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
256 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500257
Brant Knudson05952372014-09-19 17:22:22 -0500258 configure_auth_token_middleware $CINDER_CONF cinder $CINDER_AUTH_CACHE_DIR
Dan Prince82dea7c2013-10-16 18:57:15 -0400259
Sean Dague0b259c32017-02-17 11:51:36 -0500260 # Change the default nova_catalog_info and nova_catalog_admin_info values in
261 # cinder so that the service name cinder is searching for matches that set for
262 # nova in keystone.
263 if [[ -n "$CINDER_NOVA_CATALOG_INFO" ]]; then
264 iniset $CINDER_CONF DEFAULT nova_catalog_info $CINDER_NOVA_CATALOG_INFO
265 fi
266 if [[ -n "$CINDER_NOVA_CATALOG_ADMIN_INFO" ]]; then
267 iniset $CINDER_CONF DEFAULT nova_catalog_admin_info $CINDER_NOVA_CATALOG_ADMIN_INFO
268 fi
git-harryafc14232015-01-08 17:37:40 +0000269
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
Kaitlin Farra5b72b02016-01-26 22:46:13 -0500286 iniset $CINDER_CONF key_manager api_class cinder.keymgr.conf_key_mgr.ConfKeyManager
287
Dean Troyer09718332014-07-03 10:46:57 -0500288 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500289 local enabled_backends=""
290 local default_name=""
291 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500292 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500293 be_type=${be%%:*}
294 be_name=${be##*:}
295 if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
296 configure_cinder_backend_${be_type} ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500297 fi
Dean Troyera25922b2014-08-28 09:29:47 -0500298 if [[ -z "$default_name" ]]; then
299 default_name=$be_name
Dean Troyer09718332014-07-03 10:46:57 -0500300 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500301 enabled_backends+=$be_name,
Sean McGinnis29ec2822017-05-30 14:21:39 -0500302
303 iniset $CINDER_CONF $be_name volume_clear $CINDER_VOLUME_CLEAR
304
Dean Troyer09718332014-07-03 10:46:57 -0500305 done
306 iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
Matt Riedemann6a4aa782014-07-25 13:35:53 -0700307 if [[ -n "$default_name" ]]; then
308 iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
Dean Troyer09718332014-07-03 10:46:57 -0500309 fi
Patrick Eastdddb2c72016-05-03 17:34:00 -0700310 configure_cinder_image_volume_cache
Dean Troyer09718332014-07-03 10:46:57 -0500311 fi
312
Attila Fazekas29834742014-03-09 18:36:42 +0100313 if is_service_enabled swift; then
Falk Reimann22f747b2015-08-28 12:40:19 +0200314 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 +0100315 fi
316
Gordon Chung2bfbc772013-08-09 10:55:12 -0400317 if is_service_enabled ceilometer; then
Matt Riedemann45da7772017-03-05 13:07:39 -0500318 iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
Gordon Chung2bfbc772013-08-09 10:55:12 -0400319 fi
320
Dean Troyer560346b2012-12-13 17:05:24 -0600321 if is_service_enabled tls-proxy; then
322 # Set the service port for a proxy to take the original
323 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
Rob Crittendencdba7b02015-05-26 15:33:45 -0400324 iniset $CINDER_CONF DEFAULT public_endpoint $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
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700333 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400334 setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000335
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300336 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
337 _cinder_config_apache_wsgi
338 fi
339
john-griffithd0860cc2014-01-23 11:31:10 -0700340 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
341 configure_cinder_driver
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000342 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000343
Dean Troyer05bd7b82014-09-16 17:25:33 -0500344 iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400345
Matthew Treinish1fa65362017-06-23 22:32:37 +0000346 iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400347 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400348 iniset $CINDER_CONF DEFAULT glance_protocol https
Rob Crittenden4b109292014-10-21 18:17:48 -0400349 iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400350 fi
351
Flavio Percoco22c695f2016-05-11 12:49:07 -0500352 if [ "$GLANCE_V1_ENABLED" != "True" ]; then
353 iniset $CINDER_CONF DEFAULT glance_api_version 2
354 fi
355
Jordan Pittier38bee182015-05-11 16:51:10 +0200356 # Set os_privileged_user credentials (used for os-assisted-snapshots)
357 iniset $CINDER_CONF DEFAULT os_privileged_user_name nova
358 iniset $CINDER_CONF DEFAULT os_privileged_user_password "$SERVICE_PASSWORD"
Sean Dague7580a0c2016-02-17 06:23:36 -0500359 iniset $CINDER_CONF DEFAULT os_privileged_user_tenant "$SERVICE_PROJECT_NAME"
Marian Horban7159b4b2015-10-22 15:47:49 -0400360 iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100361
Davanum Srinivasc0d16c22017-05-19 10:23:46 -0400362 if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
363 iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
364 elif is_service_enabled etcd3; then
365 iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:2379"
Mehdi Abaakouk52b10742016-12-01 16:11:17 +0100366 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500367}
368
Dean Troyer671c16e2012-12-13 16:22:38 -0600369# create_cinder_accounts() - Set up common required cinder accounts
370
371# Tenant User Roles
372# ------------------------------------------------------------------
373# service cinder admin # if enabled
374
375# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100376function create_cinder_accounts {
Dean Troyer671c16e2012-12-13 16:22:38 -0600377
Dean Troyer671c16e2012-12-13 16:22:38 -0600378 # Cinder
379 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100380
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100381 create_service_user "cinder"
Bartosz Górski0abde392014-02-28 14:15:19 +0100382
Sean Dague985e9582016-02-10 07:25:24 -0500383 get_or_create_service "cinder" "volume" "Cinder Volume Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000384 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500385 "volume" \
386 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400387 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(project_id)s"
Bartosz Górski0abde392014-02-28 14:15:19 +0100388
Sean Dague985e9582016-02-10 07:25:24 -0500389 get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000390 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500391 "volumev2" \
392 "$REGION_NAME" \
Sean Dagueab0a1b82016-04-04 09:09:27 -0400393 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
Alex Meade06c7a442016-04-01 13:18:32 -0400394
395 get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000396 get_or_create_endpoint \
Alex Meade06c7a442016-04-01 13:18:32 -0400397 "volumev3" \
398 "$REGION_NAME" \
Alex Meade06c7a442016-04-01 13:18:32 -0400399 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
Patrick Eastdddb2c72016-05-03 17:34:00 -0700400
401 configure_cinder_internal_tenant
Dean Troyer671c16e2012-12-13 16:22:38 -0600402 fi
403}
404
Dean Troyerf03bafe2013-02-12 10:58:28 -0600405# create_cinder_cache_dir() - Part of the init_cinder() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100406function create_cinder_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600407 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500408 sudo install -d -o $STACK_USER $CINDER_AUTH_CACHE_DIR
Dean Troyerf03bafe2013-02-12 10:58:28 -0600409 rm -f $CINDER_AUTH_CACHE_DIR/*
410}
411
Dean Troyer67787e62012-05-02 11:48:15 -0500412# init_cinder() - Initialize database and volume group
Ian Wienandaee18c72014-02-21 15:35:08 +1100413function init_cinder {
Terry Wilson428af5a2012-11-01 16:12:39 -0400414 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600415 # (Re)create cinder database
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200416 recreate_database cinder
Dean Troyer67787e62012-05-02 11:48:15 -0500417
Clark Boylan633dbc32017-06-14 12:09:21 -0700418 time_start "dbsync"
Dean Troyerf03bafe2013-02-12 10:58:28 -0600419 # Migrate cinder database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000420 $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
Clark Boylan633dbc32017-06-14 12:09:21 -0700421 time_stop "dbsync"
Dean Troyer67787e62012-05-02 11:48:15 -0500422 fi
423
Dean Troyer09718332014-07-03 10:46:57 -0500424 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Dean Troyere8a35ac2014-07-25 12:37:41 -0500425 local be be_name be_type
Dean Troyer09718332014-07-03 10:46:57 -0500426 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500427 be_type=${be%%:*}
428 be_name=${be##*:}
429 if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
Maru Newbyc070a3d2015-01-27 17:44:44 +0000430 # Always init the default volume group for lvm.
431 if [[ "$be_type" == "lvm" ]]; then
432 init_default_lvm_volume_group
433 fi
Dean Troyere8a35ac2014-07-25 12:37:41 -0500434 init_cinder_backend_${be_type} ${be_name}
Vincent Untz0230aa82012-06-14 08:51:01 +0200435 fi
Dean Troyer09718332014-07-03 10:46:57 -0500436 done
Dean Troyer67787e62012-05-02 11:48:15 -0500437 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500438
Dean Troyer09718332014-07-03 10:46:57 -0500439 mkdir -p $CINDER_STATE_PATH/volumes
Dean Troyerf03bafe2013-02-12 10:58:28 -0600440 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500441}
442
443# install_cinder() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100444function install_cinder {
Dean Troyer67787e62012-05-02 11:48:15 -0500445 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400446 setup_develop $CINDER_DIR
Ian Wienanda881b882017-04-19 15:42:34 +1000447 if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
448 install_package tgt
449 elif [[ "$CINDER_ISCI_HELPER" == "lioadm" ]]; then
450 install_package targetcli
Attila Fazekasc70605d2015-01-26 15:44:47 +0100451 fi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300452
453 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
454 install_apache_wsgi
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300455 fi
Dean Troyer253a1a32013-04-01 18:23:22 -0500456}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400457
Dean Troyer253a1a32013-04-01 18:23:22 -0500458# install_cinderclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100459function install_cinderclient {
Ivan Kolodyazhny8d0d3112016-05-26 23:41:49 +0300460 if use_library_from_git "python-brick-cinderclient-ext"; then
461 git_clone_by_name "python-brick-cinderclient-ext"
462 setup_dev_lib "python-brick-cinderclient-ext"
463 fi
464
Sean Daguee08ab102014-11-13 17:09:28 -0500465 if use_library_from_git "python-cinderclient"; then
466 git_clone_by_name "python-cinderclient"
467 setup_dev_lib "python-cinderclient"
468 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 +0100469 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500470}
471
Steve Baker18225d92013-04-14 12:48:41 -0700472# apply config.d approach for cinder volumes directory
Ian Wienandaee18c72014-02-21 15:35:08 +1100473function _configure_tgt_for_config_d {
Steve Baker18225d92013-04-14 12:48:41 -0700474 if [[ ! -d /etc/tgt/stack.d/ ]]; then
475 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
Jordan Pittiera263e7d2016-01-07 19:40:44 +0100476 fi
477 if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
Steve Baker18225d92013-04-14 12:48:41 -0700478 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100479 fi
480}
481
Dean Troyer67787e62012-05-02 11:48:15 -0500482# start_cinder() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100483function start_cinder {
Rob Crittenden18d47782014-03-19 17:47:42 -0400484 local service_port=$CINDER_SERVICE_PORT
485 local service_protocol=$CINDER_SERVICE_PROTOCOL
486 if is_service_enabled tls-proxy; then
487 service_port=$CINDER_SERVICE_PORT_INT
488 service_protocol="http"
489 fi
Attila Fazekasc70605d2015-01-26 15:44:47 +0100490 if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
491 if is_service_enabled c-vol; then
492 # Delete any old stack.conf
493 sudo rm -f /etc/tgt/conf.d/stack.conf
494 _configure_tgt_for_config_d
495 if is_ubuntu; then
496 sudo service tgt restart
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200497 elif is_suse; then
498 # NOTE(dmllr): workaround restart bug
499 # https://bugzilla.suse.com/show_bug.cgi?id=934642
500 stop_service tgtd
501 start_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100502 else
Dirk Mueller6bc089f2015-06-01 12:39:12 +0200503 restart_service tgtd
Attila Fazekasc70605d2015-01-26 15:44:47 +0100504 fi
505 # NOTE(gfidente): ensure tgtd is running in debug mode
506 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500507 fi
508 fi
509
Clark Boylan2dfca042017-05-25 14:57:19 -0700510 if is_service_enabled c-api ; then
511 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
512 enable_apache_site osapi-volume
513 restart_apache_server
514 tail_log c-api /var/log/$APACHE_NAME/c-api.log
515 else
516 run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
517 fi
Eli Qiao4af6eea2017-02-28 15:13:02 +0800518
Clark Boylan2dfca042017-05-25 14:57:19 -0700519 echo "Waiting for Cinder API to start..."
520 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$CINDER_SERVICE_HOST:$service_port; then
521 die $LINENO "c-api did not start"
522 fi
523
524 # Start proxies if enabled
525 if is_service_enabled tls-proxy; then
526 start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
527 fi
Dean Troyer09718332014-07-03 10:46:57 -0500528 fi
529
Dean Troyer3159a822014-08-27 14:13:58 -0500530 run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
531 run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
532 run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600533
534 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
535 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
536 # has started. This is a quick fix for lp bug/1189595
Dean Troyer67787e62012-05-02 11:48:15 -0500537}
538
Dean Troyer699a29f2012-09-10 14:10:27 -0500539# stop_cinder() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100540function stop_cinder {
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300541 if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
542 disable_apache_site osapi-volume
543 restart_apache_server
544 else
545 stop_process c-api
546 fi
547
Dean Troyer699a29f2012-09-10 14:10:27 -0500548 # Kill the cinder screen windows
Dean Troyere8a35ac2014-07-25 12:37:41 -0500549 local serv
Anton Arefiev651cb1a2015-09-01 10:55:20 +0300550 for serv in c-bak c-sch c-vol; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100551 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500552 done
Dean Troyer67787e62012-05-02 11:48:15 -0500553}
Dean Troyer7903b792012-09-13 17:16:12 -0500554
Dean Troyer09718332014-07-03 10:46:57 -0500555# create_volume_types() - Create Cinder's configured volume types
556function create_volume_types {
557 # Create volume types
558 if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
Jamie Lennox494f7cd2015-05-29 08:33:03 +0000559 local be be_name
Dean Troyer09718332014-07-03 10:46:57 -0500560 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
Dean Troyere8a35ac2014-07-25 12:37:41 -0500561 be_name=${be##*:}
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300562 openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
Dean Troyer09718332014-07-03 10:46:57 -0500563 done
564 fi
565}
566
567# Compatibility for Grenade
568
569function create_cinder_volume_group {
570 # During a transition period Grenade needs to have this function defined
571 # It is effectively a no-op in the Grenade 'target' use case
572 :
573}
574
Patrick Eastdddb2c72016-05-03 17:34:00 -0700575function configure_cinder_internal_tenant {
576 # Re-use the Cinder service account for simplicity.
577 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
578 iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
579}
580
581function configure_cinder_image_volume_cache {
582 # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
583 # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
584 # be the backend specific configuration stanza in cinder.conf.
585 for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
586 local be_name=${be##*:}
587
588 iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
589
590 if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
591 iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
592 fi
593
594 if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
595 iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
596 fi
597 done
598}
599
Dean Troyercc6b4432013-04-08 15:38:03 -0500600
Dean Troyer7903b792012-09-13 17:16:12 -0500601# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100602$_XTRACE_CINDER
Sean Dague584d90e2013-03-29 14:34:53 -0400603
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100604# Tell emacs to use shell-script-mode
605## Local variables:
606## mode: shell-script
607## End: