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