blob: db53582b45b28cb66373c05bb9858d58624bcabd [file] [log] [blame]
Dean Troyer5bf7d5c2012-08-17 13:12:38 -05001# lib/n-vol
2# Install and start Nova volume service
3
4# Dependencies:
5# - functions
Dean Troyer50ac7922012-09-13 14:02:01 -05006# - DATA_DIR must be defined
Dean Troyer5bf7d5c2012-08-17 13:12:38 -05007# - KEYSTONE_AUTH_* must be defined
Dean Troyer50ac7922012-09-13 14:02:01 -05008# - NOVA_DIR, NOVA_BIN_DIR, NOVA_STATE_PATH must be defined
Dean Troyer5bf7d5c2012-08-17 13:12:38 -05009# SERVICE_{TENANT_NAME|PASSWORD} must be defined
Mate Lakata39caac2012-09-03 15:45:53 +010010# _configure_tgt_for_config_d() from lib/cinder
Dean Troyer5bf7d5c2012-08-17 13:12:38 -050011
12# stack.sh
13# ---------
14# install_nvol
15# configure_nvol
16# init_nvol
17# start_nvol
18# stop_nvol
19# cleanup_nvol
20
Dean Troyer7903b792012-09-13 17:16:12 -050021# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
Dean Troyer5bf7d5c2012-08-17 13:12:38 -050024
25
26# Defaults
27# --------
28
29# Name of the LVM volume group to use/create for iscsi volumes
30VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
31VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
32
33
34# cleanup_nvol() - Remove residual data files, anything left over from previous
35# runs that a clean run would need to clean up
36function cleanup_nvol() {
37 # kill instances (nova)
38 # delete image files (glance)
39 # This function intentionally left blank
40 :
41}
42
43# configure_nvol() - Set config files, create data dirs, etc
44function configure_nvol() {
45 # sudo python setup.py deploy
46 # iniset $XXX_CONF ...
47 # This function intentionally left blank
48 :
49}
50
51# init_nvol() - Initialize databases, etc.
52function init_nvol() {
53 # Configure a default volume group called '`stack-volumes`' for the volume
54 # service if it does not yet exist. If you don't wish to use a file backed
55 # volume group, create your own volume group called ``stack-volumes`` before
56 # invoking ``stack.sh``.
57 #
58 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
59
60 if ! sudo vgs $VOLUME_GROUP; then
61 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
62 # Only create if the file doesn't already exists
63 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
64 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
65 # Only create if the loopback device doesn't contain $VOLUME_GROUP
66 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
67 fi
68
Dean Troyer50ac7922012-09-13 14:02:01 -050069 mkdir -p $NOVA_STATE_PATH/volumes
Dean Troyer5bf7d5c2012-08-17 13:12:38 -050070
71 if sudo vgs $VOLUME_GROUP; then
72 if [[ "$os_PACKAGE" = "rpm" ]]; then
73 # RPM doesn't start the service
74 start_service tgtd
75 fi
76
77 # Remove nova iscsi targets
78 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
79 # Clean out existing volumes
80 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
81 # ``VOLUME_NAME_PREFIX`` prefixes the LVs we want
82 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
83 sudo lvremove -f $VOLUME_GROUP/$lv
84 fi
85 done
86 fi
87}
88
89# install_nvol() - Collect source and prepare
90function install_nvol() {
91 # git clone xxx
92 # Install is handled when installing Nova
93 :
94}
95
96# start_nvol() - Start running processes, including screen
97function start_nvol() {
98 # Setup the tgt configuration file
99 if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
Mate Lakata39caac2012-09-03 15:45:53 +0100100 _configure_tgt_for_config_d
Dean Troyer5bf7d5c2012-08-17 13:12:38 -0500101 sudo mkdir -p /etc/tgt/conf.d
Dean Troyer50ac7922012-09-13 14:02:01 -0500102 echo "include $NOVA_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
Dean Troyer5bf7d5c2012-08-17 13:12:38 -0500103 fi
104
105 if [[ "$os_PACKAGE" = "deb" ]]; then
106 # tgt in oneiric doesn't restart properly if tgtd isn't running
107 # do it in two steps
108 sudo stop tgt || true
109 sudo start tgt
110 else
111 restart_service tgtd
112 fi
113
Dean Troyer50ac7922012-09-13 14:02:01 -0500114 screen_it n-vol "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-volume"
Dean Troyer5bf7d5c2012-08-17 13:12:38 -0500115}
116
Dean Troyer699a29f2012-09-10 14:10:27 -0500117# stop_nvol() - Stop running processes
Dean Troyer5bf7d5c2012-08-17 13:12:38 -0500118function stop_nvol() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500119 # Kill the nova volume screen window
120 screen -S $SCREEN_NAME -p n-vol -X kill
Dean Troyer5bf7d5c2012-08-17 13:12:38 -0500121
122 stop_service tgt
123}
Dean Troyer7903b792012-09-13 17:16:12 -0500124
125# Restore xtrace
126$XTRACE