%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/botomod.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlZddlZy;ddlZddlZejd	�jej�eZWnek
reZnXeje�Zda!d	Z"d
�Z#d�Z$ddeddddd�Z%d
�Z&dddddd�Z'dd�Z(d�Z)dd�Z*d�Z+ddd�Z,d�Z-dS(u�
Boto Common Utils
=================

Note: This module depends on the dicts packed by the loader and,
therefore, must be accessed via the loader or from the __utils__ dict.

The __utils__ dict will not be automatically available to execution modules
until 2015.8.0. The `salt.utils.compat.pack_dunder` helper function
provides backwards compatibility.

This module provides common functionality for the boto execution modules.
The expected usage is to call `assign_funcs` from the `__virtual__` function
of the module. This will bring properly initialized partials of  `_get_conn`
and `_cache_id` into the module's namespace.

Example Usage:

    .. code-block:: python

        def __virtual__():
            # only required in 2015.2
            salt.utils.compat.pack_dunder(__name__)

            __utils__['boto.assign_funcs'](__name__, 'vpc')

        def test():
            conn = _get_conn()
            vpc_id = _cache_id('test-vpc')

.. versionadded:: 2015.8.0
i(tabsolute_importtprint_functiontunicode_literalsN(tpartial(tminion_mods(tsix(trange(tSaltInvocationErrorubotocC@sAtjjjdt�}|tkr=ts9tt�ant	S|S(ug
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    tcheck_boto3(
tsalttutilstversionstcheck_boto_reqstFalsetTruet__salt__Rt__opts__t__virtualname__(thas_boto_requirements((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt__virtual__Fsc	C@s�|r�t|tj�r+td|�}nt|t�rC|}n|jdd�}|jdd�}|jd|pyd�}n|r�td|d�r�td|d�}n|s�d}n|r�td|d�r�td|d�}n|r'td|d�r'td|d�}nd	j|�}|r�|||}tjrkt	j
jj|�}n|t
j|�j�}n
||}||||fS(
Nu
config.optionukeyukeyiduregionu.regionu	us-east-1u.keyu.keyidu	boto_{0}:(t
isinstanceRtstring_typesRtdicttgettNonetformattPY3R	R
tstringutilstto_bytesthashlibtmd5t	hexdigest(	tservicetregiontkeytkeyidtprofilet_profiletlabelthash_stringtcxkey((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt_get_profileTs0			
c	@s�t|||||�\}	}
}
}
|rBdj|	||�}	ndj|	|�}	|r�|	tkrqt|	=tS�tj�kr�t�fd�tj�D��}tj�tj|�tSt	Sn�r��t|	<tStj
|	�S(u
    Cache, invalidate, or retrieve an AWS resource id keyed by name.

    .. code-block:: python

        __utils__['boto.cache_id']('ec2', 'myinstance',
                                   'i-a1b2c3',
                                   profile='custom_profile')
    u{0}:{1}:{2}:idu
{0}:{1}:idc3@s-|]#\}}|�kr||fVqdS(N((t.0tktv(tresource_id(s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pys	<genexpr>�s(R)Rt__context__RtvaluesRtitemstcleartupdateR
R(R tnametsub_resourceR-t
invalidateR!R"R#R$R(t_tctx((R-s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pytcache_idss&
"


cC@s
tt|�S(u�
    Returns a partial ``cache_id`` function for the provided service.

    .. code-block:: python

        cache_id = __utils__['boto.cache_id_func']('ec2')
        cache_id('myinstance', 'i-a1b2c3')
        instance_id = cache_id('myinstance')
    (RR8(R ((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt
cache_id_func�s
c
C@st|p|�}td�|jtd�d�\}}tt|d|g�|�}t|||||�\}}}}|d}|tkr�t|SyC|j|d|d|�}	|	d
kr�tdj	|���nWn/t
jjk
rtd	j	||���nX|	t|<|	S(u�
    Return a boto connection for the service.

    .. code-block:: python

        conn = __utils__['boto.get_connection']('ec2', profile='custom_profile')
    uboto.u.itfromlistu:conntaws_access_key_idtaws_secret_access_keyuRegion "{0}" is not valid.u`No authentication credentials found when attempting to make boto {0} connection to region "{1}".N(
tstrtrsplittgetattrt
__import__R)R.tconnect_to_regionRRRtbotot	exceptiontNoAuthHandlerFound(
R tmoduleR!R"R#R$t	submoduletsvc_modR(tconn((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pytget_connection�s&(
			
cC@stt|d|�S(u�
    Returns a partial ``get_connection`` function for the provided service.

    .. code-block:: python

        get_conn = __utils__['boto.get_connection_func']('ec2')
        conn = get_conn()
    RE(RRI(R RE((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pytget_connection_func�s	cC@s1i}t|d�r%|j|d<nt|d�rD|j|d<nt|d�rr|jdkrr|j|d<nt|d�r�|jdk	r�|j|d<nd|kr�d|kr�dj|d|d�}n8d|kr�|d}nd|kr|d}nd}i|d6}|r-||d<n|S(	Nustatusureasonumessageuu
error_codeucodeu{0}: {1}uaws(thasattrtstatustreasontmessaget
error_codeRR(tetawsRNtr((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt	get_error�s(



ic@s9t|��t�fd�t|�D��o8t��S(ub
    Tests that exactly N items in an iterable are "truthy" (neither None,
    False, nor 0).
    c3@s|]}t��VqdS(N(tany(R*tj(ti(s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pys	<genexpr>�s(titertallRRT(tltn((RVs6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt	exactly_n�scC@s
t|�S(N(R[(RY((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pytexactly_one�scC@sb|r|antj|}t|dt|d|��t|dt|��t|dt�dS(u�
    Assign _get_conn and _cache_id functions to the named module.

    .. code-block:: python

        __utils__['boto.assign_partials'](__name__, 'ec2')
    u	_get_connREu	_cache_idu_exactly_oneN(RtsystmodulestsetattrRJR9R\(tmodnameR REtpacktmod((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pytassign_funcss	
co@sl|jdd�}|jdd�}xAtrg|||�}|j|�}|V|sZPn|||<q'WdS(u�
    Retrieve full set of values from a boto API call that may truncate
    its results, yielding each page as it is obtained.
    umarker_flagumarkerN(tpopRR(tfunctiontargstkwargstmarker_flagt
marker_argtrettmarker((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt
paged_calls	(.t__doc__t
__future__RRRRtloggingR]t	functoolsRtsalt.loaderRtsalt.extRtsalt.ext.six.movesRtsalt.exceptionsRtsalt.utils.stringutilsR	tsalt.utils.versionsRBtboto.exceptiont	getLoggertsetLeveltCRITICALRtHAS_BOTOtImportErrorR
t__name__tlogRRRRR)R8R9RIRJRSR[R\RcRl(((s6/usr/lib/python2.7/site-packages/salt/utils/botomod.pyt<module>!sF


		$	
%			

Zerion Mini Shell 1.0