blob: 17005af4319f845689a322063c8d7654ecc10071 [file] [log] [blame]
Dean Troyer67787e62012-05-02 11:48:15 -05001# lib/cinder
2# Install and start Cinder volume service
3
4# Dependencies:
5# - functions
Dean Troyer50ac7922012-09-13 14:02:01 -05006# - DEST, DATA_DIR 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
40# Support entry points installation of console scripts
41if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040042 CINDER_BIN_DIR=$CINDER_DIR/bin
43else
44 CINDER_BIN_DIR=/usr/local/bin
45fi
Dean Troyer67787e62012-05-02 11:48:15 -050046
47# Name of the lvm volume group to use/create for iscsi volumes
48VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
49VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
50
51# cleanup_cinder() - Remove residual data files, anything left over from previous
52# runs that a clean run would need to clean up
53function cleanup_cinder() {
54 # This function intentionally left blank
55 :
56}
57
58# configure_cinder() - Set config files, create data dirs, etc
59function configure_cinder() {
60 setup_develop $CINDER_DIR
61 setup_develop $CINDERCLIENT_DIR
62
63 if [[ ! -d $CINDER_CONF_DIR ]]; then
64 sudo mkdir -p $CINDER_CONF_DIR
65 fi
66 sudo chown `whoami` $CINDER_CONF_DIR
67
68 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
69
John Griffith4e823ff2012-07-20 13:18:17 -060070 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +010071 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -060072
73 # If Cinder ships the new rootwrap filters files, deploy them
74 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
75 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
76 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
77 # Wipe any existing rootwrap.d files first
78 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
79 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
80 fi
81 # Deploy filters to /etc/cinder/rootwrap.d
82 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
83 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
84 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
85 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
86 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
87 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
88 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
89 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
90 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
91 # Specify rootwrap.conf as first parameter to cinder-rootwrap
92 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
93 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
94 fi
95
96 TEMPFILE=`mktemp`
97 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
98 chmod 0440 $TEMPFILE
99 sudo chown root:root $TEMPFILE
100 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
101
Dean Troyer67787e62012-05-02 11:48:15 -0500102 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
103 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
104 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
105 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
106 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
107 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
108 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900109 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500110
Dean Troyer67787e62012-05-02 11:48:15 -0500111 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
112 iniset $CINDER_CONF DEFAULT auth_strategy keystone
113 iniset $CINDER_CONF DEFAULT verbose True
114 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
115 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
116 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Terry Wilson428af5a2012-11-01 16:12:39 -0400117 local dburl
118 database_connection_url dburl cinder
119 iniset $CINDER_CONF DEFAULT sql_connection $dburl
Dean Troyer67787e62012-05-02 11:48:15 -0500120 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
John Griffith4e823ff2012-07-20 13:18:17 -0600121 iniset $CINDER_CONF DEFAULT root_helper "sudo ${CINDER_ROOTWRAP}"
John Griffith43bedda2012-08-21 15:26:15 -0600122 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.openstack.volume.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500123 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
John Griffith4e823ff2012-07-20 13:18:17 -0600124
Dean Troyer4d3049e2012-11-06 20:38:14 -0600125 if [ "$SYSLOG" != "False" ]; then
126 iniset $CINDER_CONF DEFAULT use_syslog True
127 fi
128
Gary Kottonf71bf192012-08-06 11:15:36 -0400129 if is_service_enabled qpid ; then
130 iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid
ewindisch3bae7c22012-01-18 11:18:35 -0500131 elif is_service_enabled zeromq; then
132 iniset $CINDER_CONF DEFAULT rpc_backend nova.openstack.common.rpc.impl_zmq
Gary Kottonf71bf192012-08-06 11:15:36 -0400133 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
134 iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
135 iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
136 fi
137
James E. Blair213c4162012-11-06 09:38:36 +0100138 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
139 iniset $CINDER_CONF DEFAULT secure_delete False
140 fi
141
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000142 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
143 # Add color to logging output
144 iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [%(request_id)s %(user_id)s %(project_id)s%(color)s] %(instance)s%(color)s%(message)s"
145 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
146 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
147 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s TRACE %(name)s %(instance)s"
148 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000149
150 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
151 (
152 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000153 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000154 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
155 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
156 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
157 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
158 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
159 )
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000160 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500161}
162
Dean Troyer671c16e2012-12-13 16:22:38 -0600163# create_cinder_accounts() - Set up common required cinder accounts
164
165# Tenant User Roles
166# ------------------------------------------------------------------
167# service cinder admin # if enabled
168
169# Migrated from keystone_data.sh
170create_cinder_accounts() {
171
172 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
173 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
174
175 # Cinder
176 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
177 CINDER_USER=$(keystone user-create \
178 --name=cinder \
179 --pass="$SERVICE_PASSWORD" \
180 --tenant_id $SERVICE_TENANT \
181 --email=cinder@example.com \
182 | grep " id " | get_field 2)
183 keystone user-role-add \
184 --tenant_id $SERVICE_TENANT \
185 --user_id $CINDER_USER \
186 --role_id $ADMIN_ROLE
187 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
188 CINDER_SERVICE=$(keystone service-create \
189 --name=cinder \
190 --type=volume \
191 --description="Cinder Volume Service" \
192 | grep " id " | get_field 2)
193 keystone endpoint-create \
194 --region RegionOne \
195 --service_id $CINDER_SERVICE \
196 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
197 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
198 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
199 fi
200 fi
201}
202
Dean Troyer67787e62012-05-02 11:48:15 -0500203# init_cinder() - Initialize database and volume group
204function init_cinder() {
205 # Force nova volumes off
206 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
207
Terry Wilson428af5a2012-11-01 16:12:39 -0400208 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyer67787e62012-05-02 11:48:15 -0500209 # (re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400210 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500211
212 # (re)create cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400213 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500214 fi
215
216 if is_service_enabled c-vol; then
217 # Configure a default volume group called '`stack-volumes`' for the volume
218 # service if it does not yet exist. If you don't wish to use a file backed
219 # volume group, create your own volume group called ``stack-volumes`` before
220 # invoking ``stack.sh``.
221 #
Eoghan Glynn9cb17762012-07-15 10:22:45 +0100222 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
Dean Troyer67787e62012-05-02 11:48:15 -0500223
224 if ! sudo vgs $VOLUME_GROUP; then
225 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Dean Troyer67787e62012-05-02 11:48:15 -0500226 # Only create if the file doesn't already exists
227 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
228 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
229 # Only create if the loopback device doesn't contain $VOLUME_GROUP
230 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
231 fi
232
Dean Troyer50ac7922012-09-13 14:02:01 -0500233 mkdir -p $CINDER_STATE_PATH/volumes
Chuck Short3f603d92012-07-28 13:28:33 -0500234
Dean Troyer67787e62012-05-02 11:48:15 -0500235 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100236 if is_fedora || is_suse; then
237 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200238 start_service tgtd
239 fi
240
Dean Troyer67787e62012-05-02 11:48:15 -0500241 # Remove iscsi targets
242 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
243 # Clean out existing volumes
244 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
245 # VOLUME_NAME_PREFIX prefixes the LVs we want
246 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
247 sudo lvremove -f $VOLUME_GROUP/$lv
248 fi
249 done
250 fi
251 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500252
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900253 # Create cache dir
254 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
255 sudo chown `whoami` $CINDER_AUTH_CACHE_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500256}
257
258# install_cinder() - Collect source and prepare
259function install_cinder() {
260 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
261 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
262}
263
Mate Lakata39caac2012-09-03 15:45:53 +0100264# apply config.d approach (e.g. Oneiric does not have this)
265function _configure_tgt_for_config_d() {
266 if [[ ! -d /etc/tgt/conf.d/ ]]; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100267 sudo mkdir -p /etc/tgt/conf.d
Mate Lakata39caac2012-09-03 15:45:53 +0100268 echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
269 fi
270}
271
Dean Troyer67787e62012-05-02 11:48:15 -0500272# start_cinder() - Start running processes, including screen
273function start_cinder() {
274 if is_service_enabled c-vol; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100275 _configure_tgt_for_config_d
276 if [[ ! -f /etc/tgt/conf.d/stack.conf ]]; then
277 echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/stack.conf
278 fi
Vincent Untzc18b9652012-12-04 12:36:34 +0100279 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500280 # tgt in oneiric doesn't restart properly if tgtd isn't running
281 # do it in two steps
282 sudo stop tgt || true
283 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100284 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500285 # bypass redirection to systemctl during restart
286 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100287 elif is_suse; then
288 restart_service tgtd
289 else
290 # note for other distros: unstack.sh also uses the tgt/tgtd service
291 # name, and would need to be adjusted too
292 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500293 fi
294 fi
295
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400296 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
297 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
298 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Dean Troyer67787e62012-05-02 11:48:15 -0500299}
300
Dean Troyer699a29f2012-09-10 14:10:27 -0500301# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500302function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500303 # Kill the cinder screen windows
304 for serv in c-api c-sch c-vol; do
305 screen -S $SCREEN_NAME -p $serv -X kill
306 done
Dean Troyer67787e62012-05-02 11:48:15 -0500307
308 if is_service_enabled c-vol; then
309 stop_service tgt
310 fi
311}
Dean Troyer7903b792012-09-13 17:16:12 -0500312
313# Restore xtrace
314$XTRACE