Created
January 29, 2019 22:08
-
-
Save twwlogin/f483aca706376f08f799db7a61335979 to your computer and use it in GitHub Desktop.
Wait for volume to be converted in AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/create-ami.sh b/create-ami.sh | |
index 63349ca..05b614a 100755 | |
--- a/create-ami.sh | |
+++ b/create-ami.sh | |
@@ -182,6 +191,19 @@ volume_ids() { | |
python2.7 -c 'from __future__ import print_function;import sys,json; [print(task["ImportVolume"]["Volume"]["Id"]) if "Id" in task["ImportVolume"]["Volume"] else None for task in json.load(sys.stdin)["ConversionTasks"]]' | |
} | |
+volume_state() { | |
+ local _VOL=$1 | |
+ | |
+ aws --region ${AWS_REGION} --output json ec2 describe-conversion-tasks | \ | |
+ python2.7 -c 'from __future__ import print_function;import sys,json; [print(task["ImportVolume"]["Volume"]["Id"],task["State"]) if "Id" in task["ImportVolume"]["Volume"] else None for task in json.load(sys.stdin)["ConversionTasks"]]' | grep "${_VOL}" | awk '{print $NF}' | |
+} | |
+ | |
+volume_progress() { | |
+ local _VOL=$1 | |
+ aws --region ${AWS_REGION} --output json ec2 describe-conversion-tasks | \ | |
+ python2.7 -c 'from __future__ import print_function;import sys,json; [print(task["ImportVolume"]["Volume"]["Id"],task["StatusMessage"]) if ("Id" in task["ImportVolume"]["Volume"] and "StatusMessage" in task) else None for task in json.load(sys.stdin)["ConversionTasks"]]' | grep "${_VOL}" | awk '{print $2,$3}' | |
+} | |
+ | |
create_ami() { | |
local _IMGNAME=${_IMG##*/} | |
local _BUCKETNAME=${_IMGNAME} | |
@@ -227,6 +249,15 @@ create_ami() { | |
_VOL=$(for _v in ${_VOLIDS_NEW}; do echo "${_VOLIDS}" | fgrep -q $_v || | |
echo $_v; done) | |
+ pr_action "waiting for completed conversion of volume for ${_VOL}" | |
+ while /usr/bin/true; do | |
+ _STATE="$(volume_state ${_VOL})" | |
+ [ "${_STATE}" = "completed" ] && break | |
+ [ "${_STATE}" = "active" ] && _PROGRESS="$(volume_progress ${_VOL})" | |
+ [ -n "${_PROGRESS}" ] && echo "${_PROGRESS}" | |
+ sleep 10 | |
+ done | |
+ | |
# XXX | |
#echo | |
#echo "deleting local and remote disk images" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment