blob: 30be0cdd680010c0278fbe856272214873f0bec0 [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
6# - KEYSTONE_AUTH_* must be defined
7# SERVICE_{TENANT_NAME|PASSWORD} must be defined
8
9# stack.sh
10# ---------
11# install_nvol
12# configure_nvol
13# init_nvol
14# start_nvol
15# stop_nvol
16# cleanup_nvol
17
18# Print the commands being run so that we can see the command that triggers
19# an error. It is also useful for following along as the install occurs.
20set -o xtrace
21
22
23# Defaults
24# --------
25
26# Name of the LVM volume group to use/create for iscsi volumes
27VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
28VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
29
30
31# cleanup_nvol() - Remove residual data files, anything left over from previous
32# runs that a clean run would need to clean up
33function cleanup_nvol() {
34 # kill instances (nova)
35 # delete image files (glance)
36 # This function intentionally left blank
37 :
38}
39
40# configure_nvol() - Set config files, create data dirs, etc
41function configure_nvol() {
42 # sudo python setup.py deploy
43 # iniset $XXX_CONF ...
44 # This function intentionally left blank
45 :
46}
47
48# init_nvol() - Initialize databases, etc.
49function init_nvol() {
50 # Configure a default volume group called '`stack-volumes`' for the volume
51 # service if it does not yet exist. If you don't wish to use a file backed
52 # volume group, create your own volume group called ``stack-volumes`` before
53 # invoking ``stack.sh``.
54 #
55 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
56
57 if ! sudo vgs $VOLUME_GROUP; then
58 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
59 # Only create if the file doesn't already exists
60 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
61 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
62 # Only create if the loopback device doesn't contain $VOLUME_GROUP
63 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
64 fi
65
66 mkdir -p $NOVA_DIR/volumes
67
68 if sudo vgs $VOLUME_GROUP; then
69 if [[ "$os_PACKAGE" = "rpm" ]]; then
70 # RPM doesn't start the service
71 start_service tgtd
72 fi
73
74 # Remove nova iscsi targets
75 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
76 # Clean out existing volumes
77 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
78 # ``VOLUME_NAME_PREFIX`` prefixes the LVs we want
79 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
80 sudo lvremove -f $VOLUME_GROUP/$lv
81 fi
82 done
83 fi
84}
85
86# install_nvol() - Collect source and prepare
87function install_nvol() {
88 # git clone xxx
89 # Install is handled when installing Nova
90 :
91}
92
93# start_nvol() - Start running processes, including screen
94function start_nvol() {
95 # Setup the tgt configuration file
96 if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
97 sudo mkdir -p /etc/tgt/conf.d
98 echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
99 fi
100
101 if [[ "$os_PACKAGE" = "deb" ]]; then
102 # tgt in oneiric doesn't restart properly if tgtd isn't running
103 # do it in two steps
104 sudo stop tgt || true
105 sudo start tgt
106 else
107 restart_service tgtd
108 fi
109
110 screen_it n-vol "cd $NOVA_DIR && $NOVA_DIR/bin/nova-volume"
111}
112
113# stop_nvol() - Stop running processes (non-screen)
114function stop_nvol() {
115 # FIXME(dtroyer): stop only the n-vol screen window?
116
117 stop_service tgt
118}