~openstack-charm-testers/+junk/swift-rings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash -eu
RES="\033[0m"
F_GRN="\033[32m"
ZONES=(1 2 3)
CMDS=()

trap 'exit' SIGINT SIGKILL

if (($#<1)) || [ -z "$1" ] || [ $1 != 'attach' ] && [ $1 != 'detach' ]; then
    echo "REQUIRED: action [attach|detach]"
    exit 1
fi
ACTION="$1"
shift
read -a DEVS <<< $@
# NOTE: /dev/vda and /dev/vdb are normally already taken
((${#DEVS[@]})) || DEVS=(c d)

# Create some cinder volumes and attach them to each swift-storage-z* unit

for z in ${ZONES[@]}; do
    vm=`juju status swift-storage-z$z| grep instance-id| awk '{print $2}'`
    # NOTE: /dev/vdb is normally already set so add it
    devs=( /dev/vdb )
    for dev in ${DEVS[@]}; do
        devs+=( /dev/vd$dev )
        name=swift-z$z-vd$dev
        if [ $ACTION = "attach" ]; then
            if ! `cinder list| grep -q $name`; then
                cinder create 20 --display-name $name
            fi
            id=`cinder list| grep $name| awk '{print $2}'`
            nova volume-attach $vm $id /dev/vd$dev
            sleep 1
            juju ssh swift-storage-z$z/0 sudo mkfs.ext4 /dev/vd$dev
        elif [ $ACTION = "detach" ]; then
            id=`cinder list| grep $name| awk '{print $2}'`
            nova volume-detach $vm $id || true
            cinder delete $id || true
        fi        
        cinder list
    done

    if [ $ACTION = "attach" ]; then    
        devs="${devs[@]}"
        CMDS+=( "${F_GRN}juju set swift-storage-z$z block-device=\"$devs\"${RES}" )
    fi
done

echo -e "\nNow execute the following to update swift-storage config:"
for cmd in "${CMDS[@]}"; do
    echo -e $cmd
done