Skip to content
Snippets Groups Projects
Commit d7c0330f authored by Dmitry Fleytman's avatar Dmitry Fleytman Committed by Pekka Enberg
Browse files

release-ec2: Make replicated AMIs public

There is a bug in AWS engine making copied public AMIs invisible.
This patch implements a work-around for this problem as described at
https://forums.aws.amazon.com/thread.jspa?messageID=454676&#454676



Signed-off-by: default avatarDmitry Fleytman <dmitry@daynix.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent d9d3a7c4
No related branches found
No related tags found
No related merge requests found
...@@ -194,7 +194,9 @@ get_volume_state() { ...@@ -194,7 +194,9 @@ get_volume_state() {
get_ami_state() { get_ami_state() {
local AMI_ID=$1 local AMI_ID=$1
aws ec2 describe-images --image-ids $AMI_ID | get_json_value '["Images"][0]["State"]' shift
aws ec2 describe-images --image-ids $AMI_ID $* | get_json_value '["Images"][0]["State"]'
} }
detach_volume() { detach_volume() {
...@@ -257,13 +259,14 @@ wait_for_volume_state() { ...@@ -257,13 +259,14 @@ wait_for_volume_state() {
wait_for_ami_ready() { wait_for_ami_ready() {
local AMI_ID=$1 local AMI_ID=$1
shift
local STATE="unknown" local STATE="unknown"
while test x"$STATE" != x"available" while test x"$STATE" != x"available"
do do
sleep 5 sleep 5
STATE=`get_ami_state $AMI_ID` STATE=`get_ami_state $AMI_ID $*`
echo AMI is $STATE echo AMI is $STATE
done done
} }
...@@ -295,13 +298,36 @@ copy_ami_to_region() { ...@@ -295,13 +298,36 @@ copy_ami_to_region() {
make_ami_public() { make_ami_public() {
local AMI_ID=$1 local AMI_ID=$1
$EC2_HOME/bin/ec2-modify-image-attribute $AMI_ID --launch-permission --add all shift
$EC2_HOME/bin/ec2-modify-image-attribute $AMI_ID --launch-permission --add all $*
}
make_ami_private() {
local AMI_ID=$1
shift
$EC2_HOME/bin/ec2-modify-image-attribute $AMI_ID --launch-permission --remove all $*
} }
list_additional_regions() { list_additional_regions() {
$EC2_HOME/bin/ec2-describe-regions | ec2_response_value REGION REGION | grep -v $AWS_DEFAULT_REGION $EC2_HOME/bin/ec2-describe-regions | ec2_response_value REGION REGION | grep -v $AWS_DEFAULT_REGION
} }
get_own_ami_info() {
local AMI_ID=$1
shift
$EC2_HOME/bin/ec2-describe-images $* | grep $AMI_ID
}
get_public_ami_info() {
local AMI_ID=$1
shift
$EC2_HOME/bin/ec2-describe-images -x all $* | grep $AMI_ID
}
replicate_ami() { replicate_ami() {
local AMI_ID=$1 local AMI_ID=$1
local REGIONS="`list_additional_regions`" local REGIONS="`list_additional_regions`"
...@@ -317,11 +343,55 @@ replicate_ami() { ...@@ -317,11 +343,55 @@ replicate_ami() {
fi fi
amend_rstatus AMI ID in region $REGION is $AMI_IN_REGION amend_rstatus AMI ID in region $REGION is $AMI_IN_REGION
NL='
'
REPLICAS_LIST="$REPLICAS_LIST${NL}$AMI_IN_REGION $REGION"
done done
return 0; return 0;
} }
# This function implements work-around for AMIs copying problem described here:
# https://forums.aws.amazon.com/thread.jspa?messageID=454676&#454676
make_replica_public() {
local AMI_ID=$1
local REGION=$2
PUBLIC_AMI_INFO=
echo_progress Make AMI $AMI_ID from $REGION region public
echo_progress Wait for AMI to become available
wait_for_ami_ready $AMI_ID "--region $REGION"
while test x"$PUBLIC_AMI_INFO" == x""
do
make_ami_private $AMI_ID "--region $REGION"
get_own_ami_info $AMI_ID "--region $REGION"
make_ami_public $AMI_ID "--region $REGION"
get_own_ami_info $AMI_ID "--region $REGION"
for i in 1 2 3 4 5
do
sleep 5
PUBLIC_AMI_INFO=`get_public_ami_info $AMI_ID "--region $REGION"`
echo $i/5: $PUBLIC_AMI_INFO
if test x"$PUBLIC_AMI_INFO" != x""; then
return 0
fi
done
done
}
make_replicas_public() {
while read AMI; do
if test x"$AMI" != x""; then
make_replica_public $AMI
fi
done
}
BUCKET_CREATED=0 BUCKET_CREATED=0
while true; do while true; do
...@@ -477,6 +547,7 @@ while true; do ...@@ -477,6 +547,7 @@ while true; do
fi fi
echo_progress Replicating AMI to existing regions echo_progress Replicating AMI to existing regions
REPLICAS_LIST=
replicate_ami $AMI_ID replicate_ami $AMI_ID
if test x"$?" != x"0"; then if test x"$?" != x"0"; then
...@@ -484,6 +555,11 @@ while true; do ...@@ -484,6 +555,11 @@ while true; do
break; break;
fi fi
echo_progress Making replicated images public \(work-around AWS bug\)
make_replicas_public <<END_REPLICAS
$REPLICAS_LIST
END_REPLICAS
amend_rstatus Release SUCCEEDED amend_rstatus Release SUCCEEDED
break break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment