%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/netsnmp.pyo

�
���^c@@s(dZddlmZmZmZddlZeje�Zddl	m
Z
mZddlm
Z
ddlZdZidd6dd	6d
d6d
d6Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zddd�Z!dS(uN
Network SNMP
============

Manage the SNMP configuration on network devices.

:codeauthor: Mircea Ulinic <mircea@cloudflare.com>
:maturity:   new
:depends:    napalm
:platform:   unix

Dependencies
------------

- :mod:`napalm snmp management module (salt.modules.napalm_snmp) <salt.modules.napalm_snmp>`

.. versionadded: 2016.11.0
i(tabsolute_importtprint_functiontunicode_literalsN(tloadstdumps(tsixunetsnmpurou	read-onlyureadonlyurwu
read-writeuwritecC@stjjjttt�S(u_
    NAPALM library must be installed for this module to work and run in a (proxy) minion.
    (tsalttutilstnapalmtvirtualt__opts__t__virtualname__t__file__(((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt__virtual__7scC@stt|��S(uC
    Forced the datatype to dict, in case OrderedDict is used.
    (RR(tconfig((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_ordered_dict_to_dictBscC@s|j|�|S(ua
    Completed the values of the expected config for the edge cases with the default values.
    (tupdate(Rtdefaults((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_expand_configKs
cC@st|t�ot|�dkS(u
    Valid dictionary?
    i(t
isinstancetdicttlen(tdic((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_valid_dictUscC@s"t|tj�o!t|�dkS(u
    Valid str?
    i(RRtstring_typesR(tvalue((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt
_valid_str^scC@sidd6S(u4
    Returns the default values of a community.
    uroumode((((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_community_defaultsgscC@s�x!ddgD]}t||�q
W|jd�j�}|jd<|tj�krltj|�|d<n|ddkr�d|d<n|S(u#
    Clears community details.
    uaclumodeurourw(urourw(t	_str_elemtgettlowert_COMMUNITY_MODE_MAPtkeys(tcommunity_detailstkeyt_mode((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_clear_community_detailsrs 
cC@s/|j|d�}t|�r+|||<ndS(u[
    Re-adds the value of a specific key in the dict, only in case of valid str value.
    uN(tpopR(RR"t_value((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyR�scC@s�t|�stdfS|jd�}i}|s;tdfSt|�rWt�||<n�t|t�r�x�|D]p}t|�r�t�||<nt|�rmx?tj	|�D]+\}}t|�r�t
|�||<q�q�WqmqmWnXt|�r2xItj	|�D]+\}}t|�rt
|�||<qqWn
tdfSt|�sRtdfS||d<x$dddgD]}t||�qlWtdfS(	uC
    Checks the desired config and clears interesting details.
    uu	communityu"Must specify at least a community.u4Please specify a community or a list of communities.u*Please specify at least a valid community!ulocationucontactu
chassis_id(RtTrueRtFalseRRRtlistRt	iteritemsR$R(Rt
_communityt_community_tmpt_commt
_comm_namet
_comm_detailsR"((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt
_check_config�s6


!


cC@std�S(u4
    Retrieves the SNMP config from the device.
    usnmp.config(t__salt__(((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_retrieve_device_config�scC@s1||j�kri||<n||||<dS(u<
    DRY to build diff parts (added, removed, updated).
    N(R (tdifftdiff_keyR"R((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_create_diff_action�s
cC@sw||�s"t|d||�nQ||�rQ||�rQt|d||�n"||�sst|d||�ndS(u%
    Builds the diff dictionary.
    uaddeduremoveduupdatedN(R5(R3tfunR"tprevtcurr((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt_create_diff�scC@s�i}x`dddgD]O}|j|�|j|�krt|t||j|�|j|��qqWxZdgD]O}|j|�|j|�krst|t||j|�|j|��qsqsW|S(uU
    Computes the differences between the existing and the expected SNMP config.
    ulocationucontactu
chassis_idu	community(RR9RR(texistingtexpectedR3R"((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt
_compute_diff�s cC@sRt}g}d}xdddgD]}|j|i�}|sFq"n|jdd�}|jdd�}|jdi�}|jd	d�}	|dkr�d
}ntdjd|�d
|d|d|d|	dt�}
|o�|
jd�}|
jd�r"|
jd�r"|j|
jd��q"q"Wi|d6|rJdj|�ndd6S(u\
    Calls the configuration template to apply the configuration changes on the device.
    u
update_configuaddeduupdateduremovedulocationuucontactu	communityu
chassis_idu
remove_configu
snmp.{fun}R6tlocationtcontactt	communityt
chassis_idtcommituresultucommentu
(R'RR1tformatR(tappendtjoin(tchangestcfgredtreasonsR6R"t_updated_changest	_locationt_contactR+t_chassis_idt_ret((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt
_configure�s0		cC@st}d}i}i|d6|d6|d6|d6}t|�}t|�}t||�}t|t�sxd|d<|St|�\}}	|s�djd|	�|d<|St�}
|
jd�s�d	jd
|
jd��|d<|S|
jdi�}||kr"|j	idd6t
d6�|St||�}|j	|�|j	i|d6�td
t
kr�|j	idd6dd6�|St}
t
}|r�t|�}|jd�r�t
}
q�t}djd
|jd��|}n|
r�td�\}}n|j	i|d6|d6�|S(u9
    Configures the SNMP on the device as specified in the SLS file.

    SLS Example:

    .. code-block:: yaml

        snmp_example:
            netsnmp.managed:
                 - config:
                    location: Honolulu, HI, US
                 - defaults:
                    contact: noc@cloudflare.com

    Output example (for the SLS above, e.g. called snmp.sls under /router/):

    .. code-block:: bash

        $ sudo salt edge01.hnl01 state.sls router.snmp test=True
        edge01.hnl01:
        ----------
                  ID: snmp_example
            Function: snmp.managed
              Result: None
             Comment: Testing mode: configuration was not changed!
             Started: 13:29:06.872363
            Duration: 920.466 ms
             Changes:
                      ----------
                      added:
                          ----------
                          chassis_id:
                              None
                          contact:
                              noc@cloudflare.com
                          location:
                              Honolulu, HI, US

        Summary for edge01.hnl01
        ------------
        Succeeded: 1 (unchanged=1, changed=1)
        Failed:    0
        ------------
        Total states run:     1
        Total run time: 920.466 ms
    uunameuchangesuresultucommentu#User provided an empty SNMP config!u-Please provide a valid configuration: {error}terroru5Cannot retrieve SNMP config from the device: {reason}treasonuoutu"SNMP already configured as needed.utestu,Testing mode: configuration was not changed!u&Cannot push new SNMP config: 
{reason}unet.config_controlN(R(RRRRR0RBR2RRR'R<R
tNoneRMR1(tnameRRtresulttcommentREtrettexpected_configtvalidtmessaget_device_configt
device_configR3texpected_config_changet_configured((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pytmanaged%sl1

			
				
	("t__doc__t
__future__RRRtloggingt	getLoggert__name__tlogtjsonRRtsalt.extRtsalt.utils.napalmRRRR
RRRRRR$RR0R2R5R9R<RMRPR\(((s7/usr/lib/python2.7/site-packages/salt/states/netsnmp.pyt<module>s6
				
								0						'

Zerion Mini Shell 1.0