blob: ef3bd81a1f1cbfc49c91fdfecc2d9a00f55d39ed [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 Troyercc6b4432013-04-08 15:38:03 -050082
83# Functions
84# ---------
JordanP022e9912013-07-09 14:14:48 +020085# _clean_lvm_lv removes all cinder LVM volumes
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010086#
87# Usage: _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
JordanP022e9912013-07-09 14:14:48 +020088function _clean_lvm_lv() {
Dean Troyer22853c12013-01-07 15:18:12 -060089 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +020090 local lv_prefix=$2
91
Dean Troyer22853c12013-01-07 15:18:12 -060092 # Clean out existing volumes
93 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +020094 # lv_prefix prefixes the LVs we want
95 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -060096 sudo lvremove -f $vg/$lv
97 fi
98 done
JordanP022e9912013-07-09 14:14:48 +020099}
100
101# _clean_lvm_backing_file() removes the backing file of the
102# volume group used by cinder
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100103#
104# Usage: _clean_lvm_backing_file() $VOLUME_GROUP
JordanP022e9912013-07-09 14:14:48 +0200105function _clean_lvm_backing_file() {
106 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +0200107
108 # if there is no logical volume left, it's safe to attempt a cleanup
109 # of the backing file
110 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
111 # if the backing physical device is a loop device, it was probably setup by devstack
112 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
113 if [[ -n "$VG_DEV" ]]; then
114 sudo losetup -d $VG_DEV
115 rm -f $DATA_DIR/${vg}-backing-file
116 fi
117 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600118}
119
Dean Troyer67787e62012-05-02 11:48:15 -0500120# cleanup_cinder() - Remove residual data files, anything left over from previous
121# runs that a clean run would need to clean up
122function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -0500123 # ensure the volume group is cleared up because fails might
124 # leave dead volumes in the group
125 TARGETS=$(sudo tgtadm --op show --mode target)
126 if [ $? -ne 0 ]; then
127 # If tgt driver isn't running this won't work obviously
128 # So check the response and restart if need be
129 echo "tgtd seems to be in a bad state, restarting..."
130 if is_ubuntu; then
131 restart_service tgt
132 else
133 restart_service tgtd
134 fi
135 TARGETS=$(sudo tgtadm --op show --mode target)
136 fi
137
138 if [[ -n "$TARGETS" ]]; then
139 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
140 for i in "${iqn_list[@]}"; do
141 echo removing iSCSI target: $i
142 sudo tgt-admin --delete $i
143 done
144 fi
145
146 if is_service_enabled cinder; then
147 sudo rm -rf $CINDER_STATE_PATH/volumes/*
148 fi
149
150 if is_ubuntu; then
151 stop_service tgt
152 else
153 stop_service tgtd
154 fi
155
Dean Troyer22853c12013-01-07 15:18:12 -0600156 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP022e9912013-07-09 14:14:48 +0200157 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
158 _clean_lvm_backing_file $VOLUME_GROUP
JordanP51c90b82013-05-23 10:27:51 +0200159
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100160 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200161 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
162 _clean_lvm_backing_file $VOLUME_GROUP2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100163 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500164}
165
166# configure_cinder() - Set config files, create data dirs, etc
167function configure_cinder() {
Dean Troyer67787e62012-05-02 11:48:15 -0500168 if [[ ! -d $CINDER_CONF_DIR ]]; then
169 sudo mkdir -p $CINDER_CONF_DIR
170 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100171 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500172
173 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
174
John Griffith4e823ff2012-07-20 13:18:17 -0600175 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100176 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600177
178 # If Cinder ships the new rootwrap filters files, deploy them
179 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
180 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
181 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
182 # Wipe any existing rootwrap.d files first
183 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
184 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
185 fi
186 # Deploy filters to /etc/cinder/rootwrap.d
187 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
188 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
189 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
190 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
191 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
192 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
193 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
194 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
195 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
196 # Specify rootwrap.conf as first parameter to cinder-rootwrap
197 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
198 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
199 fi
200
201 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100202 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
John Griffith4e823ff2012-07-20 13:18:17 -0600203 chmod 0440 $TEMPFILE
204 sudo chown root:root $TEMPFILE
205 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
206
Dean Troyer67787e62012-05-02 11:48:15 -0500207 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
Dan Prince82dea7c2013-10-16 18:57:15 -0400208
209 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
210 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
211 inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000212 inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
Dan Prince82dea7c2013-10-16 18:57:15 -0400213 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
214 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
215 inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
216 inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
Dean Troyerbc071bc2012-10-01 14:06:44 -0500217
Dean Troyer67787e62012-05-02 11:48:15 -0500218 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
Dan Prince82dea7c2013-10-16 18:57:15 -0400219
220 iniset $CINDER_CONF keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
221 iniset $CINDER_CONF keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
222 iniset $CINDER_CONF keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000223 iniset $CINDER_CONF keystone_authtoken cafile $KEYSTONE_SSL_CA
Dan Prince82dea7c2013-10-16 18:57:15 -0400224 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
225 iniset $CINDER_CONF keystone_authtoken admin_user cinder
226 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
227 iniset $CINDER_CONF keystone_authtoken signing_dir $CINDER_AUTH_CACHE_DIR
228
Dean Troyer67787e62012-05-02 11:48:15 -0500229 iniset $CINDER_CONF DEFAULT auth_strategy keystone
Ben Nemec03997942013-08-10 09:56:16 -0500230 iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Dean Troyer67787e62012-05-02 11:48:15 -0500231 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100232 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
233 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
234 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
235 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
236 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
237 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
238 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200239 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Matt Riedemann7103a842013-12-07 13:53:33 -0800240 # NOTE(mriedem): Work around Cinder "wishlist" bug 1255593
241 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
242 iniset $CINDER_CONF lvmdriver-1 volume_clear none
243 iniset $CINDER_CONF lvmdriver-2 volume_clear none
244 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100245 else
246 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
247 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
248 fi
Nikolay Sobolevskiy08df29b2013-08-30 21:59:15 +0400249 iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST"
Dean Troyer67787e62012-05-02 11:48:15 -0500250 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100251 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500252 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800253 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500254 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500255 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sergey Kraynev84783c72013-10-10 09:08:48 -0400256 iniset $CINDER_CONF DEFAULT lock_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400257 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600258
Gordon Chung2bfbc772013-08-09 10:55:12 -0400259 if is_service_enabled ceilometer; then
260 iniset $CINDER_CONF DEFAULT notification_driver "cinder.openstack.common.notifier.rpc_notifier"
261 fi
262
Dean Troyer560346b2012-12-13 17:05:24 -0600263 if is_service_enabled tls-proxy; then
264 # Set the service port for a proxy to take the original
265 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
266 fi
267
Dean Troyer4d3049e2012-11-06 20:38:14 -0600268 if [ "$SYSLOG" != "False" ]; then
269 iniset $CINDER_CONF DEFAULT use_syslog True
270 fi
271
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900272 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400273
James E. Blair213c4162012-11-06 09:38:36 +0100274 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
275 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000276 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100277 fi
278
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700279 # Format logging
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000280 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700281 setup_colorized_logging $CINDER_CONF DEFAULT "project_id" "user_id"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000282 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000283
284 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
285 (
286 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000287 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000288 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
289 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
290 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
291 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
292 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
293 )
Mehdi Abaakoukae9c4172013-03-07 15:23:46 +0000294 elif [ "$CINDER_DRIVER" == "nfs" ]; then
295 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.nfs.NfsDriver"
296 iniset $CINDER_CONF DEFAULT nfs_shares_config "$CINDER_CONF_DIR/nfs_shares.conf"
297 echo "$CINDER_NFS_SERVERPATH" | sudo tee "$CINDER_CONF_DIR/nfs_shares.conf"
298 sudo chmod 666 $CINDER_CONF_DIR/nfs_shares.conf
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900299 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
300 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400301 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
302 # To use glusterfs, set the following in localrc:
303 # CINDER_DRIVER=glusterfs
304 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
305 # Shares are <host>:<volume> and separated by semicolons.
306
307 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
308 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
309 touch $CINDER_CONF_DIR/glusterfs_shares
310 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
311 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
312 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
313 fi
Gary Kottonc3252272013-08-13 00:32:20 -0700314 elif [ "$CINDER_DRIVER" == "vsphere" ]; then
315 echo_summary "Using VMware vCenter driver"
Gary Kottondc4f2342013-08-19 23:46:17 -0700316 iniset $CINDER_CONF DEFAULT vmware_host_ip "$VMWAREAPI_IP"
317 iniset $CINDER_CONF DEFAULT vmware_host_username "$VMWAREAPI_USER"
318 iniset $CINDER_CONF DEFAULT vmware_host_password "$VMWAREAPI_PASSWORD"
Gary Kottondc4f2342013-08-19 23:46:17 -0700319 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000320 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000321
322 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
323 # Cinder clones are slightly larger due to some extra
324 # metadata. RHEL6 will not allow auto-extending of LV's
325 # without this, leading to clones giving hard-to-track disk
326 # I/O errors.
327 # see https://bugzilla.redhat.com/show_bug.cgi?id=975052
328 sudo sed -i~ \
329 -e 's/snapshot_autoextend_threshold =.*/snapshot_autoextend_threshold = 80/' \
330 -e 's/snapshot_autoextend_percent =.*/snapshot_autoextend_percent = 20/' \
331 /etc/lvm/lvm.conf
332 fi
stackcf2d0d32013-08-05 04:51:56 -0400333 iniset $CINDER_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT
334 iniset $CINDER_CONF keystone_authtoken admin_user cinder
335 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
336 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Ian Wienand0db17132013-06-26 22:31:48 +1000337
Dean Troyer67787e62012-05-02 11:48:15 -0500338}
339
Dean Troyer671c16e2012-12-13 16:22:38 -0600340# create_cinder_accounts() - Set up common required cinder accounts
341
342# Tenant User Roles
343# ------------------------------------------------------------------
344# service cinder admin # if enabled
345
346# Migrated from keystone_data.sh
347create_cinder_accounts() {
348
349 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
350 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
351
352 # Cinder
353 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
354 CINDER_USER=$(keystone user-create \
355 --name=cinder \
356 --pass="$SERVICE_PASSWORD" \
357 --tenant_id $SERVICE_TENANT \
358 --email=cinder@example.com \
359 | grep " id " | get_field 2)
360 keystone user-role-add \
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200361 --tenant-id $SERVICE_TENANT \
362 --user-id $CINDER_USER \
363 --role-id $ADMIN_ROLE
Dean Troyer671c16e2012-12-13 16:22:38 -0600364 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
365 CINDER_SERVICE=$(keystone service-create \
366 --name=cinder \
367 --type=volume \
368 --description="Cinder Volume Service" \
369 | grep " id " | get_field 2)
370 keystone endpoint-create \
371 --region RegionOne \
372 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600373 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
374 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
375 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Mike Perezb3862f92013-02-12 02:16:41 -0800376 CINDER_V2_SERVICE=$(keystone service-create \
377 --name=cinder \
378 --type=volumev2 \
379 --description="Cinder Volume Service V2" \
380 | grep " id " | get_field 2)
381 keystone endpoint-create \
382 --region RegionOne \
383 --service_id $CINDER_V2_SERVICE \
384 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
385 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
386 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
387
Dean Troyer671c16e2012-12-13 16:22:38 -0600388 fi
389 fi
390}
391
Dean Troyerf03bafe2013-02-12 10:58:28 -0600392# create_cinder_cache_dir() - Part of the init_cinder() process
393function create_cinder_cache_dir() {
394 # Create cache dir
395 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
396 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
397 rm -f $CINDER_AUTH_CACHE_DIR/*
398}
399
400create_cinder_volume_group() {
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200401 # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100402 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
403 # service if it (they) does (do) not yet exist. If you don't wish to use a
404 # file backed volume group, create your own volume group called ``stack-volumes``
405 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600406 #
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200407 # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in
408 # the ``DATA_DIR``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600409
410 if ! sudo vgs $VOLUME_GROUP; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100411 if [ -z "$VOLUME_BACKING_DEVICE" ]; then
412 # Only create if the file doesn't already exists
413 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
414 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyerf03bafe2013-02-12 10:58:28 -0600415
Mate Lakat68ac03c2013-06-06 16:22:34 +0100416 # Only create if the loopback device doesn't contain $VOLUME_GROUP
417 if ! sudo vgs $VOLUME_GROUP; then
418 sudo vgcreate $VOLUME_GROUP $DEV
419 fi
420 else
421 sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE
Dean Troyerf03bafe2013-02-12 10:58:28 -0600422 fi
423 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100424 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
425 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
426
427 if ! sudo vgs $VOLUME_GROUP2; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100428 if [ -z "$VOLUME_BACKING_DEVICE2" ]; then
429 # Only create if the file doesn't already exists
430 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100431
Mate Lakat68ac03c2013-06-06 16:22:34 +0100432 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100433
Mate Lakat68ac03c2013-06-06 16:22:34 +0100434 # Only create if the loopback device doesn't contain $VOLUME_GROUP
435 if ! sudo vgs $VOLUME_GROUP2; then
436 sudo vgcreate $VOLUME_GROUP2 $DEV
437 fi
438 else
439 sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100440 fi
441 fi
442 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600443
444 mkdir -p $CINDER_STATE_PATH/volumes
445}
446
Dean Troyer67787e62012-05-02 11:48:15 -0500447# init_cinder() - Initialize database and volume group
448function init_cinder() {
449 # Force nova volumes off
450 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
451
Terry Wilson428af5a2012-11-01 16:12:39 -0400452 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600453 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400454 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500455
Dean Troyerf03bafe2013-02-12 10:58:28 -0600456 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400457 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500458 fi
459
460 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500461
Dean Troyerf03bafe2013-02-12 10:58:28 -0600462 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500463
Dean Troyer67787e62012-05-02 11:48:15 -0500464 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100465 if is_fedora || is_suse; then
466 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200467 start_service tgtd
468 fi
469
Dean Troyer67787e62012-05-02 11:48:15 -0500470 # Remove iscsi targets
471 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 -0600472 # Start with a clean volume group
JordanP022e9912013-07-09 14:14:48 +0200473 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100474 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200475 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100476 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500477 fi
478 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500479
Dean Troyerf03bafe2013-02-12 10:58:28 -0600480 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500481}
482
483# install_cinder() - Collect source and prepare
484function install_cinder() {
485 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400486 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500487}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400488
Dean Troyer253a1a32013-04-01 18:23:22 -0500489# install_cinderclient() - Collect source and prepare
490function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500491 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400492 setup_develop $CINDERCLIENT_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200493 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 -0500494}
495
Steve Baker18225d92013-04-14 12:48:41 -0700496# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100497function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700498 if [[ ! -d /etc/tgt/stack.d/ ]]; then
499 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
500 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100501 fi
502}
503
Dean Troyer67787e62012-05-02 11:48:15 -0500504# start_cinder() - Start running processes, including screen
505function start_cinder() {
506 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700507 # Delete any old stack.conf
508 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100509 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100510 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500511 # tgt in oneiric doesn't restart properly if tgtd isn't running
512 # do it in two steps
513 sudo stop tgt || true
514 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100515 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500516 # bypass redirection to systemctl during restart
517 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100518 elif is_suse; then
519 restart_service tgtd
520 else
521 # note for other distros: unstack.sh also uses the tgt/tgtd service
522 # name, and would need to be adjusted too
523 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500524 fi
Giulio Fidente384454d2013-09-27 13:17:34 +0200525 # NOTE(gfidente): ensure tgtd is running in debug mode
526 sudo tgtadm --mode system --op update --name debug --value on
Dean Troyer67787e62012-05-02 11:48:15 -0500527 fi
528
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400529 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400530 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000531 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600532 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
533
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 Troyer560346b2012-12-13 17:05:24 -0600537
538 # Start proxies if enabled
539 if is_service_enabled c-api && is_service_enabled tls-proxy; then
540 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
541 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500542}
543
Dean Troyer699a29f2012-09-10 14:10:27 -0500544# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500545function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500546 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000547 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500548 screen -S $SCREEN_NAME -p $serv -X kill
549 done
Dean Troyer67787e62012-05-02 11:48:15 -0500550
551 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100552 if is_ubuntu; then
553 stop_service tgt
554 else
555 stop_service tgtd
556 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500557 fi
558}
Dean Troyer7903b792012-09-13 17:16:12 -0500559
Dean Troyercc6b4432013-04-08 15:38:03 -0500560
Dean Troyer7903b792012-09-13 17:16:12 -0500561# Restore xtrace
562$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400563
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100564# Tell emacs to use shell-script-mode
565## Local variables:
566## mode: shell-script
567## End: