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 |
Dean Troyer | 50ac792 | 2012-09-13 14:02:01 -0500 | [diff] [blame] | 6 | # - DATA_DIR must be defined |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 7 | # - KEYSTONE_AUTH_* must be defined |
Dean Troyer | 50ac792 | 2012-09-13 14:02:01 -0500 | [diff] [blame] | 8 | # - NOVA_DIR, NOVA_BIN_DIR, NOVA_STATE_PATH must be defined |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 9 | # SERVICE_{TENANT_NAME|PASSWORD} must be defined |
Mate Lakat | a39caac | 2012-09-03 15:45:53 +0100 | [diff] [blame] | 10 | # _configure_tgt_for_config_d() from lib/cinder |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 11 | |
| 12 | # stack.sh |
| 13 | # --------- |
| 14 | # install_nvol |
| 15 | # configure_nvol |
| 16 | # init_nvol |
| 17 | # start_nvol |
| 18 | # stop_nvol |
| 19 | # cleanup_nvol |
| 20 | |
Dean Troyer | 7903b79 | 2012-09-13 17:16:12 -0500 | [diff] [blame] | 21 | # Save trace setting |
| 22 | XTRACE=$(set +o | grep xtrace) |
| 23 | set +o xtrace |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 24 | |
| 25 | |
| 26 | # Defaults |
| 27 | # -------- |
| 28 | |
| 29 | # Name of the LVM volume group to use/create for iscsi volumes |
| 30 | VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes} |
| 31 | VOLUME_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 |
| 36 | function 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 |
| 44 | function 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. |
| 52 | function 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 Troyer | 50ac792 | 2012-09-13 14:02:01 -0500 | [diff] [blame] | 69 | mkdir -p $NOVA_STATE_PATH/volumes |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 70 | |
| 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 |
| 90 | function install_nvol() { |
| 91 | # git clone xxx |
| 92 | # Install is handled when installing Nova |
| 93 | : |
| 94 | } |
| 95 | |
| 96 | # start_nvol() - Start running processes, including screen |
| 97 | function start_nvol() { |
| 98 | # Setup the tgt configuration file |
| 99 | if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then |
Mate Lakat | a39caac | 2012-09-03 15:45:53 +0100 | [diff] [blame] | 100 | _configure_tgt_for_config_d |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 101 | sudo mkdir -p /etc/tgt/conf.d |
Dean Troyer | 50ac792 | 2012-09-13 14:02:01 -0500 | [diff] [blame] | 102 | echo "include $NOVA_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 103 | 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 Troyer | 50ac792 | 2012-09-13 14:02:01 -0500 | [diff] [blame] | 114 | screen_it n-vol "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-volume" |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 115 | } |
| 116 | |
Dean Troyer | 699a29f | 2012-09-10 14:10:27 -0500 | [diff] [blame] | 117 | # stop_nvol() - Stop running processes |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 118 | function stop_nvol() { |
Dean Troyer | 699a29f | 2012-09-10 14:10:27 -0500 | [diff] [blame] | 119 | # Kill the nova volume screen window |
| 120 | screen -S $SCREEN_NAME -p n-vol -X kill |
Dean Troyer | 5bf7d5c | 2012-08-17 13:12:38 -0500 | [diff] [blame] | 121 | |
| 122 | stop_service tgt |
| 123 | } |
Dean Troyer | 7903b79 | 2012-09-13 17:16:12 -0500 | [diff] [blame] | 124 | |
| 125 | # Restore xtrace |
| 126 | $XTRACE |