[ec2_vpc_net] Add retries to describe_vpc_attribute call (#39256)

* [ec2_vpc_net] Add retries to describe_vpc_attribute call

* Use new AnsibleAWSModule client-based waiters
pull/53205/head
Sloane Hertel 7 years ago committed by Ryan Brown
parent cc06f4cba1
commit ec9c59f52b

@ -195,6 +195,11 @@ class AnsibleAWSModule(object):
class _RetryingBotoClientWrapper(object):
__never_wait = (
'get_paginator', 'can_paginate',
'get_waiter', 'generate_presigned_url',
)
def __init__(self, client, retry):
self.client = client
self.retry = retry
@ -212,7 +217,9 @@ class _RetryingBotoClientWrapper(object):
def __getattr__(self, name):
unwrapped = getattr(self.client, name)
if callable(unwrapped):
if name in self.__never_wait:
return unwrapped
elif callable(unwrapped):
wrapped = self._create_optional_retry_wrapper_function(unwrapped)
setattr(self, name, wrapped)
return wrapped

@ -166,8 +166,8 @@ except ImportError:
from time import sleep, time
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info, ec2_argument_spec, camel_dict_to_snake_dict,
ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict, AWSRetry)
from ansible.module_utils.ec2 import (AWSRetry, camel_dict_to_snake_dict,
ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict)
from ansible.module_utils.six import string_types
@ -312,8 +312,7 @@ def wait_for_vpc_attribute(connection, module, vpc_id, attribute, expected_value
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
argument_spec = dict(
name=dict(required=True),
cidr_block=dict(type='list', required=True),
tenancy=dict(choices=['default', 'dedicated'], default='default'),
@ -325,7 +324,6 @@ def main():
multi_ok=dict(type='bool', default=False),
purge_cidrs=dict(type='bool', default=False),
)
)
module = AnsibleAWSModule(
argument_spec=argument_spec,
@ -345,8 +343,12 @@ def main():
changed = False
region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
connection = module.client(
'ec2',
retry_decorator=AWSRetry.jittered_backoff(
retries=8, delay=3, catch_extra_error_codes=['InvalidVpcID.NotFound']
)
)
if dns_hostnames and not dns_support:
module.fail_json(msg='In order to enable DNS Hostnames you must also enable DNS support')
@ -396,8 +398,8 @@ def main():
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to update tags")
current_dns_enabled = connection.describe_vpc_attribute(Attribute='enableDnsSupport', VpcId=vpc_id)['EnableDnsSupport']['Value']
current_dns_hostnames = connection.describe_vpc_attribute(Attribute='enableDnsHostnames', VpcId=vpc_id)['EnableDnsHostnames']['Value']
current_dns_enabled = connection.describe_vpc_attribute(Attribute='enableDnsSupport', VpcId=vpc_id, aws_retry=True)['EnableDnsSupport']['Value']
current_dns_hostnames = connection.describe_vpc_attribute(Attribute='enableDnsHostnames', VpcId=vpc_id, aws_retry=True)['EnableDnsHostnames']['Value']
if current_dns_enabled != dns_support:
changed = True
if not module.check_mode:

Loading…
Cancel
Save