Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # We expect pool mappings such as
- # "//host/share=pool0,//host/share2=pool1"
- raw_mappings=$1
- new_hostname=$2
- new_backendname=$3
- db_host=$4
- db_user=$5
- db_pass=$6
- debug_only=$7
- if [[ $# -lt 6 ]]; then
- echo "Usage: $0 pool_mappings new_cinder_hostname new_backendname db_host db_user db_pass <debug_only>"
- echo "Example: $0 '//sofs/share1=pool1,//sofs/share2=pool2' cinderhost cinderbackend dbhost dbuser dbpass true"
- exit 1
- fi
- declare -A pool_mappings
- for mapping in $(echo $raw_mappings | tr ',' '\n'); do
- pattern="(.*)=(.*)"
- if [[ $mapping =~ $pattern ]]; then
- share=${BASH_REMATCH[1]}
- pool=${BASH_REMATCH[2]}
- pool_mappings[$share]="$pool"
- else
- echo "Invalid pool mappings: $raw_mappings"
- echo "$mapping"
- exit 1
- fi
- done
- for share in ${!pool_mappings[@]}; do
- pool=${pool_mappings[$share]}
- new_host="$new_hostname@$new_backendname#$pool"
- echo "Executing: update volumes set host="$new_host" where provider_location="$share""
- dbg=$(echo $debug_only | grep -iE "true|y|yes|debug")
- if [[ -z $dbg ]]; then
- mysql --host=$db_host --user=$db_user --password=$db_pass cinder << EOF
- update volumes set host="$new_host" where provider_location="$share"
- EOF
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement