Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/module_utils/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/module_utils/cloud.pyo

�
�Udac@s~dZddlZddlmZddlZddlZddddd�Zddded	�Zd
efd��YZ	dS(s�
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()

i����N(twrapsi
ii<cs����fd�}|S(s� 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]
    c3sLxEtd��D]4}��|}�dkr6|nt|��VqWdS(Ni(trangetNonetmin(tretrytsleep(tbackofftdelayt	max_delaytretries(s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytbackoff_genCs((R	RRRR
((RRRR	s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyt_exponential_backoff0sics����fd�}|S(s� 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]
    c3s@x9td��D](}�jdt��d|��VqWdS(Nii(RtrandintR(R(t_randomRRR	(s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyR
`s((R	RRR
R
((R
RRR	s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyt_full_jitter_backoffJst
CloudRetrycBs�eZdZdZed��Zedd��Zedd��Z	edddddd��Z
eddddd	��Zeddd
dd��ZRS(
s� CloudRetry can be used by any cloud provider, in order to implement a
        backoff algorithm/retry effect based on Status Code from Exceptions.
    cCsdS(sz Return the status code from the exception object
        Args:
            error (object): The exception itself.
        N((terror((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytstatus_code_from_exceptionnscCsdS(s� 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.
        N((t
response_codetcatch_extra_error_codes((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytfoundvscs���fd�}|S(s$ 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.
        cs(t������fd��}|S(Ncs�x���D]�}y�||�SWq
tk
r�}t|�j�r��j|�}�j|��r�djt|�|�}tjtj|�t	j
|�q�|�q�|�q
Xq
W�||�S(Ns{0}: Retrying in {1} seconds...(t	Exceptiont
isinstancet
base_classRRtformattstrtsyslogtLOG_INFOttimeR(targstkwargsRteRtmsg(tbackoff_strategyRtclstf(s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyt
retry_func�s	(R(R#R$(R!RR"(R#s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytdeco�s$((R"R!RR%((R!RR"s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyt_backoff~s	i
iii<c
Cs+|jtd|d|d|d|�|�S(sE
        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
        R	RRR(R&R(R"R	RRRR((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytexponential_backoff�scCs%|jtd|d|d|�|�S(s
        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
        R	RR(R&R(R"R	RRR((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pytjittered_backoff�sg�������?cCs,|jd|dd|d|ddd|�S(s�
        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
        R	iRRRRN(R'R(R"ttriesRRR((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyR�s	N(
t__name__t
__module__t__doc__RRtstaticmethodRRtclassmethodR&R'R(R(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyRfs!(
R,trandomt	functoolsRRRRRtobjectR(((s>/usr/lib/python2.7/site-packages/ansible/module_utils/cloud.pyt<module>)s

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]