Advertisement
Guest User

Untitled

a guest
Dec 20th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # We expect pool mappings such as
  4. # "//host/share=pool0,//host/share2=pool1"
  5. raw_mappings=$1
  6. new_hostname=$2
  7. new_backendname=$3
  8. db_host=$4
  9. db_user=$5
  10. db_pass=$6
  11. debug_only=$7
  12.  
  13. if [[ $# -lt 6 ]]; then
  14.    echo "Usage: $0 pool_mappings new_cinder_hostname new_backendname db_host db_user db_pass <debug_only>"
  15.    echo "Example: $0 '//sofs/share1=pool1,//sofs/share2=pool2' cinderhost cinderbackend dbhost dbuser dbpass true"
  16.    exit 1
  17. fi
  18.  
  19. declare -A pool_mappings
  20.  
  21. for mapping in $(echo $raw_mappings | tr ',' '\n'); do
  22.     pattern="(.*)=(.*)"
  23.     if [[ $mapping =~ $pattern ]]; then
  24.         share=${BASH_REMATCH[1]}
  25.         pool=${BASH_REMATCH[2]}
  26.         pool_mappings[$share]="$pool"
  27.     else
  28.         echo "Invalid pool mappings: $raw_mappings"
  29.         echo "$mapping"
  30.         exit 1
  31.     fi
  32. done
  33.  
  34. for share in ${!pool_mappings[@]}; do
  35.     pool=${pool_mappings[$share]}
  36.     new_host="$new_hostname@$new_backendname#$pool"
  37.  
  38.     echo "Executing: update volumes set host="$new_host" where provider_location="$share""
  39.  
  40.     dbg=$(echo $debug_only | grep -iE "true|y|yes|debug")
  41.     if [[ -z $dbg ]]; then
  42.         mysql --host=$db_host --user=$db_user --password=$db_pass cinder << EOF
  43. update volumes set host="$new_host" where provider_location="$share"
  44.  
  45. EOF
  46.     fi
  47. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement