Anons79 Mini Shell

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

�
�Udac@s�ddlZddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZmZddlmZdd	lmZdd
lmZmZmZmZmZmZmZmZy0ddlmZm Z ddl!m"Z"e#Z$Wne%k
rKe&Z$nXe'd
dddddg�Z(e'd:d;d<d=g�Z)d�Z*d�Z+d�Z,d�Z-de.fd��YZ/de/fd��YZ0de/fd ��YZ1d!e0fd"��YZ2d#�Z3d$�Z4d%e#d&�Z5dd'�Z7d(�Z8d)�Z9d*�Z:d+�Z;d,�Z<d-�Z=d.�Z>d/�Z?d0�Z@dd1d2�ZAd3d4�ZBd5�ZCd6�ZDd%d7�ZEd8d>d9��YZFdS(?i����N(tchain(t	inet_aton(tdumps(tto_texttto_bytes(tMapping(t	iteritemststring_types(tbasic(tboolean(tto_bitst
is_netmaskt
is_masklent
to_netmaskt
to_masklent	to_subnettto_ipv6_networktVALID_MASKS(tEnvironmenttStrictUndefined(tUndefinedErrortgetgtteqtneqtlttletmintmaxtexactlytnecCs@t|tttf�r"t|�S|dk	r5|gSt�SdS(N(t
isinstancetlistttupletsettNone(tval((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytto_list@s

ccsAx:|D]2}t|t�r4t|�jd�}n|VqWdS(Ns
(RRRtsplit(tstdouttitem((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytto_linesIs
cCs�ttdtdt�dt�dtdd�dtdd�dtdd	d
t�dtdd	d
t�dtdd	d
t��|�}||jd
�S(NtcommandtkeytoutputtpromptttypeR tanswertnewlinetbooltdefaulttsendonlyt	check_alltcommands(tComplexListtdicttTruetFalsetparams(tmodulet	transform((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyttransform_commandsPs			cCst|t�rt|�S|S(N(RR tsorted(R$((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt	sort_list^s
tEntitycBsAeZdZddded�Zd�Zd�Zed�Z	RS(sTransforms a dict to with an argument spec

    This class will take a dict and apply an Ansible argument spec to the
    values.  The resulting dict will contain all of the keys in the param
    with appropriate values set.

    Example::

        argument_spec = dict(
            command=dict(key=True),
            display=dict(default='text', choices=['text', 'json']),
            validate=dict(type='bool')
        )
        transform = Entity(module, argument_spec)
        value = dict(command='foo')
        result = transform(value)
        print result
        {'command': 'foo', 'display': 'text', 'validate': None}

    Supported argument spec:
        * key - specifies how to map a single value to a dict
        * read_from - read and apply the argument_spec from the module
        * required - a value is required
        * type - type of value (uses AnsibleModule type checker)
        * fallback - implements fallback function
        * choices - set of valid options
        * default - default value
    c
Cs�|dkrgn|}|p!i|_||_x^|D]V}t�|j|<|rg||j|d<n|r7||kr7t|j|d<q7q7Wt|jj��|_t}x�t	|j�D]�\}}	|	j
d�r]|	d|jjkr|jdd|	d�n|jjj
|	d�}
x6t	|
�D]%\}}||	kr1||	|<q1q1Wn|	j
d�r�|r�|jdd�nt}t|	d<q�q�WdS(Nt	read_fromR+tmsgsargument %s does not exists#only one key value can be specifiedtrequired(
R#t_attributest_moduleR7R8t	frozensettkeyst
attr_namesR9Rtgett
argument_spect	fail_json(
tselfR;tattrstargsRGtfrom_argspectargt_has_keytnametattrtspecR+tvalue((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt__init__�s0	
cCs|jS(N(RD(RL((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt	serialize�scCsYi}xLt|j�D];\}}|jd�r>|||<q|jd�||<qW|S(NR+R2(RRDRI(RLRUtobjRRRS((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytto_dict�s
c

Csut|t�s!|j|�}n|rkt|�j|j�}|rk|jjdddj|��qknxt	|j
�D]�\}}|j|�dkr�|jd�||<n|jd�ro|j|�ro|jdd�}|d}g}i}	|dk	rox0|dD]$}
t|
t�r.|
}	q|
}qWy|||	�||<Wqlt
jk
rhq{qlXqon|jd�r�|j|�dkr�|jjdd	|�nd
|kr|||d
kr|jjdd|dj|d
�||f�qn||dk	rG|jd
d�}|jj|}|||�q{|j|�r{|jj|||<q{q{W|S(NRBsinvalid keys: %st,R2tfallbackiiRCsmissing required attribute %stchoicess%s must be one of %s, got %ss, R.tstr(N(RR7RYR"t
differenceRHRERKtjoinRRDRIR#RtAnsibleFallbackNotFoundt _CHECK_ARGUMENT_TYPES_DISPATCHERR:(
RLRUtstricttunknownRRRSR[tfallback_strategyt
fallback_argstfallback_kwargsR(t
value_typettype_checker((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt__call__�sF&
	

$7N(
t__name__t
__module__t__doc__R#R9RVRWRYR8Ri(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR@ds
 			tEntityCollectioncBseZdZed�ZRS(s/Extends ```Entity``` to handle a list of dicts cCs�|dkr3tt|�j|jj|�g}nt|ttf�s^|jj	dd�ng|D]!}tt|�j||�^qeS(NRBsvalue must be an iterable(
R#tsuperRmRiRER:RR R!RK(RLtiterableRbti((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRi�s
'(RjRkRlR8Ri(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRm�stComplexDictcBseZd�ZRS(cOs#tt|�j||||�dS(N(RnRqRV(RLRMR;RNtkwargs((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRV�s(RjRkRV(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRq�sR6cBseZd�ZRS(cOs#tt|�j||||�dS(N(RnR6RV(RLRMR;RNRr((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRV�s(RjRkRV(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR6�scCsZt|t�std��nt|t�sT|dkrEt�}qTtd��nt�}x�t|�D]�\}}t|t�r�|j|�}|dk	rt|||�}|r�|||<q�qqj|j|�}|dk	rjt||�t|�kr|||<qqjqjWx<t|j	��j
|j	��D]}|j|�||<q9W|S(sq Generate a dict object of differences

    This function will compare two dict objects and return the difference
    between them as a dict object.  For scalar values, the key will reflect
    the updated value.  If the key does not exist in `comparable`, then then no
    key will be returned.  For lists, the value in comparable will wholly replace
    the value in base for the key.  For dicts, the returned value will only
    return keys that are different.

    :param base: dict object to base the diff on
    :param comparable: dict object to compare against base

    :returns: new dict object with differences
    s`base` must be of type <dict>s#`comparable` must be of type <dict>N(RR7tAssertionErrorR#RRIt	dict_diffR?R"RGR^(tbaset
comparabletupdatesR+RUR(tsub_difftcomparable_value((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRt�s*	(cCsgt|t�std��nt|t�s<td��nt�}x�t|�D]�\}}t|t�r�||kr�|j|�}|dk	r�t||t�r�t|||�||<q�||||<q�|||<q |||<qRt|t�r�||kr�|j|�}|dk	r�y#tt	t
||���||<Wq�tk
r�|jg|D]}||krb|^qb�|||<q�Xq�|||<q |||<qR||kr|j|�}|dk	r	t
||�t
|�kr�|||<q|||<q |||<qR|||<qRWx<t	|j��j|j��D]}|j|�||<qFW|S(s� Return a new dict object that combines base and other

    This will create a new dict object that is a combination of the key/value
    pairs from base and other.  When both keys exist, the value will be
    selected from other.  If the value is a list object, the two lists will
    be combined and duplicate entries removed.

    :param base: dict object to serve as base
    :param other: dict object to combine with base

    :returns: new combined dict object
    s`base` must be of type <dict>s`other` must be of type <dict>N(RR7RsRRIR#Rt
dict_mergeR R"Rt	TypeErrortextendR?RGR^(RutothertcombinedR+RUR(Rptother_value((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRz!sJ
	

#
,




(RRcCsXi}xK|D]C}|j�}|r7|j|�}n|j|�}|||<q
W|S(s�Rotates a list of dictionaries to be a dictionary of dictionaries.

    :param param_list: The aforementioned list of dictionaries
    :param unique_key: The name of a key which is present and unique in all of param_list's dictionaries. The value
    behind this key will be the key each dictionary can be found at in the new root dictionary
    :param remove_key: If True, remove unique_key from the individual dictionaries before returning.
    (tcopytpopRI(t
param_listt
unique_keyt
remove_keyt
param_dictR:RR((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytparam_list_to_dictbs
cs$tjdt|�tj�}|r9|j�\�}n-d�dt|�kr`td��n|}|dkr�|dk	r�t|�|�}n't|�r�||�}||�}nt	�fd�t
D����tt��r�t
krtd���ntt��}|||�S(Ns^(.+)\((.+)\)$Rt s)invalid expression: cannot contain spacesc3s'|]\}}�|kr|VqdS(N((t.0taliastoper(top(sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pys	<genexpr>�ssunknown operator: %s(tretmatchR]tItgroupsRsR#R.tcallabletnexttALIASESthasattrtoperatort	OPERATORSt
ValueErrortgetattr(texprR$tcastR�RPtfunc((R�sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytconditionalvs"cCs|r
|S|SdS(s  value ? true_val : false_val N((RUttrue_valt	false_val((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytternary�scCs3x,|D]$}d||kr||d=qqWdS(NR2((RTR(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytremove_default_spec�s
cCs<ytj|�Wntjk
r(tSX|jd�dkS(Nt.i(tsocketRterrorR9tcount(taddress((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytvalidate_ip_address�s
cCs3ytjtj|�Wntjk
r.tSXtS(N(R�t	inet_ptontAF_INET6R�R9R8(R�((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytvalidate_ip_v6_address�s
cCs1|r-dt|�ko#dknr-tStS(Nii (tintR9R8(tprefix((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytvalidate_prefix�s)cCs�|jdi�}x�t|�D]�\}}||kr||krT||||<q�d|krwt|d�||<q�d|kr�|d||<q�d||<qqWd|kr�t|dp�t�|d<n||d<|S(NtproviderR[R2t	authorize(RIRt	_fallbackR#R	R9(RTRNR�R+RU((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt
load_provider�s
cCsu|d}g}i}x0|dD]$}t|t�r?|}q!|}q!Wy|||�SWntjk
rpnXdS(Nii(RR7RR`(R[tstrategyRNRrR(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR��s
	
cCs�i}|s|Sx�t|�D]|\}}d|krIi|d|6}nCd|kr|ddkrit|d�|6}n
id|6}|j|�qW|S(s�
    Generate dictionary which is in sync with argspec

    :param spec: A dictionary that is the argspec of the module
    :rtype: A dictionary
    :returns: A dictionary in sync with argspec with default value
    R2R.R7toptionsN(Rt
generate_dictR#tupdate(RTRXR+R$tdct((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR��s
cCsDtjd||tj�}|r:|jd�j�}nd}|S(s�
    Parse config based on argument

    :param cfg: A text string which is a line of configuration.
    :param arg: A text string which is to be matched.
    :rtype: A text string
    :returns: A text string if match is found
    s
%s (.+)(\n|$)iN(R�tsearchtMtgrouptstripR#(tcfgRPR�tresult((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytparse_conf_arg�s
	tnocCsYtjd||�}|r |S|dk	rUtjd||f|�}|rU|SndS(s�
    Parse config based on command

    :param cfg: A text string which is a line of configuration.
    :param cmd: A text string which is the command to be matched
    :param res1: A text string to be returned if the command is present
    :param res2: A text string to be returned if the negate command
                 is present
    :param delete_str: A text string to identify the start of the
                 negate command
    :rtype: A text string
    :returns: A text string if match is found
    s
\n\s+%s(\n|$)s\n\s+%s %s(\n|$)N(R�R�R#(R�tcmdtres1tres2t
delete_strR�((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytparse_conf_cmd_arg�sttextcCs|j|�}t|�ru|dkr=t|dd�}q{|dkr_t|dd�}q{t|dd�}nd}|S(s�
    :param cfg: The top level configuration lxml Element tree object
    :param path: The relative xpath w.r.t to top level element (cfg)
           to be searched in the xml hierarchy
    :param data: The type of data to be returned for the matched xml node.
        Valid values are text, tag, attrib, with default as text.
    :return: Returns the required type for the matched xml node or else None
    ttagitattribR�N(txpathtlenR�R#(R�tpathtdataR�R�((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytget_xml_conf_args	c	Cs!i}|s|Sx
t|�D]�\}}d}t|t�rct|�}|ri||6}qn�t|t�r�|r�tg|D]}t|t�^q��r�g|D]}t|�^q�}|ri||6}qn+|dgiddgkri||6}n|r|j|�qqW|S(s�
    Generate final config dictionary

    :param cfg_dict: A dictionary parsed in the facts system
    :rtype: A dictionary
    :returns: A dictionary by eliminating keys that have null values
    tN((RR#RR7tremove_emptiesR tallR�(tcfg_dictt	final_cfgR+R$R�t	child_valtx((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR�,s&(cCsGtj}ttji|d6��t_tj|�j}|t_|S(s�
    Validate if the input data against the AnsibleModule spec format
    :param spec: Ansible argument spec
    :param data: Data to be validated
    :return:
    tANSIBLE_MODULE_ARGS(Rt
_ANSIBLE_ARGSRtjsonRt
AnsibleModuleR:(RTR�R:tvalidated_data((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytvalidate_configJs
		cCs)x"|D]}|||kr|SqWdS(N(R#(RRtlstR+R(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pytsearch_obj_in_listXs
tTemplatecBs)eZd�Zded�Zd�ZRS(cCsEtstd��ntdt�|_|jjjitd6�dS(Nsgjinja2 is required but does not appear to be installed.  It can be installed using `pip install jinja2`t	undefinedR�(t
HAS_JINJA2tImportErrorRRtenvtfiltersR�R�(RL((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRVascCs�|p	i}|j|�s|Sy|jj|�j|�}Wntk
r^|sXdS�nX|r�ytj|�SWq�tk
r�t	|�SXndSdS(N(
t
contains_varsR�tfrom_stringtrenderRR#tasttliteral_evalt	ExceptionR](RLRUt	variablestfail_on_undefined((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyRiis

cCsRt|t�rNx<|jj|jj|jjfD]}||kr1tSq1WntS(N(RRR�tblock_start_stringtvariable_start_stringtcomment_start_stringR8R9(RLR�tmarker((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR�~s
(N(RjRkRVR#R8RiR�(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyR�_s	(sminR(smaxR(Rseq(RR((GR�R�R�R�R�t	itertoolsRRRtansible.module_utils._textRRt/ansible.module_utils.common._collections_compatRtansible.module_utils.sixRRtansible.module_utilsRt)ansible.module_utils.parsing.convert_boolR	t#ansible.module_utils.common.networkR
RRR
RRRRtjinja2RRtjinja2.exceptionsRR8R�R�R9RFR�R�R%R)R=R?tobjectR@RmRqR6RtRzR�R#R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((sM/usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.pyt<module>s`:


					x	,	A											

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