%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sXdZddlmZmZmZy:ddlmZddlmZddlm	Z
eZWne
k
rueZnXddlZddlmZddlmZd	Zd
ZdZeZdZd
ddgZdddgZidd
6dd6dd6dd6dd6dd6dd6Zd�Zd�Zdd�Z d�Z!eed�Z"d �Z#dS(!u�
BGP Finder
==========

.. versionadded:: 2017.7.0

Runner to search BGP neighbors details.

Configuration
-------------

- Minion (proxy) config

    The ``bgp.neighbors`` function must be appened in the list of ``mine_functions``:

    .. code-block:: yaml

        mine_functions:
          bgp.neighbors: []

    Which instructs Salt to cache the data returned by the ``neighbors`` function
    from the :mod:`NAPALM BGP module <salt.modules.napalm_bgp.neighbors>`.

    How often the mines are refreshed, can be specified using:

    .. code-block:: yaml

        mine_interval: <X minutes>

- Master config

    By default the following options can be configured on the master.
    They are not mandatory, but available in case the user has different requirements.

    tgt: ``*``
        From what minions will collect the mine data.
        Default: ``*`` (collect mine data from all minions)

    tgt_type: ``glob``
        Minion matching expression form. Default: ``glob``.

    return_fields
        What fields to return in the output.
        It can display all the fields from the ``neighbors`` function
        from the :mod:`NAPALM BGP module <salt.modules.napalm_bgp.neighbors>`.

        Some fields cannot be removed:

        - ``as_number``: the AS number of the neighbor
        - ``device``: the minion ID
        - ``neighbor_address``: the neighbor remote IP address

        By default, the following extra fields are returned (displayed):

        - ``connection_stats``: connection stats, as described below
        - ``import_policy``: the name of the import policy
        - ``export_policy``: the name of the export policy

        Special fields:

        - ``vrf``: return the name of the VRF.
        - ``connection_stats``: returning an output of the form ``<State>
          <Active>/<Received>/<Accepted>/<Damped>``, e.g.  ``Established
          398/399/399/0`` similar to the usual output from network devices.
        - ``interface_description``: matches the neighbor details with the
          corresponding interface and returns its description. This will reuse
          functionality from the :mod:`net runner
          <salt.runners.net.interfaces>`, so the user needs to enable the mines
          as specified in the documentation.
        - ``interface_name``: matches the neighbor details with the
          corresponding interface and returns the name.  Similar to
          ``interface_description``, this will reuse functionality from the
          :mod:`net runner <salt.runners.net.interfaces>`, so the user needs to
          enable the mines as specified in the documentation.

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    outputter: ``table``
        Specify the outputter name when displaying on the CLI. Default: :mod:`table <salt.output.table_out>`.

    Configuration example:

    .. code-block:: yaml

        runners:
          bgp:
            tgt: 'edge*'
            tgt_type: 'glob'
            return_fields:
              - up
              - connection_state
              - previous_connection_state
              - suppress_4byte_as
              - holdtime
              - flap_count
            outputter: yaml
i(tabsolute_importtprint_functiontunicode_literals(t	IPNetwork(t	IPAddress(thelpersN(tsix(tmapubgpu*uglobutableudeviceu	as_numberuneighbor_addressuconnection_statsu
import_policyu
export_policyuDeviceu	AS NumberuNeighbor IPu&State|#Active/Received/Accepted/Dampedu	Policy INu
Policy OUTuVRFuvrfcC@str
tStdfS(Nu,The napalm-base module could not be imported(tHAS_NAPALM_BASEt__virtualname__tFalse(((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt__virtual__�scC@s�tjdi�jdi�}i|jdt�d6|jdt�d6|jdt�d6t|jdt�d6|jdt�d6S(u(
    Return the bgp runner options.
    urunnersubgputgtutgt_typeudisplayu
return_fieldsu	outputter(t__opts__tgett_DEFAULT_TARGETt_DEFAULT_EXPR_FORMt_DEFAULT_DISPLAYt_DEFAULT_INCLUDED_FIELDSt_DEFAULT_RETURN_FIELDSt_DEFAULT_OUTPUTTER(trunner_opts((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt_get_bgp_runner_opts�scC@s1|st�}ntd|ddd|d�S(u\
    Helper to return the mine data from the minions, as configured on the runner opts.
    umine.getutgtu
bgp.neighborsttgt_typeutgt_type(Rt__salt__(topts((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt	_get_mine�s
cC@sDx=tj|�D],\}}||kr|||krtSqWtS(uT
    Compare two dictionaries and return a boolean value if their values match.
    (Rt	iteritemsR
tTrue(tdict1tdict2tkargtwarg((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt_compare_match�sc
C@sz|rr|dkrMtjji|d6|d6dtd|dddd�}ntjj||t�}t|�n|SdS(u%
    Display or return the rows.
    utableurowsulabelsttitletrows_keyt
labels_keyN(tsalttoutputt
out_formatRtprint(trowstlabelsR!tdisplayt	outputtertret((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt_display_runner�s	
c@s�t�}�jdd5�}�jd|d�}�jd|d�}i}|j��x<tj|�D]+\}}|jd�rj�j|�qjqjW|r��r�|r�td�ngS�jdd5�}	�jdd5�}
�jdd5�}|rt|�nd5}g}
i}xW|d	D]K}|t	krFt	|||<q#d
j
td�|jd���||<q#Wt
t|d	�tt��}td
|�}|s�g}|r�|jdjddj
g|D]}tj|�^q����n|
r|jdjd|
��n|r8|jdjd|��n�ru|jdjddj
t�fd������ndj
|�}nx�tj|�D]�\}}|jd�s�q�n|	r�||	kr�q�n|jdi�}x�tj|�D]�\}}xytj|�D]h\}}|r2||kr2qnxA|D]9}�r[t�|�r[q9n|
r||
|jd�kr|q9n|r�|jd�r�t|jd��}||kr�q9q�ni|d6|jd�d6|d6}d|kr�||d<nd|krwd jd!|jd"d#�d$|jd%d#�d&|jd'd#�d(|jd)d#�d*|jd+d#��}||d<nd,|ks�d-|kr7td.d/|d|jd�d0t�}|rd,|kr�|d1d,|d,<nd-|kr4|d1d2|d-<q4q7d,|krd3|d,<nd-|kr7d3|d-<q7nx+|D]#}||kr>||||<q>q>W|
j|�q9WqWq�Wq�Wt|
||d0|d4|�S(6u�
    Search for BGP neighbors details in the mines of the ``bgp.neighbors`` function.

    Arguments:

    asns
        A list of AS numbers to search for.
        The runner will return only the neighbors of these AS numbers.

    device
        Filter by device name (minion ID).

    ip
        Search BGP neighbor using the IP address.
        In multi-VRF environments, the same IP address could be used by
        more than one neighbors, in different routing tables.

    network
        Search neighbors within a certain IP network.

    title
        Custom title.

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    outputter: ``table``
        Specify the outputter name when displaying on the CLI. Default: :mod:`table <salt.output.table_out>`.

    In addition, any field from the output of the ``neighbors`` function
    from the :mod:`NAPALM BGP module <salt.modules.napalm_bgp.neighbors>` can be used as a filter.

    CLI Example:

    .. code-block:: bash

        salt-run bgp.neighbors 13335 15169
        salt-run bgp.neighbors 13335 ip=172.17.19.1
        salt-run bgp.neighbors multipath=True
        salt-run bgp.neighbors up=False export_policy=my-export-policy multihop=False
        salt-run bgp.neighbors network=192.168.0.0/16

    Output example:

    .. code-block:: text

        BGP Neighbors for 13335, 15169
        ________________________________________________________________________________________________________________________________________________________________
        |    Device    | AS Number |         Neighbor Address        | State|#Active/Received/Accepted/Damped |         Policy IN         |         Policy OUT         |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.bjm01 |   13335   |          172.17.109.11          |        Established 0/398/398/0         |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.bjm01 |   13335   |          172.17.109.12          |       Established 397/398/398/0        |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.flw01 |   13335   |          192.168.172.11         |        Established 1/398/398/0         |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.oua01 |   13335   |          172.17.109.17          |          Established 0/0/0/0           |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.bjm01 |   15169   |             2001::1             |       Established 102/102/102/0        |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.bjm01 |   15169   |             2001::2             |       Established 102/102/102/0        |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
        | edge01.tbg01 |   13335   |          192.168.172.17         |          Established 0/1/1/0           |       import-policy       |        export-policy       |
        ________________________________________________________________________________________________________________________________________________________________
    utitleudisplayu	outputteru__pubu8Please specify at least an AS Number or an output filterudeviceuipunetworku
return_fieldsu cS@s
|j�S(N(R!(tword((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt<lambda>Hsu_RuBGP Neighbors for {asns}tasnsu, u:Selecting neighbors having the remote IP address: {ipaddr}tipaddru2Selecting neighbors within the IP network: {ipnet}tipnetu<Searching for BGP neighbors having the attributes: {attrmap}tattrmapc@sdjd|d�|�S(Nu
{key}={value}tkeytvalue(tformat(R4(tkwargs(s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyR/Xsu
uresultuouturemote_addressuneighbor_addressu	as_numberuvrfuconnection_statsu/{state} {active}/{received}/{accepted}/{damped}tstateuconnection_statei����tactiveuactive_prefix_counttreceivedureceived_prefix_counttaccepteduaccepted_prefix_counttdampedusuppressed_prefix_countuinterface_descriptionuinterface_nameunet.interfacestdeviceR*iu	interfaceuR+N(RtpoptNonetupdateRRt
startswithR'Rt_DEFAULT_LABELS_MAPPINGtjoinRtsplittlisttsetRRtappendR6t	text_typeR
R RRR
R-(R0R7RR!R*R+tkwargs_copyRt_R=tneighbor_ipR2t	ipnet_objR(R)tfieldtdisplay_fieldstget_bgp_neighbors_allttitle_partstasntminiontget_bgp_neighbors_miniontget_bgp_neighbors_minion_outtvrftvrf_bgp_neighborstget_bgp_neighbors_minion_asntneighbortneighbor_ip_objtrowtconnection_statstnet_find((R7s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt	neighbors�s�B	

, 2(
	

	
	

($t__doc__t
__future__RRRtnetaddrRRtnapalm_baseRtnapalm_helpersRRtImportErrorR
tsalt.outputR$tsalt.extRtsalt.ext.six.movesRR	RRRRRRRBRRR?RR R-R](((s4/usr/lib/python2.7/site-packages/salt/runners/bgp.pyt<module>csJ


		
	
		


Zerion Mini Shell 1.0