User:Dzahn/swift-add

From Wikitech
< User:Dzahn(Difference between revisions)
Jump to: navigation, search
(temp paste)
 
(some tweaks)
Line 1: Line 1:
<pre>
+
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 
# add devices (drives) to swift rings
 
# add devices (drives) to swift rings
Line 5: Line 5:
 
# dzahn - 20120307
 
# dzahn - 20120307
  
declare -a devices=({c..l})
+
 
 +
DRY_RUN=1
 +
 
 +
# uncomment set -x to watch what's executed as it runs
 +
#set -x
 +
 
 +
declare -a devices=({c..l}) #(upper bound is letter l not # 1!)
 
declare -a rings=( account container object)
 
declare -a rings=( account container object)
  
 
read -p "Which zone to add to?" zone
 
read -p "Which zone to add to?" zone
 
# zone=5
 
# zone=5
read -p "Weight to use? (100 for 2TB drives)" weight
+
read -p "Weight to use? (100 for 2TB drives; scale up or down linearly)" weight
 
# weight=100
 
# 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)
+
myIP="$(ip addr show eth0 | awk '/ inet /{split($2,A,"/"); print A[1]; q}')"
  
 
builder=$(which swift-ring-builder)
 
builder=$(which swift-ring-builder)
Line 26: Line 32:
  
 
         for device in "${devices[@]}" ; do
 
         for device in "${devices[@]}" ; do
                 # $builder /etc/swift/${ring}.builder add z${zone}-${myIP}:${myPort}/sd${device}1 ${weight}
+
                 cmd=($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}"
+
                 if [ "${DRY_RUN}" -ge 1 ]; then
 +
                        printf '%s ' "${cmd[@]}" | perl -pe 'chomp;s/\s*$/\n/;' # echo can eat some params; printf is more generic/covers corner cases
 +
                else
 +
                        "${cmd[@]}"
 +
                fi
 +
                       
 
         done
 
         done
  
         $builder /etc/swift/${ring}.builder search ${myIP}
+
         if [ ! "${DRY_RUN}" -ge 1 ]; then
        $builder /etc/swift/${ring}.builder rebalance
+
                $builder /etc/swift/${ring}.builder search "${myIP}"
 +
                $builder /etc/swift/${ring}.builder rebalance
 +
        fi
 
done
 
done
</pre>
+
</syntaxhighlight>

Revision as of 07:19, 7 March 2012

#!/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
 
 
DRY_RUN=1
 
# uncomment set -x to watch what's executed as it runs
#set -x
 
declare -a devices=({c..l}) #(upper bound is letter l not # 1!)
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; scale up or down linearly)" weight
# weight=100
myIP="$(ip addr show eth0 | awk '/ inet /{split($2,A,"/"); print A[1]; q}')"
 
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
                cmd=($builder /etc/swift/${ring}.builder add "z${zone}-${myIP}:${myPort}/sd${device}1" "${weight}")
                if [ "${DRY_RUN}" -ge 1 ]; then
                        printf '%s ' "${cmd[@]}" | perl -pe 'chomp;s/\s*$/\n/;' # echo can eat some params; printf is more generic/covers corner cases
                else
                        "${cmd[@]}"
                fi
 
        done
 
        if [ ! "${DRY_RUN}" -ge 1 ]; then
                $builder /etc/swift/${ring}.builder search "${myIP}"
                $builder /etc/swift/${ring}.builder rebalance
        fi
done
Personal tools
Namespaces

Variants
Actions
Navigation
Ops documentation
Wiki
Toolbox