Skip to content

Commit

Permalink
Merge pull request ansible-collections#536 from tremble/ec2_vpc_peeri…
Browse files Browse the repository at this point in the history
…ng_info/retries

ec2_vpc_peering_info - Add AWSRetry decorator

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
ansible-zuul[bot] authored Apr 12, 2021
2 parents 4f828d3 + 9f1dd2a commit 1cd3938
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/536-ec2_vpc_peering_info-retry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_vpc_peering_info - add retries on common AWS failures (https://github.com/ansible-collections/community.aws/pull/536).
16 changes: 7 additions & 9 deletions plugins/modules/ec2_vpc_peering_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,24 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils._text import to_native
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict


def date_handler(obj):
return obj.isoformat() if hasattr(obj, 'isoformat') else obj


def get_vpc_peers(client, module):
params = dict()
params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters'))
if module.params.get('peer_connection_ids'):
params['VpcPeeringConnectionIds'] = module.params.get('peer_connection_ids')
try:
result = json.loads(json.dumps(client.describe_vpc_peering_connections(**params), default=date_handler))
except Exception as e:
module.fail_json(msg=to_native(e))
result = client.describe_vpc_peering_connections(aws_retry=True, **params)
result = normalize_boto3_result(result)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe peering connections")

return result['VpcPeeringConnections']

Expand All @@ -244,7 +242,7 @@ def main():
module.deprecate("The 'ec2_vpc_peering_facts' module has been renamed to 'ec2_vpc_peering_info'", date='2021-12-01', collection_name='community.aws')

try:
ec2 = module.client('ec2')
ec2 = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff())
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')

Expand Down

0 comments on commit 1cd3938

Please sign in to comment.