Skip to content

Commit

Permalink
Add AWSRetry to remaining _info modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Nov 26, 2020
1 parent 4ba6f2b commit fcdc83c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions plugins/modules/aws_caller_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ..module_utils.core import AnsibleAWSModule
from ..module_utils.ec2 import AWSRetry


def main():
Expand All @@ -78,21 +79,21 @@ def main():
if module._name == 'aws_caller_facts':
module.deprecate("The 'aws_caller_facts' module has been renamed to 'aws_caller_info'", date='2021-12-01', collection_name='amazon.aws')

client = module.client('sts')
client = module.client('sts', retry_decorator=AWSRetry.jittered_backoff())

try:
caller_info = client.get_caller_identity()
caller_info = client.get_caller_identity(aws_retry=True)
caller_info.pop('ResponseMetadata', None)
except (BotoCoreError, ClientError) as e:
module.fail_json_aws(e, msg='Failed to retrieve caller identity')

iam_client = module.client('iam')
iam_client = module.client('iam', retry_decorator=AWSRetry.jittered_backoff())

try:
# Although a list is returned by list_account_aliases AWS supports maximum one alias per account.
# If an alias is defined it will be returned otherwise a blank string is filled in as account_alias.
# see https://docs.aws.amazon.com/cli/latest/reference/iam/list-account-aliases.html#output
response = iam_client.list_account_aliases()
response = iam_client.list_account_aliases(aws_retry=True)
if response and response['AccountAliases']:
caller_info['account_alias'] = response['AccountAliases'][0]
else:
Expand Down
8 changes: 6 additions & 2 deletions plugins/modules/ec2_snapshot_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@

from ..module_utils.core import AnsibleAWSModule
from ..module_utils.core import is_boto3_error_code
from ..module_utils.ec2 import AWSRetry
from ..module_utils.ec2 import ansible_dict_to_boto3_filter_list
from ..module_utils.ec2 import boto3_tag_list_to_ansible_dict

Expand All @@ -195,7 +196,10 @@ def list_ec2_snapshots(connection, module):
filters = ansible_dict_to_boto3_filter_list(module.params.get("filters"))

try:
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
snapshots = connection.describe_snapshots(
aws_retry=True,
SnapshotIds=snapshot_ids, OwnerIds=owner_ids,
RestorableByUserIds=restorable_by_user_ids, Filters=filters)
except is_boto3_error_code('InvalidSnapshot.NotFound') as e:
if len(snapshot_ids) > 1:
module.warn("Some of your snapshots may exist, but %s" % str(e))
Expand Down Expand Up @@ -235,7 +239,7 @@ def main():
if module._name == 'ec2_snapshot_facts':
module.deprecate("The 'ec2_snapshot_facts' module has been renamed to 'ec2_snapshot_info'", date='2021-12-01', collection_name='amazon.aws')

connection = module.client('ec2')
connection = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff())

list_ec2_snapshots(connection, module)

Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/ec2_vpc_dhcp_option_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ..module_utils.core import AnsibleAWSModule
from ..module_utils.ec2 import AWSRetry
from ..module_utils.ec2 import ansible_dict_to_boto3_filter_list
from ..module_utils.ec2 import boto3_tag_list_to_ansible_dict

Expand All @@ -107,7 +108,7 @@ def list_dhcp_options(client, module):
params['DhcpOptionsIds'] = module.params.get("dhcp_options_ids")

try:
all_dhcp_options = client.describe_dhcp_options(**params)
all_dhcp_options = client.describe_dhcp_options(aws_retry=True, **params)
except botocore.exceptions.ClientError as e:
module.fail_json_aws(e)

Expand All @@ -130,10 +131,10 @@ def main():
module.deprecate("The 'ec2_vpc_dhcp_option_facts' module has been renamed to 'ec2_vpc_dhcp_option_info'",
date='2021-12-01', collection_name='amazon.aws')

connection = module.client('ec2')
client = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff())

# call your function here
results = list_dhcp_options(connection, module)
results = list_dhcp_options(client, module)

module.exit_json(dhcp_options=results)

Expand Down

0 comments on commit fcdc83c

Please sign in to comment.