blob: c572db49d23d85d54fad71ba4ba27d06449b9a11 [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:
5# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01006# - DEST, DATA_DIR, STACK_USER must be defined
Dean Troyer67787e62012-05-02 11:48:15 -05007# SERVICE_{TENANT_NAME|PASSWORD} must be defined
Dean Troyerbc071bc2012-10-01 14:06:44 -05008# ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -05009
10# stack.sh
11# ---------
Attila Fazekasb79574b2012-12-01 10:42:46 +010012# install_cinder
13# configure_cinder
14# init_cinder
15# start_cinder
16# stop_cinder
17# cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050018
Dean Troyer7903b792012-09-13 17:16:12 -050019# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050022
23
24# Defaults
25# --------
26
Mate Lakatb2fdafe2012-11-20 15:52:21 +000027# set up default driver
28CINDER_DRIVER=${CINDER_DRIVER:-default}
29
Dean Troyer67787e62012-05-02 11:48:15 -050030# set up default directories
31CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050032CINDERCLIENT_DIR=$DEST/python-cinderclient
33CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060034CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
35
Dean Troyer50ac7922012-09-13 14:02:01 -050036CINDER_CONF_DIR=/etc/cinder
37CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060038CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050039
Dean Troyer560346b2012-12-13 17:05:24 -060040# Public facing bits
41CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
42CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
43CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
44CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
45
Dean Troyer50ac7922012-09-13 14:02:01 -050046# Support entry points installation of console scripts
47if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040048 CINDER_BIN_DIR=$CINDER_DIR/bin
49else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010050 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040051fi
Dean Troyer67787e62012-05-02 11:48:15 -050052
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010053# Support for multi lvm backend configuration (default is no support)
54CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
55
Dean Troyerb7490da2013-03-18 16:07:56 -050056# Should cinder perform secure deletion of volumes?
57# Defaults to true, can be set to False to avoid this bug when testing:
58# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
59CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
60
Sean Daguef35ff722013-05-16 16:31:12 -040061# Cinder reports allocations back to the scheduler on periodic intervals
62# it turns out we can get an "out of space" issue when we run tests too
63# quickly just because cinder didn't realize we'd freed up resources.
64# Make this configurable so that devstack-gate/tempest can set it to
65# less than the 60 second default
66# https://bugs.launchpad.net/cinder/+bug/1180976
67CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
68
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010069# Name of the lvm volume groups to use/create for iscsi volumes
Dean Troyer67787e62012-05-02 11:48:15 -050070VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
JordanP51c90b82013-05-23 10:27:51 +020071VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010072VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-}
JordanP51c90b82013-05-23 10:27:51 +020073
74# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010075VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
JordanP51c90b82013-05-23 10:27:51 +020076VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
Mate Lakat68ac03c2013-06-06 16:22:34 +010077VOLUME_BACKING_DEVICE2=${VOLUME_BACKING_DEVICE2:-}
JordanP51c90b82013-05-23 10:27:51 +020078
Dean Troyer67787e62012-05-02 11:48:15 -050079VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
80
Dean Troyercc6b4432013-04-08 15:38:03 -050081
82# Functions
83# ---------
JordanP51c90b82013-05-23 10:27:51 +020084# _cleanup_lvm removes all cinder volumes and the backing file of the
85# volume group used by cinder
86# _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
87function _cleanup_lvm() {
Dean Troyer22853c12013-01-07 15:18:12 -060088 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +020089 local lv_prefix=$2
90
Dean Troyer22853c12013-01-07 15:18:12 -060091 # Clean out existing volumes
92 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +020093 # lv_prefix prefixes the LVs we want
94 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -060095 sudo lvremove -f $vg/$lv
96 fi
97 done
JordanP51c90b82013-05-23 10:27:51 +020098
99 # if there is no logical volume left, it's safe to attempt a cleanup
100 # of the backing file
101 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
102 # if the backing physical device is a loop device, it was probably setup by devstack
103 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
104 if [[ -n "$VG_DEV" ]]; then
105 sudo losetup -d $VG_DEV
106 rm -f $DATA_DIR/${vg}-backing-file
107 fi
108 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600109}
110
Dean Troyer67787e62012-05-02 11:48:15 -0500111# cleanup_cinder() - Remove residual data files, anything left over from previous
112# runs that a clean run would need to clean up
113function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -0500114 # ensure the volume group is cleared up because fails might
115 # leave dead volumes in the group
116 TARGETS=$(sudo tgtadm --op show --mode target)
117 if [ $? -ne 0 ]; then
118 # If tgt driver isn't running this won't work obviously
119 # So check the response and restart if need be
120 echo "tgtd seems to be in a bad state, restarting..."
121 if is_ubuntu; then
122 restart_service tgt
123 else
124 restart_service tgtd
125 fi
126 TARGETS=$(sudo tgtadm --op show --mode target)
127 fi
128
129 if [[ -n "$TARGETS" ]]; then
130 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
131 for i in "${iqn_list[@]}"; do
132 echo removing iSCSI target: $i
133 sudo tgt-admin --delete $i
134 done
135 fi
136
137 if is_service_enabled cinder; then
138 sudo rm -rf $CINDER_STATE_PATH/volumes/*
139 fi
140
141 if is_ubuntu; then
142 stop_service tgt
143 else
144 stop_service tgtd
145 fi
146
Dean Troyer22853c12013-01-07 15:18:12 -0600147 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP51c90b82013-05-23 10:27:51 +0200148 _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
149
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100150 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP51c90b82013-05-23 10:27:51 +0200151 _cleanup_lvm $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100152 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500153}
154
155# configure_cinder() - Set config files, create data dirs, etc
156function configure_cinder() {
Dean Troyer67787e62012-05-02 11:48:15 -0500157 if [[ ! -d $CINDER_CONF_DIR ]]; then
158 sudo mkdir -p $CINDER_CONF_DIR
159 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100160 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500161
162 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
163
John Griffith4e823ff2012-07-20 13:18:17 -0600164 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100165 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600166
167 # If Cinder ships the new rootwrap filters files, deploy them
168 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
169 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
170 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
171 # Wipe any existing rootwrap.d files first
172 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
173 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
174 fi
175 # Deploy filters to /etc/cinder/rootwrap.d
176 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
177 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
178 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
179 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
180 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
181 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
182 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
183 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
184 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
185 # Specify rootwrap.conf as first parameter to cinder-rootwrap
186 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
187 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
188 fi
189
190 TEMPFILE=`mktemp`
191 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
192 chmod 0440 $TEMPFILE
193 sudo chown root:root $TEMPFILE
194 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
195
Dean Troyer67787e62012-05-02 11:48:15 -0500196 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
197 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
198 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
199 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
200 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
201 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
202 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900203 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500204
Dean Troyer67787e62012-05-02 11:48:15 -0500205 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
206 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000207 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500208 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100209 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
210 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
211 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
212 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
213 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
214 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
215 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200216 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100217 else
218 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
219 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
220 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500221 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100222 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500223 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800224 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500225 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500226 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400227 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600228
Dean Troyer560346b2012-12-13 17:05:24 -0600229 if is_service_enabled tls-proxy; then
230 # Set the service port for a proxy to take the original
231 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
232 fi
233
Dean Troyer4d3049e2012-11-06 20:38:14 -0600234 if [ "$SYSLOG" != "False" ]; then
235 iniset $CINDER_CONF DEFAULT use_syslog True
236 fi
237
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900238 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400239
James E. Blair213c4162012-11-06 09:38:36 +0100240 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
241 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000242 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100243 fi
244
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000245 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
246 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800247 iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user_id)s %(project_id)s%(color)s] %(instance)s%(color)s%(message)s"
248 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000249 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
Joe Gordon07db7132013-01-30 13:07:25 -0800250 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000251 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000252
253 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
254 (
255 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000256 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000257 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
258 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
259 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
260 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
261 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
262 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900263 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
264 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400265 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
266 # To use glusterfs, set the following in localrc:
267 # CINDER_DRIVER=glusterfs
268 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
269 # Shares are <host>:<volume> and separated by semicolons.
270
271 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
272 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
273 touch $CINDER_CONF_DIR/glusterfs_shares
274 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
275 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
276 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
277 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000278 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500279}
280
Dean Troyer671c16e2012-12-13 16:22:38 -0600281# create_cinder_accounts() - Set up common required cinder accounts
282
283# Tenant User Roles
284# ------------------------------------------------------------------
285# service cinder admin # if enabled
286
287# Migrated from keystone_data.sh
288create_cinder_accounts() {
289
290 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
291 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
292
293 # Cinder
294 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
295 CINDER_USER=$(keystone user-create \
296 --name=cinder \
297 --pass="$SERVICE_PASSWORD" \
298 --tenant_id $SERVICE_TENANT \
299 --email=cinder@example.com \
300 | grep " id " | get_field 2)
301 keystone user-role-add \
302 --tenant_id $SERVICE_TENANT \
303 --user_id $CINDER_USER \
304 --role_id $ADMIN_ROLE
305 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
306 CINDER_SERVICE=$(keystone service-create \
307 --name=cinder \
308 --type=volume \
309 --description="Cinder Volume Service" \
310 | grep " id " | get_field 2)
311 keystone endpoint-create \
312 --region RegionOne \
313 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600314 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
315 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
316 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600317 fi
318 fi
319}
320
Dean Troyerf03bafe2013-02-12 10:58:28 -0600321# create_cinder_cache_dir() - Part of the init_cinder() process
322function create_cinder_cache_dir() {
323 # Create cache dir
324 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
325 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
326 rm -f $CINDER_AUTH_CACHE_DIR/*
327}
328
329create_cinder_volume_group() {
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100330 # According to the CINDER_MULTI_LVM_BACKEND value, configure one or two default volumes
331 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
332 # service if it (they) does (do) not yet exist. If you don't wish to use a
333 # file backed volume group, create your own volume group called ``stack-volumes``
334 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600335 #
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100336 # By default, the two backing files are 5G in size, and are stored in
337 # ``/opt/stack/data``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600338
339 if ! sudo vgs $VOLUME_GROUP; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100340 if [ -z "$VOLUME_BACKING_DEVICE" ]; then
341 # Only create if the file doesn't already exists
342 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
343 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyerf03bafe2013-02-12 10:58:28 -0600344
Mate Lakat68ac03c2013-06-06 16:22:34 +0100345 # Only create if the loopback device doesn't contain $VOLUME_GROUP
346 if ! sudo vgs $VOLUME_GROUP; then
347 sudo vgcreate $VOLUME_GROUP $DEV
348 fi
349 else
350 sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE
Dean Troyerf03bafe2013-02-12 10:58:28 -0600351 fi
352 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100353 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
354 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
355
356 if ! sudo vgs $VOLUME_GROUP2; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100357 if [ -z "$VOLUME_BACKING_DEVICE2" ]; then
358 # Only create if the file doesn't already exists
359 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100360
Mate Lakat68ac03c2013-06-06 16:22:34 +0100361 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100362
Mate Lakat68ac03c2013-06-06 16:22:34 +0100363 # Only create if the loopback device doesn't contain $VOLUME_GROUP
364 if ! sudo vgs $VOLUME_GROUP2; then
365 sudo vgcreate $VOLUME_GROUP2 $DEV
366 fi
367 else
368 sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100369 fi
370 fi
371 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600372
373 mkdir -p $CINDER_STATE_PATH/volumes
374}
375
Dean Troyer67787e62012-05-02 11:48:15 -0500376# init_cinder() - Initialize database and volume group
377function init_cinder() {
378 # Force nova volumes off
379 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
380
Terry Wilson428af5a2012-11-01 16:12:39 -0400381 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600382 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400383 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500384
Dean Troyerf03bafe2013-02-12 10:58:28 -0600385 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400386 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500387 fi
388
389 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500390
Dean Troyerf03bafe2013-02-12 10:58:28 -0600391 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500392
Dean Troyer67787e62012-05-02 11:48:15 -0500393 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100394 if is_fedora || is_suse; then
395 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200396 start_service tgtd
397 fi
398
Dean Troyer67787e62012-05-02 11:48:15 -0500399 # Remove iscsi targets
400 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 -0600401 # Start with a clean volume group
402 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100403 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
404 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
405 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500406 fi
407 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500408
Dean Troyerf03bafe2013-02-12 10:58:28 -0600409 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500410}
411
412# install_cinder() - Collect source and prepare
413function install_cinder() {
414 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400415 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500416}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400417
Dean Troyer253a1a32013-04-01 18:23:22 -0500418# install_cinderclient() - Collect source and prepare
419function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500420 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400421 setup_develop $CINDERCLIENT_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500422}
423
Steve Baker18225d92013-04-14 12:48:41 -0700424# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100425function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700426 if [[ ! -d /etc/tgt/stack.d/ ]]; then
427 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
428 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100429 fi
430}
431
Dean Troyer67787e62012-05-02 11:48:15 -0500432# start_cinder() - Start running processes, including screen
433function start_cinder() {
434 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700435 # Delete any old stack.conf
436 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100437 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100438 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500439 # tgt in oneiric doesn't restart properly if tgtd isn't running
440 # do it in two steps
441 sudo stop tgt || true
442 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100443 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500444 # bypass redirection to systemctl during restart
445 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100446 elif is_suse; then
447 restart_service tgtd
448 else
449 # note for other distros: unstack.sh also uses the tgt/tgtd service
450 # name, and would need to be adjusted too
451 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500452 fi
453 fi
454
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400455 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
456 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
457 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000458 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600459
460 # Start proxies if enabled
461 if is_service_enabled c-api && is_service_enabled tls-proxy; then
462 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
463 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500464}
465
Dean Troyer699a29f2012-09-10 14:10:27 -0500466# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500467function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500468 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000469 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500470 screen -S $SCREEN_NAME -p $serv -X kill
471 done
Dean Troyer67787e62012-05-02 11:48:15 -0500472
473 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100474 if is_ubuntu; then
475 stop_service tgt
476 else
477 stop_service tgtd
478 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500479 fi
480}
Dean Troyer7903b792012-09-13 17:16:12 -0500481
Dean Troyercc6b4432013-04-08 15:38:03 -0500482
Dean Troyer7903b792012-09-13 17:16:12 -0500483# Restore xtrace
484$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400485
486# Local variables:
487# mode: shell-script
488# End: