blob: 75e9c97e80790ce97295a0dc09b20eb4a29f5d1b [file] [log] [blame]
Dean Troyer67787e62012-05-02 11:48:15 -05001# lib/cinder
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Cinder** volume service
Dean Troyer67787e62012-05-02 11:48:15 -05003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
Dean Troyer67787e62012-05-02 11:48:15 -05006# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01007# - DEST, DATA_DIR, STACK_USER must be defined
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01008# - SERVICE_{TENANT_NAME|PASSWORD} must be defined
9# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -050010
11# stack.sh
12# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013# - install_cinder
14# - configure_cinder
15# - init_cinder
16# - start_cinder
17# - stop_cinder
18# - cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050019
Dean Troyer7903b792012-09-13 17:16:12 -050020# Save trace setting
21XTRACE=$(set +o | grep xtrace)
22set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050023
24
25# Defaults
26# --------
27
Mate Lakatb2fdafe2012-11-20 15:52:21 +000028# set up default driver
29CINDER_DRIVER=${CINDER_DRIVER:-default}
30
Dean Troyer67787e62012-05-02 11:48:15 -050031# set up default directories
32CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050033CINDERCLIENT_DIR=$DEST/python-cinderclient
34CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060035CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
36
Dean Troyer50ac7922012-09-13 14:02:01 -050037CINDER_CONF_DIR=/etc/cinder
38CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060039CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050040
Dean Troyer560346b2012-12-13 17:05:24 -060041# Public facing bits
42CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
43CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
44CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
45CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
46
Dean Troyer50ac7922012-09-13 14:02:01 -050047# Support entry points installation of console scripts
48if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040049 CINDER_BIN_DIR=$CINDER_DIR/bin
50else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010051 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040052fi
Dean Troyer67787e62012-05-02 11:48:15 -050053
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010054# Support for multi lvm backend configuration (default is no support)
55CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
56
Dean Troyerb7490da2013-03-18 16:07:56 -050057# Should cinder perform secure deletion of volumes?
58# Defaults to true, can be set to False to avoid this bug when testing:
59# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
60CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
61
Sean Daguef35ff722013-05-16 16:31:12 -040062# Cinder reports allocations back to the scheduler on periodic intervals
63# it turns out we can get an "out of space" issue when we run tests too
64# quickly just because cinder didn't realize we'd freed up resources.
65# Make this configurable so that devstack-gate/tempest can set it to
66# less than the 60 second default
67# https://bugs.launchpad.net/cinder/+bug/1180976
68CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
69
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010070# Name of the lvm volume groups to use/create for iscsi volumes
Dean Troyer67787e62012-05-02 11:48:15 -050071VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
JordanP51c90b82013-05-23 10:27:51 +020072VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010073VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-}
JordanP51c90b82013-05-23 10:27:51 +020074
75# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010076VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
JordanP51c90b82013-05-23 10:27:51 +020077VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010078VOLUME_BACKING_DEVICE2=${VOLUME_BACKING_DEVICE2:-}
JordanP51c90b82013-05-23 10:27:51 +020079
Dean Troyer67787e62012-05-02 11:48:15 -050080VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
81
Dean Troyer4237f592014-01-29 16:22:11 -060082# Tell Tempest this project is present
83TEMPEST_SERVICES+=,cinder
84
Dean Troyercc6b4432013-04-08 15:38:03 -050085
86# Functions
87# ---------
JordanP022e9912013-07-09 14:14:48 +020088# _clean_lvm_lv removes all cinder LVM volumes
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010089#
90# Usage: _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
JordanP022e9912013-07-09 14:14:48 +020091function _clean_lvm_lv() {
Dean Troyer22853c12013-01-07 15:18:12 -060092 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +020093 local lv_prefix=$2
94
Dean Troyer22853c12013-01-07 15:18:12 -060095 # Clean out existing volumes
96 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +020097 # lv_prefix prefixes the LVs we want
98 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -060099 sudo lvremove -f $vg/$lv
100 fi
101 done
JordanP022e9912013-07-09 14:14:48 +0200102}
103
104# _clean_lvm_backing_file() removes the backing file of the
105# volume group used by cinder
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100106#
107# Usage: _clean_lvm_backing_file() $VOLUME_GROUP
JordanP022e9912013-07-09 14:14:48 +0200108function _clean_lvm_backing_file() {
109 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +0200110
111 # if there is no logical volume left, it's safe to attempt a cleanup
112 # of the backing file
113 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
114 # if the backing physical device is a loop device, it was probably setup by devstack
Dean Troyer53ffc712013-12-17 11:13:40 -0600115 if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then
116 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
JordanP51c90b82013-05-23 10:27:51 +0200117 sudo losetup -d $VG_DEV
118 rm -f $DATA_DIR/${vg}-backing-file
119 fi
120 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600121}
122
Dean Troyer67787e62012-05-02 11:48:15 -0500123# cleanup_cinder() - Remove residual data files, anything left over from previous
124# runs that a clean run would need to clean up
125function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -0500126 # ensure the volume group is cleared up because fails might
127 # leave dead volumes in the group
128 TARGETS=$(sudo tgtadm --op show --mode target)
129 if [ $? -ne 0 ]; then
130 # If tgt driver isn't running this won't work obviously
131 # So check the response and restart if need be
132 echo "tgtd seems to be in a bad state, restarting..."
133 if is_ubuntu; then
134 restart_service tgt
135 else
136 restart_service tgtd
137 fi
138 TARGETS=$(sudo tgtadm --op show --mode target)
139 fi
140
141 if [[ -n "$TARGETS" ]]; then
142 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
143 for i in "${iqn_list[@]}"; do
144 echo removing iSCSI target: $i
145 sudo tgt-admin --delete $i
146 done
147 fi
148
149 if is_service_enabled cinder; then
150 sudo rm -rf $CINDER_STATE_PATH/volumes/*
151 fi
152
153 if is_ubuntu; then
154 stop_service tgt
155 else
156 stop_service tgtd
157 fi
158
Dean Troyer22853c12013-01-07 15:18:12 -0600159 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP022e9912013-07-09 14:14:48 +0200160 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
161 _clean_lvm_backing_file $VOLUME_GROUP
JordanP51c90b82013-05-23 10:27:51 +0200162
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100163 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200164 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
165 _clean_lvm_backing_file $VOLUME_GROUP2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100166 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500167}
168
Thierry Carrez63e17842014-01-10 14:23:03 +0100169# configure_cinder_rootwrap() - configure Cinder's rootwrap
170function configure_cinder_rootwrap() {
John Griffith4e823ff2012-07-20 13:18:17 -0600171 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100172 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600173
Thierry Carrezd5d49742014-02-06 16:00:08 +0100174 # Deploy new rootwrap filters files (owned by root).
175 # Wipe any existing rootwrap.d files first
176 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
177 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
John Griffith4e823ff2012-07-20 13:18:17 -0600178 fi
Thierry Carrezd5d49742014-02-06 16:00:08 +0100179 # Deploy filters to /etc/cinder/rootwrap.d
180 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
181 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
182 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
183 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
184 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
185 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
186 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
187 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
188 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
189 # Specify rootwrap.conf as first parameter to rootwrap
190 ROOTWRAP_CSUDOER_CMD="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf *"
John Griffith4e823ff2012-07-20 13:18:17 -0600191
Thierry Carrezd5d49742014-02-06 16:00:08 +0100192 # Set up the rootwrap sudoers for cinder
John Griffith4e823ff2012-07-20 13:18:17 -0600193 TEMPFILE=`mktemp`
Thierry Carrezd5d49742014-02-06 16:00:08 +0100194 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$TEMPFILE
John Griffith4e823ff2012-07-20 13:18:17 -0600195 chmod 0440 $TEMPFILE
196 sudo chown root:root $TEMPFILE
197 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
Thierry Carrez63e17842014-01-10 14:23:03 +0100198}
199
200# configure_cinder() - Set config files, create data dirs, etc
201function configure_cinder() {
202 if [[ ! -d $CINDER_CONF_DIR ]]; then
203 sudo mkdir -p $CINDER_CONF_DIR
204 fi
205 sudo chown $STACK_USER $CINDER_CONF_DIR
206
207 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
208
209 configure_cinder_rootwrap
John Griffith4e823ff2012-07-20 13:18:17 -0600210
Dean Troyer67787e62012-05-02 11:48:15 -0500211 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400212
213 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
214 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
215 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000216 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400217 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
218 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
219 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
220 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500221
Dean Troyer67787e62012-05-02 11:48:15 -0500222 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
Dan Prince82dea7c2013-10-16 18:57:15 -0400223
224 iniset $CINDER_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
225 iniset $CINDER_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
226 iniset $CINDER_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000227 iniset $CINDER_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA
Dan Prince82dea7c2013-10-16 18:57:15 -0400228 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
229 iniset $CINDER_CONF keystone_authtoken admin_user cinder
230 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
231 iniset $CINDER_CONF keystone_authtoken signing_dir $CINDER_AUTH_CACHE_DIR
232
Dean Troyer67787e62012-05-02 11:48:15 -0500233 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500234 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer67787e62012-05-02 11:48:15 -0500235 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100236 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
237 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
238 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
239 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
240 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
241 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
242 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200243 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Matt Riedemann7103a842013-12-07 13:53:33 -0800244 # NOTE(mriedem): Work around Cinder "wishlist" bug 1255593
245 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
246 iniset $CINDER_CONF lvmdriver-1 volume_clear none
247 iniset $CINDER_CONF lvmdriver-2 volume_clear none
248 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100249 else
250 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
251 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
252 fi
Nikolay Sobolevskiy08df29b2013-08-30 21:59:15 +0400253 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST"
Dean Troyer67787e62012-05-02 11:48:15 -0500254 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100255 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500256 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800257 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500258 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500259 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sergey Kraynev84783c72013-10-10 09:08:48 -0400260 iniset $CINDER_CONF DEFAULT lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400261 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600262
Gordon Chung2bfbc772013-08-09 10:55:12 -0400263 if is_service_enabled ceilometer; then
264 iniset $CINDER_CONF DEFAULT notification_driver "cinder.openstack.common.notifier.rpc_notifier"
265 fi
266
Dean Troyer560346b2012-12-13 17:05:24 -0600267 if is_service_enabled tls-proxy; then
268 # Set the service port for a proxy to take the original
269 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
270 fi
271
Dean Troyer4d3049e2012-11-06 20:38:14 -0600272 if [ "$SYSLOG" != "False" ]; then
273 iniset $CINDER_CONF DEFAULT use_syslog True
274 fi
275
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900276 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400277
James E. Blair213c4162012-11-06 09:38:36 +0100278 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
279 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000280 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100281 fi
282
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700283 # Format logging
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000284 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700285 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000286 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000287
288 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
289 (
290 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000291 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000292 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
293 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
294 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
295 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
296 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
297 )
Mehdi Abaakoukae9c4172013-03-07 15:23:46 +0000298 elif [ "$CINDER_DRIVER" == "nfs" ]; then
299 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.nfs.NfsDriver"
300 iniset $CINDER_CONF DEFAULT nfs_shares_config "$CINDER_CONF_DIR/nfs_shares.conf"
301 echo "$CINDER_NFS_SERVERPATH" | sudo tee "$CINDER_CONF_DIR/nfs_shares.conf"
302 sudo chmod 666 $CINDER_CONF_DIR/nfs_shares.conf
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900303 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
304 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400305 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
306 # To use glusterfs, set the following in localrc:
307 # CINDER_DRIVER=glusterfs
308 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
309 # Shares are <host>:<volume> and separated by semicolons.
310
311 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
312 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
313 touch $CINDER_CONF_DIR/glusterfs_shares
314 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
315 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
316 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
317 fi
Gary Kottonc3252272013-08-13 00:32:20 -0700318 elif [ "$CINDER_DRIVER" == "vsphere" ]; then
319 echo_summary "Using VMware vCenter driver"
Gary Kottondc4f2342013-08-19 23:46:17 -0700320 iniset $CINDER_CONF DEFAULT vmware_host_ip "$VMWAREAPI_IP"
321 iniset $CINDER_CONF DEFAULT vmware_host_username "$VMWAREAPI_USER"
322 iniset $CINDER_CONF DEFAULT vmware_host_password "$VMWAREAPI_PASSWORD"
Gary Kottondc4f2342013-08-19 23:46:17 -0700323 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000324 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000325
326 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
327 # Cinder clones are slightly larger due to some extra
328 # metadata. RHEL6 will not allow auto-extending of LV's
329 # without this, leading to clones giving hard-to-track disk
330 # I/O errors.
331 # see https://bugzilla.redhat.com/show_bug.cgi?id=975052
332 sudo sed -i~ \
333 -e 's/snapshot_autoextend_threshold =.*/snapshot_autoextend_threshold = 80/' \
334 -e 's/snapshot_autoextend_percent =.*/snapshot_autoextend_percent = 20/' \
335 /etc/lvm/lvm.conf
336 fi
Vincent Hou21fe4e72013-11-21 03:10:27 -0500337 configure_API_version $CINDER_CONF $IDENTITY_API_VERSION
stackcf2d0d32013-08-05 04:51:56 -0400338 iniset $CINDER_CONF keystone_authtoken admin_user cinder
339 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
340 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Ian Wienand0db17132013-06-26 22:31:48 +1000341
Dean Troyer67787e62012-05-02 11:48:15 -0500342}
343
Dean Troyer671c16e2012-12-13 16:22:38 -0600344# create_cinder_accounts() - Set up common required cinder accounts
345
346# Tenant User Roles
347# ------------------------------------------------------------------
348# service cinder admin # if enabled
349
350# Migrated from keystone_data.sh
351create_cinder_accounts() {
352
353 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
354 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
355
356 # Cinder
357 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
358 CINDER_USER=$(keystone user-create \
359 --name=cinder \
360 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100361 --tenant-id $SERVICE_TENANT \
Dean Troyer671c16e2012-12-13 16:22:38 -0600362 --email=cinder@example.com \
363 | grep " id " | get_field 2)
364 keystone user-role-add \
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200365 --tenant-id $SERVICE_TENANT \
366 --user-id $CINDER_USER \
367 --role-id $ADMIN_ROLE
Dean Troyer671c16e2012-12-13 16:22:38 -0600368 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
369 CINDER_SERVICE=$(keystone service-create \
370 --name=cinder \
371 --type=volume \
372 --description="Cinder Volume Service" \
373 | grep " id " | get_field 2)
374 keystone endpoint-create \
375 --region RegionOne \
376 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600377 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
378 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
379 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Mike Perezb3862f92013-02-12 02:16:41 -0800380 CINDER_V2_SERVICE=$(keystone service-create \
Juan Manuel Olle4ad37632014-01-06 15:07:09 -0300381 --name=cinderv2 \
Mike Perezb3862f92013-02-12 02:16:41 -0800382 --type=volumev2 \
383 --description="Cinder Volume Service V2" \
384 | grep " id " | get_field 2)
385 keystone endpoint-create \
386 --region RegionOne \
387 --service_id $CINDER_V2_SERVICE \
388 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
389 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
390 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
391
Dean Troyer671c16e2012-12-13 16:22:38 -0600392 fi
393 fi
394}
395
Dean Troyerf03bafe2013-02-12 10:58:28 -0600396# create_cinder_cache_dir() - Part of the init_cinder() process
397function create_cinder_cache_dir() {
398 # Create cache dir
399 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
400 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
401 rm -f $CINDER_AUTH_CACHE_DIR/*
402}
403
404create_cinder_volume_group() {
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200405 # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100406 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
407 # service if it (they) does (do) not yet exist. If you don't wish to use a
408 # file backed volume group, create your own volume group called ``stack-volumes``
409 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600410 #
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200411 # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in
412 # the ``DATA_DIR``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600413
414 if ! sudo vgs $VOLUME_GROUP; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100415 if [ -z "$VOLUME_BACKING_DEVICE" ]; then
416 # Only create if the file doesn't already exists
417 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
418 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyerf03bafe2013-02-12 10:58:28 -0600419
Mate Lakat68ac03c2013-06-06 16:22:34 +0100420 # Only create if the loopback device doesn't contain $VOLUME_GROUP
421 if ! sudo vgs $VOLUME_GROUP; then
422 sudo vgcreate $VOLUME_GROUP $DEV
423 fi
424 else
425 sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE
Dean Troyerf03bafe2013-02-12 10:58:28 -0600426 fi
427 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100428 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
429 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
430
431 if ! sudo vgs $VOLUME_GROUP2; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100432 if [ -z "$VOLUME_BACKING_DEVICE2" ]; then
433 # Only create if the file doesn't already exists
434 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100435
Mate Lakat68ac03c2013-06-06 16:22:34 +0100436 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100437
Mate Lakat68ac03c2013-06-06 16:22:34 +0100438 # Only create if the loopback device doesn't contain $VOLUME_GROUP
439 if ! sudo vgs $VOLUME_GROUP2; then
440 sudo vgcreate $VOLUME_GROUP2 $DEV
441 fi
442 else
443 sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100444 fi
445 fi
446 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600447
448 mkdir -p $CINDER_STATE_PATH/volumes
449}
450
Dean Troyer67787e62012-05-02 11:48:15 -0500451# init_cinder() - Initialize database and volume group
452function init_cinder() {
453 # Force nova volumes off
454 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
455
Terry Wilson428af5a2012-11-01 16:12:39 -0400456 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600457 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400458 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500459
Dean Troyerf03bafe2013-02-12 10:58:28 -0600460 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400461 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500462 fi
463
464 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500465
Dean Troyerf03bafe2013-02-12 10:58:28 -0600466 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500467
Dean Troyer67787e62012-05-02 11:48:15 -0500468 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100469 if is_fedora || is_suse; then
470 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200471 start_service tgtd
472 fi
473
Dean Troyer67787e62012-05-02 11:48:15 -0500474 # Remove iscsi targets
475 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
Dean Troyer22853c12013-01-07 15:18:12 -0600476 # Start with a clean volume group
JordanP022e9912013-07-09 14:14:48 +0200477 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100478 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200479 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100480 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500481 fi
482 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500483
Dean Troyerf03bafe2013-02-12 10:58:28 -0600484 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500485}
486
487# install_cinder() - Collect source and prepare
488function install_cinder() {
489 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400490 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500491}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400492
Dean Troyer253a1a32013-04-01 18:23:22 -0500493# install_cinderclient() - Collect source and prepare
494function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500495 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400496 setup_develop $CINDERCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200497 sudo install -D -m 0644 -o $STACK_USER {$CINDERCLIENT_DIR/tools/,/etc/bash_completion.d/}cinder.bash_completion
Dean Troyer67787e62012-05-02 11:48:15 -0500498}
499
Steve Baker18225d92013-04-14 12:48:41 -0700500# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100501function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700502 if [[ ! -d /etc/tgt/stack.d/ ]]; then
503 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
504 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100505 fi
506}
507
Dean Troyer67787e62012-05-02 11:48:15 -0500508# start_cinder() - Start running processes, including screen
509function start_cinder() {
510 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700511 # Delete any old stack.conf
512 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100513 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100514 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500515 # tgt in oneiric doesn't restart properly if tgtd isn't running
516 # do it in two steps
517 sudo stop tgt || true
518 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100519 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500520 # bypass redirection to systemctl during restart
521 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100522 elif is_suse; then
523 restart_service tgtd
524 else
525 # note for other distros: unstack.sh also uses the tgt/tgtd service
526 # name, and would need to be adjusted too
527 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500528 fi
Giulio Fidente384454d2013-09-27 13:17:34 +0200529 # NOTE(gfidente): ensure tgtd is running in debug mode
530 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500531 fi
532
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400533 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400534 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000535 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600536 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
537
538 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
539 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
540 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600541
542 # Start proxies if enabled
543 if is_service_enabled c-api && is_service_enabled tls-proxy; then
544 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
545 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500546}
547
Dean Troyer699a29f2012-09-10 14:10:27 -0500548# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500549function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500550 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000551 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500552 screen_stop $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500553 done
Dean Troyer67787e62012-05-02 11:48:15 -0500554
555 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100556 if is_ubuntu; then
557 stop_service tgt
558 else
559 stop_service tgtd
560 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500561 fi
562}
Dean Troyer7903b792012-09-13 17:16:12 -0500563
Dean Troyercc6b4432013-04-08 15:38:03 -0500564
Dean Troyer7903b792012-09-13 17:16:12 -0500565# Restore xtrace
566$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400567
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100568# Tell emacs to use shell-script-mode
569## Local variables:
570## mode: shell-script
571## End: