Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #!/bin/bash -ex
  2.  
  3. if [ "$RS_REBOOT" == "true" ];then
  4. echo "rebooting, skipping script."
  5. exit 0
  6. fi
  7.  
  8. volume_name="Follower-$RS_INSTANCE_UUID"
  9.  
  10. #volume_type=$VOLUME_TYPE
  11. rsc_cmd='sudo /home/rightlink/rsc --rl10 cm15'
  12. rsc_json_cmd="/home/rightlink/rsc"
  13.  
  14. #get the current instance values
  15. instance=`$rsc_cmd index_instance_session /api/sessions/instance`
  16. instance_href=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json`
  17. cloud_id=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json | cut -d '/' -f 4`
  18. #cloud_id=`$rsc_cmd --x1 ':has(.rel:val("cloud")).href' index_instance_session /api/sessions/instance | cut -d '/' -f 4`
  19. datacenter_href=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("datacenter")).href' json`
  20.  
  21. #volume_type_href_command="$rsc_cmd --x1 \ ':has(.rel:val("self")).href' \
  22. #$index /api/clouds/$cloud_id/volume_types \ "filter[]=name==${volume_type}""
  23. #$volume_type_href=`$volume_type_href_cmd`
  24.  
  25. #create the new volume
  26. echo "Creating volume: $volume_name."
  27. $rsc_cmd create /api/clouds/$cloud_id/volumes \
  28. "volume[name]=$volume_name" \
  29. "volume[size]=$VOLUME_SIZE"
  30. # "volume[datacenter_href]=$datacenter_href"
  31. # "volume[volume_type_href]=$volume_type_href"
  32. volume=`$rsc_cmd index /api/clouds/$cloud_id/volumes "filter[]=name==$volume_name"`
  33. volume_status=`echo $volume | $rsc_json_cmd --x1 .status json`
  34.  
  35. #wait for volume to becaome available
  36. while [ "$volume_status" != "available" ];do
  37. sleep 5
  38. echo "Getting volume status"
  39. volume=`$rsc_cmd index /api/clouds/$cloud_id/volumes "filter[]=name==$volume_name"`
  40. volume_status=`echo $volume | $rsc_json_cmd --x1 .status json`
  41. done
  42.  
  43. # get volume_href from the last volumes request
  44. volume_href=`echo $volume | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json`
  45.  
  46. # attach the volume to instance
  47. echo "Attaching volume: $volume_name to $instance_href"
  48. $rsc_cmd create /api/clouds/$cloud_id/volume_attachments \
  49. "volume_attachment[instance_href]=$instance_href" \
  50. "volume_attachment[volume_href]=$volume_href" \
  51. "volume_attachment[device]=/dev/vdc"
  52.  
  53. echo "Volume $volume_name created and attached."
  54.  
  55. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement