Skip to content

Commit

Permalink
[promoted]Merge pull request ansible-collections#537 from tremble/ec2…
Browse files Browse the repository at this point in the history
…_vpc_endpoint_info/retries

Update ec2_vpc_endpoint_info AWS retries

Reviewed-by: https://github.com/apps/ansible-zuul

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@893d08c
  • Loading branch information
ansible-zuul[bot] authored Apr 12, 2021
2 parents 652a808 + 1735051 commit edeed33
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions plugins/modules/ec2_vpc_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,42 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
def _describe_endpoints(client, **params):
paginator = client.get_paginator('describe_vpc_endpoints')
return paginator.paginate(**params).build_full_result()


@AWSRetry.jittered_backoff()
def _describe_endpoint_services(client, **params):
paginator = client.get_paginator('describe_vpc_endpoint_services')
return paginator.paginate(**params).build_full_result()


def get_supported_services(client, module):
results = list()
params = dict()
while True:
response = client.describe_vpc_endpoint_services(**params)
results.extend(response['ServiceNames'])
if 'NextToken' in response:
params['NextToken'] = response['NextToken']
else:
break
try:
services = _describe_endpoint_services(client)
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
module.fail_json_aws(e, msg="Failed to get endpoint servicess")

results = list(services['ServiceNames'])
return dict(service_names=results)


@AWSRetry.exponential_backoff()
def get_endpoints(client, module):
results = list()
params = dict()
params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters'))
if module.params.get('vpc_endpoint_ids'):
params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids')
try:
paginator = client.get_paginator('describe_vpc_endpoints')
results = paginator.paginate(**params).build_full_result()['VpcEndpoints']

results = _describe_endpoints(client, **params)['VpcEndpoints']
results = normalize_boto3_result(results)
except is_boto3_error_code('InvalidVpcEndpointId.NotFound'):
module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[])
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed to get endpoints")

return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results])


Expand Down

0 comments on commit edeed33

Please sign in to comment.