%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZy_ddlZddlZddlZddlZddlZejd�jej�eZWnek
reZnXeje�Z dZ!d	�Z"d
�Z#d�Z$ddeddddd�Z&d
�Z'dddddd�Z(dd�Z)d�Z*d�Z+dd�Z,d�Z-ddddd�Z.d�Z/d�Z0d�Z1dS(u�
Boto3 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 `apply_funcs` from the `__virtual__` function
of the module. This will bring properly initilized 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.apply_funcs'](__name__, 'vpc')

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

.. versionadded:: 2015.8.0
i(tabsolute_importtprint_functiontunicode_literalsN(tpartial(trange(tSaltInvocationError(tsixuboto3cC@s&tjjj�}|tkr"tS|S(ug
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    (tsalttutilstversionstcheck_boto_reqstTruet__virtualname__(thas_boto((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt__virtual__HscC@sR|tkrt|Stjdi�}||kr:||S|tkrNt|SdS(u*
    Look up the value for an option.
    umasterN(t__opts__t
__pillar__tget(tvaluetmaster_opts((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt_optionSsc	C@s�|rxt|tj�r't|�}nt|t�r?|}n|jdd�}|jdd�}|jdd�}n|r�t|d�r�t|d�}n|s�d}tjd|�n|r�t|d�r�t|d�}n|rt|d�rt|d�}nd	j	|�}|ru|||}tj
rYtjj
j|�}n|tj|�j�}n
||}||||fS(
Nukeyukeyiduregionu.regionu	us-east-1uAssuming default region %su.keyu.keyidu	boto_{0}:(t
isinstanceRtstring_typesRtdictRtNonetlogtinfotformattPY3RRtstringutilstto_bytesthashlibtmd5t	hexdigest(	tservicetregiontkeytkeyidtprofilet_profiletlabelthash_stringtcxkey((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt_get_profile`s2		
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(s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pys	<genexpr>�s(R+Rt__context__RtvaluesRtitemstcleartupdatetFalseR(R"tnametsub_resourceR/t
invalidateR#R$R%R&R*t_tctx((R/s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pytcache_id�s&
"


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')
    (RR;(R"((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt
cache_id_func�s
c	C@s
|p	|}t|||||�\}}}}|d}|tkrNt|Sy|tjjd|d|d|�}|dkr�tdj|���n|j|�}|dkr�tdj|���nWn/t	j
jk
r�tdj||���nX|t|<|S(u�
    Return a boto connection for the service.

    .. code-block:: python

        conn = __utils__['boto.get_connection']('ec2', profile='custom_profile')
    u:conn3taws_access_key_idtaws_secret_access_keytregion_nameuRegion "{0}" is not valid.u`No authentication credentials found when attempting to make boto {0} connection to region "{1}".N(R+R0tboto3tsessiontSessionRRRtclienttbotot	exceptiontNoAuthHandlerFound(	R"tmoduleR#R$R%R&R*RAtconn((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.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()
    RG(RRI(R"RG((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pytget_connection_func�s	cC@s(t||dd|�\}}}}|S(ue
    Retrieve the region for a particular AWS service based on configured region and/or profile.
    N(R+R(R"R#R&R9((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt
get_region�s$cC@sSi}d}tjrt|d�r4|j|d<nt|d�rS|j|d<ntj|�dkr~tj|�|d<nt|d�r�|jdk	r�|j|d<nd|kr�d|kr�dj|d|d�}q/d|kr�|d}q/d|kr/|d}q/ntj	r/|j
d}ni|d6}|rO||d	<n|S(
Nuustatusureasonumessageu
error_codeucodeu{0}: {1}iuaws(RtPY2thasattrtstatustreasont	text_typet
error_codeRRRtargs(tetawstmessagetr((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.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(s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pys	<genexpr>s(titertallRRX(tltn((RZs7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt	exactly_nscC@s
t|�S(N(R_(R]((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pytexactly_onesu	_get_connu	_cache_idu_exactly_onecC@sbtj|}t||t|d|��t||t|��|dk	r^t||t�ndS(u�
    Assign _get_conn and _cache_id functions to the named module.

    .. code-block:: python

        _utils__['boto.assign_partials'](__name__, 'ec2')
    RGN(tsystmodulestsetattrRJR<RR`(tmodnameR"RGtget_conn_funcnametcache_id_funcnametexactly_one_funcnametmod((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pytassign_funcss


co@sl|jdd�}|jdd�}xAtrg|||�}|j|�}|V|sZPn|||<q'WdS(uRetrieve full set of values from a boto3 API call that may truncate
    its results, yielding each page as it is obtained.
    umarker_flagu
NextMarkeru
marker_arguMarkerN(tpopRR(tfunctionRRtkwargstmarker_flagt
marker_argtrettmarker((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt
paged_call0s	cC@sut|ttf�r)td�|D��St|t�rRtd�|j�D��St|tj�rqtj|�S|S(Ncs@s|]}t|�VqdS(N(tordered(R,tx((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pys	<genexpr>Ascs@sH|]>\}}t|tj�r0tj|�n|t|�fVqdS(N(RRRRPRr(R,R-R.((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pys	<genexpr>Cs(	RtlistttupletsortedRR2RRRP(tobj((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyRr?s
cC@st|�t|�kS(uI Compare two parsed JSON objects, given non-ordering in JSON objects
    (Rr(tlefttright((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pytjson_objs_equalIs(2t__doc__t
__future__RRRRtloggingRat	functoolsRtsalt.ext.six.movesRtsalt.exceptionsRtsalt.extRtsalt.utils.stringutilsRtsalt.utils.versionsRDR@tboto.exceptiont
boto3.sessiontbotocoret	getLoggertsetLeveltCRITICALRtHAS_BOTOtImportErrorR5t__name__RRRRR+RR;R<RIRJRKRWR_R`RiRqRrRz(((s7/usr/lib/python2.7/site-packages/salt/utils/boto3mod.pyt<module>!sT


		
	"$	
%							

Zerion Mini Shell 1.0