%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlZy;ddl
Z
ddlZejd�jej�eZWnek
r�eZnXeje�ZdZd�Zd�Zddddd	�Zddddd
�Zddddd�Zddddd�Zddddd
�Z ddddd�Z!ddddd�Z"ddddd�Z#ddddd�Z$d�Z%d�Z&eddddd�Z'ddddd�Z(d�Z)d�Z*d�Z+dS(u�
Connection module for Amazon Kinesis

.. versionadded:: 2017.7.0

:configuration: This module accepts explicit Kinesis credentials but can also
    utilize IAM roles assigned to the instance trough Instance Profiles.
    Dynamic credentials are then automatically obtained from AWS API and no
    further configuration is necessary. More Information available at:

    .. code-block:: text

        http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

    If IAM roles are not used you need to specify them either in a pillar or
    in the minion's config file:

    .. code-block:: yaml

        kinesis.keyid: GKTADJGHEIQSXMKKRBJ08H
        kinesis.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        kinesis.region: us-east-1

    If a region is not specified, the default is us-east-1.

    It's also possible to specify key, keyid and region via a profile, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

        myprofile:
            keyid: GKTADJGHEIQSXMKKRBJ08H
            key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

:depends: boto3

i(tabsolute_importtprint_functiontunicode_literalsN(trangeuboto3uboto_kinesiscC@s7tjjj�}|tkr3tdtd�tS|S(u-
    Only load if boto3 libraries exist.
    uboto3.assign_funcsukinesis(tsalttutilstversionstcheck_boto_reqstTruet	__utils__t__name__t__virtualname__(t
has_boto_reqs((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt__virtual__Ks
cC@st|dd|�S(u�
    Stream info from AWS, via describe_stream
    Only returns the first "page" of shards (up to 100); use _get_full_stream() for all shards.

    CLI example::

        salt myminion boto_kinesis._get_basic_stream my_stream existing_conn
    udescribe_streamt
StreamName(t_execute_with_retries(tstream_nametconn((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt_get_basic_streamVs	c		C@s�td|d|d|d|�}i}t||�d}|}xc|ddr�t|dd	|d
|dddd
�}|d}|ddc|dd7<qCW||d<|S(u�
    Get complete stream info from AWS, via describe_stream, including all shards.

    CLI example::

        salt myminion boto_kinesis._get_full_stream my_stream region=us-east-1
    tregiontkeytkeyidtprofileuresultuStreamDescriptionu
HasMoreShardsudescribe_streamRtExclusiveStartShardIduShardsi����uShardId(t	_get_connRR(	RRRRRRtrtstreamtfull_stream((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt_get_full_streambs!
 
c
	C@s�td|d|d|d|�}d}d}d}xa|dkr�tjt||��|d7}t||�}	d	|	kr�|	S|	d
dd}q6W|	d
dd
r�t|||||�}	n|	S(u^
    Get complete stream info from AWS, returning only when the stream is in the ACTIVE state.
    Continues to retry when stream is updating or creating.
    If the stream is deleted during retries, the loop will catch the error and break.

    CLI example::

        salt myminion boto_kinesis.get_stream_when_active my_stream region=us-east-1
    RRRRii
uACTIVEiuerroruresultuStreamDescriptionuStreamStatusu
HasMoreShardsN(RtNonettimetsleept_jittered_backoffRR(
RRRRRRt
stream_statustattempttmax_retry_delaytstream_response((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytget_stream_when_active|s
!
c	C@sktd|d|d|d|�}i}t||�}d|kr]t|d<|d|d<n
t|d<|S(u�
    Check if the stream exists. Returns False and the error if it does not.

    CLI example::

        salt myminion boto_kinesis.exists my_stream region=us-east-1
    RRRRuerroruresult(RRtFalseR(RRRRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytexists�s!

c	C@sYtd|d|d|d|�}t|dd|d|�}d|krUt|d	<n|S(
u�
    Create a stream with name stream_name and initial number of shards num_shards.

    CLI example::

        salt myminion boto_kinesis.create_stream my_stream N region=us-east-1
    RRRRu
create_streamt
ShardCountRuerroruresult(RRR(Rt
num_shardsRRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt
create_stream�s!	
c	C@sStd|d|d|d|�}t|dd|�}d|krOt|d<n|S(	u�
    Delete the stream with name stream_name. This cannot be undone! All data will be lost!!

    CLI example::

        salt myminion boto_kinesis.delete_stream my_stream region=us-east-1
    RRRRu
delete_streamRuerroruresult(RRR(RRRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt
delete_stream�s!	
c	C@sYtd|d|d|d|�}t|dd|d|�}d|krUt|d	<n|S(
u�
    Increase stream retention period to retention_hours

    CLI example::

        salt myminion boto_kinesis.increase_stream_retention_period my_stream N region=us-east-1
    RRRRu increase_stream_retention_periodRtRetentionPeriodHoursuerroruresult(RRR(Rtretention_hoursRRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt increase_stream_retention_period�s	!	
c	C@sYtd|d|d|d|�}t|dd|d|�}d|krUt|d	<n|S(
u�
    Decrease stream retention period to retention_hours

    CLI example::

        salt myminion boto_kinesis.decrease_stream_retention_period my_stream N region=us-east-1
    RRRRu decrease_stream_retention_periodRR,uerroruresult(RRR(RR-RRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt decrease_stream_retention_period�s	!	
c	C@sYtd|d|d|d|�}t|dd|d|�}d|krUt|d	<n|S(
u�
    Enable enhanced monitoring for the specified shard-level metrics on stream stream_name

    CLI example::

        salt myminion boto_kinesis.enable_enhanced_monitoring my_stream ["metrics", "to", "enable"] region=us-east-1
    RRRRuenable_enhanced_monitoringRtShardLevelMetricsuerroruresult(RRR(RtmetricsRRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytenable_enhanced_monitoring�s	!	
c	C@sYtd|d|d|d|�}t|dd|d|�}d|krUt|d	<n|S(
u�
    Disable enhanced monitoring for the specified shard-level metrics on stream stream_name

    CLI example::

        salt myminion boto_kinesis.disable_enhanced_monitoring my_stream ["metrics", "to", "disable"] region=us-east-1
    RRRRudisable_enhanced_monitoringRR0uerroruresult(RRR(RR1RRRRRR((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytdisable_enhanced_monitorings	!	
cC@sd}d}g|d<x�|dD]�}|d}d|dkrWtjd|�q!n|dj|�t|dd	�|dd	<t|dd
�|dd
<|dd	|kr�|dd	}n|dd
|kr!|dd
}q!q!W|djdd��|||fS(
u 
    Collect some data: number of open shards, key range, etc.
    Modifies stream_details to add a sorted list of OpenShards.
    Returns (min_hash_key, max_hash_key, stream_details)

    CLI example::

        salt myminion boto_kinesis.get_info_for_reshard existing_stream_details
    iu
OpenShardsuShardsuShardIduEndingSequenceNumberuSequenceNumberRangeuskipping closed shard %suHashKeyRangeuStartingHashKeyu
EndingHashKeyRcS@st|dd�S(NuHashKeyRangeuStartingHashKey(tlong_int(tshard((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt<lambda>>s(tlogtdebugtappendR4tsort(tstream_detailstmin_hash_keytmax_hash_keyR5tshard_id((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytget_info_for_reshard"s&


cC@s'tjdkrt|�St|�SdS(uS
    The hash key is a 128-bit int, sent as a string.
    It's necessary to convert to int/long for comparison operations.
    This helper method handles python 2/3 incompatibility

    CLI example::

        salt myminion boto_kinesis.long_int some_MD5_hash_as_string

    :return: long object if python 2.X, int object if python 3.X
    iN(i(tsystversion_infotlongtint(thash_key((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyR4Cs
cC@s�td|d|d|d|�}i}t|||||�}	d|	krO|	S|	dd}
t|
�\}}}
tjdt|
d	�||�xEt|
d	�D]3\}
}|d
}d|dkr�tjd
|�q�n|dd}|dd}||||
|
}||||
d|
}||kr@|}ntjd|
||||k�tjd|
||||k�||kr�d|d<|S||kr�q�n||dkr7|rtjd|||�t|dd|d|dt|d��}ntjd|||�d|kr3t	|d<n|St
|
|�}|scdj|�|d<|S|r�tjd|||�t|dd|d|d|�}ntjd |||�d|kr�t	|d<n|Sq�Wtjd!�t|d<|S("u
    Reshard a kinesis stream.  Each call to this function will wait until the stream is ACTIVE,
    then make a single split or merge operation. This function decides where to split or merge
    with the assumption that the ultimate goal is a balanced partition space.

    For safety, user must past in force=True; otherwise, the function will dry run.

    CLI example::

        salt myminion boto_kinesis.reshard my_stream N True region=us-east-1

    :return: True if a split or merge was found/performed, False if nothing is needed
    RRRRuerroruresultuStreamDescriptionu5found %s open shards, min_hash_key %s max_hash_key %su
OpenShardsuShardIduEndingSequenceNumberuSequenceNumberRangeu)this should never happen! closed shard %suHashKeyRangeuStartingHashKeyu
EndingHashKeyiu$Shard %s (%s) should start at %s: %su"Shard %s (%s) should end at %s: %su3starting hash keys mismatch, don't know what to do!u)%s should end at %s, actual %s, splittingusplit_shardRtShardToSplittNewStartingHashKeyu*%s should end at %s, actual %s would splitu#failed to find next shard after {0}u+%s should continue past %s, merging with %sumerge_shardstShardToMergetAdjacentShardToMergeu/%s should continue past %s, would merge with %su"No split or merge action necessary(
RR%R?R7R8tlent	enumerateRtstrRt_get_next_open_shardtformatR&(Rtdesired_sizetforceRRRRRRR$R;R<R=t	shard_numR5R>tstarting_hash_keytending_hash_keytexpected_starting_hash_keytexpected_ending_hash_keyt
next_shard_id((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytreshardUs�!	
		
	

	
	

	
	



c		C@s�td|d|d|d|�}g}d}x�|dk	r�|rOi|d6ni}t|d|�}d|krw|S|r�|jd	�r�|d	ni}||jd
g�7}|jdt�tdfkr�|d
nd}q0Wi|d	6S(u�
    Return a list of all streams visible to the current account

    CLI example:

    .. code-block:: bash

        salt myminion boto_kinesis.list_streams
    RRRRuuExclusiveStartStreamNameulist_streamsuerroruresultuStreamNamesuHasMoreStreamsutruei����N(RRRtgetR&R(	RRRRRtstreamstexclusive_start_stream_nametargstret((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pytlist_streams�s
!%2cC@sKt}x>|dD]2}|d}||kr9t}qn|r|SqWdS(u�
    Return the next open shard after shard_id

    CLI example::

        salt myminion boto_kinesis._get_next_open_shard existing_stream_details shard_id
    u
OpenShardsuShardIdN(R&R(R;R>tfoundR5tcurrent_shard_id((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyRL�s
c
K@s/i}d}d}x�t|�D]�}tjd||�y't||�}||�|d<|SWqtjjk
r�}|jdd}	d|	ks�d|	kr�tjd	d
t	�t
jt||��q|jd|d<tj
|d�d
|d<|SqXqWdj||�|d<tj
|d�|S(u�
    Retry if we're rate limited by AWS or blocked by another call.
    Give up and return error message if resource not found or argument is invalid.

    conn
        The connection established by the calling method via _get_conn()

    function
        The function to call on conn. i.e. create_stream

    **kwargs
        Any kwargs required by the above function, with their keywords
        i.e. StreamName=stream_name

    Returns:
        The result dict with the HTTP response and JSON data if applicable
        as 'result', or an error as 'error'

    CLI example::

        salt myminion boto_kinesis._execute_with_retries existing_conn function_name function_kwargs

    ii
uattempt: %s function: %suresultuErroruCodeuLimitExceededExceptionuResourceInUseExceptionuRetrying due to AWS exceptiontexc_infouerroru7Tried to execute function {0} {1} times, but was unableN(RR7tinfotgetattrtbotocoret
exceptionstClientErrortresponseR8RRRR terrorRRM(
RtfunctiontkwargsRtmax_attemptsR#R"tfntet
error_code((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyR�s*
cC@sttj�d||�S(u�
    Basic exponential backoff

    CLI example::

        salt myminion boto_kinesis._jittered_backoff current_attempt_number max_delay_in_seconds
    i(tmintrandom(R"R#((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyR "s(,t__doc__t
__future__RRRtloggingRRnR@tsalt.ext.six.movesRtsalt.utils.versionsRtboto3Rbt	getLoggertsetLeveltCRITICALRtHAS_BOTOtImportErrorR&R
R7RR
RRRR%R'R*R+R.R/R2R3R?R4RVR\RLRR (((s=/usr/lib/python2.7/site-packages/salt/modules/boto_kinesis.pyt<module>,sF


		 	!	n		4

Zerion Mini Shell 1.0