Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/module_utils/network/avi/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyc

�
�Udac@@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	y,ddl
mZmZm
Z
mZmZWnek
r�eZnXejjdd�dkr�eje�Zn	e
�Zd	�Zd
efd��YZdddd�Zd
�Zd�Zejd�Zejd�Z ejd�Z!d�Z"dd�Z#ddddddddddddgZ$d �Z%d!�Z&d"�Z'dS(#i(tabsolute_importN(tdeepcopy(tenv_fallback(t
ApiSessiontObjectNotFoundtavi_sdk_syslog_loggertAviCredentialstHAS_AVItAVI_LOG_HANDLERttsyslogcC@sSt|t�rtStjddkrOyt|t�SWqOtk
rKtSXndS(s=
    :param x:
    :return: True if it is of type string
    iiN(t
isinstancetstrtTruetsystversion_infotunicodet	NameErrortFalse(tx((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyt_check_type_strings
tAviCheckModeResponsecB@s#eZdZdd�Zd�ZRS(s.
    Class to support ansible check mode.
    i�cC@s||_||_dS(N(tobjtstatus_code(tselfRR((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyt__init__0s	cC@s|jS(N(R(R((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytjson4s(t__name__t
__module__t__doc__RR(((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyR+scC@s�|dk	rA|jdkrA|jdd|j|j||f�St�}|j|�d|j|j|jf}|j	j
d�}d}	|s�|j	j
di�}	|	r�|	ji||6�q�i||6}	n|r�|j�n|}
|
r#|j	j
dd�r#d|
kr#|
d|
d<n|
r[|j	j
d	d�r[d
|
kr[|
d
|
d	<n|rm|rm|nd}|r|nd}|s�t
d|	�ni}
|jd|d
|
d|d|
d|�S(s�
    :param module: AnsibleModule
    :param rsp: ApiResponse from avi_api
    :param changed: boolean
    :param req: ApiRequest to avi_api
    :param existing_obj: object to be passed debug output
    :param api_context: api login context

    helper function to return the right ansible based on the error code and
    changed
    Returns: specific ansible module exit function
    i+tmsgs'Error %d Msg %s req: %s api_context:%s s%s:%s:%st!avi_disable_session_cache_as_facttapi_contexttobj_usernametusernametobj_passwordtpasswordtavi_api_contexttchangedRtold_objt
ansible_factsN(tNoneRt	fail_jsonttextRtupdate_from_ansible_modulet
controllerR"tporttparamstgettupdateRtdictt	exit_json(tmoduletrspR&treqtexisting_objR t	api_credstkeytdisable_facttfact_contexttobj_valtold_obj_valtapi_context_valtansible_facts_val((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytansible_return8s8		

	cC@s�g}xd|jj�D]S\}}|jdt�s||krFqn||dkri|j|�qiqqWtjd|�x|D]}|j|d�q�W|S(s�
    It purges the optional arguments to be sent to the controller.
    :param obj: dictionary of the ansible object passed as argument.
    :param module: AnsibleModule
    return modified obj
    trequiredspurging fields %sN(	t
argument_spectitemsR0RR)tappendtlogtdebugtpop(RR4tpurge_fieldstparamtspec((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytpurge_optional_fieldsks
cC@smt|�tkr|Sg}x2|j�D]$\}}t|�tkr�d|krc|ddkso|dkr|j|�qMt|�|sM|j|�qMq)t|�tkrg}x0|D](}t|�}|r�|j|�q�q�W|r|||<qM|j|�q)t|t�s.t|t�r)|dkrM|j|�qMq)q)Wx|D]
}||=qXW|S(s�
    cleans up any field that is marked as state: absent. It needs to be removed
    from the object if it is present.
    :param obj:
    :return: Purged object
    tstatetabsents{'state': 'absent'}(ttypeR2RCRDtcleanup_absent_fieldstlistRR(Rtcleanup_keystktvtnew_listtelem((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyRO�s4



s!^/api/[\w/]+\?name\=[\w]+[^#<>]*$shttps://[\w.0-9:-]+/api/.+shttps://[\w.0-9:-]+/api/.*#.+cC@s�t|�tttttfkr<t|�}t|�}nt|�oQt|�sXtSt|�}}t|�}tj	|�r�|j
d�d}nctj	|�r�|jdd�d}|jdd�d}n%tj	|�r�|j
d�d}nt
j	|�ru|j
dd�d}|j
d�d}|jdd�}|d}t|�dkrl|dnd}n||||fk}|s�tjd	||||�n|S(
s
    compares two references
    1. check for exact reference
    2. check for obj_type/uuid
    3. check for name

    if x is ref=name then extract uuid and name from y and use it.
    if x is http_ref then
        strip x and y
        compare them.

    if x and y are urls then match with split on #
    if x is a RE_REF_MATCH then extract name
    if y is a REF_MATCH then extract name
    :param x: first string
    :param y: second string from controller's object

    Returns
        True if they are equivalent else False
    sname=it#isapi/t/i����R	sx: %s y: %s y_name %s y_uuid %s(RNtinttfloattbooltcomplexRRRtRE_REF_MATCHtmatchtsplittHTTP_REF_MATCHtrsplittHTTP_REF_W_NAME_MATCHtlenRERF(Rtyty_uuidty_nametpathtuuid_or_nametpartstresult((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyt
ref_n_str_cmp�s2!
%	c
	C@s�|st�}nt|t�s0t|t�r=t||�St|�ttgkr_||kSt|�tkr�t|�t|�kr�tj	dt|�t|��t
Sx;t||�D]'}t|d|dd|�s�t
Sq�Wnt|�tkr�|j
dd�|j
dd�|j
dd�|j
dd�|j
dd�g|j�D]}||krY|^qY}|r�t
Sg}xT|j�D]F\}}|dkr�|j|�q�nt|t�r8d	|kr|d	d
krt|�tkr||kr|j|�q5t
Sq�|s�|j|�q�q�t|t�r^|r^|j|�q�t|t�s�||kr�t||t�r�|dkr�||kr�|j|�q�|r�||kr�|j|�q�q�q�Wx|D]}|j
|�q�Wt|j��}t|j��}	|j|	�s3t
SxJ|j�D]9\}}||kr\t
St|||d|�s@t
Sq@WntS(
s
    compares whether x is fully contained in y. The comparision is different
    from a simple dictionary compare for following reasons
    1. Some fields could be references. The object in controller returns the
        full URL for those references. However, the ansible script would have
        it specified as /api/pool?name=blah. So, the reference fields need
        to match uuid, relative reference based on name and actual reference.

    2. Optional fields with defaults: In case there are optional fields with
        defaults then controller automatically fills it up. This would
        cause the comparison with Ansible object specification to always return
        changed.

    3. Optional fields without defaults: This is most tricky. The issue is
        how to specify deletion of such objects from ansible script. If the
        ansible playbook has object specified as Null then Avi controller will
        reject for non Message(dict) type fields. In addition, to deal with the
        defaults=null issue all the fields that are set with None are purged
        out before comparing with Avi controller's version

        So, the solution is to pass state: absent if any optional field needs
        to be deleted from the configuration. The script would return changed
        =true if it finds a key in the controller version and it is marked with
        state: absent in ansible playbook. Alternatively, it would return
        false if key is not present in the controller object. Before, doing
        put or post it would purge the fields that are marked state: absent.

    :param x: first string
    :param y: second string from controller's object
    :param sensitive_fields: sensitive fields to ignore for diff

    Returns:
        True if x is subset of y else False
    sx has %d items y has %diitsensitive_fieldst_last_modifiedttenanttapi_versiontapi_verisonRLRMs{'state': 'absent'}N(tsetRRRjRNRPR2RbRERFRtziptavi_obj_cmpRGR)tkeysRCRDtissubsetR
(
RRcRktiRRtd_xkst
d_x_absent_ksRStx_keysty_keys((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyRr�sj#

+
.
RLR-R"R$Rntavi_credentialstavi_api_update_methodtavi_api_patch_opR Rmttenant_uuidRcC@sx|jjd�}|r.|jjd�r.|S|rp|jjd�rpd|j|j|jf}|j|�SdSdS(NR Rs%s:%s:%s(R/R0R-R"R.R)(R4R8R R9((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytget_api_contextPs


cC@st�}|j|�t||�}|r�tj|j|jd|jd|jd|j	d|j
d|dd|jd|dd|d�}nNtj|j|jd|jd|jd|j	d|j
d|jd|j�}|j
d	}|j
jd
d�}|j
jdd
�}|j}	|j
jdd-�}
|j
jdd-�}|j}|rw|dkrwd||f}
n
d|}
t|j
�}|jdd�}|jdd�}xtD]}|j|d-�q�Wt||�d|kr|d|d<|jd�nd|kr6|d|d<|jd�nd|kryd|kry|dkry|d|d<|d|d<ntjd|�|r�yE|j|
d|d|didd6dd6d|	�}|j�}Wq
tk
r�d-}q
Xn|
r�idd6dd6}|jdd-�rA|djd�d }||d!<n|j||
d|d|d|d|	�}|r
d"|kr
d"|kr
|d"jd#�d }|d"jd�d }||kr�d-}q�q
n;|j|
d|d|didd6dd6d|	�j�}|d$kr'd-}t}t}|r�|r�yX|
d-k	rn|j||
d|d|d|	�}n!|j|
d|d|d|	�}Wq�tk
r�q�Xn|r�|r�t}n|r�|j d%kr�t}q�t}n|st!|||d&|d'|j"��S|r'|j#d(|j$�Snd-}d-}|r�|
d-k	rn|dkrn|d}d||f}
n|dkrt%|||�}t&|�}|r�|}|r�t'd)|�}q�|j(|
d*|d|d|d|	�}q�|r�t'd)|�}q�n~|r t'd)|�}t}n`|jdd-�i||6}|j)|
d*|d|d|d|	�}|j�}t%||�}|r�tj*d+|�tj*d,|�q�nKt}|}|r�t'd)d-�}n'|j+|d*|d|d|d|	�}t!||||d&|d'|j"��S(.si
    This converts the Ansible module into AVI object and invokes APIs
    :param module: Ansible module
    :param obj_type: string representing Avi object type
    :param sensitive_fields: sensitive fields to be excluded for comparison
        purposes.
    Returns:
        success: module.exit_json with obj=avi object
        faliure: module.fail_json
    R$ttimeoutRmR}ttokent	csrftokenR.t
session_idRLR{tputR|taddtnametuuidtclusters%s/%ss%s/R	R!R"R#t	full_nametuserspassed object %s R/tinclude_refstinclude_nameRnt	cloud_refsname=iscloud_ref.namet
tenant_refRVRMi�R7R RRtdatasEXISTING OBJ %ss
NEW OBJ %sN(,RR,R~Rtget_sessionR-R"R$RRmR}R.R�R/R0RnR)t
check_modeRRGt
POP_FIELDSRKREtinfoRRR^tget_object_by_nameRtdelete_by_nametdeleteR
RR@tget_contextR*R+RrRORR�tpatchRFtpost(R4tobj_typeRkR8R tapiRLtavi_update_methodtavi_patch_opRnR�R�R�tobj_pathRRmR}RRR7R/tcloudtexisting_obj_tenantt
obj_tenantR5R&terrR6tobj_uuidt
patch_data((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytavi_ansible_api]s	
					
	
						
		


$	





			

	
cC@s�tdtdtdgf�dtdtdgf�dtdtdgfdt�d	td
ddd
�dtd
d�dtd
ddd
�dtdd�dtd
ddd�dtd
ddd
dt�dtd
ddd
dt�dtd
ddd
dt��}tdtdtdgf�dtdtdgf�dtdtdgfdt�dtd
d�dtd
d�d	td
ddd
�dtd
dddd|�dtdd�dtd
tdd��	S( sH
    Returns common arguments for all Avi modules
    :return: dict
    R-tfallbacktAVI_CONTROLLERR"tAVI_USERNAMER$tAVI_PASSWORDtno_logRntdefaults16.4.4RNRRmtadminR}R	R.RXRi,R�R�R�RzR2toptionsR RRZN(R2RR
R)R(tcredentials_spec((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pytavi_common_argument_specs.	((t
__future__RtostretloggingRtcopyRtansible.module_utils.basicRt(ansible.module_utils.network.avi.avi_apiRRRRRtImportErrorRtenvironR0t	getLoggerRRERtobjectRR)R@RKROtcompileR\R_RaRjRrR�R~R�R�(((sR/usr/lib/python2.7/site-packages/ansible/module_utils/network/avi/ansible_utils.pyt<module>s<,

		
2		&	3l		
	�

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