Skip to content

Commit

Permalink
New collection build
Browse files Browse the repository at this point in the history
  • Loading branch information
jillr committed Mar 13, 2020
1 parent b99cff2 commit 24d7724
Show file tree
Hide file tree
Showing 45 changed files with 853 additions and 137 deletions.
1 change: 0 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license_file: COPYING
tags: null
dependencies:
ansible.netcommon: '>=0.1.0'
community.general: '>=0.1.0'
repository: [email protected]:ansible-collection-migration/ansible.amazon.git
documentation: https://github.com/ansible-collection-migration/ansible.amazon/tree/master/docs
homepage: https://github.com/ansible-collection-migration/ansible.amazon
Expand Down
46 changes: 46 additions & 0 deletions meta/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugin_routing:
modules:
aws_az_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
aws_caller_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
cloudformation_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_ami_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_eni_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_group_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_snapshot_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_vol_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_vpc_dhcp_option_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_vpc_net_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
ec2_vpc_subnet_facts:
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
6 changes: 5 additions & 1 deletion plugins/module_utils/aws/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
"""
import traceback
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import get_aws_connection_info, boto3_conn
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import camel_dict_to_snake_dict, AWSRetry, HAS_BOTO3, boto3_tag_list_to_ansible_dict, ansible_dict_to_boto3_tag_list
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (camel_dict_to_snake_dict,
AWSRetry,
HAS_BOTO3,
boto3_tag_list_to_ansible_dict,
ansible_dict_to_boto3_tag_list)
from ansible.module_utils._text import to_bytes


Expand Down
5 changes: 4 additions & 1 deletion plugins/module_utils/aws/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from ansible.module_utils._text import to_text
from ansible_collections.ansible.amazon.plugins.module_utils.aws.waiters import get_waiter
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import compare_aws_tags, AWSRetry, ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (compare_aws_tags,
AWSRetry,
ansible_dict_to_boto3_tag_list,
boto3_tag_list_to_ansible_dict)

try:
from botocore.exceptions import BotoCoreError, ClientError, WaiterError
Expand Down
220 changes: 220 additions & 0 deletions plugins/module_utils/cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#
# (c) 2016 Allen Sanabria, <[email protected]>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

"""
This module adds shared support for generic cloud modules
In order to use this module, include it as part of a custom
module as shown below.
from ansible.module_utils.cloud import CloudRetry
The 'cloud' module provides the following common classes:
* CloudRetry
- The base class to be used by other cloud providers, in order to
provide a backoff/retry decorator based on status codes.
- Example using the AWSRetry class which inherits from CloudRetry.
@AWSRetry.exponential_backoff(retries=10, delay=3)
get_ec2_security_group_ids_from_names()
@AWSRetry.jittered_backoff()
get_ec2_security_group_ids_from_names()
"""
import random
from functools import wraps
import syslog
import time


def _exponential_backoff(retries=10, delay=2, backoff=2, max_delay=60):
""" Customizable exponential backoff strategy.
Args:
retries (int): Maximum number of times to retry a request.
delay (float): Initial (base) delay.
backoff (float): base of the exponent to use for exponential
backoff.
max_delay (int): Optional. If provided each delay generated is capped
at this amount. Defaults to 60 seconds.
Returns:
Callable that returns a generator. This generator yields durations in
seconds to be used as delays for an exponential backoff strategy.
Usage:
>>> backoff = _exponential_backoff()
>>> backoff
<function backoff_backoff at 0x7f0d939facf8>
>>> list(backoff())
[2, 4, 8, 16, 32, 60, 60, 60, 60, 60]
"""
def backoff_gen():
for retry in range(0, retries):
sleep = delay * backoff ** retry
yield sleep if max_delay is None else min(sleep, max_delay)
return backoff_gen


def _full_jitter_backoff(retries=10, delay=3, max_delay=60, _random=random):
""" Implements the "Full Jitter" backoff strategy described here
https://www.awsarchitectureblog.com/2015/03/backoff.html
Args:
retries (int): Maximum number of times to retry a request.
delay (float): Approximate number of seconds to sleep for the first
retry.
max_delay (int): The maximum number of seconds to sleep for any retry.
_random (random.Random or None): Makes this generator testable by
allowing developers to explicitly pass in the a seeded Random.
Returns:
Callable that returns a generator. This generator yields durations in
seconds to be used as delays for a full jitter backoff strategy.
Usage:
>>> backoff = _full_jitter_backoff(retries=5)
>>> backoff
<function backoff_backoff at 0x7f0d939facf8>
>>> list(backoff())
[3, 6, 5, 23, 38]
>>> list(backoff())
[2, 1, 6, 6, 31]
"""
def backoff_gen():
for retry in range(0, retries):
yield _random.randint(0, min(max_delay, delay * 2 ** retry))
return backoff_gen


class CloudRetry(object):
""" CloudRetry can be used by any cloud provider, in order to implement a
backoff algorithm/retry effect based on Status Code from Exceptions.
"""
# This is the base class of the exception.
# AWS Example botocore.exceptions.ClientError
base_class = None

@staticmethod
def status_code_from_exception(error):
""" Return the status code from the exception object
Args:
error (object): The exception itself.
"""
pass

@staticmethod
def found(response_code, catch_extra_error_codes=None):
""" Return True if the Response Code to retry on was found.
Args:
response_code (str): This is the Response Code that is being matched against.
"""
pass

@classmethod
def _backoff(cls, backoff_strategy, catch_extra_error_codes=None):
""" Retry calling the Cloud decorated function using the provided
backoff strategy.
Args:
backoff_strategy (callable): Callable that returns a generator. The
generator should yield sleep times for each retry of the decorated
function.
"""
def deco(f):
@wraps(f)
def retry_func(*args, **kwargs):
for delay in backoff_strategy():
try:
return f(*args, **kwargs)
except Exception as e:
if isinstance(e, cls.base_class):
response_code = cls.status_code_from_exception(e)
if cls.found(response_code, catch_extra_error_codes):
msg = "{0}: Retrying in {1} seconds...".format(str(e), delay)
syslog.syslog(syslog.LOG_INFO, msg)
time.sleep(delay)
else:
# Return original exception if exception is not a ClientError
raise e
else:
# Return original exception if exception is not a ClientError
raise e
return f(*args, **kwargs)

return retry_func # true decorator

return deco

@classmethod
def exponential_backoff(cls, retries=10, delay=3, backoff=2, max_delay=60, catch_extra_error_codes=None):
"""
Retry calling the Cloud decorated function using an exponential backoff.
Kwargs:
retries (int): Number of times to retry a failed request before giving up
default=10
delay (int or float): Initial delay between retries in seconds
default=3
backoff (int or float): backoff multiplier e.g. value of 2 will
double the delay each retry
default=1.1
max_delay (int or None): maximum amount of time to wait between retries.
default=60
"""
return cls._backoff(_exponential_backoff(
retries=retries, delay=delay, backoff=backoff, max_delay=max_delay), catch_extra_error_codes)

@classmethod
def jittered_backoff(cls, retries=10, delay=3, max_delay=60, catch_extra_error_codes=None):
"""
Retry calling the Cloud decorated function using a jittered backoff
strategy. More on this strategy here:
https://www.awsarchitectureblog.com/2015/03/backoff.html
Kwargs:
retries (int): Number of times to retry a failed request before giving up
default=10
delay (int): Initial delay between retries in seconds
default=3
max_delay (int): maximum amount of time to wait between retries.
default=60
"""
return cls._backoff(_full_jitter_backoff(
retries=retries, delay=delay, max_delay=max_delay), catch_extra_error_codes)

@classmethod
def backoff(cls, tries=10, delay=3, backoff=1.1, catch_extra_error_codes=None):
"""
Retry calling the Cloud decorated function using an exponential backoff.
Compatibility for the original implementation of CloudRetry.backoff that
did not provide configurable backoff strategies. Developers should use
CloudRetry.exponential_backoff instead.
Kwargs:
tries (int): Number of times to try (not retry) before giving up
default=10
delay (int or float): Initial delay between retries in seconds
default=3
backoff (int or float): backoff multiplier e.g. value of 2 will
double the delay each retry
default=1.1
"""
return cls.exponential_backoff(
retries=tries - 1, delay=delay, backoff=backoff, max_delay=None, catch_extra_error_codes=catch_extra_error_codes)
2 changes: 1 addition & 1 deletion plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ansible.module_utils.ansible_release import __version__
from ansible.module_utils.basic import missing_required_lib, env_fallback
from ansible.module_utils._text import to_native, to_text
from ansible_collections.community.general.plugins.module_utils.cloud import CloudRetry
from ansible_collections.ansible.amazon.plugins.module_utils.cloud import CloudRetry
from ansible.module_utils.six import string_types, binary_type, text_type
from ansible.module_utils.common.dict_transformations import (
camel_dict_to_snake_dict, snake_dict_to_camel_dict,
Expand Down
8 changes: 7 additions & 1 deletion plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@
except ImportError:
HAS_BOTO3 = False

from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list, AWSRetry, boto3_conn, boto_exception, ec2_argument_spec, get_aws_connection_info
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ansible_dict_to_boto3_tag_list,
AWSRetry,
boto3_conn,
boto_exception,
ec2_argument_spec,
get_aws_connection_info,
)
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native

Expand Down
6 changes: 5 additions & 1 deletion plugins/modules/ec2_ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@
'''

import time
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict, compare_aws_tags
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ansible_dict_to_boto3_tag_list,
boto3_tag_list_to_ansible_dict,
camel_dict_to_snake_dict,
compare_aws_tags,
)
from ansible_collections.ansible.amazon.plugins.module_utils.aws.core import AnsibleAWSModule

try:
Expand Down
6 changes: 5 additions & 1 deletion plugins/modules/ec2_ami_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@
pass # caught by AnsibleAWSModule

from ansible_collections.ansible.amazon.plugins.module_utils.aws.core import AnsibleAWSModule
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list, camel_dict_to_snake_dict, boto3_tag_list_to_ansible_dict
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ansible_dict_to_boto3_tag_list,
camel_dict_to_snake_dict,
boto3_tag_list_to_ansible_dict,
ansible_dict_to_boto3_filter_list,
)


def list_ec2_images(ec2_client, module):
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ec2_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (AnsibleAWSError, connect_to_aws,
ec2_argument_spec, get_aws_connection_info,
get_ec2_security_group_ids_from_names)
ec2_argument_spec, get_aws_connection_info,
get_ec2_security_group_ids_from_names)


def get_eni_info(interface):
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/ec2_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@
from ansible_collections.ansible.amazon.plugins.module_utils.aws.iam import get_aws_account_id
from ansible_collections.ansible.amazon.plugins.module_utils.aws.waiters import get_waiter
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import AWSRetry, camel_dict_to_snake_dict, compare_aws_tags
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list, boto3_tag_list_to_ansible_dict, ansible_dict_to_boto3_tag_list
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ansible_dict_to_boto3_filter_list,
boto3_tag_list_to_ansible_dict,
ansible_dict_to_boto3_tag_list,
)
from ansible.module_utils.common.network import to_ipv6_subnet, to_subnet
from ansible_collections.ansible.netcommon.plugins.module_utils.compat.ipaddress import ip_network, IPv6Network
from ansible.module_utils._text import to_text
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/ec2_group_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@
pass # caught by AnsibleAWSModule

from ansible_collections.ansible.amazon.plugins.module_utils.aws.core import AnsibleAWSModule
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (boto3_tag_list_to_ansible_dict, ansible_dict_to_boto3_filter_list, camel_dict_to_snake_dict)
from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (boto3_tag_list_to_ansible_dict,
ansible_dict_to_boto3_filter_list,
camel_dict_to_snake_dict,
)


def main():
Expand Down
Loading

0 comments on commit 24d7724

Please sign in to comment.