%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/napalm.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlmZddl
ZddlZddlZyeddlZddljZeZeZy eejjd�d�ZWnek
r�dZnXWnGek
rDeZyddlZeZWqEek
r@eZqEXnXyddlm Z eZ!Wnek
rxeZ!nXej"e#�Z$d�Z%d	�Z&d
�Z'd�Z(d�Z)d
�Z*dd�Z,dd�Z-d�Z.d�Z/edd�Z0dS(u�
Utils for the NAPALM modules and proxy.

.. seealso::

    - :mod:`NAPALM grains: select network devices based on their characteristics <salt.grains.napalm>`
    - :mod:`NET module: network basic features <salt.modules.napalm_network>`
    - :mod:`NTP operational and configuration management module <salt.modules.napalm_ntp>`
    - :mod:`BGP operational and configuration management module <salt.modules.napalm_bgp>`
    - :mod:`Routes details <salt.modules.napalm_route>`
    - :mod:`SNMP configuration module <salt.modules.napalm_snmp>`
    - :mod:`Users configuration management <salt.modules.napalm_users>`

.. versionadded:: 2017.7.0
i(tabsolute_importtunicode_literalstprint_functionN(twraps(tsixu.(tConnectionClosedExceptioncC@s1tjjj�o0|jdi�jd�dkS(u!
    Is this a NAPALM proxy?
    uproxyu	proxytypeunapalm(tsalttutilstplatformtis_proxytget(topts((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyR	BscC@s|jdi�jdt�S(u#
    Is always alive required?
    uproxyualways_alive(R
tTrue(R((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytis_always_aliveIscC@s#t|�rt|�p"t|�S(u,
    Should this proxy be always alive?
    (R	R
t	is_minion(R((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytnot_always_alivePscC@stjjj�od|kS(u+
    Is this a NAPALM straight minion?
    unapalm(RRRR	(R((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyRWscC@s`trtdkstr4t|�s0t|�r4|Stdjd|ddjd|��fSdS(u"
    Returns the __virtual__.
    iuW"{vname}"" {filename} cannot be loaded: NAPALM is not installed: ``pip install napalm``tvnametfilenameu({filename})N(t
HAS_NAPALMtNAPALM_MAJORtHAS_NAPALM_BASER	RtFalsetformat(RtvirtualnameR((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytvirtual^s0	c
O@s�t}d'}|jdi�}|jdt�}|jdt�}|r�tjd�tjd�tj|d�|dj|�tjd�tj|d�t|�}nz�y�|jdt�s�t	d	��ni}	|	j|�x9t
j|	�D](\}
}|d'kr�|j|
�q�q�Wt|jd
�|�||�}t}Wn�t	k
r:}|jdd�}
t
j�}t|t�r�d
jd|d|jd��}nN|r|tr|t|t�r|t|d<djd|
�}tj|�tj|�tjd|
�t|ddt�tjd|
�t|ddt�tjd|
�tjd|�t||||�Sdjd|jdd�d|jdi�jd�r�djd|jdi�jd��ndd |jd!d�d|d"|�}tj|�tj|�iid#6td$6|d%6|d&6SXWd'|rtt|�rt|jd(t�rt|d
j�nXi|d#6|d$6dd%6S()u�
    Calls arbitrary methods from the network driver instance.
    Please check the readthedocs_ page for the updated list of getters.

    .. _readthedocs: http://napalm.readthedocs.org/en/latest/support/index.html#getters-support-matrix

    method
        Specifies the name of the method to be called.

    *args
        Arguments.

    **kwargs
        More arguments.

    :return: A dictionary with three keys:

        * result (True/False): if the operation succeeded
        * out (object): returns the object as-is from the call
        * comment (string): provides more details in case the call failed
        * traceback (string): complete traceback in case of exception.         Please submit an issue including this traceback         on the `correct driver repo`_ and make sure to read the FAQ_

    .. _`correct driver repo`: https://github.com/napalm-automation/napalm/issues/new
    .. FAQ_: https://github.com/napalm-automation/napalm#faq

    Example:

    .. code-block:: python

        salt.utils.napalm.call(
            napalm_object,
            'cli',
            [
                'show version',
                'show chassis fan'
            ]
        )
    u__opts__u__retryuforce_reconnectuForced reconnection initiatedu'The current opts (under the proxy key):uproxyuUpdated to:uUPu
not connecteduDRIVERuHOSTNAMEu[unspecified hostname]u;{method} is not implemented for the NAPALM {driver} driver!tmethodtdriveruDRIVER_NAMEu0Disconnected from {device}. Trying to reconnect.tdeviceuClearing the connection with %sucloset__retryu!Re-opening the connection with %suopenuConnection re-opened with %suRe-executing %suGCannot execute "{method}" on {device}{port} as {user}. Reason: {error}!tportu
OPTIONAL_ARGSuportu:{port}utuseruUSERNAMEterroruouturesultucommentu	tracebackNuCLOSE(RtNoneR
tpopRtlogtdebugtupdatet
get_devicet	ExceptionRt	iteritemstgetattrt	tracebackt
format_exct
isinstancetNotImplementedErrorRtHAS_CONN_CLOSED_EXC_CLASSRRtcallRtclose(t
napalm_deviceRtargstkwargstresulttoutRtretrytforce_reconnecttkwargs_copytkargtwargRthostnameterr_tbtcomment((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyR.qs|)



!
	


	H	


$c
C@s�i}t|�r$|jdi�n|jdi�}|jd�sT|jd�rm|jdt�|d<n|s�tjd�n|jd�p�|jd�p�|jd�p�|jd�|d	<|jd
�p�|jd�|d<|jd
�p|jd�|d<|jd�p7|jd�p7|jd�p7d|d<|jdd�|d<|jdi�|d<|jdt�|d<|jd�|d<t|d<d|dkr�t|dd<n|dr�d |dkr�d!|dd <n|S("uh
    Returns the options of the napalm device.
    :pram: opts
    :return: the network device opts
    uproxyunapalmumultiprocessinguHIncorrect minion config. Please specify at least the napalm driver name!uhostuhostnameufqdnuipuHOSTNAMEuusernameuuseruUSERNAMEudriveruosuDRIVER_NAMEupasswdupasswordupassuuPASSWORDutimeouti<uTIMEOUTu
optional_argsu
OPTIONAL_ARGSualways_aliveuALWAYS_ALIVEuprovideruPROVIDERuUPuconfig_locku	keepalivei(R	R
RR"RR(Rtsalt_objtnetwork_devicetdevice_dict((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytget_device_optss80

c	C@s�tjd�t|d|�}t}|jd�r�ytj|jd��}Wq�tk
r�}tjd|jd�dt	�tjd�q�Xn|j
|jd��}yo||jdd	�|jd
d	�|jdd	�d|d
d|d�|d<|jd�j�t	|d<Wn�tjj
k
r�}djd|jdd�d|jdi�jd�r�djd|jdi�jd��nd	d|jd
d	��}tj|�tjd|�tjj
|��nX|S(u�
    Initialise the connection with the network device through NAPALM.
    :param: opts
    :return: the network device object
    uSetting up NAPALM connectionR=uPROVIDERuUnable to import %stexc_infouFalling back to napalm-baseuDRIVER_NAMEuHOSTNAMEuuUSERNAMEuPASSWORDttimeoutuTIMEOUTt
optional_argsu
OPTIONAL_ARGSuDRIVERuUPu1Cannot connect to {hostname}{port} as {username}.R:u[unspecified hostname]Ruportu:{port}tusernameuPlease check error: %s(R"R#R@tnapalm_baseR
t	importlibt
import_moduletImportErrorRRtget_network_drivertopent
exceptionstConnectionExceptionR(RR=R>tprovider_libtierrt_driver_Rtbase_err_msg((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyR%0s>
	
	H

c@st���fd��}|S(ue
    This decorator is used to make the execution module functions
    available outside a proxy minion, or when running inside a proxy
    minion. If we are running in a proxy, retrieve the connection details
    from the __proxy__ injected variable.  If we are not, then
    use the connection information from the opts.
    :param func:
    :return:
    c@s��j}|jd�}tj|jd��}|jdi�jdt�}|jdt�}|r�tjd�tjd�tj|d�|dj|�tjd�tj|d�nt	|�r|r|r�t
|�|d	<q�|d
�|d	<n�t	|�r�|r�d|ks8d|kr�|dr�yt
|�|d	<Wq�tjj
k
r�}tj|�djd
tj|j��SXq�|d|d	<n�tjd�|jd�}|ddi�}	|ddi�}
tjd�tj|	�tjjj|�}|	j|�tjd�tj|	�|	jd�ps|	jd�ps|	jd�ps|	jd�}|r�|
r�t|
t�r�||
kr�|
|}
tjd|�tj|
�|	j|
�tjd|�tj|	�ntj|�}|	|d<d|ks-d|kr�|dr�yt
|d|�|d	<Wq�tjj
k
r�}tj|�djd
tj|j��SXn|d|d	<t|�r�||d	d<n�||�}|r�tjd�|d	}t|ddt�}n|S(Nu	__proxy__u__opts__uproxyualways_aliveuforce_reconnectu!Usage of reconnect force detecteduOpts before merginguOpts after mergingu
napalm_deviceunapalm.get_deviceuinherit_napalm_deviceu {base_msg}. See log for details.tbase_msgu$Not running in a NAPALM Proxy Minionu__salt__u
config.getunapalmunapalm_inventoryu&NAPALM opts found in the Minion configu(Merging the found opts with the CLI argsuhostuhostnameufqdnuipu!Found %s in the NAPALM inventory:uIMerging the config for %s with the details found in the napalm inventory:R=u3That was a forced reconnect, gracefully clearing upucloseR(t__globals__R
tcopytdeepcopyRRR"R#R$R	R%RERKRLRRRt	text_typetmsgRRR1tclean_kwargsR+tdictRR.(R1R2twrapped_global_namespacetproxyRtalways_aliveR6tncet	_salt_objtnapalm_optstnapalm_inventoryRWthosttinventory_optstretRtclosing(tfunc(s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytfunc_wrapperps�	



		










		

(R(RdRe((Rds5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytproxy_napalm_wrapfs
vcC@s&i|d6id6td6dd6}|S(u6
    Return the default dict of the state output.
    unameuchangesuresultuucomment(R(tnameRb((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pytdefault_ret�s
c
C@s�i}|d|d<d|kr1|d|d<nd|krN|d|d<nd|krt|rt|d|d<qtn|r�d|kr�|d|d<n|jd�r�djd|dd|d�|d<n|jd�rd	jd|dd
|d�|d<n|jd�rNdjd|ddtjj|dd
d|��|d<n|jdt�sd|S|jdt�s�|r�d|d<|S|jitd6|d6dj|d�d6�|S|jitd6id6�|S(u�
    Return the final state output.
    ret
        The initial state output structure.
    loaded
        The loaded dictionary.
    ucommentudiffu	commit_iducompliance_reportu
loaded_configu+{comment_base}

Configuration diff:

{diff}tcomment_basetdiffu,{comment_base}

Loaded config:

{loaded_cfg}t
loaded_cfgu0{comment_base}

Compliance report:

{compliance}t
complianceunestedRuresultualready_configureduchangesuConfiguration changed!
{}N(	R
RRtoutputt
string_formatRRR R$(RbtloadedttestR#tcompliance_reportRtchanges((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyt
loaded_ret�sJ		
	
)
		(1t__doc__t
__future__RRRRSR)tloggingRFt	functoolsRtsalt.extRtsalt.outputRtsalt.utils.platformtsalt.utils.argstnapalmtnapalm.basetbaseRERRRRtintt__version__tsplitRtAttributeErrorRHtnapalm_base.exceptionsRR-t	getLoggert__file__R"R	R
RRRR.R R@R%RfRhRs(((s5/usr/lib/python2.7/site-packages/salt/utils/napalm.pyt<module>sV 






						�+6	�	

Zerion Mini Shell 1.0