Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/module_utils/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/module_utils/ec2.pyo

�
�Udac@s�ddlZddlZddlZddlmZddlmZmZddlm	Z	m
Z
ddlmZddl
mZmZmZddlmZmZmZmZdZy"ddlZddlZeZWn#ek
r�ej�ZeZnXdZy"ddl Z ddl!Z!eZ"Wn#e#k
rIej�ZeZ"nXyddl$m%Z%eZ&Wnek
r}eZ&nXd	e#fd
��YZ'd�Z(defd
��YZ)ddddd�Z*ddddd�Z+e+Z,d�Z-d�Z.d�Z/ed�Z0d�Z1d�Z2d�Z3d�Z4d�Z5ddd�Z6ddd�Z7ded�Z8d�Z9d�Z:d �Z;d!�Z<d"�Z=ed#�Z>dS($i����N(t__version__(tmissing_required_libtenv_fallback(t	to_nativetto_text(t
CloudRetry(tstring_typestbinary_typet	text_type(tcamel_dict_to_snake_dicttsnake_dict_to_camel_dictt_camel_to_snaket_snake_to_camel(t
cmp_to_keytAnsibleAWSErrorcBseZRS((t__name__t
__module__(((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyRFscCstrtjjStd�S(s�
    Allow for boto3 not being installed when using these utils by wrapping
    botocore.exceptions instead of assigning from it directly.
    N(t	HAS_BOTO3tbotocoret
exceptionstClientErrorttypetNone(((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt_botocore_exception_maybeJs
tAWSRetrycBs2eZe�Zed��Zedd��ZRS(cCs|jddS(NtErrortCode(tresponse(terror((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytstatus_code_from_exceptionWscCsYdddddddg}|r1|j|�ntjd�}||kpX|j|�S(	NtRequestLimitExceededtUnavailabletServiceUnavailabletInternalFailuret
InternalErrortTooManyRequestsExceptiont
Throttlings
^\w+.NotFound(textendtretcompiletsearch(t
response_codetcatch_extra_error_codestretry_ont	not_found((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytfound[s
			N(RRRt
base_clasststaticmethodRRR-(((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyRTs	c
Ks�y&td|d|d|d||�SWn�tk
rU}|jddt|��n|tjjtjjtjjtjj	fk
r�}|jdt|��n0tjj
k
r�}|jdd|j�nXdS(Nt	conn_typetresourcetregiontendpointtmsgsCouldn't connect to AWS: %ssoThe %s module requires a region and none was found in configuration, environment variables or module parameters(t_boto3_connt
ValueErrort	fail_jsonRRRtProfileNotFoundtPartialCredentialsErrortNoCredentialsErrortConfigParseErrort
NoRegionErrort_name(tmoduleR0R1R2R3tparamste((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt
boto3_connss& c		Ks9|jdd�}|dkr-td��n|jd�r`|jd�}djt�|_ntjj	ddjt��}t
jjd|�}|dkr�|j
|d|d	|d
||�S|dkr�|j|d|d	|d
||�S|j|d	|d
||�}|j
|d	|d
||�}||fSdS(Ntprofile_nametbothR1tclients�There is an issue in the calling code. You must specify either both, resource, or client to the conn_type parameter in the boto3_conn function calltconfigsAnsible/{0}tuser_agent_extratregion_nametendpoint_url(RCsresourcesclient(tpopRR6tgettformatRRFRREtConfigtboto3tsessiontSessionR1RD(	R0R1R2R3R?tprofileRERNRD((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR5�s"	""cCsrt|d�r|j}nSt|d�r^t|j�dt|�dtt|��}ndt|f}|S(s{
    Extracts the error message from a boto exception.

    :param err: Exception from boto
    :return: Error message
    t
error_messagetmessaget s - s%s: %s(thasattrRQtstrRRRt	Exception(terrR((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytboto_exception�s4cCs�tdtdtdgfdtdd�dt�dtd	d
dgdt�d
td	ddg�dtdtdd�dtd	dgdt�dt��S(Ntdebug_botocore_endpoint_logstfallbacktANSIBLE_DEBUG_BOTOCORE_LOGStdefaultRtbooltec2_urltaws_secret_keytaliasestec2_secret_keyt
secret_keytno_logtaws_access_keytec2_access_keyt
access_keytvalidate_certstsecurity_tokentaccess_tokenRP(tdictRtFalsetTrue(((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytaws_common_argument_spec�s$	cCs2t�}|jtdtdddg���|S(NR2R`t
aws_regiont
ec2_region(RmtupdateRj(tspec((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytec2_argument_spec�s
	c
Csl|jjd�}|jjd�}|jjd�}|jjd�}|jjd�}|jjd�}|jjd�}|s�dtjkr�tjd}q�d	tjkr�tjd	}q�n|s�tjjd
�r�tjd
}q�tjjd�rtjd}q�tjjd�r1tjd}q�trdtjjd
d�rdtjjd
d�}q�tr�tjjdd�r�tjjdd�}q�d}n|s{tjjd�r�tjd}q{tjjd�r�tjd}q{tjjd�rtjd}q{tr?tjjd
d�r?tjjd
d�}q{trrtjjdd�rrtjjdd�}q{d}n|s�dtjkr�tjd}q�dtjkr�tjd}q�dtjkr�tjd}q�|s?tr tjjdd�}|s<tjjdd�}q<q�|jdt	d�dt
�q�tr�y"tj
jd|�jd�}Wq�tjjk
r�}	q�Xq�|jdt	d�dt�n|s�tjjd�r�tjd}q�tjjd�r�tjd}q�tjjd �rtjd }q�trDtjjd
d!�rDtjjd
d!�}q�trwtjjdd!�rwtjjdd!�}q�d}ntr�|r�td|d|d"|�}
||
d#<|rtddddd"d�}
||
d$<qn8td|d|d|�}
|r||
d$<n||
d<xB|
j�D]4\}}t|t�r't|d%d&�|
|<q'q'W|||
fS('NR^RdR_RhR2RPRgtAWS_URLtEC2_URLtAWS_ACCESS_KEY_IDtAWS_ACCESS_KEYtEC2_ACCESS_KEYtCredentialstaws_access_key_idR\tAWS_SECRET_ACCESS_KEYtAWS_SECRET_KEYtEC2_SECRET_KEYtaws_secret_access_keyt
AWS_REGIONtAWS_DEFAULT_REGIONt
EC2_REGIONtBotoRnRoR4tbotot	exceptionRMtAWS_SECURITY_TOKENtAWS_SESSION_TOKENtEC2_SECURITY_TOKENtaws_security_tokentaws_session_tokentverifyRBsutf-8tstrict(R?RJtostenvirontHAS_BOTOR�RERR7RtBOTO_IMP_ERRRRRNROtget_config_variableRR8t
BOTO3_IMP_ERRRjtitemst
isinstanceRR(
R>RMR^RfRbRhR2RBRgR@tboto_paramstparamtvalue((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytget_aws_connection_info�s�		"		
	

cCs-t|�\}}}||d|d|fS(s] for compatibility mode with old modules that don't/can't yet
        use ec2_connect method RyR}(R�(R>R2R^R�((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt
get_ec2_creds=scCsEd|}tjj|d�rA|jjtjj|d��n|S(s, monkey patch for boto issue boto/boto#2100 sprofile R�(R�REt
has_optiontprovidertset_security_tokenRJ(tconnRBRP((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt"boto_fix_security_token_in_profileDs
"cKs�y|j||�}Wn#tjjk
r;td��nX|s�|g|j�D]}|j^qRkr�td||jf��q�td||jf��n|jd�r�t	||d�}n|S(Ns;Profile given for AWS was not found.  Please fix and retry.s�Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade boto or extend with endpoints_paths:Unknown problem connecting to region %s for aws module %s.RB(
tconnect_to_regionR�R�tProfileNotFoundErrorRtregionstnameRRJR�(t
aws_moduleR2R?R�taws_module_region((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytconnect_to_awsLs(cCs�t|�\}}}|rxyttj||�}Wq�tjjttjjfk
rt}|j	dt
|��q�Xnp|r�ytj||�}Wq�tjjttjjfk
r�}|j	dt
|��q�Xn|j	dd�|S(s Return an ec2 connectionR4s*Either region or ec2_url must be specified(R�R�R�tec2R�tNoAuthHandlerFoundRR�R�R7RUtconnect_ec2_endpoint(R>R2R^R�R�R@((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytec2_connect\s$$cCsjg}x]|j�D]O\}}i|d6}t|t�rK|g|d<n
||d<|j|�qW|S(s' Convert an Ansible dict of filters to list of dicts that boto3 can use
    Args:
        filters_dict (dict): Dict of AWS filters.
    Basic Usage:
        >>> filters = {'some-aws-id': 'i-01234567'}
        >>> ansible_dict_to_boto3_filter_list(filters)
        {
            'some-aws-id': 'i-01234567'
        }
    Returns:
        List: List of AWS filters and their values
        [
            {
                'Name': 'some-aws-id',
                'Values': [
                    'i-01234567',
                ]
            }
        ]
    tNametValues(R�R�Rtappend(tfilters_dicttfilters_listtktvtfilter_dict((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt!ansible_dict_to_boto3_filter_listts

cs�|r|ri||6}nidd6dd6}|s:iSxW|j�D]I\���|dkrG�|dkrGt��fd�|D��SqGWtdt|�t|�f��dS(	s Convert a boto3 list of resource tags to a flat dict of key:value pairs
    Args:
        tags_list (list): List of dicts representing AWS tags.
        tag_name_key_name (str): Value to use as the key for all tag keys (useful because boto3 doesn't always use "Key")
        tag_value_key_name (str): Value to use as the key for all tag values (useful because boto3 doesn't always use "Value")
    Basic Usage:
        >>> tags_list = [{'Key': 'MyTagKey', 'Value': 'MyTagValue'}]
        >>> boto3_tag_list_to_ansible_dict(tags_list)
        [
            {
                'Key': 'MyTagKey',
                'Value': 'MyTagValue'
            }
        ]
    Returns:
        Dict: Dict of key:value pairs representing AWS tags
         {
            'MyTagKey': 'MyTagValue',
        }
    R�tkeytValuetKeyic3s#|]}|�|�fVqdS(N((t.0ttag(R�R�(s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pys	<genexpr>�ss4Couldn't find tag key (candidates %s) in tag list %sN(R�RjR6RU(t	tags_listttag_name_key_namettag_value_key_namettag_candidates((R�R�s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytboto3_tag_list_to_ansible_dict�s !R�R�cCsHg}x;|j�D]-\}}|ji||6t|�|6�qW|S(s Convert a flat dict of key:value pairs representing AWS resource tags to a boto3 list of dicts
    Args:
        tags_dict (dict): Dict representing AWS resource tags.
        tag_name_key_name (str): Value to use as the key for all tag keys (useful because boto3 doesn't always use "Key")
        tag_value_key_name (str): Value to use as the key for all tag values (useful because boto3 doesn't always use "Value")
    Basic Usage:
        >>> tags_dict = {'MyTagKey': 'MyTagValue'}
        >>> ansible_dict_to_boto3_tag_list(tags_dict)
        {
            'MyTagKey': 'MyTagValue'
        }
    Returns:
        List: List of dicts containing tag keys and values
        [
            {
                'Key': 'MyTagKey',
                'Value': 'MyTagValue'
            }
        ]
    (R�R�R(t	tags_dictR�R�R�R�R�((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytansible_dict_to_boto3_tag_list�s%cs�d��d�}g}t|t�r3|g}n�r�|rridd6|gd6g}|jd|�d}q�|j�d}n4|r�i|d6}|jd|�}n|j�}t|�j��fd	�|D��}tt|�t|��}	t|�d
kr�ddl}
g|D]}|
j	d
|�r"|^q"|(g|D]}|
j	d
|�sN|^qN}t|�d
kr�t
ddj|���q�n|g|D]6}
t�|
���|	kr�t||
���^q�7}|S(sy Return list of security group IDs from security group names. Note that security group names are not unique
     across VPCs.  If a name exists across multiple VPCs and no VPC ID is supplied, all matching IDs will be returned. This
     will probably lead to a boto exception if you attempt to assign both IDs to a resource so ensure you wrap the call in
     a try block
     cSs|r|dS|jSdS(Nt	GroupName(R�(tsgRM((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytget_sg_name�scSs|r|dS|jSdS(NtGroupId(tid(R�RM((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt	get_sg_id�ssvpc-idR�R�tFilterstSecurityGroupstfiltersc3s$|]}t�|���VqdS(N(RU(R�tall_sg(RMR�(s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pys	<genexpr>
sii����Nssg-[a-fA-F0-9]+$s+The following group names are not valid: %ss, (
R�Rtdescribe_security_groupstget_all_security_groupstsett
differencetlisttlenR&tmatchR6tjoinRU(tsec_group_listtec2_connectiontvpc_idRMR�tsec_group_id_listR�tall_sec_groupst	unmatchedtsec_group_name_listR&R�tstill_unmatchedR�((RMR�s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt%get_ec2_security_group_ids_from_names�s4		
(,+GcCs�t|t�r]x3|D]@}t|g�}t|t�rIt|�}n|j|�qWn�t|t�s{t|t�r�t|�}|jd�r�|j	d�r�|j
d�d}n|gSt|t�rEt|j��}|j
�xU|D]J}t||g�}t|t�r+t|�}n|j||f�q�Wnt|�dkrwt|dt�rw|d}nt|t�r�tr�|j
dtt��q�|j
�n|S(s�
        Takes a policy and returns a list, the contents of which are all hashable and sorted.
        Example input policy:
        {'Version': '2012-10-17',
         'Statement': [{'Action': 's3:PutObjectAcl',
                        'Sid': 'AddCannedAcl2',
                        'Resource': 'arn:aws:s3:::test_policy/*',
                        'Effect': 'Allow',
                        'Principal': {'AWS': ['arn:aws:iam::XXXXXXXXXXXX:user/username1', 'arn:aws:iam::XXXXXXXXXXXX:user/username2']}
                       }]}
        Returned value:
        [('Statement',  ((('Action', (u's3:PutObjectAcl',)),
                          ('Effect', (u'Allow',)),
                          ('Principal', ('AWS', ((u'arn:aws:iam::XXXXXXXXXXXX:user/username1',), (u'arn:aws:iam::XXXXXXXXXXXX:user/username2',)))),
                          ('Resource', (u'arn:aws:s3:::test_policy/*',)), ('Sid', (u'AddCannedAcl2',)))),
         ('Version', (u'2012-10-17',)))]

    s
arn:aws:iam::s:roott:iiiR�(R�R�t_hashable_policyttupleR�RRRt
startswithtendswithtsplitRjtkeystsortR�tPY3_COMPARISONR
tpy3cmp(tpolicytpolicy_listteacht
tupleifiedtsorted_keysR�((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR�s4


%

cCs�y(||krdS||kr#dSdSWnutk
r�}t|�jd�}t|�jd�}d||fkr�||kr�dS||kr�dSn�nXdS(sh Python 2 can sort lists of mixed types. Strings < tuples. Without this function this fails on Python 3.ii����iRUR�N(t	TypeErrorRtfind(tatbR@tstr_indttup_ind((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR�MscCs(tt|g��tt|g��kS(sy Compares the existing policy and the updated policy
        Returns True if there is a difference between policies.
    (R�R�(tcurrent_policyt
new_policy((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytcompare_policiescscs��fd��i}xh|j�D]Z\}}t|t�rPt|�||<q"t|t�rr�|�||<q"|||<q"W|S(s1 Sort any lists in an IAM JSON policy so that comparison of two policies with identical values but
    different orders will return true
    Args:
        policy_dict (dict): Dict representing IAM JSON policy.
    Basic Usage:
        >>> my_iam_policy = {'Principle': {'AWS':["31","7","14","101"]}
        >>> sort_json_policy_dict(my_iam_policy)
    Returns:
        Dict: Will return a copy of the policy as a Dict but any List will be sorted
        {
            'Principle': {
                'AWS': [ '7', '14', '31', '101' ]
            }
        }
    cs�g}xe|D]]}t|t�r8|jt|��q
t|t�r]|j�|��q
|j|�q
W|jdd��|S(NR�cSs#t|t�rt|j��S|S(N(R�RjtsortedR�(tx((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt<lambda>�s(R�RjR�tsort_json_policy_dictR�R�(tmy_listtchecked_listtitem(t
value_is_list(s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR�|s
(R�R�RjR�R�(tpolicy_dicttordered_policy_dictR�R�((R�s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR�jscCs
|dkrdSt|��}t|t�r�x�|D]i}||kr�t||t�r|t||||d�||<q�t||||�||<q5|Sq5Wndt|t�r�xRtt|��D] }|jt|||��q�Wn|r	t	�d||�S|S(s�
        Allows to cast elements within a dictionary to a specific type
        Example of usage:

        DEPLOYMENT_CONFIGURATION_TYPE_MAP = {
            'maximum_percent': 'int',
            'minimum_healthy_percent': 'int'
        }

        deployment_configuration = map_complex_type(module.params['deployment_configuration'],
                                                    DEPLOYMENT_CONFIGURATION_TYPE_MAP)

        This ensures all keys within the root element are casted and valid integers
    Nit__builtins__(
RRR�RjR�tmap_complex_typetrangeR�R�tglobals(tcomplex_typettype_maptnew_typeR�ti((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyR��s,
	cCs�i}g}x6|j�D](}||kr|r|j|�qqWxTt|j��t|�D]6}t||�|j|�krb||||<qbqbW||fS(s�
    Compare two dicts of AWS tags. Dicts are expected to of been created using 'boto3_tag_list_to_ansible_dict' helper function.
    Two dicts are returned - the first is tags to be set, the second is any tags to remove. Since the AWS APIs differ
    these may not be able to be used out of the box.

    :param current_tags_dict:
    :param new_tags_dict:
    :param purge_tags:
    :return: tag_key_value_pairs_to_set: a dict of key value pairs that need to be set in AWS. If all tags are identical this dict will be empty
    :return: tag_keys_to_unset: a list of key names (type str) that need to be unset in AWS. If no tags need to be unset this list will be empty
    (R�R�R�RRJ(tcurrent_tags_dictt
new_tags_dictt
purge_tagsttag_key_value_pairs_to_setttag_keys_to_unsetR�((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pytcompare_aws_tags�s
#(?R�R&t	tracebackt$ansible.module_utils.ansible_releaseRtansible.module_utils.basicRRtansible.module_utils._textRRtansible.module_utils.cloudRtansible.module_utils.sixRRRt0ansible.module_utils.common.dict_transformationsR	R
RRRR�R�tboto.ec2RlR�tImportErrort
format_excRkR�RMRRRVt	functoolsR
R�RRRRAR5tboto3_inventory_connRXRmRrR�R�R�R�R�R�R�R�R�R�R�R�R�R�R(((s</usr/lib/python2.7/site-packages/ansible/module_utils/ec2.pyt<module>sj"








	

			
u					$$@	3			.	*

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