관리-도구
편집 파일: api.cpython-39.pyc
a �����)g�����������������������@���s����d�Z�ddlmZmZmZ�eZddlZddlZddl Z ddl Z ddlZddlZddl m��m��mZ�ddd�Zddd�Zddd �Zdd d�Zdd d�Zddd�Zdd��Zddd�ZdS�)a��� This module adds shared support for generic api modules In order to use this module, include it as part of a custom module as shown below. The 'api' module provides the following common argument specs: * rate limit spec - rate: number of requests per time unit (int) - rate_limit: time window in which the limit is applied in seconds * retry spec - retries: number of attempts - retry_pause: delay between attempts in seconds �����)�absolute_import�division�print_functionNc�����������������C���s*���t�t�dd�t�dd�d�}|�r&|�|���|S�)z7Creates an argument spec for working with rate limiting�int��type)�rate� rate_limit��dict�update��specZarg_spec��r����</usr/lib/python3.9/site-packages/ansible/module_utils/api.py�rate_limit_argument_spec'���s����� r���c�����������������C���s,���t�t�dd�t�ddd�d�}|�r(|�|���|S�)z2Creates an argument spec for working with retryingr���r����float�����r����default��retries�retry_pauser ���r ���r���r���r����retry_argument_spec2���s���� � r���c�����������������C���s>���t�t�dd�t�ddd�t�dd�t�ddd�d�}|�r:|�|���|S�)N�strr���T)r���Zno_log�boolr���)Zapi_usernameZapi_passwordZapi_urlZvalidate_certsr ���r ���r���r���r����basic_auth_argument_spec=���s���� � r���c��������������������s4���d��|�dur$|dur$t�|�t�|�������fdd�}|S�)zrate limiting decoratorNc��������������������s���dg�����fdd�}|S�)Ng��������c���������������������sd���t�jdkrtj}ntj}�d�urR|���d��}�|�}|dkrHt�|��|���d<���|�i�|��}|S�)N)��������r���)�sys�version_info�time�process_timeZclock�sleep)�args�kwargsZ real_time�elapsed�left�ret)�f�last�minrater���r����ratelimitedR���s���� z0rate_limit.<locals>.wrapper.<locals>.ratelimitedr���)r)���r,����r+���)r)���r*���r����wrapperO���s����zrate_limit.<locals>.wrapper)r���)r���r ���r.���r���r-���r���r ���I���s ����r ���r���c��������������������s������fdd�}|S�)zRetry decoratorc��������������������s�������fdd�}|S�)Nc���������������������sl���d}�d�urhd�}|d7�}|�kr,t�d����z��|�i�|��}W�n�t�yP���Y�n0�|rXqdt����q|S�d�S�)Nr���r���zRetry limit exceeded: %d)� Exceptionr!���r#���)r$���r%���Zretry_countr(���)r)���r���r���r���r����retriedh���s����z'retry.<locals>.wrapper.<locals>.retriedr���)r)���r0���r���)r)���r���r.���f���s����zretry.<locals>.wrapperr���)r���r���r.���r���r���r����retryd���s����r1���� ���r����<���c�������������� ���c���s0���t�d|��D�] }t�dt||d|����V��q dS�)aD��The "Full Jitter" backoff strategy. Ref: https://www.awsarchitectureblog.com/2015/03/backoff.html :param retries: The number of delays to generate. :param delay_base: The base time in seconds used to calculate the exponential backoff. :param delay_threshold: The maximum time in seconds for any delay. r�������N)�range�randomZrandint�min)r���Z delay_baseZdelay_thresholdr1���r���r���r����generate_jittered_backoff}���s���� r8���c�����������������C���s���dS�)NFr���)Zexception_or_resultr���r���r����retry_never����s����r9���c��������������������s0���dd��}||����~��du�rt�����fdd�}|S�)z�Generic retry decorator. :param backoff_iterator: An iterable of delays in seconds. :param should_retry_error: A callable that takes an exception of the decorated function and decides whether to retry or not (returns a bool). c�����������������s���s&���t��|��\}}|V��t�|�V��qd�S�)N)� itertools�tee�copy)Zoriginal_iteratorZ_copiable_iteratorZ_first_iterator_copyr���r���r����_emit_isolated_iterator_copies����s����zGretry_with_delays_and_condition.<locals>._emit_isolated_iterator_copiesNc��������������������s���t���������fdd��}|S�)Nc���������������������sr���t�j�g|��R�i�|��}t���D�]J}z|��W���S��ty^�}�z�|�sJ��W�Y�d}~n d}~0�0�t�|��q |��S�)z�This assumes the function has not already been called. If backoff_iterator is empty, we should still run the function a single time with no delay. N)� functools�partial�nextr/���r!���r#���)r$���r%���Zcall_retryable_functionZdelay�e)�backoff_iterator_generator�function�should_retry_errorr���r����run_function����s����zOretry_with_delays_and_condition.<locals>.function_wrapper.<locals>.run_function)r>����wraps)rC���rE����rB���rD���)rC���r����function_wrapper����s����z9retry_with_delays_and_condition.<locals>.function_wrapper)r9���)Zbackoff_iteratorrD���r=���rH���r���rG���r����retry_with_delays_and_condition����s����rI���)N)N)N)NN)Nr���)r2���r���r3���)N)�__doc__Z __future__r���r���r���r���Z __metaclass__r<���r>���r:���r6���r���r!���Z"ansible.module_utils.compat.typingZmodule_utils�compat�typing�tr���r���r���r ���r1���r8���r9���rI���r���r���r���r����<module> ���s"���