Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -ex
- if [ "$RS_REBOOT" == "true" ];then
- echo "rebooting, skipping script."
- exit 0
- fi
- volume_name="Follower-$RS_INSTANCE_UUID"
- #volume_type=$VOLUME_TYPE
- rsc_cmd='sudo /home/rightlink/rsc --rl10 cm15'
- rsc_json_cmd="/home/rightlink/rsc"
- #get the current instance values
- instance=`$rsc_cmd index_instance_session /api/sessions/instance`
- instance_href=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json`
- cloud_id=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json | cut -d '/' -f 4`
- #cloud_id=`$rsc_cmd --x1 ':has(.rel:val("cloud")).href' index_instance_session /api/sessions/instance | cut -d '/' -f 4`
- datacenter_href=`echo $instance | $rsc_json_cmd --x1 ':has(.rel:val("datacenter")).href' json`
- #volume_type_href_command="$rsc_cmd --x1 \ ':has(.rel:val("self")).href' \
- #$index /api/clouds/$cloud_id/volume_types \ "filter[]=name==${volume_type}""
- #$volume_type_href=`$volume_type_href_cmd`
- #create the new volume
- echo "Creating volume: $volume_name."
- $rsc_cmd create /api/clouds/$cloud_id/volumes \
- "volume[name]=$volume_name" \
- "volume[size]=$VOLUME_SIZE"
- # "volume[datacenter_href]=$datacenter_href"
- # "volume[volume_type_href]=$volume_type_href"
- volume=`$rsc_cmd index /api/clouds/$cloud_id/volumes "filter[]=name==$volume_name"`
- volume_status=`echo $volume | $rsc_json_cmd --x1 .status json`
- #wait for volume to becaome available
- while [ "$volume_status" != "available" ];do
- sleep 5
- echo "Getting volume status"
- volume=`$rsc_cmd index /api/clouds/$cloud_id/volumes "filter[]=name==$volume_name"`
- volume_status=`echo $volume | $rsc_json_cmd --x1 .status json`
- done
- # get volume_href from the last volumes request
- volume_href=`echo $volume | $rsc_json_cmd --x1 ':has(.rel:val("self")).href' json`
- # attach the volume to instance
- echo "Attaching volume: $volume_name to $instance_href"
- $rsc_cmd create /api/clouds/$cloud_id/volume_attachments \
- "volume_attachment[instance_href]=$instance_href" \
- "volume_attachment[volume_href]=$volume_href" \
- "volume_attachment[device]=/dev/vdc"
- echo "Volume $volume_name created and attached."
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement