#!/bin/bash
# add devices (drives) to swift rings
# http://wikitech.wikimedia.org/view/Swift/How_To#Add_a_device_.28drive.29_to_a_ring
# dzahn - 20120307
declare -a devices=({c..l})
declare -a rings=( account container object)
read -p "Which zone to add to?" zone
# zone=5
read -p "Weight to use? (100 for 2TB drives)" weight
# weight=100
myIP=$(ip a s eth0 | grep -o
"[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | head -n1)
builder=$(which swift-ring-builder)
for ring in "${rings[@]}" ; do
case "$ring" in
object) myPort=6000;;
container) myPort=6001;;
account) myPort=6002;;
esac
for device in "${devices[@]}" ; do
# $builder /etc/swift/${ring}.builder add
z${zone}-${myIP}:${myPort}/sd${device}1 ${weight}
echo "$builder /etc/swift/${ring}.builder add
z${zone}-${myIP}:${myPort}/sd${device}1 ${weight}"
done
$builder /etc/swift/${ring}.builder search ${myIP}
done