77
88source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /log.sh"
99source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /aws.sh"
10- source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /assertions .sh"
10+ source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /assert .sh"
1111
12- # Get the name of the ASG this EC2 Instance is in
12+ # Get the name of the ASG this EC2 Instance is in. This is done by looking up the instance's tags. This method will
13+ # wait up until the specified number of retries if the tags or instances are not yet available.
1314function aws_wrapper_get_asg_name {
15+ local readonly max_retries=" $1 "
16+ local readonly sleep_between_retries=" $2 "
17+
1418 local instance_id
1519 instance_id=$( aws_get_instance_id)
1620
1721 local instance_region
1822 instance_region=$( aws_get_instance_region)
1923
20- aws_wrapper_get_instance_tag " $instance_id " " $instance_region " " aws:autoscaling:groupName"
24+ aws_wrapper_get_instance_tag " $instance_id " " $instance_region " " aws:autoscaling:groupName" " $max_retries " " $sleep_between_retries "
2125}
2226
2327# Look up the tags for the specified Instance and extract the value for the specified tag key
2428function aws_wrapper_get_instance_tag {
2529 local readonly instance_id=" $1 "
2630 local readonly instance_region=" $2 "
2731 local readonly tag_key=" $3 "
28-
29- local readonly max_retries=60
30- local readonly sleep_between_retries=5
32+ local readonly max_retries=" ${4:- 60} "
33+ local readonly sleep_between_retries=" ${5:- 5} "
3134
3235 for (( i= 0 ; i< "$max_retries "; i++ )) ; do
3336 local tags
34- tags=$( aws_wrapper_wait_for_instance_tags " $instance_id " " $instance_region " )
37+ tags=$( aws_wrapper_wait_for_instance_tags " $instance_id " " $instance_region " " $max_retries " " $sleep_between_retries " )
3538 assert_not_empty_or_null " $tags " " tags for Instance $instance_id in $instance_region "
3639
3740 local tag_value
@@ -57,12 +60,11 @@ function aws_wrapper_get_instance_tag {
5760function aws_wrapper_wait_for_instance_tags {
5861 local readonly instance_id=" $1 "
5962 local readonly instance_region=" $2 "
63+ local readonly max_retries=" ${3:- 60} "
64+ local readonly sleep_between_retries=" ${4:- 5} "
6065
6166 log_info " Looking up tags for Instance $instance_id in $instance_region "
6267
63- local readonly max_retries=60
64- local readonly sleep_between_retries=5
65-
6668 for (( i= 0 ; i< "$max_retries "; i++ )) ; do
6769 local tags
6870 tags=$( aws_get_instance_tags " $instance_id " " $instance_region " )
@@ -88,9 +90,8 @@ function aws_wrapper_wait_for_instance_tags {
8890function aws_wrapper_get_asg_size {
8991 local readonly asg_name=" $1 "
9092 local readonly aws_region=" $2 "
91-
92- local readonly max_retries=60
93- local readonly sleep_between_retries=5
93+ local readonly max_retries=" ${3:- 60} "
94+ local readonly sleep_between_retries=" ${4:- 5} "
9495
9596 for (( i= 0 ; i< "$max_retries "; i++ )) ; do
9697 log_info " Looking up the size of the Auto Scaling Group $asg_name in $aws_region "
@@ -121,12 +122,12 @@ function aws_wrapper_get_asg_size {
121122function aws_wrapper_wait_for_instances_in_asg {
122123 local readonly asg_name=" $1 "
123124 local readonly aws_region=" $2 "
125+ local readonly max_retries=" ${3:- 60} "
126+ local readonly sleep_between_retries=" ${4:- 5} "
124127
125128 local asg_size
126- asg_size=$( aws_wrapper_get_asg_size " $asg_name " " $aws_region " )
127-
128- local readonly max_retries=60
129- local readonly sleep_between_retries=5
129+ asg_size=$( aws_wrapper_get_asg_size " $asg_name " " $aws_region " " $max_retries " " $sleep_between_retries " )
130+ assert_not_empty_or_null " $asg_size " " size of ASG $asg_name in $aws_region "
130131
131132 log_info " Looking up Instances in ASG $asg_name in $aws_region "
132133 for (( i= 0 ; i< "$max_retries "; i++ )) ; do
@@ -157,9 +158,11 @@ function aws_wrapper_get_ips_in_asg {
157158 local readonly asg_name=" $1 "
158159 local readonly aws_region=" $2 "
159160 local readonly use_public_ips=" $3 "
161+ local readonly max_retries=" ${4:- 60} "
162+ local readonly sleep_between_retries=" ${5:- 5} "
160163
161164 local instances
162- instances=$( aws_describe_instances_in_asg " $asg_name " " $aws_region " )
165+ instances=$( aws_wrapper_wait_for_instances_in_asg " $asg_name " " $aws_region " " $max_retries " " $sleep_between_retries " )
163166 assert_not_empty_or_null " $instances " " Get info about Instances in ASG $asg_name in $aws_region "
164167
165168 local readonly ip_param=$( [[ " $use_public_ips " == " true" ]] && echo " PublicIpAddress" || echo " PrivateIpAddress" )
@@ -172,9 +175,11 @@ function aws_wrapper_get_hostnames_in_asg {
172175 local readonly asg_name=" $1 "
173176 local readonly aws_region=" $2 "
174177 local readonly use_public_hostnames=" $3 "
178+ local readonly max_retries=" ${4:- 60} "
179+ local readonly sleep_between_retries=" ${5:- 5} "
175180
176181 local instances
177- instances=$( aws_wrapper_wait_for_instances_in_asg " $asg_name " " $aws_region " )
182+ instances=$( aws_wrapper_wait_for_instances_in_asg " $asg_name " " $aws_region " " $max_retries " " $sleep_between_retries " )
178183 assert_not_empty_or_null " $instances " " Get info about Instances in ASG $asg_name in $aws_region "
179184
180185 local readonly hostname_param=$( [[ " $use_public_hostnames " == " true" ]] && echo " PublicDnsName" || echo " PrivateDnsName" )
0 commit comments