blob: b7f765b3918e1a40e642256c5f268f22922c2955 [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# ---------
JordanP022e9912013-07-09 14:14:48 +020084# _clean_lvm_lv removes all cinder LVM volumes
85# _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
86function _clean_lvm_lv() {
Dean Troyer22853c12013-01-07 15:18:12 -060087 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +020088 local lv_prefix=$2
89
Dean Troyer22853c12013-01-07 15:18:12 -060090 # Clean out existing volumes
91 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +020092 # lv_prefix prefixes the LVs we want
93 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -060094 sudo lvremove -f $vg/$lv
95 fi
96 done
JordanP022e9912013-07-09 14:14:48 +020097}
98
99# _clean_lvm_backing_file() removes the backing file of the
100# volume group used by cinder
101# _clean_lvm_backing_file() $VOLUME_GROUP
102function _clean_lvm_backing_file() {
103 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +0200104
105 # if there is no logical volume left, it's safe to attempt a cleanup
106 # of the backing file
107 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
108 # if the backing physical device is a loop device, it was probably setup by devstack
109 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
110 if [[ -n "$VG_DEV" ]]; then
111 sudo losetup -d $VG_DEV
112 rm -f $DATA_DIR/${vg}-backing-file
113 fi
114 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600115}
116
Dean Troyer67787e62012-05-02 11:48:15 -0500117# cleanup_cinder() - Remove residual data files, anything left over from previous
118# runs that a clean run would need to clean up
119function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -0500120 # ensure the volume group is cleared up because fails might
121 # leave dead volumes in the group
122 TARGETS=$(sudo tgtadm --op show --mode target)
123 if [ $? -ne 0 ]; then
124 # If tgt driver isn't running this won't work obviously
125 # So check the response and restart if need be
126 echo "tgtd seems to be in a bad state, restarting..."
127 if is_ubuntu; then
128 restart_service tgt
129 else
130 restart_service tgtd
131 fi
132 TARGETS=$(sudo tgtadm --op show --mode target)
133 fi
134
135 if [[ -n "$TARGETS" ]]; then
136 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
137 for i in "${iqn_list[@]}"; do
138 echo removing iSCSI target: $i
139 sudo tgt-admin --delete $i
140 done
141 fi
142
143 if is_service_enabled cinder; then
144 sudo rm -rf $CINDER_STATE_PATH/volumes/*
145 fi
146
147 if is_ubuntu; then
148 stop_service tgt
149 else
150 stop_service tgtd
151 fi
152
Dean Troyer22853c12013-01-07 15:18:12 -0600153 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP022e9912013-07-09 14:14:48 +0200154 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
155 _clean_lvm_backing_file $VOLUME_GROUP
JordanP51c90b82013-05-23 10:27:51 +0200156
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100157 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200158 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
159 _clean_lvm_backing_file $VOLUME_GROUP2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100160 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500161}
162
163# configure_cinder() - Set config files, create data dirs, etc
164function configure_cinder() {
Dean Troyer67787e62012-05-02 11:48:15 -0500165 if [[ ! -d $CINDER_CONF_DIR ]]; then
166 sudo mkdir -p $CINDER_CONF_DIR
167 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100168 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500169
170 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
171
John Griffith4e823ff2012-07-20 13:18:17 -0600172 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100173 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600174
175 # If Cinder ships the new rootwrap filters files, deploy them
176 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
177 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
178 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
179 # Wipe any existing rootwrap.d files first
180 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
181 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
182 fi
183 # Deploy filters to /etc/cinder/rootwrap.d
184 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
185 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
186 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
187 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
188 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
189 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
190 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
191 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
192 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
193 # Specify rootwrap.conf as first parameter to cinder-rootwrap
194 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
195 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
196 fi
197
198 TEMPFILE=`mktemp`
199 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
200 chmod 0440 $TEMPFILE
201 sudo chown root:root $TEMPFILE
202 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
203
Dean Troyer67787e62012-05-02 11:48:15 -0500204 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
205 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
206 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
207 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
208 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
209 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
210 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900211 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500212
Dean Troyer67787e62012-05-02 11:48:15 -0500213 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
214 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000215 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500216 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100217 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
218 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
219 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
220 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
221 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
222 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
223 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
Giulio Fidente97e1bd02013-06-04 05:33:52 +0200224 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100225 else
226 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
227 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
228 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500229 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100230 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500231 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800232 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500233 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500234 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400235 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600236
Gordon Chung2bfbc772013-08-09 10:55:12 -0400237 if is_service_enabled ceilometer; then
238 iniset $CINDER_CONF DEFAULT notification_driver "cinder.openstack.common.notifier.rpc_notifier"
239 fi
240
Dean Troyer560346b2012-12-13 17:05:24 -0600241 if is_service_enabled tls-proxy; then
242 # Set the service port for a proxy to take the original
243 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
244 fi
245
Dean Troyer4d3049e2012-11-06 20:38:14 -0600246 if [ "$SYSLOG" != "False" ]; then
247 iniset $CINDER_CONF DEFAULT use_syslog True
248 fi
249
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900250 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400251
James E. Blair213c4162012-11-06 09:38:36 +0100252 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
253 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000254 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100255 fi
256
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000257 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
258 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800259 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"
260 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 +0000261 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 -0800262 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 +0000263 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000264
265 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
266 (
267 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000268 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000269 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
270 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
271 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
272 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
273 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
274 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900275 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
276 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400277 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
278 # To use glusterfs, set the following in localrc:
279 # CINDER_DRIVER=glusterfs
280 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
281 # Shares are <host>:<volume> and separated by semicolons.
282
283 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
284 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
285 touch $CINDER_CONF_DIR/glusterfs_shares
286 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
287 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
288 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
289 fi
Gary Kottonc3252272013-08-13 00:32:20 -0700290 elif [ "$CINDER_DRIVER" == "vsphere" ]; then
291 echo_summary "Using VMware vCenter driver"
292 iniset $CINDER_CONF DEFAULT enabled_backends vmware
293 iniset $CINDER_CONF vmware host_ip "$VMWAREAPI_IP"
294 iniset $CINDER_CONF vmware host_username "$VMWAREAPI_USER"
295 iniset $CINDER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
296 iniset $CINDER_CONF vmware cluster_name "$VMWAREAPI_CLUSTER"
297 iniset $CINDER_CONF vmware volume_driver "cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000298 fi
Ian Wienand0db17132013-06-26 22:31:48 +1000299
300 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
301 # Cinder clones are slightly larger due to some extra
302 # metadata. RHEL6 will not allow auto-extending of LV's
303 # without this, leading to clones giving hard-to-track disk
304 # I/O errors.
305 # see https://bugzilla.redhat.com/show_bug.cgi?id=975052
306 sudo sed -i~ \
307 -e 's/snapshot_autoextend_threshold =.*/snapshot_autoextend_threshold = 80/' \
308 -e 's/snapshot_autoextend_percent =.*/snapshot_autoextend_percent = 20/' \
309 /etc/lvm/lvm.conf
310 fi
stackcf2d0d32013-08-05 04:51:56 -0400311 iniset $CINDER_CONF keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT
312 iniset $CINDER_CONF keystone_authtoken admin_user cinder
313 iniset $CINDER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
314 iniset $CINDER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
Ian Wienand0db17132013-06-26 22:31:48 +1000315
Dean Troyer67787e62012-05-02 11:48:15 -0500316}
317
Dean Troyer671c16e2012-12-13 16:22:38 -0600318# create_cinder_accounts() - Set up common required cinder accounts
319
320# Tenant User Roles
321# ------------------------------------------------------------------
322# service cinder admin # if enabled
323
324# Migrated from keystone_data.sh
325create_cinder_accounts() {
326
327 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
328 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
329
330 # Cinder
331 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
332 CINDER_USER=$(keystone user-create \
333 --name=cinder \
334 --pass="$SERVICE_PASSWORD" \
335 --tenant_id $SERVICE_TENANT \
336 --email=cinder@example.com \
337 | grep " id " | get_field 2)
338 keystone user-role-add \
339 --tenant_id $SERVICE_TENANT \
340 --user_id $CINDER_USER \
341 --role_id $ADMIN_ROLE
342 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
343 CINDER_SERVICE=$(keystone service-create \
344 --name=cinder \
345 --type=volume \
346 --description="Cinder Volume Service" \
347 | grep " id " | get_field 2)
348 keystone endpoint-create \
349 --region RegionOne \
350 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600351 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
352 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
353 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600354 fi
355 fi
356}
357
Dean Troyerf03bafe2013-02-12 10:58:28 -0600358# create_cinder_cache_dir() - Part of the init_cinder() process
359function create_cinder_cache_dir() {
360 # Create cache dir
361 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
362 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
363 rm -f $CINDER_AUTH_CACHE_DIR/*
364}
365
366create_cinder_volume_group() {
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200367 # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100368 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
369 # service if it (they) does (do) not yet exist. If you don't wish to use a
370 # file backed volume group, create your own volume group called ``stack-volumes``
371 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600372 #
Attila Fazekasa6ed3dc2013-07-01 22:49:31 +0200373 # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in
374 # the ``DATA_DIR``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600375
376 if ! sudo vgs $VOLUME_GROUP; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100377 if [ -z "$VOLUME_BACKING_DEVICE" ]; then
378 # Only create if the file doesn't already exists
379 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
380 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
Dean Troyerf03bafe2013-02-12 10:58:28 -0600381
Mate Lakat68ac03c2013-06-06 16:22:34 +0100382 # Only create if the loopback device doesn't contain $VOLUME_GROUP
383 if ! sudo vgs $VOLUME_GROUP; then
384 sudo vgcreate $VOLUME_GROUP $DEV
385 fi
386 else
387 sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE
Dean Troyerf03bafe2013-02-12 10:58:28 -0600388 fi
389 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100390 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
391 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
392
393 if ! sudo vgs $VOLUME_GROUP2; then
Mate Lakat68ac03c2013-06-06 16:22:34 +0100394 if [ -z "$VOLUME_BACKING_DEVICE2" ]; then
395 # Only create if the file doesn't already exists
396 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100397
Mate Lakat68ac03c2013-06-06 16:22:34 +0100398 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100399
Mate Lakat68ac03c2013-06-06 16:22:34 +0100400 # Only create if the loopback device doesn't contain $VOLUME_GROUP
401 if ! sudo vgs $VOLUME_GROUP2; then
402 sudo vgcreate $VOLUME_GROUP2 $DEV
403 fi
404 else
405 sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100406 fi
407 fi
408 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600409
410 mkdir -p $CINDER_STATE_PATH/volumes
411}
412
Dean Troyer67787e62012-05-02 11:48:15 -0500413# init_cinder() - Initialize database and volume group
414function init_cinder() {
415 # Force nova volumes off
416 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
417
Terry Wilson428af5a2012-11-01 16:12:39 -0400418 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600419 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400420 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500421
Dean Troyerf03bafe2013-02-12 10:58:28 -0600422 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400423 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500424 fi
425
426 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500427
Dean Troyerf03bafe2013-02-12 10:58:28 -0600428 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500429
Dean Troyer67787e62012-05-02 11:48:15 -0500430 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100431 if is_fedora || is_suse; then
432 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200433 start_service tgtd
434 fi
435
Dean Troyer67787e62012-05-02 11:48:15 -0500436 # Remove iscsi targets
437 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 -0600438 # Start with a clean volume group
JordanP022e9912013-07-09 14:14:48 +0200439 _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100440 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP022e9912013-07-09 14:14:48 +0200441 _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100442 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500443 fi
444 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500445
Dean Troyerf03bafe2013-02-12 10:58:28 -0600446 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500447}
448
449# install_cinder() - Collect source and prepare
450function install_cinder() {
451 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400452 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500453}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400454
Dean Troyer253a1a32013-04-01 18:23:22 -0500455# install_cinderclient() - Collect source and prepare
456function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500457 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400458 setup_develop $CINDERCLIENT_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500459}
460
Steve Baker18225d92013-04-14 12:48:41 -0700461# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100462function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700463 if [[ ! -d /etc/tgt/stack.d/ ]]; then
464 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
465 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100466 fi
467}
468
Dean Troyer67787e62012-05-02 11:48:15 -0500469# start_cinder() - Start running processes, including screen
470function start_cinder() {
471 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700472 # Delete any old stack.conf
473 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100474 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100475 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500476 # tgt in oneiric doesn't restart properly if tgtd isn't running
477 # do it in two steps
478 sudo stop tgt || true
479 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100480 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500481 # bypass redirection to systemctl during restart
482 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100483 elif is_suse; then
484 restart_service tgtd
485 else
486 # note for other distros: unstack.sh also uses the tgt/tgtd service
487 # name, and would need to be adjusted too
488 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500489 fi
490 fi
491
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400492 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400493 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000494 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
John Griffithe6d4fe52013-07-15 17:35:54 -0600495 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
496
497 # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
498 # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
499 # has started. This is a quick fix for lp bug/1189595
Dean Troyer560346b2012-12-13 17:05:24 -0600500
501 # Start proxies if enabled
502 if is_service_enabled c-api && is_service_enabled tls-proxy; then
503 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
504 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500505}
506
Dean Troyer699a29f2012-09-10 14:10:27 -0500507# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500508function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500509 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000510 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500511 screen -S $SCREEN_NAME -p $serv -X kill
512 done
Dean Troyer67787e62012-05-02 11:48:15 -0500513
514 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100515 if is_ubuntu; then
516 stop_service tgt
517 else
518 stop_service tgtd
519 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500520 fi
521}
Dean Troyer7903b792012-09-13 17:16:12 -0500522
Dean Troyercc6b4432013-04-08 15:38:03 -0500523
Dean Troyer7903b792012-09-13 17:16:12 -0500524# Restore xtrace
525$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400526
527# Local variables:
528# mode: shell-script
529# End: