HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/__pycache__/napalm.cpython-310.pyc
o

�N�g�,�@s�dZddlZddlZddlZe�e�ZdZdgZ	ia
iaddgZdd�Z
d(dd	�Zd(d
d�Zd(dd
�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(dd�Zd(d d!�Zd(d"d#�Zd(d$d%�Zd(d&d'�ZdS))z�
NAPALM Grains
=============

:codeauthor: Mircea Ulinic <ping@mirceaulinic.net>
:maturity:   new
:depends:    napalm
:platform:   unix

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

- :mod:`NAPALM proxy module <salt.proxies.napalm>`

.. versionadded:: 2016.11.0
�N�napalmZsecretZenable_passwordcCstjj�ttt�S)z_
    NAPALM library must be installed for this module to work and run in a (proxy) minion.
    )�salt�utilsrZvirtual�__opts__�__virtualname__�__file__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/napalm.py�__virtual__2sr
cCsRts'|rtjj�t�r|d�atS|s'tjj�t�r'tjjjtdfii��atS)zM
    Retrieves the grains from the network device if not cached already.
    znapalm.get_grainsZ	get_facts)	�GRAINS_CACHErrr�is_proxyr�	is_minion�call�DEVICE_CACHE��proxyrrr	�_retrieve_grains_cache>s
�rcCsPts&|rtjj�t�rd|vr|d�atS|s&tjj�t�r&tjj�t�atS)zA
    Loads the network device details if not cached already.
    znapalm.get_device)rrrrrrr
Z
get_devicerrrr	�_retrieve_device_cacheMs
�rcCs:t|d�}|�dd�r|�di�r|�d��|�SdSdS)z?
    Retrieves the grain value from the cached dictionary.
    r�resultF�outN)r�get)�namerZgrainsrrr	�
_get_grain]s
�rcCst|d�}|�|���S)z+
    Retrieves device-specific grains.
    r)rr�upper)rrZdevicerrr	�_get_device_grainfs
rcC�dtd|d�iS)z�
    Returns the Operating System name running on the network device.

    Example: junos, iosxr, eos, ios etc.

    CLI Example - select all network devices running JunOS:

    .. code-block:: bash

        salt -G 'os:junos' test.ping
    �osZdriver_namer)rrrrr	�getoss�rcCr)a�
    Returns the OS version.

    Example: 13.3R6.5, 6.0.2 etc.

    CLI Example - select all network devices running JunOS 13.3R6.5 and return the model:

    .. code-block:: bash

        salt -G 'os:junos and version:13.3R6.5' grains.get model

    Output:

    .. code-block:: yaml

        edge01.bjm01:
            MX2000
        edge01.sjc01:
            MX960
        edge01.mrs01:
            MX480
        edge01.muc01:
            MX240
    �version�
os_versionr�rrrrr	r��rcC�dtd|d�iS)a
    Returns the network device chassis model.

    Example: MX480, ASR-9904-AC etc.

    CLI Example - select all Juniper MX480 routers and execute traceroute to 8.8.8.8:

    .. code-block:: bash

        salt -G 'model:MX480' net.traceroute 8.8.8.8
    �modelrr!rrrr	r$�rr$cCr)a�
    Returns the chassis serial number.

    Example: FOX1234W00F

    CLI Example - select all devices whose serial number begins with `FOX` and display the serial number value:

    .. code-block:: bash

        salt -G 'serial:FOX*' grains.get serial

    Output:

    .. code-block:: yaml

        edge01.icn01:
            FOXW00F001
        edge01.del01:
            FOXW00F002
        edge01.yyz01:
            FOXW00F003
        edge01.mrs01:
            FOXW00F004
    �serialZ
serial_numberrr!rrrr	r%�r"r%cCr#)z�
    Returns the network device vendor.

    Example: juniper, cisco, arista etc.

    CLI Example - select all devices produced by Cisco and shutdown:

    .. code-block:: bash

        salt -G 'vendor:cisco' net.cli "shut"
    �vendorrr!rrrr	r&�rr&cCr#)z�
    Returns the uptime in seconds.

    CLI Example - select all devices started/restarted within the last hour:

    .. code-block:: bash

        salt -G 'uptime<3600' test.ping
    �uptimerr!rrrr	r'�s
r'cCr)aK
    Returns the complete interfaces list of the network device.

    Example: ['lc-0/0/0', 'pfe-0/0/0', 'xe-1/3/0', 'lo0', 'irb', 'demux0', 'fxp0']

    CLI Example - select all devices that have a certain interface, e.g.: xe-1/1/1:

    .. code-block:: bash

        salt -G 'interfaces:xe-1/1/1' test.ping

    Output:

    .. code-block:: yaml

        edge01.yyz01:
            True
        edge01.maa01:
            True
        edge01.syd01:
            True
        edge01.del01:
            True
        edge01.dus01:
            True
        edge01.kix01:
            True
    �
interfacesZinterface_listrr!rrrr	r(�sr(cCs*|rtjj�t�rdtd|d�iSdSdS)aB
    Return the username.

    .. versionadded:: 2017.7.0

    CLI Example - select all devices using `foobar` as username for connection:

    .. code-block:: bash

        salt -G 'username:foobar' test.ping

    Output:

    .. code-block:: yaml

        device1:
            True
        device2:
            True
    �usernamerN�rrrrrrrrrr	r)s�r)cCr#)a@
    Return the hostname as configured on the network device.

    CLI Example:

    .. code-block:: bash

        salt 'device*' grains.get hostname

    Output:

    .. code-block:: yaml

        device1:
            edge01.yyz01
        device2:
            edge01.bjm01
        device3:
            edge01.flw01
    �hostnamerr!rrrr	r+ sr+cCs*|rtjj�t�rdtd|d�iSdSdS)a]
    This grain is set by the NAPALM grain module
    only when running in a proxy minion.
    When Salt is installed directly on the network device,
    thus running a regular minion, the ``host`` grain
    provides the physical hostname of the network device,
    as it would be on an ordinary minion server.
    When running in a proxy minion, ``host`` points to the
    value configured in the pillar: :mod:`NAPALM proxy module <salt.proxy.napalm>`.

    .. note::

        The diference between ``host`` and ``hostname`` is that
        ``host`` provides the physical location - either domain name or IP address,
        while ``hostname`` provides the hostname as configured on the device.
        They are not necessarily the same.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt 'device*' grains.get host

    Output:

    .. code-block:: yaml

        device1:
            ip-172-31-13-136.us-east-2.compute.internal
        device2:
            ip-172-31-11-193.us-east-2.compute.internal
        device3:
            ip-172-31-2-181.us-east-2.compute.internal
    �hostr+rNr*rrrr	r,8s%�r,cCs|t�dd�sdSt|d�}|r<|d}dggd�i}tjj�|d�}|r*||dd<tjj�|d	�}|r:||dd	<|SdS)
a�
    Return the DNS information of the host.
    This grain is a dictionary having two keys:

    - ``A``
    - ``AAAA``

    .. note::
        This grain is disabled by default, as the proxy startup may be slower
        when the lookup fails.
        The user can enable it using the ``napalm_host_dns_grain`` option (in
        the pillar or proxy configuration file):

        .. code-block:: yaml

            napalm_host_dns_grain: true

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt 'device*' grains.get host_dns

    Output:

    .. code-block:: yaml

        device1:
            A:
                - 172.31.9.153
            AAAA:
                - fd52:188c:c068::1
        device2:
            A:
                - 172.31.46.249
            AAAA:
                - fdca:3b17:31ab::17
        device3:
            A:
                - 172.31.8.167
            AAAA:
                - fd0f:9fd6:5fab::1
    Znapalm_host_dns_grainFNrr,�host_dns)�A�AAAAr.r/)rrr,rrZdns�lookup)rZdevice_hostZdevice_host_valueZhost_dns_retZdns_aZdns_aaaarrr	r-cs.
�r-cCs6td|d�pi}|rtrtD]}|�|d�qd|iS)a�
    Return the connection optional args.

    .. note::

        Sensible data will not be returned.

    .. versionadded:: 2017.7.0

    CLI Example - select all devices connecting via port 1234:

    .. code-block:: bash

        salt -G 'optional_args:port:1234' test.ping

    Output:

    .. code-block:: yaml

        device1:
            True
        device2:
            True
    �
optional_argsrN)r�_FORBIDDEN_OPT_ARGS�pop)rZopt_args�argrrr	r1�s
r1)N)�__doc__�loggingZsalt.utils.dnsrZsalt.utils.napalm�	getLogger�__name__�logrZ__proxyenabled__rrr2r
rrrrrrr$r%r&r'r(r)r+r,r-r1rrrr	�<module>s:
�




	







 


+=