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/proxy/__pycache__/netmiko_px.cpython-310.pyc
o

�N�gd1�@sdZddlZddlZddlZddlZz&ddlmZz
ddlmZm	Z	Wne
y4ddlmZm	Z	YnwdZWne
yCdZYnwdgZ
dZe�e�ZiZdZd	d
�Zdd�Zefd
d�Zejefdd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)a�
Netmiko
=======

.. versionadded:: 2019.2.0

Proxy module for managing network devices via
`Netmiko <https://github.com/ktbyers/netmiko>`_.

:codeauthor: Mircea Ulinic <ping@mirceaulinic.net> & Kirk Byers <ktbyers@twb-tech.com>
:maturity:   new
:depends:    netmiko
:platform:   unix

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

The ``netmiko`` proxy modules requires Netmiko to be installed: ``pip install netmiko``.

Pillar
------

The ``netmiko`` proxy configuration requires the following parameters in order
to connect to the network device:

- ``device_type`` - Class selection based on device type. Supported options:

  - ``a10``: A10 Networks
  - ``accedian``: Accedian Networks
  - ``alcatel_aos``: Alcatel AOS
  - ``alcatel_sros``: Alcatel SROS
  - ``apresia_aeos``: Apresia AEOS
  - ``arista_eos``: Arista EOS
  - ``aruba_os``: Aruba
  - ``avaya_ers``: Avaya ERS
  - ``avaya_vsp``: Avaya VSP
  - ``brocade_fastiron``: Brocade Fastiron
  - ``brocade_netiron``: Brocade Netiron
  - ``brocade_nos``: Brocade NOS
  - ``brocade_vdx``: Brocade NOS
  - ``brocade_vyos``: VyOS
  - ``checkpoint_gaia``: Check Point GAiA
  - ``calix_b6``: Calix B6
  - ``ciena_saos``: Ciena SAOS
  - ``cisco_asa``: Cisco SA
  - ``cisco_ios``: Cisco IOS
  - ``cisco_nxos``: Cisco NX-oS
  - ``cisco_s300``: Cisco S300
  - ``cisco_tp``: Cisco TpTcCe
  - ``cisco_wlc``: Cisco WLC
  - ``cisco_xe``: Cisco IOS
  - ``cisco_xr``: Cisco XR
  - ``coriant``: Coriant
  - ``dell_force10``: Dell Force10
  - ``dell_os10``: Dell OS10
  - ``dell_powerconnect``: Dell PowerConnect
  - ``eltex``: Eltex
  - ``enterasys``: Enterasys
  - ``extreme``: Extreme
  - ``extreme_wing``: Extreme Wing
  - ``f5_ltm``: F5 LTM
  - ``fortinet``: Fortinet
  - ``generic_termserver``: TerminalServer
  - ``hp_comware``: HP Comware
  - ``hp_procurve``: HP Procurve
  - ``huawei``: Huawei
  - ``huawei_vrpv8``: Huawei VRPV8
  - ``juniper``: Juniper Junos
  - ``juniper_junos``: Juniper Junos
  - ``linux``: Linux
  - ``mellanox``: Mellanox
  - ``mrv_optiswitch``: MrvOptiswitch
  - ``netapp_cdot``: NetAppcDot
  - ``netscaler``: Netscaler
  - ``ovs_linux``: OvsLinux
  - ``paloalto_panos``: PaloAlto Panos
  - ``pluribus``: Pluribus
  - ``quanta_mesh``: Quanta Mesh
  - ``ruckus_fastiron``: Ruckus Fastiron
  - ``ubiquiti_edge``: Ubiquiti Edge
  - ``ubiquiti_edgeswitch``: Ubiquiti Edge
  - ``vyatta_vyos``: VyOS
  - ``vyos``: VyOS
  - ``brocade_fastiron_telnet``: Brocade Fastiron over Telnet
  - ``brocade_netiron_telnet``: Brocade Netiron over Telnet
  - ``cisco_ios_telnet``: Cisco IOS over Telnet
  - ``apresia_aeos_telnet``: Apresia AEOS over Telnet
  - ``arista_eos_telnet``: Arista EOS over Telnet
  - ``hp_procurve_telnet``: HP Procurve over Telnet
  - ``hp_comware_telnet``: HP Comware over Telnet
  - ``juniper_junos_telnet``: Juniper Junos over Telnet
  - ``calix_b6_telnet``: Calix B6 over Telnet
  - ``dell_powerconnect_telnet``: Dell PowerConnect over Telnet
  - ``generic_termserver_telnet``: TerminalServer over Telnet
  - ``extreme_telnet``: Extreme Networks over Telnet
  - ``ruckus_fastiron_telnet``: Ruckus Fastiron over Telnet
  - ``cisco_ios_serial``: Cisco IOS over serial port

- ``ip`` - IP address of target device (not required if ``host`` is provided)

- ``host`` - Hostname of target device (not required if ``ip`` is provided)

- ``username`` - Username to authenticate against target device, if required

- ``password`` - Password to authenticate against target device, if required

- ``secret`` - The enable password if target device requires one

- ``port`` - The destination port used to connect to the target device

- ``global_delay_factor`` - Multiplication factor affecting Netmiko delays
  (default: ``1``)

- ``use_keys`` - Connect to target device using SSH keys (default: ``False``)

- ``key_file`` - Filename path of the SSH key file to use

- ``allow_agent`` - Enable use of SSH key-agent

- ``ssh_strict`` - Automatically reject unknown SSH host keys (default:
  ``False``, which means unknown SSH host keys will be accepted)

- ``system_host_keys`` - Load host keys from the user's "known_hosts" file
  (default: ``False``)

- ``alt_host_keys`` - If ``True``,  host keys will be loaded from the file
  specified in ``alt_key_file`` (default: ``False``)

- ``alt_key_file`` - SSH host key file to use (if ``alt_host_keys=True``)

- ``ssh_config_file`` - File name of OpenSSH configuration file

- ``timeout`` - Connection timeout, in seconds (default: ``90``)

- ``session_timeout`` - Set a timeout for parallel requests, in seconds
  (default: ``60``)

- ``keepalive`` - Send SSH keepalive packets at a specific interval, in
  seconds. Currently defaults to ``0``, for backwards compatibility (it will
  not attempt to keep the connection alive using the KEEPALIVE packets).

- ``default_enter`` - Character(s) to send to correspond to enter key (default:
  ``\n``)

- ``response_return`` - Character(s) to use in normalized return data to
  represent enter key (default: ``\n``)

- ``always_alive`` - In certain less dynamic environments, maintaining the
  remote connection permanently open with the network device is not always
  beneficial. In that case, the user can select to initialize the connection
  only when needed, by setting this option to ``False``. By default this option
  is set to ``True`` (maintains the connection with the remote network device)

- ``multiprocessing`` - Overrides the :conf_minion:`multiprocessing` option,
  per proxy minion, as the Netmiko communication channel is mainly SSH
  (default: ``False``)

- ``connection_timeout`` - The number of seconds to attempt to connect to
  the device in seconds.
  (default: ``300``)

Proxy Pillar Example
--------------------

.. code-block:: yaml

    proxy:
      proxytype: netmiko
      device_type: juniper_junos
      host: router1.example.com
      username: example
      password: example

.. code-block:: yaml

    proxy:
      proxytype: netmiko
      device_type: cisco_ios
      ip: 1.2.3.4
      username: test
      use_keys: true
      secret: w3@k
�N)�ConnectHandler)�NetMikoAuthenticationException�NetMikoTimeoutExceptionTF�netmikoi,cCstsdStS)z>
    Proxy module available only if Netmiko is installed.
    )FzBThe netmiko proxy module requires netmiko library to be installed.)�HAS_NETMIKO�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/netmiko_px.py�__virtual__�sr
c
Cs�itd<|tdd<|dtdd<t�d|d�|�di�}|�d|�dd��}|�d|�dd��|d<|�d	t�tdd	<|��}|�d
d�|�dd�|�dd�|�d	d�|tdd<|�d
|�dd��}|tdd
<|s�z*t��}|tdd<dtdd<dtdd<Wd�WdS1s�wYWdSty�}ztj	ddd�WYd}~dSd}~wt
y�}ztj	ddd�WYd}~dSd}~wwdtdd<dtdd<dS)zP
    Open the connection to the network device
    managed through netmiko.
    �netmiko_device�opts�idzInit for %s�proxyZskip_connect_on_initF�multiprocessing�connection_timeoutZ	proxytypeN�args�always_aliveZproxy_always_aliveT�
connection�initialized�upz&Unable to setup the netmiko connection)�exc_info)�__context__�log�debug�get�DEFAULT_CONNECTION_TIMEOUT�copy�pop�make_conr�errorr)rZ
proxy_dictZskip_connectZnetmiko_connection_argsZ
_always_alive�conZt_errZau_errrrr	�init�sR����&����r!c
Cs�t�dtdd�tdd}t��}|��}d}d}	ztdi|��}W	|StyB}zt�d|�|}WYd}~nd}~wwt��||krS|rO|�td��q)	NzCreating connection to %srr
rTzGot exception %rzUnable to create connectionr)rrr�timerr�	Exception�warning)rr�startZfound_exceptionr�excrrr	r's*����rccs��dtdvr*tdd}|jdurt|�}|tdd<|jjr)t�}|tdd<n
t|�}|tdd<dtdd<z|VWtddsK|��dSdStddsX|��ww)NrrTrr)r�remote_connr�closed�
disconnect)rr rrr	r>s(�
��
�rcCstt�d|�dd��tdd}tddsdSt�r8t�r8t|��}|jj�	�Wd�S1s3wYd	S)
z?
    Return the connection status with the network device.
    zChecking if %s is still aliver
�rrrTNF)
rrrr�pingrrr'Z	transport�is_alive)rrr rrr	�aliveSs

 �r-cC�td�dd�S)z'
    Connection open successfully?
    rrF�rrrrrr	r+b�r+cCr.)z+
    Connection finished initializing?
    rrFr/rrrr	rir0rcCstd�S)z,
    Closes connection with the device.
    r))�call)rrrr	�shutdownpsr2cCstd�d�S)z'
    Return the connection object.
    rrr/rrrr	�conn|sr3cCstddS)z)
    Return the Netmiko device args.
    rr)rrrrr	r�srcOs`tjjjdi|��}tdd}t|��}t||�|i|��Wd�S1s)wYdS)z,
    Calls an arbitrary netmiko method.
    rrNr)�salt�utilsrZclean_kwargsrr�getattr)�methodr�kwargsrr rrr	r1�s

$�r1) �__doc__�
contextlib�loggingr"Zsalt.utils.argsr4rrrr�ImportErrorZnetmiko.ssh_exceptionrZ__proxyenabled__r�	getLogger�__name__rrrr
r!r�contextmanagerrr-r+rr2r3rr1rrrr	�<module>sD9��
1