blob: 6636397e1818e1a992de5e6b821bd3d100bafa6f [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
70# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Dean Troyer67787e62012-05-02 11:48:15 -050071VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010072VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
Dean Troyer67787e62012-05-02 11:48:15 -050073VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
74
Dean Troyercc6b4432013-04-08 15:38:03 -050075
76# Functions
77# ---------
78
Dean Troyer22853c12013-01-07 15:18:12 -060079# _clean_volume_group removes all cinder volumes from the specified volume group
80# _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
81function _clean_volume_group() {
82 local vg=$1
83 local vg_prefix=$2
84 # Clean out existing volumes
85 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
86 # vg_prefix prefixes the LVs we want
87 if [[ "${lv#$vg_prefix}" != "$lv" ]]; then
88 sudo lvremove -f $vg/$lv
89 fi
90 done
91}
92
Dean Troyer67787e62012-05-02 11:48:15 -050093# cleanup_cinder() - Remove residual data files, anything left over from previous
94# runs that a clean run would need to clean up
95function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -050096 # ensure the volume group is cleared up because fails might
97 # leave dead volumes in the group
98 TARGETS=$(sudo tgtadm --op show --mode target)
99 if [ $? -ne 0 ]; then
100 # If tgt driver isn't running this won't work obviously
101 # So check the response and restart if need be
102 echo "tgtd seems to be in a bad state, restarting..."
103 if is_ubuntu; then
104 restart_service tgt
105 else
106 restart_service tgtd
107 fi
108 TARGETS=$(sudo tgtadm --op show --mode target)
109 fi
110
111 if [[ -n "$TARGETS" ]]; then
112 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
113 for i in "${iqn_list[@]}"; do
114 echo removing iSCSI target: $i
115 sudo tgt-admin --delete $i
116 done
117 fi
118
119 if is_service_enabled cinder; then
120 sudo rm -rf $CINDER_STATE_PATH/volumes/*
121 fi
122
123 if is_ubuntu; then
124 stop_service tgt
125 else
126 stop_service tgtd
127 fi
128
Dean Troyer22853c12013-01-07 15:18:12 -0600129 # Campsite rule: leave behind a volume group at least as clean as we found it
130 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100131 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
132 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
133 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500134}
135
136# configure_cinder() - Set config files, create data dirs, etc
137function configure_cinder() {
Dean Troyer67787e62012-05-02 11:48:15 -0500138 if [[ ! -d $CINDER_CONF_DIR ]]; then
139 sudo mkdir -p $CINDER_CONF_DIR
140 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100141 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500142
143 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
144
John Griffith4e823ff2012-07-20 13:18:17 -0600145 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100146 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600147
148 # If Cinder ships the new rootwrap filters files, deploy them
149 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
150 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
151 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
152 # Wipe any existing rootwrap.d files first
153 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
154 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
155 fi
156 # Deploy filters to /etc/cinder/rootwrap.d
157 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
158 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
159 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
160 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
161 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
162 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
163 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
164 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
165 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
166 # Specify rootwrap.conf as first parameter to cinder-rootwrap
167 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
168 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
169 fi
170
171 TEMPFILE=`mktemp`
172 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
173 chmod 0440 $TEMPFILE
174 sudo chown root:root $TEMPFILE
175 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
176
Dean Troyer67787e62012-05-02 11:48:15 -0500177 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
178 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
179 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
180 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
181 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
182 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
183 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900184 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500185
Dean Troyer67787e62012-05-02 11:48:15 -0500186 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
187 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000188 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500189 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100190 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
191 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
192 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
193 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
194 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
195 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
196 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200197 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100198 else
199 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
200 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
201 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500202 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100203 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500204 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800205 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500206 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500207 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400208 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600209
Dean Troyer560346b2012-12-13 17:05:24 -0600210 if is_service_enabled tls-proxy; then
211 # Set the service port for a proxy to take the original
212 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
213 fi
214
Dean Troyer4d3049e2012-11-06 20:38:14 -0600215 if [ "$SYSLOG" != "False" ]; then
216 iniset $CINDER_CONF DEFAULT use_syslog True
217 fi
218
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900219 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400220
James E. Blair213c4162012-11-06 09:38:36 +0100221 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
222 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000223 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100224 fi
225
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000226 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
227 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800228 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"
229 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 +0000230 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 -0800231 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 +0000232 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000233
234 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
235 (
236 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000237 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000238 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
239 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
240 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
241 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
242 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
243 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900244 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
245 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400246 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
247 # To use glusterfs, set the following in localrc:
248 # CINDER_DRIVER=glusterfs
249 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
250 # Shares are <host>:<volume> and separated by semicolons.
251
252 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
253 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
254 touch $CINDER_CONF_DIR/glusterfs_shares
255 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
256 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
257 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
258 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000259 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500260}
261
Dean Troyer671c16e2012-12-13 16:22:38 -0600262# create_cinder_accounts() - Set up common required cinder accounts
263
264# Tenant User Roles
265# ------------------------------------------------------------------
266# service cinder admin # if enabled
267
268# Migrated from keystone_data.sh
269create_cinder_accounts() {
270
271 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
272 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
273
274 # Cinder
275 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
276 CINDER_USER=$(keystone user-create \
277 --name=cinder \
278 --pass="$SERVICE_PASSWORD" \
279 --tenant_id $SERVICE_TENANT \
280 --email=cinder@example.com \
281 | grep " id " | get_field 2)
282 keystone user-role-add \
283 --tenant_id $SERVICE_TENANT \
284 --user_id $CINDER_USER \
285 --role_id $ADMIN_ROLE
286 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
287 CINDER_SERVICE=$(keystone service-create \
288 --name=cinder \
289 --type=volume \
290 --description="Cinder Volume Service" \
291 | grep " id " | get_field 2)
292 keystone endpoint-create \
293 --region RegionOne \
294 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600295 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
296 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
297 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600298 fi
299 fi
300}
301
Dean Troyerf03bafe2013-02-12 10:58:28 -0600302# create_cinder_cache_dir() - Part of the init_cinder() process
303function create_cinder_cache_dir() {
304 # Create cache dir
305 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
306 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
307 rm -f $CINDER_AUTH_CACHE_DIR/*
308}
309
310create_cinder_volume_group() {
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100311 # According to the CINDER_MULTI_LVM_BACKEND value, configure one or two default volumes
312 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
313 # service if it (they) does (do) not yet exist. If you don't wish to use a
314 # file backed volume group, create your own volume group called ``stack-volumes``
315 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600316 #
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100317 # By default, the two backing files are 5G in size, and are stored in
318 # ``/opt/stack/data``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600319
320 if ! sudo vgs $VOLUME_GROUP; then
321 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
322
323 # Only create if the file doesn't already exists
324 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
325
326 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
327
328 # Only create if the loopback device doesn't contain $VOLUME_GROUP
329 if ! sudo vgs $VOLUME_GROUP; then
330 sudo vgcreate $VOLUME_GROUP $DEV
331 fi
332 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100333 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
334 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
335
336 if ! sudo vgs $VOLUME_GROUP2; then
337 VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
338
339 # Only create if the file doesn't already exists
340 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
341
342 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
343
344 # Only create if the loopback device doesn't contain $VOLUME_GROUP
345 if ! sudo vgs $VOLUME_GROUP2; then
346 sudo vgcreate $VOLUME_GROUP2 $DEV
347 fi
348 fi
349 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600350
351 mkdir -p $CINDER_STATE_PATH/volumes
352}
353
Dean Troyer67787e62012-05-02 11:48:15 -0500354# init_cinder() - Initialize database and volume group
355function init_cinder() {
356 # Force nova volumes off
357 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
358
Terry Wilson428af5a2012-11-01 16:12:39 -0400359 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600360 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400361 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500362
Dean Troyerf03bafe2013-02-12 10:58:28 -0600363 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400364 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500365 fi
366
367 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500368
Dean Troyerf03bafe2013-02-12 10:58:28 -0600369 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500370
Dean Troyer67787e62012-05-02 11:48:15 -0500371 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100372 if is_fedora || is_suse; then
373 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200374 start_service tgtd
375 fi
376
Dean Troyer67787e62012-05-02 11:48:15 -0500377 # Remove iscsi targets
378 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 -0600379 # Start with a clean volume group
380 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100381 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
382 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
383 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500384 fi
385 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500386
Dean Troyerf03bafe2013-02-12 10:58:28 -0600387 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500388}
389
390# install_cinder() - Collect source and prepare
391function install_cinder() {
392 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400393 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500394}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400395
Dean Troyer253a1a32013-04-01 18:23:22 -0500396# install_cinderclient() - Collect source and prepare
397function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500398 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400399 setup_develop $CINDERCLIENT_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500400}
401
Steve Baker18225d92013-04-14 12:48:41 -0700402# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100403function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700404 if [[ ! -d /etc/tgt/stack.d/ ]]; then
405 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
406 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100407 fi
408}
409
Dean Troyer67787e62012-05-02 11:48:15 -0500410# start_cinder() - Start running processes, including screen
411function start_cinder() {
412 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700413 # Delete any old stack.conf
414 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100415 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100416 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500417 # tgt in oneiric doesn't restart properly if tgtd isn't running
418 # do it in two steps
419 sudo stop tgt || true
420 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100421 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500422 # bypass redirection to systemctl during restart
423 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100424 elif is_suse; then
425 restart_service tgtd
426 else
427 # note for other distros: unstack.sh also uses the tgt/tgtd service
428 # name, and would need to be adjusted too
429 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500430 fi
431 fi
432
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400433 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
434 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
435 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000436 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600437
438 # Start proxies if enabled
439 if is_service_enabled c-api && is_service_enabled tls-proxy; then
440 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
441 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500442}
443
Dean Troyer699a29f2012-09-10 14:10:27 -0500444# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500445function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500446 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000447 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500448 screen -S $SCREEN_NAME -p $serv -X kill
449 done
Dean Troyer67787e62012-05-02 11:48:15 -0500450
451 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100452 if is_ubuntu; then
453 stop_service tgt
454 else
455 stop_service tgtd
456 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500457 fi
458}
Dean Troyer7903b792012-09-13 17:16:12 -0500459
Dean Troyercc6b4432013-04-08 15:38:03 -0500460
Dean Troyer7903b792012-09-13 17:16:12 -0500461# Restore xtrace
462$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400463
464# Local variables:
465# mode: shell-script
466# End: