From ab65dce565868079e14db959bd445ff19b1c7b4f Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 23 Mar 2022 11:01:02 -0700 Subject: [PATCH 1/2] Roll docs for Netmiko 4.0.0 --- docs/netmiko/a10/a10_ssh.html | 104 +- docs/netmiko/a10/index.html | 89 +- docs/netmiko/accedian/accedian_ssh.html | 215 +- docs/netmiko/accedian/index.html | 168 +- docs/netmiko/adtran/adtran.html | 292 +- docs/netmiko/adtran/index.html | 112 +- docs/netmiko/alcatel/alcatel_aos_ssh.html | 229 +- docs/netmiko/alcatel/index.html | 188 +- .../allied_telesis/allied_telesis_awplus.html | 154 +- docs/netmiko/allied_telesis/index.html | 57 +- docs/netmiko/apresia/apresia_aeos.html | 246 +- docs/netmiko/apresia/index.html | 114 +- docs/netmiko/arista/arista.html | 331 +- docs/netmiko/arista/index.html | 144 +- docs/netmiko/aruba/aruba_ssh.html | 163 +- docs/netmiko/aruba/index.html | 125 +- docs/netmiko/base_connection.html | 5029 ++++++++++------- docs/netmiko/broadcom/broadcom_icos_ssh.html | 149 +- docs/netmiko/broadcom/index.html | 115 +- docs/netmiko/brocade/brocade_fos_ssh.html | 276 +- docs/netmiko/brocade/index.html | 235 +- docs/netmiko/calix/calix_b6.html | 384 +- docs/netmiko/calix/index.html | 114 +- docs/netmiko/cdot/cdot_cros_ssh.html | 278 +- docs/netmiko/cdot/index.html | 211 +- docs/netmiko/centec/centec_os.html | 201 +- docs/netmiko/centec/index.html | 114 +- docs/netmiko/channel.html | 540 ++ .../checkpoint/checkpoint_gaia_ssh.html | 139 +- docs/netmiko/checkpoint/index.html | 115 +- docs/netmiko/ciena/ciena_saos.html | 500 +- docs/netmiko/ciena/index.html | 188 +- docs/netmiko/cisco/cisco_asa_ssh.html | 190 +- docs/netmiko/cisco/cisco_ftd_ssh.html | 142 +- docs/netmiko/cisco/cisco_ios.html | 487 +- docs/netmiko/cisco/cisco_nxos_ssh.html | 237 +- docs/netmiko/cisco/cisco_s300.html | 483 +- docs/netmiko/cisco/cisco_tp_tcce.html | 118 +- docs/netmiko/cisco/cisco_viptela.html | 471 ++ docs/netmiko/cisco/cisco_wlc_ssh.html | 311 +- docs/netmiko/cisco/cisco_xr.html | 409 +- docs/netmiko/cisco/index.html | 2105 ++++--- docs/netmiko/cisco_base_connection.html | 432 +- docs/netmiko/citrix/index.html | 208 +- docs/netmiko/citrix/netscaler_ssh.html | 270 +- docs/netmiko/cli_tools/index.html | 75 + docs/netmiko/cli_tools/netmiko_cfg.html | 521 ++ docs/netmiko/cli_tools/netmiko_grep.html | 513 ++ docs/netmiko/cli_tools/netmiko_show.html | 511 ++ docs/netmiko/cloudgenix/cloudgenix_ion.html | 215 +- docs/netmiko/cloudgenix/index.html | 166 +- docs/netmiko/coriant/coriant_ssh.html | 202 +- docs/netmiko/coriant/index.html | 159 +- docs/netmiko/dell/dell_dnos6.html | 210 +- docs/netmiko/dell/dell_force10_ssh.html | 81 +- docs/netmiko/dell/dell_isilon_ssh.html | 436 +- docs/netmiko/dell/dell_os10_ssh.html | 194 +- docs/netmiko/dell/dell_powerconnect.html | 342 +- docs/netmiko/dell/dell_sonic_ssh.html | 329 ++ docs/netmiko/dell/index.html | 990 ++-- docs/netmiko/dlink/dlink_ds.html | 400 +- docs/netmiko/dlink/index.html | 138 +- docs/netmiko/eltex/eltex_esr_ssh.html | 248 +- docs/netmiko/eltex/eltex_ssh.html | 91 +- docs/netmiko/eltex/index.html | 253 +- docs/netmiko/endace/endace_ssh.html | 156 +- docs/netmiko/endace/index.html | 105 +- docs/netmiko/enterasys/enterasys_ssh.html | 88 +- docs/netmiko/enterasys/index.html | 77 +- docs/netmiko/ericsson/ericsson_ipos.html | 449 +- docs/netmiko/ericsson/index.html | 314 +- docs/netmiko/exceptions.html | 362 ++ docs/netmiko/extreme/extreme_ers_ssh.html | 104 +- docs/netmiko/extreme/extreme_exos.html | 659 ++- docs/netmiko/extreme/extreme_netiron.html | 238 +- docs/netmiko/extreme/extreme_nos_ssh.html | 147 +- docs/netmiko/extreme/extreme_slx_ssh.html | 147 +- .../netmiko/extreme/extreme_tierraos_ssh.html | 329 ++ docs/netmiko/extreme/extreme_vsp_ssh.html | 102 +- docs/netmiko/extreme/extreme_wing_ssh.html | 78 +- docs/netmiko/extreme/index.html | 1160 ++-- docs/netmiko/f5/f5_linux_ssh.html | 55 +- docs/netmiko/f5/f5_tmsh_ssh.html | 218 +- docs/netmiko/f5/index.html | 231 +- docs/netmiko/flexvnf/flexvnf_ssh.html | 392 +- docs/netmiko/flexvnf/index.html | 307 +- docs/netmiko/fortinet/fortinet_ssh.html | 277 +- docs/netmiko/fortinet/index.html | 208 +- docs/netmiko/hp/hp_comware.html | 448 +- docs/netmiko/hp/hp_procurve.html | 675 +-- docs/netmiko/hp/index.html | 289 +- docs/netmiko/huawei/huawei.html | 668 +-- docs/netmiko/huawei/huawei_smartax.html | 240 +- docs/netmiko/huawei/index.html | 443 +- docs/netmiko/index.html | 3743 +++++++----- docs/netmiko/ipinfusion/index.html | 128 +- docs/netmiko/ipinfusion/ipinfusion_ocnos.html | 230 +- docs/netmiko/juniper/index.html | 391 +- docs/netmiko/juniper/juniper.html | 614 +- docs/netmiko/juniper/juniper_screenos.html | 285 +- docs/netmiko/keymile/index.html | 379 +- docs/netmiko/keymile/keymile_nos_ssh.html | 75 +- docs/netmiko/keymile/keymile_ssh.html | 371 +- docs/netmiko/linux/index.html | 213 +- docs/netmiko/linux/linux_ssh.html | 320 +- docs/netmiko/mellanox/index.html | 131 +- .../netmiko/mellanox/mellanox_mlnxos_ssh.html | 184 +- docs/netmiko/mikrotik/index.html | 298 +- docs/netmiko/mikrotik/mikrotik_ssh.html | 843 +-- docs/netmiko/mrv/index.html | 184 +- docs/netmiko/mrv/mrv_lx.html | 107 +- docs/netmiko/mrv/mrv_ssh.html | 117 +- docs/netmiko/netapp/index.html | 131 +- docs/netmiko/netapp/netapp_cdot_ssh.html | 179 +- docs/netmiko/netgear/index.html | 97 +- docs/netmiko/netgear/netgear_prosafe_ssh.html | 135 +- docs/netmiko/no_config.html | 189 + docs/netmiko/no_enable.html | 221 + docs/netmiko/nokia/index.html | 181 +- docs/netmiko/nokia/nokia_sros.html | 517 +- docs/netmiko/oneaccess/index.html | 12 +- docs/netmiko/oneaccess/oneaccess_oneos.html | 44 +- docs/netmiko/ovs/index.html | 55 +- docs/netmiko/ovs/ovs_linux_ssh.html | 55 +- docs/netmiko/paloalto/index.html | 156 +- docs/netmiko/paloalto/paloalto_panos.html | 722 +-- docs/netmiko/pluribus/index.html | 230 +- docs/netmiko/pluribus/pluribus_ssh.html | 262 +- docs/netmiko/quanta/index.html | 118 +- docs/netmiko/quanta/quanta_mesh_ssh.html | 145 +- docs/netmiko/rad/index.html | 160 +- docs/netmiko/rad/rad_etx.html | 409 +- docs/netmiko/raisecom/index.html | 140 +- docs/netmiko/raisecom/raisecom_roap.html | 250 +- docs/netmiko/ruckus/index.html | 119 +- docs/netmiko/ruckus/ruckus_fastiron.html | 264 +- docs/netmiko/ruijie/index.html | 114 +- docs/netmiko/ruijie/ruijie_os.html | 195 +- docs/netmiko/scp_functions.html | 101 +- docs/netmiko/scp_handler.html | 440 +- docs/netmiko/session_log.html | 279 + docs/netmiko/sixwind/index.html | 73 +- docs/netmiko/sixwind/sixwind_os.html | 393 +- docs/netmiko/snmp_autodetect.html | 104 +- docs/netmiko/sophos/index.html | 186 +- docs/netmiko/sophos/sophos_sfos_ssh.html | 220 +- docs/netmiko/ssh_auth.html | 101 + docs/netmiko/ssh_autodetect.html | 137 +- docs/netmiko/supermicro/index.html | 142 +- docs/netmiko/supermicro/smci_smis.html | 289 +- docs/netmiko/terminal_server/index.html | 116 +- .../terminal_server/terminal_server.html | 183 +- docs/netmiko/tplink/index.html | 151 +- docs/netmiko/tplink/tplink_jetstream.html | 360 +- docs/netmiko/ubiquiti/edge_ssh.html | 140 +- docs/netmiko/ubiquiti/edgerouter_ssh.html | 86 +- docs/netmiko/ubiquiti/index.html | 253 +- docs/netmiko/ubiquiti/unifiswitch_ssh.html | 65 +- docs/netmiko/utilities.html | 590 +- docs/netmiko/vyos/index.html | 277 +- docs/netmiko/vyos/vyos_ssh.html | 375 +- docs/netmiko/watchguard/fireware_ssh.html | 95 +- docs/netmiko/watchguard/index.html | 77 +- docs/netmiko/yamaha/index.html | 114 +- docs/netmiko/yamaha/yamaha.html | 294 +- docs/netmiko/zte/index.html | 119 +- docs/netmiko/zte/zte_zxros.html | 214 +- docs/netmiko/zyxel/index.html | 322 ++ docs/netmiko/zyxel/zyxel_ssh.html | 336 ++ 169 files changed, 26174 insertions(+), 26393 deletions(-) create mode 100644 docs/netmiko/channel.html create mode 100644 docs/netmiko/cisco/cisco_viptela.html create mode 100644 docs/netmiko/cli_tools/index.html create mode 100644 docs/netmiko/cli_tools/netmiko_cfg.html create mode 100644 docs/netmiko/cli_tools/netmiko_grep.html create mode 100644 docs/netmiko/cli_tools/netmiko_show.html create mode 100644 docs/netmiko/dell/dell_sonic_ssh.html create mode 100644 docs/netmiko/exceptions.html create mode 100644 docs/netmiko/extreme/extreme_tierraos_ssh.html create mode 100644 docs/netmiko/no_config.html create mode 100644 docs/netmiko/no_enable.html create mode 100644 docs/netmiko/session_log.html create mode 100644 docs/netmiko/ssh_auth.html create mode 100644 docs/netmiko/zyxel/index.html create mode 100644 docs/netmiko/zyxel/zyxel_ssh.html diff --git a/docs/netmiko/a10/a10_ssh.html b/docs/netmiko/a10/a10_ssh.html index 842617403..394134f04 100644 --- a/docs/netmiko/a10/a10_ssh.html +++ b/docs/netmiko/a10/a10_ssh.html @@ -24,28 +24,25 @@

Module netmiko.a10.a10_ssh

Source code
"""A10 support."""
-import time
 from netmiko.cisco_base_connection import CiscoSSHConnection
 
 
 class A10SSH(CiscoSSHConnection):
     """A10 support."""
 
-    def session_preparation(self):
+    def session_preparation(self) -> None:
         """A10 requires to be enable mode to disable paging."""
-        self._test_channel_read()
+        self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.enable()
 
-        # Will not do anything without A10 specific command
+        # terminal width ill not do anything without A10 specific command
         # self.set_terminal_width()
         self.disable_paging(command="terminal length 0")
 
-        # Clear the read buffer
-        time.sleep(0.3 * self.global_delay_factor)
-        self.clear_buffer()
-
-    def save_config(self, *args, **kwargs):
+    def save_config(
+        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
+    ) -> str:
         """Not Implemented"""
         raise NotImplementedError
@@ -61,7 +58,7 @@

Classes

class A10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

A10 support.

@@ -69,152 +66,123 @@

Classes

:param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

). -:type default_enter: str

+

).

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

) -:type response_return: str

+

)

    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
             to select smallest of global and specific. Sets default global_delay_factor to .1
-            (default: False)
-    :type fast_cli: boolean
+            (default: True)
 
     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
-    :type session_log: str
 
     :param session_log_record_writes: The session log generally only records channel reads due
             to eliminate command duplication due to command echo. You can enable this if you
             want to record both channel reads and channel writes in the log (default: False).
-    :type session_log_record_writes: boolean
 
     :param session_log_file_mode: "write" or "append" for session_log file mode
             (default: "write")
-    :type session_log_file_mode: str
 
     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
             (default: False)
-    :type allow_auto_change: bool
 
     :param encoding: Encoding to be used when writing bytes to the output channel.
             (default: ascii)
-    :type encoding: str
 
     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
             communication to the target host (default: None).
-    :type sock: socket
 
     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
             (default: None). Global attribute takes precedence over function `cmd_verify`
             argument. Value of `None` indicates to use function `cmd_verify` argument.
-    :type global_cmd_verify: bool|None
 
     :param auto_connect: Control whether Netmiko automatically establishes the connection as
             part of the object creation (default: True).
-    :type auto_connect: bool
+
+    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
+            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
+            eliminated in Netmiko 5.x (default: False).
 
Source code
class A10SSH(CiscoSSHConnection):
     """A10 support."""
 
-    def session_preparation(self):
+    def session_preparation(self) -> None:
         """A10 requires to be enable mode to disable paging."""
-        self._test_channel_read()
+        self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.enable()
 
-        # Will not do anything without A10 specific command
+        # terminal width ill not do anything without A10 specific command
         # self.set_terminal_width()
         self.disable_paging(command="terminal length 0")
 
-        # Clear the read buffer
-        time.sleep(0.3 * self.global_delay_factor)
-        self.clear_buffer()
-
-    def save_config(self, *args, **kwargs):
+    def save_config(
+        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
+    ) -> str:
         """Not Implemented"""
         raise NotImplementedError
@@ -227,13 +195,15 @@

Ancestors

Methods

-def save_config(self, *args, **kwargs) +def save_config(self, cmd='', confirm=False, confirm_response='')

Not Implemented

Source code -
def save_config(self, *args, **kwargs):
+
def save_config(
+    self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
+) -> str:
     """Not Implemented"""
     raise NotImplementedError
@@ -245,19 +215,15 @@

Methods

A10 requires to be enable mode to disable paging.

Source code -
def session_preparation(self):
+
def session_preparation(self) -> None:
     """A10 requires to be enable mode to disable paging."""
-    self._test_channel_read()
+    self._test_channel_read(pattern=r"[>#]")
     self.set_base_prompt()
     self.enable()
 
-    # Will not do anything without A10 specific command
+    # terminal width ill not do anything without A10 specific command
     # self.set_terminal_width()
-    self.disable_paging(command="terminal length 0")
-
-    # Clear the read buffer
-    time.sleep(0.3 * self.global_delay_factor)
-    self.clear_buffer()
+ self.disable_paging(command="terminal length 0")
@@ -269,9 +235,8 @@

Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -282,9 +247,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -295,6 +260,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • diff --git a/docs/netmiko/a10/index.html b/docs/netmiko/a10/index.html index e9bc02dba..e9903e2f0 100644 --- a/docs/netmiko/a10/index.html +++ b/docs/netmiko/a10/index.html @@ -45,7 +45,7 @@

    Classes

    class A10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    A10 support.

    @@ -53,152 +53,123 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class A10SSH(CiscoSSHConnection):
         """A10 support."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """A10 requires to be enable mode to disable paging."""
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.enable()
     
    -        # Will not do anything without A10 specific command
    +        # terminal width ill not do anything without A10 specific command
             # self.set_terminal_width()
             self.disable_paging(command="terminal length 0")
     
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def save_config(self, *args, **kwargs):
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             """Not Implemented"""
             raise NotImplementedError
    @@ -211,13 +182,15 @@

    Ancestors

    Methods

    -def save_config(self, *args, **kwargs) +def save_config(self, cmd='', confirm=False, confirm_response='')

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(
    +    self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -229,19 +202,15 @@

    Methods

    A10 requires to be enable mode to disable paging.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """A10 requires to be enable mode to disable paging."""
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.enable()
     
    -    # Will not do anything without A10 specific command
    +    # terminal width ill not do anything without A10 specific command
         # self.set_terminal_width()
    -    self.disable_paging(command="terminal length 0")
    -
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="terminal length 0")
    @@ -253,9 +222,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -266,9 +234,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -279,6 +247,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • diff --git a/docs/netmiko/accedian/accedian_ssh.html b/docs/netmiko/accedian/accedian_ssh.html index 6eb8fafc4..23062de0e 100644 --- a/docs/netmiko/accedian/accedian_ssh.html +++ b/docs/netmiko/accedian/accedian_ssh.html @@ -22,51 +22,36 @@

    Module netmiko.accedian.accedian_ssh

    Source code -
    import time
    +
    from typing import Optional
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    -class AccedianSSH(CiscoSSHConnection):
    -    def session_preparation(self):
    -        self._test_channel_read()
    +class AccedianSSH(NoEnable, NoConfig, CiscoSSHConnection):
    +    def session_preparation(self) -> None:
    +        self._test_channel_read(pattern=r"[:#]")
             self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def enable(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def check_config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return False
    -
    -    def config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return ""
    -
    -    def exit_config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return ""
     
         def set_base_prompt(
    -        self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2
    -    ):
    +        self,
    +        pri_prompt_terminator: str = ":",
    +        alt_prompt_terminator: str = "#",
    +        delay_factor: float = 2.0,
    +        pattern: Optional[str] = None,
    +    ) -> str:
             """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
             super().set_base_prompt(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 delay_factor=delay_factor,
    +            pattern=pattern,
             )
             return self.base_prompt
     
    -    def save_config(self, *args, **kwargs):
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             """Not Implemented"""
             raise NotImplementedError
    @@ -82,257 +67,193 @@

    Classes

    class AccedianSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class AccedianSSH(CiscoSSHConnection):
    -    def session_preparation(self):
    -        self._test_channel_read()
    +
    class AccedianSSH(NoEnable, NoConfig, CiscoSSHConnection):
    +    def session_preparation(self) -> None:
    +        self._test_channel_read(pattern=r"[:#]")
             self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def enable(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        raise AttributeError("Accedian devices do not support enable mode!")
    -
    -    def check_config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return False
    -
    -    def config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return ""
    -
    -    def exit_config_mode(self):
    -        """Accedian devices do not have a config mode."""
    -        return ""
     
         def set_base_prompt(
    -        self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2
    -    ):
    +        self,
    +        pri_prompt_terminator: str = ":",
    +        alt_prompt_terminator: str = "#",
    +        delay_factor: float = 2.0,
    +        pattern: Optional[str] = None,
    +    ) -> str:
             """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
             super().set_base_prompt(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 delay_factor=delay_factor,
    +            pattern=pattern,
             )
             return self.base_prompt
     
    -    def save_config(self, *args, **kwargs):
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             """Not Implemented"""
             raise NotImplementedError

    Ancestors

    Methods

    -
    -def check_config_mode(self) -
    -
    -

    Accedian devices do not have a config mode.

    -
    -Source code -
    def check_config_mode(self):
    -    """Accedian devices do not have a config mode."""
    -    return False
    -
    -
    -
    -def config_mode(self) -
    -
    -

    Accedian devices do not have a config mode.

    -
    -Source code -
    def config_mode(self):
    -    """Accedian devices do not have a config mode."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self) -
    -
    -

    Accedian devices do not have a config mode.

    -
    -Source code -
    def exit_config_mode(self):
    -    """Accedian devices do not have a config mode."""
    -    return ""
    -
    -
    -def save_config(self, *args, **kwargs) +def save_config(self, cmd='', confirm=False, confirm_response='')

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(
    +    self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Not Implemented"""
         raise NotImplementedError
    -def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='#', delay_factor=2) +def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='#', delay_factor=2.0, pattern=None)

    Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

    Source code
    def set_base_prompt(
    -    self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2
    -):
    +    self,
    +    pri_prompt_terminator: str = ":",
    +    alt_prompt_terminator: str = "#",
    +    delay_factor: float = 2.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
         super().set_base_prompt(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             delay_factor=delay_factor,
    +        pattern=pattern,
         )
         return self.base_prompt
    @@ -342,23 +263,25 @@

    Inherited members

    • CiscoSSHConnection:
        +
      • check_config_mode
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -369,6 +292,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_terminal_width
      • special_login_handler
      • @@ -401,9 +325,6 @@

        Index

      • AccedianSSH

        diff --git a/docs/netmiko/accedian/index.html b/docs/netmiko/accedian/index.html index 5129c6543..a626e5195 100644 --- a/docs/netmiko/accedian/index.html +++ b/docs/netmiko/accedian/index.html @@ -45,257 +45,193 @@

        Classes

        class AccedianSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
        -

        Base Class for cisco-like behavior.

        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code -
        class AccedianSSH(CiscoSSHConnection):
        -    def session_preparation(self):
        -        self._test_channel_read()
        +
        class AccedianSSH(NoEnable, NoConfig, CiscoSSHConnection):
        +    def session_preparation(self) -> None:
        +        self._test_channel_read(pattern=r"[:#]")
                 self.set_base_prompt()
        -        # Clear the read buffer
        -        time.sleep(0.3 * self.global_delay_factor)
        -        self.clear_buffer()
        -
        -    def check_enable_mode(self, *args, **kwargs):
        -        raise AttributeError("Accedian devices do not support enable mode!")
        -
        -    def enable(self, *args, **kwargs):
        -        raise AttributeError("Accedian devices do not support enable mode!")
        -
        -    def exit_enable_mode(self, *args, **kwargs):
        -        raise AttributeError("Accedian devices do not support enable mode!")
        -
        -    def check_config_mode(self):
        -        """Accedian devices do not have a config mode."""
        -        return False
        -
        -    def config_mode(self):
        -        """Accedian devices do not have a config mode."""
        -        return ""
        -
        -    def exit_config_mode(self):
        -        """Accedian devices do not have a config mode."""
        -        return ""
         
             def set_base_prompt(
        -        self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2
        -    ):
        +        self,
        +        pri_prompt_terminator: str = ":",
        +        alt_prompt_terminator: str = "#",
        +        delay_factor: float = 2.0,
        +        pattern: Optional[str] = None,
        +    ) -> str:
                 """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                 super().set_base_prompt(
                     pri_prompt_terminator=pri_prompt_terminator,
                     alt_prompt_terminator=alt_prompt_terminator,
                     delay_factor=delay_factor,
        +            pattern=pattern,
                 )
                 return self.base_prompt
         
        -    def save_config(self, *args, **kwargs):
        +    def save_config(
        +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
        +    ) -> str:
                 """Not Implemented"""
                 raise NotImplementedError

        Ancestors

        Methods

        -
        -def check_config_mode(self) -
        -
        -

        Accedian devices do not have a config mode.

        -
        -Source code -
        def check_config_mode(self):
        -    """Accedian devices do not have a config mode."""
        -    return False
        -
        -
        -
        -def config_mode(self) -
        -
        -

        Accedian devices do not have a config mode.

        -
        -Source code -
        def config_mode(self):
        -    """Accedian devices do not have a config mode."""
        -    return ""
        -
        -
        -
        -def exit_config_mode(self) -
        -
        -

        Accedian devices do not have a config mode.

        -
        -Source code -
        def exit_config_mode(self):
        -    """Accedian devices do not have a config mode."""
        -    return ""
        -
        -
        -def save_config(self, *args, **kwargs) +def save_config(self, cmd='', confirm=False, confirm_response='')

        Not Implemented

        Source code -
        def save_config(self, *args, **kwargs):
        +
        def save_config(
        +    self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
        +) -> str:
             """Not Implemented"""
             raise NotImplementedError
        -def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='#', delay_factor=2) +def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='#', delay_factor=2.0, pattern=None)

        Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

        Source code
        def set_base_prompt(
        -    self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2
        -):
        +    self,
        +    pri_prompt_terminator: str = ":",
        +    alt_prompt_terminator: str = "#",
        +    delay_factor: float = 2.0,
        +    pattern: Optional[str] = None,
        +) -> str:
             """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
             super().set_base_prompt(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 delay_factor=delay_factor,
        +        pattern=pattern,
             )
             return self.base_prompt
        @@ -305,23 +241,25 @@

        Inherited members

        • CiscoSSHConnection:
            +
          • check_config_mode
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • establish_connection
          • +
          • exit_config_mode
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -332,6 +270,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_terminal_width
          • special_login_handler
          • @@ -369,9 +308,6 @@

            Index

          • AccedianSSH

            diff --git a/docs/netmiko/adtran/adtran.html b/docs/netmiko/adtran/adtran.html index e3eda974c..f9ab8d592 100644 --- a/docs/netmiko/adtran/adtran.html +++ b/docs/netmiko/adtran/adtran.html @@ -22,52 +22,67 @@

            Module netmiko.adtran.adtran

            Source code -
            import time
            +
            from typing import Any, Optional
             import re
             from netmiko.cisco_base_connection import CiscoBaseConnection
             
             
             class AdtranOSBase(CiscoBaseConnection):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     if kwargs.get("global_cmd_verify") is None:
                         kwargs["global_cmd_verify"] = False
                     return super().__init__(*args, **kwargs)
             
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self.ansi_escape_codes = True
                     self._test_channel_read()
                     self.set_base_prompt()
                     self.disable_paging(command="terminal length 0")
            -        # Clear the read buffer
            -        time.sleep(0.3 * self.global_delay_factor)
            -        self.clear_buffer()
             
            -    def check_enable_mode(self, check_string="#"):
            +    def check_enable_mode(self, check_string: str = "#") -> bool:
                     return super().check_enable_mode(check_string=check_string)
             
            -    def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE):
            -        return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
            +    def enable(
            +        self,
            +        cmd: str = "enable",
            +        pattern: str = "ssword",
            +        enable_pattern: Optional[str] = None,
            +        re_flags: int = re.IGNORECASE,
            +    ) -> str:
            +        return super().enable(
            +            cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
            +        )
             
            -    def exit_enable_mode(self, exit_command="disable"):
            +    def exit_enable_mode(self, exit_command: str = "disable") -> str:
                     return super().exit_enable_mode(exit_command=exit_command)
             
            -    def check_config_mode(self, check_string=")#"):
            -        return super().check_config_mode(check_string=check_string)
            +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
            +        return super().check_config_mode(check_string=check_string, pattern=pattern)
             
            -    def config_mode(self, config_command="config term", pattern=""):
            -        return super().config_mode(config_command=config_command, pattern=pattern)
            +    def config_mode(
            +        self, config_command: str = "config term", pattern: str = "", re_flags: int = 0
            +    ) -> str:
            +        """Enter configuration mode."""
            +        return super().config_mode(
            +            config_command=config_command, pattern=pattern, re_flags=re_flags
            +        )
             
            -    def exit_config_mode(self, exit_config="end", pattern="#"):
            +    def exit_config_mode(self, exit_config: str = "end", pattern: str = "#") -> str:
                     return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
             
                 def set_base_prompt(
            -        self, pri_prompt_terminator=">", alt_prompt_terminator="#", **kwargs
            -    ):
            +        self,
            +        pri_prompt_terminator: str = ">",
            +        alt_prompt_terminator: str = "#",
            +        delay_factor: float = 1.0,
            +        pattern: Optional[str] = None,
            +    ) -> str:
                     return super().set_base_prompt(
                         pri_prompt_terminator=pri_prompt_terminator,
                         alt_prompt_terminator=alt_prompt_terminator,
            -            **kwargs
            +            delay_factor=delay_factor,
            +            pattern=pattern,
                     )
             
             
            @@ -76,7 +91,7 @@ 

            Module netmiko.adtran.adtran

            class AdtranOSTelnet(AdtranOSBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs)
            @@ -101,175 +116,163 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class AdtranOSBase(CiscoBaseConnection):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     if kwargs.get("global_cmd_verify") is None:
                         kwargs["global_cmd_verify"] = False
                     return super().__init__(*args, **kwargs)
             
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self.ansi_escape_codes = True
                     self._test_channel_read()
                     self.set_base_prompt()
                     self.disable_paging(command="terminal length 0")
            -        # Clear the read buffer
            -        time.sleep(0.3 * self.global_delay_factor)
            -        self.clear_buffer()
             
            -    def check_enable_mode(self, check_string="#"):
            +    def check_enable_mode(self, check_string: str = "#") -> bool:
                     return super().check_enable_mode(check_string=check_string)
             
            -    def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE):
            -        return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
            +    def enable(
            +        self,
            +        cmd: str = "enable",
            +        pattern: str = "ssword",
            +        enable_pattern: Optional[str] = None,
            +        re_flags: int = re.IGNORECASE,
            +    ) -> str:
            +        return super().enable(
            +            cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
            +        )
             
            -    def exit_enable_mode(self, exit_command="disable"):
            +    def exit_enable_mode(self, exit_command: str = "disable") -> str:
                     return super().exit_enable_mode(exit_command=exit_command)
             
            -    def check_config_mode(self, check_string=")#"):
            -        return super().check_config_mode(check_string=check_string)
            +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
            +        return super().check_config_mode(check_string=check_string, pattern=pattern)
             
            -    def config_mode(self, config_command="config term", pattern=""):
            -        return super().config_mode(config_command=config_command, pattern=pattern)
            +    def config_mode(
            +        self, config_command: str = "config term", pattern: str = "", re_flags: int = 0
            +    ) -> str:
            +        """Enter configuration mode."""
            +        return super().config_mode(
            +            config_command=config_command, pattern=pattern, re_flags=re_flags
            +        )
             
            -    def exit_config_mode(self, exit_config="end", pattern="#"):
            +    def exit_config_mode(self, exit_config: str = "end", pattern: str = "#") -> str:
                     return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
             
                 def set_base_prompt(
            -        self, pri_prompt_terminator=">", alt_prompt_terminator="#", **kwargs
            -    ):
            +        self,
            +        pri_prompt_terminator: str = ">",
            +        alt_prompt_terminator: str = "#",
            +        delay_factor: float = 1.0,
            +        pattern: Optional[str] = None,
            +    ) -> str:
                     return super().set_base_prompt(
                         pri_prompt_terminator=pri_prompt_terminator,
                         alt_prompt_terminator=alt_prompt_terminator,
            -            **kwargs
            +            delay_factor=delay_factor,
            +            pattern=pattern,
                     )

            Ancestors

            @@ -284,6 +287,22 @@

            Subclasses

          Methods

          +
          +def config_mode(self, config_command='config term', pattern='', re_flags=0) +
          +
          +

          Enter configuration mode.

          +
          +Source code +
          def config_mode(
          +    self, config_command: str = "config term", pattern: str = "", re_flags: int = 0
          +) -> str:
          +    """Enter configuration mode."""
          +    return super().config_mode(
          +        config_command=config_command, pattern=pattern, re_flags=re_flags
          +    )
          +
          +
          def session_preparation(self)
          @@ -291,15 +310,12 @@

          Methods

          Prepare the session after the connection has been established.

          Source code -
          def session_preparation(self):
          +
          def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self.ansi_escape_codes = True
               self._test_channel_read()
               self.set_base_prompt()
          -    self.disable_paging(command="terminal length 0")
          -    # Clear the read buffer
          -    time.sleep(0.3 * self.global_delay_factor)
          -    self.clear_buffer()
          + self.disable_paging(command="terminal length 0")
        @@ -311,9 +327,7 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -324,9 +338,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -338,6 +352,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -361,131 +376,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -506,9 +494,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -519,9 +506,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -533,6 +520,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -557,136 +545,109 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
    Source code
    class AdtranOSTelnet(AdtranOSBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -705,9 +666,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -718,9 +678,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -732,6 +692,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -765,6 +726,7 @@

    Index

  • AdtranOSBase

  • diff --git a/docs/netmiko/adtran/index.html b/docs/netmiko/adtran/index.html index 43bc6695f..0386aecd4 100644 --- a/docs/netmiko/adtran/index.html +++ b/docs/netmiko/adtran/index.html @@ -53,131 +53,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -198,9 +171,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -211,9 +183,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -225,6 +197,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -249,136 +222,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class AdtranOSTelnet(AdtranOSBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -397,9 +343,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -410,9 +355,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -424,6 +369,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/alcatel/alcatel_aos_ssh.html b/docs/netmiko/alcatel/alcatel_aos_ssh.html index 93c9c3d88..81aa5abd2 100644 --- a/docs/netmiko/alcatel/alcatel_aos_ssh.html +++ b/docs/netmiko/alcatel/alcatel_aos_ssh.html @@ -24,48 +24,25 @@

    Module netmiko.alcatel.alcatel_aos_ssh

    Source code
    """Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8)."""
    -import time
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    -class AlcatelAosSSH(CiscoSSHConnection):
    +class AlcatelAosSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8)."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             # Prompt can be anything, but best practice is to end with > or #
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        pass
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
     
         def save_config(
    -        self, cmd="write memory flash-synchro", confirm=False, confirm_response=""
    -    ):
    +        self,
    +        cmd: str = "write memory flash-synchro",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Save Config"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -83,7 +60,7 @@ 

    Classes

    class AlcatelAosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8).

    @@ -91,172 +68,121 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class AlcatelAosSSH(CiscoSSHConnection):
    +
    class AlcatelAosSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8)."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             # Prompt can be anything, but best practice is to end with > or #
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        pass
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
     
         def save_config(
    -        self, cmd="write memory flash-synchro", confirm=False, confirm_response=""
    -    ):
    +        self,
    +        cmd: str = "write memory flash-synchro",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Save Config"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -264,84 +190,14 @@ 

    Classes

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    pass
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    def save_config(self, cmd='write memory flash-synchro', confirm=False, confirm_response='')
    @@ -350,8 +206,11 @@

    Methods

    Source code
    def save_config(
    -    self, cmd="write memory flash-synchro", confirm=False, confirm_response=""
    -):
    +    self,
    +    cmd: str = "write memory flash-synchro",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Save Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -363,20 +222,25 @@ 

    Inherited members

    • CiscoSSHConnection:
        +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -387,6 +251,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -419,13 +284,7 @@

        Index

        • AlcatelAosSSH

          -
            -
          • check_config_mode
          • -
          • check_enable_mode
          • -
          • config_mode
          • -
          • enable
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • + diff --git a/docs/netmiko/alcatel/index.html b/docs/netmiko/alcatel/index.html index 2a79906db..c650d1984 100644 --- a/docs/netmiko/alcatel/index.html +++ b/docs/netmiko/alcatel/index.html @@ -45,7 +45,7 @@

            Classes

            class AlcatelAosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8).

            @@ -53,172 +53,121 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class AlcatelAosSSH(CiscoSSHConnection):
    +
    class AlcatelAosSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8)."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             # Prompt can be anything, but best practice is to end with > or #
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on AOS"""
    -        pass
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        pass
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No config mode on AOS"""
    -        return ""
     
         def save_config(
    -        self, cmd="write memory flash-synchro", confirm=False, confirm_response=""
    -    ):
    +        self,
    +        cmd: str = "write memory flash-synchro",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Save Config"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -226,84 +175,14 @@ 

    Classes

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    pass
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on AOS

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No config mode on AOS"""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on AOS

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on AOS"""
    -    pass
    -
    -
    def save_config(self, cmd='write memory flash-synchro', confirm=False, confirm_response='')
    @@ -312,8 +191,11 @@

    Methods

    Source code
    def save_config(
    -    self, cmd="write memory flash-synchro", confirm=False, confirm_response=""
    -):
    +    self,
    +    cmd: str = "write memory flash-synchro",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Save Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -325,20 +207,25 @@ 

    Inherited members

    • CiscoSSHConnection:
        +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -349,6 +236,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -386,13 +274,7 @@

        Index

        • AlcatelAosSSH

          -
            -
          • check_config_mode
          • -
          • check_enable_mode
          • -
          • config_mode
          • -
          • enable
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • + diff --git a/docs/netmiko/allied_telesis/allied_telesis_awplus.html b/docs/netmiko/allied_telesis/allied_telesis_awplus.html index 6f462da97..c0aa2a9a9 100644 --- a/docs/netmiko/allied_telesis/allied_telesis_awplus.html +++ b/docs/netmiko/allied_telesis/allied_telesis_awplus.html @@ -29,7 +29,7 @@

            Module netmiko.allied_telesis.allied_telesis_awplusModule netmiko.allied_telesis.allied_telesis_awplusClasses

            class AlliedTelesisAwplusBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Implement methods for interacting with Allied Telesis devices.

            @@ -89,138 +89,111 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class AlliedTelesisAwplusBase(CiscoBaseConnection):
         """Implement methods for interacting with Allied Telesis devices."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established.
     
    @@ -233,23 +206,23 @@ 

    Classes

    self.set_base_prompt() time.sleep(0.3 * self.global_delay_factor) - def _enter_shell(self): + def _enter_shell(self) -> str: """Enter the Bourne Shell.""" - return self.send_command("start shell sh", expect_string=r"[\$#]") + return self._send_command_str("start shell sh", expect_string=r"[\$#]") - def _return_cli(self): + def _return_cli(self) -> str: """Return to the Awplus CLI.""" - return self.send_command("exit", expect_string=r"[#>]") + return self._send_command_str("exit", expect_string=r"[#>]") - def exit_config_mode(self, exit_config="exit", pattern=""): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit configuration mode.""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output += self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Exit with uncommitted changes?" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "yes", strip_prompt=False, strip_command=False ) if self.check_config_mode(): @@ -274,15 +247,15 @@

    Methods

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="exit", pattern=""):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
         """Exit configuration mode."""
         output = ""
         if self.check_config_mode():
    -        output = self.send_command_timing(
    +        output += self._send_command_timing_str(
                 exit_config, strip_prompt=False, strip_command=False
             )
             if "Exit with uncommitted changes?" in output:
    -            output += self.send_command_timing(
    +            output += self._send_command_timing_str(
                     "yes", strip_prompt=False, strip_command=False
                 )
             if self.check_config_mode():
    @@ -299,7 +272,7 @@ 

    Methods

    Set the base prompt for interaction ('>').

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established.
     
    @@ -322,9 +295,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -334,9 +306,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -348,6 +320,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -363,7 +336,7 @@

    Inherited members

    class AlliedTelesisAwplusSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Allied Telesis devices.

    @@ -371,131 +344,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -516,9 +462,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -529,9 +474,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -543,6 +488,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/allied_telesis/index.html b/docs/netmiko/allied_telesis/index.html index accdd643b..b2985295a 100644 --- a/docs/netmiko/allied_telesis/index.html +++ b/docs/netmiko/allied_telesis/index.html @@ -45,7 +45,7 @@

    Classes

    class AlliedTelesisAwplusSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Allied Telesis devices.

    @@ -53,131 +53,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -198,9 +171,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -211,9 +183,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -225,6 +197,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/apresia/apresia_aeos.html b/docs/netmiko/apresia/apresia_aeos.html index cd3dfd6fd..6f5b09867 100644 --- a/docs/netmiko/apresia/apresia_aeos.html +++ b/docs/netmiko/apresia/apresia_aeos.html @@ -22,28 +22,39 @@

    Module netmiko.apresia.apresia_aeos

    Source code -
    import time
    +
    from typing import Any, Optional
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
     class ApresiaAeosBase(CiscoSSHConnection):
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def disable_paging(self, command="", delay_factor=1):
    -        self.enable()
    -        check_command = "show running-config | include terminal length 0"
    -        output = self.send_command(check_command)
    +    def disable_paging(
    +        self,
    +        command: str = "terminal length 0",
    +        delay_factor: Optional[float] = None,
    +        cmd_verify: bool = True,
    +        pattern: Optional[str] = None,
    +    ) -> str:
     
    -        if self.allow_auto_change and "terminal length 0" not in output:
    -            self.send_config_set("terminal length 0")
    +        self.enable()
    +        check_command = f"show running-config | include {command}"
    +        show_run = self._send_command_str(check_command)
    +
    +        output = ""
    +        if self.allow_auto_change and command not in show_run:
    +            output += super().disable_paging(
    +                command=command,
    +                delay_factor=delay_factor,
    +                cmd_verify=cmd_verify,
    +                pattern=pattern,
    +            )
             self.exit_enable_mode()
    +        return output
     
     
     class ApresiaAeosSSH(ApresiaAeosBase):
    @@ -51,7 +62,7 @@ 

    Module netmiko.apresia.apresia_aeos

    class ApresiaAeosTelnet(ApresiaAeosBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs)
    @@ -68,7 +79,7 @@

    Classes

    class ApresiaAeosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -76,152 +87,136 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class ApresiaAeosBase(CiscoSSHConnection):
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def disable_paging(self, command="", delay_factor=1):
    -        self.enable()
    -        check_command = "show running-config | include terminal length 0"
    -        output = self.send_command(check_command)
    +    def disable_paging(
    +        self,
    +        command: str = "terminal length 0",
    +        delay_factor: Optional[float] = None,
    +        cmd_verify: bool = True,
    +        pattern: Optional[str] = None,
    +    ) -> str:
     
    -        if self.allow_auto_change and "terminal length 0" not in output:
    -            self.send_config_set("terminal length 0")
    -        self.exit_enable_mode()
    + self.enable() + check_command = f"show running-config | include {command}" + show_run = self._send_command_str(check_command) + + output = "" + if self.allow_auto_change and command not in show_run: + output += super().disable_paging( + command=command, + delay_factor=delay_factor, + cmd_verify=cmd_verify, + pattern=pattern, + ) + self.exit_enable_mode() + return output

    Ancestors

      @@ -243,14 +238,11 @@

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           self._test_channel_read(pattern=r"[>#]")
           self.set_base_prompt()
      -    self.disable_paging()
      -    # Clear the read buffer
      -    time.sleep(0.3 * self.global_delay_factor)
      -    self.clear_buffer()
      + self.disable_paging()
    @@ -262,9 +254,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -275,9 +266,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -289,6 +280,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -304,7 +296,7 @@

    Inherited members

    class ApresiaAeosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -312,131 +304,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -458,9 +423,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -471,9 +435,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -485,6 +449,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -509,136 +474,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class ApresiaAeosTelnet(ApresiaAeosBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -658,9 +596,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -671,9 +608,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -685,6 +622,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/apresia/index.html b/docs/netmiko/apresia/index.html index 1c569d740..432058152 100644 --- a/docs/netmiko/apresia/index.html +++ b/docs/netmiko/apresia/index.html @@ -45,7 +45,7 @@

    Classes

    class ApresiaAeosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -53,131 +53,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -199,9 +172,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -212,9 +184,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -226,6 +198,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -250,136 +223,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class ApresiaAeosTelnet(ApresiaAeosBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -399,9 +345,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -412,9 +357,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -426,6 +371,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/arista/arista.html b/docs/netmiko/arista/arista.html index 59b03bb3e..7792ecae4 100644 --- a/docs/netmiko/arista/arista.html +++ b/docs/netmiko/arista/arista.html @@ -22,18 +22,18 @@

    Module netmiko.arista.arista

    Source code -
    import re
    +
    from typing import Any, Optional, Union, Sequence
    +from typing import TYPE_CHECKING
    +import re
     from netmiko.cisco_base_connection import CiscoSSHConnection
     from netmiko.cisco_base_connection import CiscoFileTransfer
     
    +if TYPE_CHECKING:
    +    from netmiko.base_connection import BaseConnection
     
    -class AristaBase(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
     
    -    def session_preparation(self):
    +class AristaBase(CiscoSSHConnection):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             cmd = "terminal width 511"
             # Arista will echo immediately and then when the device really responds (like NX-OS)
    @@ -43,16 +43,18 @@ 

    Module netmiko.arista.arista

    def enable( self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = r"\#", + re_flags: int = re.IGNORECASE, + ) -> str: return super().enable( cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags ) - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[>\#]" + ) -> bool: """ Checks if the device is in configuration mode or not. @@ -67,7 +69,12 @@

    Module netmiko.arista.arista

    output = output.replace("(s2)", "") return check_string in output - def config_mode(self, config_command="configure terminal", pattern="", re_flags=0): + def config_mode( + self, + config_command: str = "configure terminal", + pattern: str = "", + re_flags: int = 0, + ) -> str: """Force arista to read pattern all the way to prompt on the next line.""" if not re_flags: @@ -81,13 +88,15 @@

    Module netmiko.arista.arista

    config_command=config_command, pattern=pattern, re_flags=re_flags ) - def _enter_shell(self): + def _enter_shell(self) -> str: """Enter the Bourne Shell.""" - return self.send_command("bash", expect_string=r"[\$#]") + output = self._send_command_str("bash", expect_string=r"[\$#]") + return output - def _return_cli(self): + def _return_cli(self) -> str: """Return to the CLI.""" - return self.send_command("exit", expect_string=r"[#>]") + output = self._send_command_str("exit", expect_string=r"[#>]") + return output class AristaSSH(AristaBase): @@ -95,7 +104,7 @@

    Module netmiko.arista.arista

    class AristaTelnet(AristaBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs) @@ -106,13 +115,13 @@

    Module netmiko.arista.arista

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/mnt/flash", - direction="put", - **kwargs, - ): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/mnt/flash", + direction: str = "put", + **kwargs: Any, + ) -> None: return super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -122,37 +131,39 @@

    Module netmiko.arista.arista

    **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} file:{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=4 - ) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=600) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError
    @@ -167,7 +178,7 @@

    Classes

    class AristaBase -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -175,141 +186,109 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class AristaBase(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             cmd = "terminal width 511"
             # Arista will echo immediately and then when the device really responds (like NX-OS)
    @@ -319,16 +298,18 @@ 

    Classes

    def enable( self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = r"\#", + re_flags: int = re.IGNORECASE, + ) -> str: return super().enable( cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags ) - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[>\#]" + ) -> bool: """ Checks if the device is in configuration mode or not. @@ -343,7 +324,12 @@

    Classes

    output = output.replace("(s2)", "") return check_string in output - def config_mode(self, config_command="configure terminal", pattern="", re_flags=0): + def config_mode( + self, + config_command: str = "configure terminal", + pattern: str = "", + re_flags: int = 0, + ) -> str: """Force arista to read pattern all the way to prompt on the next line.""" if not re_flags: @@ -357,13 +343,15 @@

    Classes

    config_command=config_command, pattern=pattern, re_flags=re_flags ) - def _enter_shell(self): + def _enter_shell(self) -> str: """Enter the Bourne Shell.""" - return self.send_command("bash", expect_string=r"[\$#]") + output = self._send_command_str("bash", expect_string=r"[\$#]") + return output - def _return_cli(self): + def _return_cli(self) -> str: """Return to the CLI.""" - return self.send_command("exit", expect_string=r"[#>]")
    + output = self._send_command_str("exit", expect_string=r"[#>]") + return output

    Ancestors

      @@ -388,7 +376,9 @@

      Methods

      Can also be (s2)

      Source code -
      def check_config_mode(self, check_string=")#", pattern=r"[>\#]"):
      +
      def check_config_mode(
      +    self, check_string: str = ")#", pattern: str = r"[>\#]"
      +) -> bool:
           """
           Checks if the device is in configuration mode or not.
       
      @@ -411,7 +401,12 @@ 

      Methods

      Force arista to read pattern all the way to prompt on the next line.

      Source code -
      def config_mode(self, config_command="configure terminal", pattern="", re_flags=0):
      +
      def config_mode(
      +    self,
      +    config_command: str = "configure terminal",
      +    pattern: str = "",
      +    re_flags: int = 0,
      +) -> str:
           """Force arista to read pattern all the way to prompt on the next line."""
       
           if not re_flags:
      @@ -433,7 +428,7 @@ 

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           cmd = "terminal width 511"
           # Arista will echo immediately and then when the device really responds (like NX-OS)
      @@ -450,7 +445,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • disable_paging
    • disconnect
    • @@ -462,9 +456,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -476,6 +470,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • @@ -502,13 +497,13 @@

      Inherited members

      def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/mnt/flash", - direction="put", - **kwargs, - ): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/mnt/flash", + direction: str = "put", + **kwargs: Any, + ) -> None: return super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -518,37 +513,39 @@

      Inherited members

      **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} file:{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=4 - ) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=600) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError

      Ancestors

      @@ -583,7 +580,7 @@

      Inherited members

    class AristaSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -591,131 +588,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -737,7 +707,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -750,9 +719,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -764,6 +733,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -788,136 +758,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class AristaTelnet(AristaBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -937,7 +880,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -950,9 +892,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -964,6 +906,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/arista/index.html b/docs/netmiko/arista/index.html index a9a4e1087..6fb17e5a0 100644 --- a/docs/netmiko/arista/index.html +++ b/docs/netmiko/arista/index.html @@ -56,13 +56,13 @@

    Classes

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/mnt/flash", - direction="put", - **kwargs, - ): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/mnt/flash", + direction: str = "put", + **kwargs: Any, + ) -> None: return super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -72,37 +72,39 @@

    Classes

    **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} file:{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=4 - ) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=600) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: Union[str, Sequence[str], None] = None) -> None: raise NotImplementedError

    Ancestors

    @@ -137,7 +139,7 @@

    Inherited members

    class AristaSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -145,131 +147,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -291,7 +266,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -304,9 +278,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -318,6 +292,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -342,136 +317,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class AristaTelnet(AristaBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -491,7 +439,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -504,9 +451,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -518,6 +465,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/aruba/aruba_ssh.html b/docs/netmiko/aruba/aruba_ssh.html index e38861c6d..68912a967 100644 --- a/docs/netmiko/aruba/aruba_ssh.html +++ b/docs/netmiko/aruba/aruba_ssh.html @@ -30,15 +30,14 @@

    Module netmiko.aruba.aruba_ssh

    For use with Aruba OS Controllers. """ -import time -import re +from typing import Any from netmiko.cisco_base_connection import CiscoSSHConnection class ArubaSSH(CiscoSSHConnection): """Aruba OS support""" - def __init__(self, **kwargs): + def __init__(self, **kwargs: Any) -> None: if kwargs.get("default_enter") is None: kwargs["default_enter"] = "\r" # Aruba has an auto-complete on space behavior that is problematic @@ -46,36 +45,35 @@

    Module netmiko.aruba.aruba_ssh

    kwargs["global_cmd_verify"] = False return super().__init__(**kwargs) - def session_preparation(self): + def session_preparation(self) -> None: """Aruba OS requires enable mode to disable paging.""" # Aruba switches output ansi codes self.ansi_escape_codes = True - - delay_factor = self.select_delay_factor(delay_factor=0) - time.sleep(1 * delay_factor) - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() - self.disable_paging(command="no paging") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() + self.disable_paging(command="no page") - def check_config_mode(self, check_string="(config) #", pattern=""): + def check_config_mode( + self, check_string: str = "(config) #", pattern: str = r"[>#]" + ) -> bool: """ Checks if the device is in configuration mode or not. Aruba uses "(<controller name>) (config) #" as config prompt """ - if not pattern: - pattern = re.escape(self.base_prompt[:16]) return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure term", pattern=""): - """ - Aruba auto completes on space so 'configure' needs fully spelled-out. - """ - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, + config_command: str = "configure term", + pattern: str = "", + re_flags: int = 0, + ) -> str: + """Aruba auto completes on space so 'configure' needs fully spelled-out.""" + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    @@ -97,138 +95,111 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class ArubaSSH(CiscoSSHConnection):
         """Aruba OS support"""
     
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
             # Aruba has an auto-complete on space behavior that is problematic
    @@ -236,36 +207,35 @@ 

    Classes

    kwargs["global_cmd_verify"] = False return super().__init__(**kwargs) - def session_preparation(self): + def session_preparation(self) -> None: """Aruba OS requires enable mode to disable paging.""" # Aruba switches output ansi codes self.ansi_escape_codes = True - - delay_factor = self.select_delay_factor(delay_factor=0) - time.sleep(1 * delay_factor) - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() - self.disable_paging(command="no paging") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() + self.disable_paging(command="no page") - def check_config_mode(self, check_string="(config) #", pattern=""): + def check_config_mode( + self, check_string: str = "(config) #", pattern: str = r"[>#]" + ) -> bool: """ Checks if the device is in configuration mode or not. Aruba uses "(<controller name>) (config) #" as config prompt """ - if not pattern: - pattern = re.escape(self.base_prompt[:16]) return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure term", pattern=""): - """ - Aruba auto completes on space so 'configure' needs fully spelled-out. - """ - return super().config_mode(config_command=config_command, pattern=pattern)
    + def config_mode( + self, + config_command: str = "configure term", + pattern: str = "", + re_flags: int = 0, + ) -> str: + """Aruba auto completes on space so 'configure' needs fully spelled-out.""" + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )

    Ancestors

      @@ -276,36 +246,41 @@

      Ancestors

      Methods

      -def check_config_mode(self, check_string='(config) #', pattern='') +def check_config_mode(self, check_string='(config) #', pattern='[>#]')

      Checks if the device is in configuration mode or not.

      Aruba uses "() (config) #" as config prompt

      Source code -
      def check_config_mode(self, check_string="(config) #", pattern=""):
      +
      def check_config_mode(
      +    self, check_string: str = "(config) #", pattern: str = r"[>#]"
      +) -> bool:
           """
           Checks if the device is in configuration mode or not.
       
           Aruba uses "(<controller name>) (config) #" as config prompt
           """
      -    if not pattern:
      -        pattern = re.escape(self.base_prompt[:16])
           return super().check_config_mode(check_string=check_string, pattern=pattern)
      -def config_mode(self, config_command='configure term', pattern='') +def config_mode(self, config_command='configure term', pattern='', re_flags=0)

      Aruba auto completes on space so 'configure' needs fully spelled-out.

      Source code -
      def config_mode(self, config_command="configure term", pattern=""):
      -    """
      -    Aruba auto completes on space so 'configure' needs fully spelled-out.
      -    """
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      +
      def config_mode(
      +    self,
      +    config_command: str = "configure term",
      +    pattern: str = "",
      +    re_flags: int = 0,
      +) -> str:
      +    """Aruba auto completes on space so 'configure' needs fully spelled-out."""
      +    return super().config_mode(
      +        config_command=config_command, pattern=pattern, re_flags=re_flags
      +    )
      @@ -315,20 +290,14 @@

      Methods

      Aruba OS requires enable mode to disable paging.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Aruba OS requires enable mode to disable paging."""
           # Aruba switches output ansi codes
           self.ansi_escape_codes = True
      -
      -    delay_factor = self.select_delay_factor(delay_factor=0)
      -    time.sleep(1 * delay_factor)
      -    self._test_channel_read()
      +    self._test_channel_read(pattern=r"[>#]")
           self.set_base_prompt()
           self.enable()
      -    self.disable_paging(command="no paging")
      -    # Clear the read buffer
      -    time.sleep(0.3 * self.global_delay_factor)
      -    self.clear_buffer()
      + self.disable_paging(command="no page")
    @@ -339,7 +308,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • disable_paging
  • disconnect
  • @@ -351,9 +319,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -365,6 +333,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • diff --git a/docs/netmiko/aruba/index.html b/docs/netmiko/aruba/index.html index e071fc610..7419d6574 100644 --- a/docs/netmiko/aruba/index.html +++ b/docs/netmiko/aruba/index.html @@ -53,138 +53,111 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class ArubaSSH(CiscoSSHConnection):
         """Aruba OS support"""
     
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
             # Aruba has an auto-complete on space behavior that is problematic
    @@ -192,36 +165,35 @@ 

    Classes

    kwargs["global_cmd_verify"] = False return super().__init__(**kwargs) - def session_preparation(self): + def session_preparation(self) -> None: """Aruba OS requires enable mode to disable paging.""" # Aruba switches output ansi codes self.ansi_escape_codes = True - - delay_factor = self.select_delay_factor(delay_factor=0) - time.sleep(1 * delay_factor) - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() - self.disable_paging(command="no paging") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() + self.disable_paging(command="no page") - def check_config_mode(self, check_string="(config) #", pattern=""): + def check_config_mode( + self, check_string: str = "(config) #", pattern: str = r"[>#]" + ) -> bool: """ Checks if the device is in configuration mode or not. Aruba uses "(<controller name>) (config) #" as config prompt """ - if not pattern: - pattern = re.escape(self.base_prompt[:16]) return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure term", pattern=""): - """ - Aruba auto completes on space so 'configure' needs fully spelled-out. - """ - return super().config_mode(config_command=config_command, pattern=pattern)
    + def config_mode( + self, + config_command: str = "configure term", + pattern: str = "", + re_flags: int = 0, + ) -> str: + """Aruba auto completes on space so 'configure' needs fully spelled-out.""" + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )

    Ancestors

      @@ -232,36 +204,41 @@

      Ancestors

      Methods

      -def check_config_mode(self, check_string='(config) #', pattern='') +def check_config_mode(self, check_string='(config) #', pattern='[>#]')

      Checks if the device is in configuration mode or not.

      Aruba uses "() (config) #" as config prompt

      Source code -
      def check_config_mode(self, check_string="(config) #", pattern=""):
      +
      def check_config_mode(
      +    self, check_string: str = "(config) #", pattern: str = r"[>#]"
      +) -> bool:
           """
           Checks if the device is in configuration mode or not.
       
           Aruba uses "(<controller name>) (config) #" as config prompt
           """
      -    if not pattern:
      -        pattern = re.escape(self.base_prompt[:16])
           return super().check_config_mode(check_string=check_string, pattern=pattern)
      -def config_mode(self, config_command='configure term', pattern='') +def config_mode(self, config_command='configure term', pattern='', re_flags=0)

      Aruba auto completes on space so 'configure' needs fully spelled-out.

      Source code -
      def config_mode(self, config_command="configure term", pattern=""):
      -    """
      -    Aruba auto completes on space so 'configure' needs fully spelled-out.
      -    """
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      +
      def config_mode(
      +    self,
      +    config_command: str = "configure term",
      +    pattern: str = "",
      +    re_flags: int = 0,
      +) -> str:
      +    """Aruba auto completes on space so 'configure' needs fully spelled-out."""
      +    return super().config_mode(
      +        config_command=config_command, pattern=pattern, re_flags=re_flags
      +    )
      @@ -271,20 +248,14 @@

      Methods

      Aruba OS requires enable mode to disable paging.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Aruba OS requires enable mode to disable paging."""
           # Aruba switches output ansi codes
           self.ansi_escape_codes = True
      -
      -    delay_factor = self.select_delay_factor(delay_factor=0)
      -    time.sleep(1 * delay_factor)
      -    self._test_channel_read()
      +    self._test_channel_read(pattern=r"[>#]")
           self.set_base_prompt()
           self.enable()
      -    self.disable_paging(command="no paging")
      -    # Clear the read buffer
      -    time.sleep(0.3 * self.global_delay_factor)
      -    self.clear_buffer()
      + self.disable_paging(command="no page")
    @@ -295,7 +266,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • disable_paging
  • disconnect
  • @@ -307,9 +277,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -321,6 +291,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • diff --git a/docs/netmiko/base_connection.html b/docs/netmiko/base_connection.html index 1b793275c..85508950e 100644 --- a/docs/netmiko/base_connection.html +++ b/docs/netmiko/base_connection.html @@ -34,6 +34,23 @@

    Module netmiko.base_connection

    Also defines methods that should generally be supported by child classes """ +from typing import ( + Optional, + Callable, + Any, + List, + Dict, + TypeVar, + cast, + Type, + Sequence, + TextIO, + Union, + Tuple, + Deque, +) +from typing import TYPE_CHECKING +from types import TracebackType import io import re import socket @@ -42,31 +59,99 @@

    Module netmiko.base_connection

    from collections import deque from os import path from threading import Lock +import functools +import logging import paramiko import serial from tenacity import retry, stop_after_attempt, wait_exponential +import warnings from netmiko import log -from netmiko.netmiko_globals import MAX_BUFFER, BACKSPACE_CHAR -from netmiko.ssh_exception import ( +from netmiko.netmiko_globals import BACKSPACE_CHAR +from netmiko.exceptions import ( NetmikoTimeoutException, NetmikoAuthenticationException, ConfigInvalidException, + ReadException, + ReadTimeout, ) +from netmiko.channel import Channel, SSHChannel, TelnetChannel, SerialChannel +from netmiko.session_log import SessionLog from netmiko.utilities import ( write_bytes, check_serial_port, - get_structured_data, - get_structured_data_genie, - get_structured_data_ttp, + structured_data_converter, run_ttp_template, select_cmd_verify, + calc_old_timeout, ) from netmiko.utilities import m_exec_time # noqa +if TYPE_CHECKING: + from os import PathLike + +# For decorators +F = TypeVar("F", bound=Callable[..., Any]) + + +DELAY_FACTOR_DEPR_SIMPLE_MSG = """\n +Netmiko 4.x and later has deprecated the use of delay_factor and/or +max_loops in this context. You should remove any use of delay_factor=x +from this method call.\n""" + + +# Logging filter for #2597 +class SecretsFilter(logging.Filter): + def __init__(self, no_log: Optional[Dict[Any, str]] = None) -> None: + self.no_log = no_log + + def filter(self, record: logging.LogRecord) -> bool: + """Removes secrets (no_log) from messages""" + if self.no_log: + for hidden_data in self.no_log.values(): + record.msg = record.msg.replace(hidden_data, "********") + return True + + +def lock_channel(func: F) -> F: + @functools.wraps(func) + def wrapper_decorator(self: "BaseConnection", *args: Any, **kwargs: Any) -> Any: + self._lock_netmiko_session() + try: + return_val = func(self, *args, **kwargs) + finally: + # Always unlock the channel, even on exception. + self._unlock_netmiko_session() + return return_val + + return cast(F, wrapper_decorator) + -class BaseConnection(object): +def log_writes(func: F) -> F: + """Handle both session_log and log of writes.""" + + @functools.wraps(func) + def wrapper_decorator(self: "BaseConnection", out_data: str) -> None: + func(self, out_data) + try: + log.debug( + "write_channel: {}".format( + str(write_bytes(out_data, encoding=self.encoding)) + ) + ) + if self.session_log: + if self.session_log.fin or self.session_log.record_writes: + self.session_log.write(out_data) + except UnicodeDecodeError: + # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2) + pass + return None + + return cast(F, wrapper_decorator) + + +class BaseConnection: """ Defines vendor independent methods. @@ -75,183 +160,165 @@

    Module netmiko.base_connection

    def __init__( self, - ip="", - host="", - username="", - password=None, - secret="", - port=None, - device_type="", - verbose=False, - global_delay_factor=1, - global_cmd_verify=None, - use_keys=False, - key_file=None, - pkey=None, - passphrase=None, - allow_agent=False, - ssh_strict=False, - system_host_keys=False, - alt_host_keys=False, - alt_key_file="", - ssh_config_file=None, + ip: str = "", + host: str = "", + username: str = "", + password: Optional[str] = None, + secret: str = "", + port: Optional[int] = None, + device_type: str = "", + verbose: bool = False, + global_delay_factor: float = 1.0, + global_cmd_verify: Optional[bool] = None, + use_keys: bool = False, + key_file: Optional[str] = None, + pkey: Optional[paramiko.PKey] = None, + passphrase: Optional[str] = None, + disabled_algorithms: Optional[Dict[str, Any]] = None, + allow_agent: bool = False, + ssh_strict: bool = False, + system_host_keys: bool = False, + alt_host_keys: bool = False, + alt_key_file: str = "", + ssh_config_file: Optional[str] = None, # # Connect timeouts # ssh-connect --> TCP conn (conn_timeout) --> SSH-banner (banner_timeout) # --> Auth response (auth_timeout) - conn_timeout=5, - auth_timeout=None, # Timeout to wait for authentication response - banner_timeout=15, # Timeout to wait for the banner to be presented (post TCP-connect) + conn_timeout: int = 10, + # Timeout to wait for authentication response + auth_timeout: Optional[int] = None, + banner_timeout: int = 15, # Timeout to wait for the banner to be presented # Other timeouts - blocking_timeout=20, # Read blocking timeout - timeout=100, # TCP connect timeout | overloaded to read-loop timeout - session_timeout=60, # Used for locking/sharing the connection - keepalive=0, - default_enter=None, - response_return=None, - serial_settings=None, - fast_cli=False, - _legacy_mode=True, - session_log=None, - session_log_record_writes=False, - session_log_file_mode="write", - allow_auto_change=False, - encoding="ascii", - sock=None, - auto_connect=True, - ): + blocking_timeout: int = 20, # Read blocking timeout + timeout: int = 100, # TCP connect timeout | overloaded to read-loop timeout + session_timeout: int = 60, # Used for locking/sharing the connection + read_timeout_override: Optional[float] = None, + keepalive: int = 0, + default_enter: Optional[str] = None, + response_return: Optional[str] = None, + serial_settings: Optional[Dict[str, Any]] = None, + fast_cli: bool = True, + _legacy_mode: bool = False, + session_log: Optional[SessionLog] = None, + session_log_record_writes: bool = False, + session_log_file_mode: str = "write", + allow_auto_change: bool = False, + encoding: str = "ascii", + sock: Optional[socket.socket] = None, + auto_connect: bool = True, + delay_factor_compat: bool = False, + ) -> None: """ Initialize attributes for establishing connection to target device. :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: \n). - :type default_enter: str :param response_return: Character(s) to use in normalized return data to represent enter key (default: \n) - :type response_return: str :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor to select smallest of global and specific. Sets default global_delay_factor to .1 - (default: False) - :type fast_cli: boolean + (default: True) :param session_log: File path or BufferedIOBase subclass object to write the session log to. - :type session_log: str :param session_log_record_writes: The session log generally only records channel reads due to eliminate command duplication due to command echo. You can enable this if you want to record both channel reads and channel writes in the log (default: False). - :type session_log_record_writes: boolean :param session_log_file_mode: "write" or "append" for session_log file mode (default: "write") - :type session_log_file_mode: str :param allow_auto_change: Allow automatic configuration changes for terminal settings. (default: False) - :type allow_auto_change: bool :param encoding: Encoding to be used when writing bytes to the output channel. (default: ascii) - :type encoding: str :param sock: An open socket or socket-like object (such as a `.Channel`) to use for communication to the target host (default: None). - :type sock: socket :param global_cmd_verify: Control whether command echo verification is enabled or disabled (default: None). Global attribute takes precedence over function `cmd_verify` argument. Value of `None` indicates to use function `cmd_verify` argument. - :type global_cmd_verify: bool|None :param auto_connect: Control whether Netmiko automatically establishes the connection as part of the object creation (default: True). - :type auto_connect: bool + + :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko + 3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be + eliminated in Netmiko 5.x (default: False). """ - self.remote_conn = None + + self.remote_conn: Union[ + None, telnetlib.Telnet, paramiko.Channel, serial.Serial + ] = None # Does the platform support a configuration mode self._config_mode = True + self._read_buffer = "" + self.delay_factor_compat = delay_factor_compat self.TELNET_RETURN = "\r\n" if default_enter is None: @@ -289,24 +356,46 @@

    Module netmiko.base_connection

    self.conn_timeout = conn_timeout self.session_timeout = session_timeout self.timeout = timeout + self.read_timeout_override = read_timeout_override self.keepalive = keepalive self.allow_auto_change = allow_auto_change self.encoding = encoding self.sock = sock - - # Netmiko will close the session_log if we open the file + self.fast_cli = fast_cli + self._legacy_mode = _legacy_mode + self.global_delay_factor = global_delay_factor + self.global_cmd_verify = global_cmd_verify + if self.fast_cli and self.global_delay_factor == 1: + self.global_delay_factor = 0.1 self.session_log = None - self.session_log_record_writes = session_log_record_writes self._session_log_close = False - # Ensures last write operations prior to disconnect are recorded. - self._session_log_fin = False + + # prevent logging secret data + no_log = {} + if self.password: + no_log["password"] = self.password + if self.secret: + no_log["secret"] = self.secret + log.addFilter(SecretsFilter(no_log=no_log)) + + # Netmiko will close the session_log if we open the file if session_log is not None: if isinstance(session_log, str): # If session_log is a string, open a file corresponding to string name. - self.open_session_log(filename=session_log, mode=session_log_file_mode) + self.session_log = SessionLog( + file_name=session_log, + file_mode=session_log_file_mode, + no_log=no_log, + record_writes=session_log_record_writes, + ) + self.session_log.open() elif isinstance(session_log, io.BufferedIOBase): # In-memory buffer or an already open file handle - self.session_log = session_log + self.session_log = SessionLog( + buffered_io=session_log, + no_log=no_log, + record_writes=session_log_record_writes, + ) else: raise ValueError( "session_log must be a path to a file, a file handle, " @@ -332,13 +421,6 @@

    Module netmiko.base_connection

    comm_port = check_serial_port(comm_port) self.serial_settings.update({"port": comm_port}) - self.fast_cli = fast_cli - self._legacy_mode = _legacy_mode - self.global_delay_factor = global_delay_factor - self.global_cmd_verify = global_cmd_verify - if self.fast_cli and self.global_delay_factor == 1: - self.global_delay_factor = 0.1 - # set in set_base_prompt method self.base_prompt = "" self._session_locker = Lock() @@ -353,6 +435,7 @@

    Module netmiko.base_connection

    else: self.protocol = "ssh" + self.key_policy: paramiko.client.MissingHostKeyPolicy if not ssh_strict: self.key_policy = paramiko.AutoAddPolicy() else: @@ -369,6 +452,7 @@

    Module netmiko.base_connection

    self.system_host_keys = system_host_keys self.alt_host_keys = alt_host_keys self.alt_key_file = alt_key_file + self.disabled_algorithms = disabled_algorithms or {} # For SSH proxy support self.ssh_config_file = ssh_config_file @@ -377,25 +461,30 @@

    Module netmiko.base_connection

    if auto_connect: self._open() - def _open(self): + def _open(self) -> None: """Decouple connection creation from __init__ for mocking.""" self._modify_connection_params() self.establish_connection() self._try_session_preparation() - def __enter__(self): + def __enter__(self) -> "BaseConnection": """Establish a session using a Context Manager.""" return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """Gracefully close connection on Context Manager exit.""" self.disconnect() - def _modify_connection_params(self): + def _modify_connection_params(self) -> None: """Modify connection parameters prior to SSH connection.""" pass - def _timeout_exceeded(self, start, msg="Timeout exceeded!"): + def _timeout_exceeded(self, start: float, msg: str = "Timeout exceeded!") -> bool: """Raise NetmikoTimeoutException if waiting too much in the serving queue. :param start: Initial start time to see if session lock timeout has been exceeded @@ -412,7 +501,7 @@

    Module netmiko.base_connection

    raise NetmikoTimeoutException(msg) return False - def _lock_netmiko_session(self, start=None): + def _lock_netmiko_session(self, start: Optional[float] = None) -> bool: """Try to acquire the Netmiko session lock. If not available, wait in the queue until the channel is available again. @@ -428,68 +517,33 @@

    Module netmiko.base_connection

    time.sleep(0.1) return True - def _unlock_netmiko_session(self): + def _unlock_netmiko_session(self) -> None: """ Release the channel at the end of the task. """ if self._session_locker.locked(): self._session_locker.release() - def _write_channel(self, out_data): - """Generic handler that will write to both SSH and telnet channel. + def _autodetect_fs(self, cmd: str = "", pattern: str = "") -> str: + raise NotImplementedError - :param out_data: data to be written to the channel - :type out_data: str (can be either unicode/byte string) - """ - if self.protocol == "ssh": - self.remote_conn.sendall(write_bytes(out_data, encoding=self.encoding)) - elif self.protocol == "telnet": - self.remote_conn.write(write_bytes(out_data, encoding=self.encoding)) - elif self.protocol == "serial": - self.remote_conn.write(write_bytes(out_data, encoding=self.encoding)) - self.remote_conn.flush() - else: - raise ValueError("Invalid protocol specified") - try: - log.debug( - "write_channel: {}".format( - write_bytes(out_data, encoding=self.encoding) - ) - ) - if self._session_log_fin or self.session_log_record_writes: - self._write_session_log(out_data) - except UnicodeDecodeError: - # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2) - pass + def _enter_shell(self) -> str: + raise NotImplementedError - def _write_session_log(self, data): - if self.session_log is not None and len(data) > 0: - # Hide the password and secret in the session_log - if self.password: - data = data.replace(self.password, "********") - if self.secret: - data = data.replace(self.secret, "********") - if isinstance(self.session_log, io.BufferedIOBase): - data = self.normalize_linefeeds(data) - self.session_log.write(write_bytes(data, encoding=self.encoding)) - else: - self.session_log.write(self.normalize_linefeeds(data)) - self.session_log.flush() + def _return_cli(self) -> str: + raise NotImplementedError - def write_channel(self, out_data): - """Generic handler that will write to both SSH and telnet channel. + @lock_channel + @log_writes + def write_channel(self, out_data: str) -> None: + """Generic method that will write data out the channel. :param out_data: data to be written to the channel - :type out_data: str (can be either unicode/byte string) + :type out_data: str """ - self._lock_netmiko_session() - try: - self._write_channel(out_data) - finally: - # Always unlock the SSH channel, even on exception. - self._unlock_netmiko_session() + self.channel.write_channel(out_data) - def is_alive(self): + def is_alive(self) -> bool: """Returns a boolean flag with the state of the connection.""" null = chr(0) if self.remote_conn is None: @@ -501,9 +555,11 @@

    Module netmiko.base_connection

    # IAC = Interpret as Command; it comes before the NOP. log.debug("Sending IAC + NOP") # Need to send multiple times to test connection - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) + assert isinstance(self.remote_conn, telnetlib.Telnet) + telnet_socket = self.remote_conn.get_socket() + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) return True except AttributeError: return False @@ -513,203 +569,236 @@

    Module netmiko.base_connection

    # Try sending ASCII null byte to maintain the connection alive log.debug("Sending the NULL byte") self.write_channel(null) - return self.remote_conn.transport.is_active() + assert isinstance(self.remote_conn, paramiko.Channel) + assert self.remote_conn.transport is not None + result = self.remote_conn.transport.is_active() + assert isinstance(result, bool) + return result except (socket.error, EOFError): log.error("Unable to send", exc_info=True) # If unable to send, we can tell for sure that the connection is unusable return False return False - def _read_channel(self): - """Generic handler that will read all the data from an SSH or telnet channel.""" - if self.protocol == "ssh": - output = "" - while True: - if self.remote_conn.recv_ready(): - outbuf = self.remote_conn.recv(MAX_BUFFER) - if len(outbuf) == 0: - raise EOFError("Channel stream closed by remote device.") - output += outbuf.decode("utf-8", "ignore") - else: - break - elif self.protocol == "telnet": - output = self.remote_conn.read_very_eager().decode("utf-8", "ignore") - elif self.protocol == "serial": - output = "" - while self.remote_conn.in_waiting > 0: - output += self.remote_conn.read(self.remote_conn.in_waiting).decode( - "utf-8", "ignore" - ) + @lock_channel + def read_channel(self) -> str: + """Generic handler that will read all the data from given channel.""" + new_data = self.channel.read_channel() + new_data = self.normalize_linefeeds(new_data) if self.ansi_escape_codes: - output = self.strip_ansi_escape_codes(output) - log.debug(f"read_channel: {output}") - self._write_session_log(output) + new_data = self.strip_ansi_escape_codes(new_data) + log.debug(f"read_channel: {new_data}") + if self.session_log: + self.session_log.write(new_data) + + # If data had been previously saved to the buffer, the prepend it to output + # do post read_channel so session_log/log doesn't record buffered data twice + if self._read_buffer: + output = self._read_buffer + new_data + self._read_buffer = "" + else: + output = new_data return output - def read_channel(self): - """Generic handler that will read all the data from an SSH or telnet channel.""" - output = "" - self._lock_netmiko_session() - try: - output = self._read_channel() - finally: - # Always unlock the SSH channel, even on exception. - self._unlock_netmiko_session() - return output + def read_until_pattern( + self, + pattern: str = "", + read_timeout: float = 10.0, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read channel until pattern is detected. - def _read_channel_expect(self, pattern="", re_flags=0, max_loops=150): - """Function that reads channel until pattern is detected. + Will return string up to and including pattern. - pattern takes a regular expression. + Returns ReadTimeout if pattern not detected in read_timeout seconds. - By default pattern will be self.base_prompt + :param pattern: Regular expression pattern used to identify that reading is done. - Note: this currently reads beyond pattern. In the case of SSH it reads MAX_BUFFER. - In the case of telnet it reads all non-blocking data. + :param read_timeout: maximum time to wait looking for pattern. Will raise ReadTimeout. + A read_timeout value of 0 will cause the loop to never timeout (i.e. it will keep + reading indefinitely until pattern is detected. - There are dependencies here like determining whether in config_mode that are actually - depending on reading beyond pattern. + :param re_flags: regex flags used in conjunction with pattern (defaults to no flags). - :param pattern: Regular expression pattern used to identify the command is done \ - (defaults to self.base_prompt) - :type pattern: str (regular expression) + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ + if max_loops is not None: + msg = """\n +Netmiko 4.x has deprecated the use of max_loops with read_until_pattern. +You should convert all uses of max_loops over to read_timeout=x +where x is the total number of seconds to wait before timing out.\n""" + warnings.warn(msg, DeprecationWarning) - :param re_flags: regex flags used in conjunction with pattern to search for prompt \ - (defaults to no flags) - :type re_flags: int + if self.read_timeout_override: + read_timeout = self.read_timeout_override - :param max_loops: max number of iterations to read the channel before raising exception. - Will default to be based upon self.timeout. - :type max_loops: int - """ output = "" - if not pattern: - pattern = re.escape(self.base_prompt) - log.debug(f"Pattern is: {pattern}") - - i = 1 - loop_delay = 0.1 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # argument for backwards compatibility). - if max_loops == 150: - max_loops = int(self.timeout / loop_delay) - while i < max_loops: - if self.protocol == "ssh": - try: - # If no data available will wait timeout seconds trying to read - self._lock_netmiko_session() - new_data = self.remote_conn.recv(MAX_BUFFER) - if len(new_data) == 0: - raise EOFError("Channel stream closed by remote device.") - new_data = new_data.decode("utf-8", "ignore") - if self.ansi_escape_codes: - new_data = self.strip_ansi_escape_codes(new_data) - log.debug(f"_read_channel_expect read_data: {new_data}") - output += new_data - self._write_session_log(new_data) - except socket.timeout: - raise NetmikoTimeoutException( - "Timed-out reading channel, data not available." - ) - finally: - self._unlock_netmiko_session() - elif self.protocol == "telnet" or "serial": - output += self.read_channel() + loop_delay = 0.01 + start_time = time.time() + # if read_timeout == 0 or 0.0 keep reading indefinitely + while (time.time() - start_time < read_timeout) or (not read_timeout): + output += self.read_channel() if re.search(pattern, output, flags=re_flags): + results = re.split(pattern, output, maxsplit=1, flags=re_flags) + + # The string matched by pattern must be retained in the output string. + # re.split will do this if capturing parentesis are used. + if len(results) == 2: + # no capturing parenthesis, convert and try again. + pattern = f"({pattern})" + results = re.split(pattern, output, maxsplit=1, flags=re_flags) + + if len(results) != 3: + # well, we tried + msg = f"""Unable to successfully split output based on pattern: +pattern={pattern} +output={repr(output)} +results={results} +""" + raise ReadException(msg) + + # Process such that everything before and including pattern is return. + # Everything else is retained in the _read_buffer + output, match_str, buffer = results + output = output + match_str + if buffer: + self._read_buffer += buffer log.debug(f"Pattern found: {pattern} {output}") return output - time.sleep(loop_delay * self.global_delay_factor) - i += 1 - raise NetmikoTimeoutException( - f"Timed-out reading channel, pattern not found in output: {pattern}" - ) + time.sleep(loop_delay) + + msg = f"""\n\nPattern not detected: {repr(pattern)} in output. + +Things you might try to fix this: +1. Adjust the regex pattern to better identify the terminating string. Note, in +many situations the pattern is automatically based on the network device's prompt. +2. Increase the read_timeout to a larger value. + +You can also look at the Netmiko session_log or debug log for more information.\n\n""" + raise ReadTimeout(msg) - def _read_channel_timing(self, delay_factor=1, max_loops=150): + def read_channel_timing( + self, + last_read: float = 2.0, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + ) -> str: """Read data on the channel based on timing delays. - Attempt to read channel max_loops number of times. If no data this will cause a 15 second - delay. + General pattern is keep reading until no new data is read. + Once no new data is read wait `last_read` amount of time (one last read). + As long as no new data, then return data. + + `read_timeout` is an absolute timer for how long to keep reading (which presupposes + we are still getting new data). - Once data is encountered read channel for another two seconds (2 * delay_factor) to make - sure reading of channel is complete. + Setting `read_timeout` to zero will cause read_channel_timing to never expire based + on an absolute timeout. It will only complete based on timeout based on their being + no new data. - :param delay_factor: multiplicative factor to adjust delay when reading channel (delays - get multiplied by this factor) - :type delay_factor: int or float + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: maximum number of loops to iterate through before returning channel data. - Will default to be based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ - # Time to delay in each read loop - loop_delay = 0.1 - final_delay = 2 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # and delay_factor arguments for backwards compatibility). - delay_factor = self.select_delay_factor(delay_factor) - if delay_factor == 1 and max_loops == 150: - max_loops = int(self.timeout / loop_delay) + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) - # FIX: Cleanup in future versions of Netmiko - if delay_factor < 1: - if not self._legacy_mode and self.fast_cli: - delay_factor = 1 + if self.read_timeout_override: + read_timeout = self.read_timeout_override + # Time to delay in each read loop + loop_delay = 0.1 channel_data = "" - i = 0 - while i <= max_loops: - time.sleep(loop_delay * delay_factor) + start_time = time.time() + + # Set read_timeout to 0 to never timeout + while (time.time() - start_time < read_timeout) or (not read_timeout): + time.sleep(loop_delay) new_data = self.read_channel() + # gather new output if new_data: channel_data += new_data - else: - # Safeguard to make sure really done - time.sleep(final_delay * delay_factor) + # if we have some output, but nothing new, then do the last read + elif channel_data != "": + # Make sure really done (i.e. no new data) + time.sleep(last_read) new_data = self.read_channel() if not new_data: break else: channel_data += new_data - i += 1 - return channel_data + else: + msg = f"""\n +read_channel_timing's absolute timer expired. - def read_until_prompt(self, *args, **kwargs): - """Read channel until self.base_prompt detected. Return ALL data available.""" - return self._read_channel_expect(*args, **kwargs) +The network device was continually outputting data for longer than {read_timeout} +seconds. - def read_until_pattern(self, *args, **kwargs): - """Read channel until pattern detected. Return ALL data available.""" - return self._read_channel_expect(*args, **kwargs) +If this is expected i.e. the command you are executing is continually emitting +data for a long period of time, then you can set 'read_timeout=x' seconds. If +you want Netmiko to keep reading indefinitely (i.e. to only stop when there is +no new data), then you can set 'read_timeout=0'. - def read_until_prompt_or_pattern(self, pattern="", re_flags=0): - """Read until either self.base_prompt or pattern is detected. +You can look at the Netmiko session_log or debug log for more information. - :param pattern: the pattern used to identify that the output is complete (i.e. stop \ - reading when pattern is detected). pattern will be combined with self.base_prompt to \ - terminate output reading when the first of self.base_prompt or pattern is detected. - :type pattern: regular expression string +""" + raise ReadTimeout(msg) + return channel_data - :param re_flags: regex flags used in conjunction with pattern to search for prompt \ - (defaults to no flags) - :type re_flags: int + def read_until_prompt( + self, + read_timeout: float = 10.0, + read_entire_line: bool = False, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read channel up to and including self.base_prompt.""" + pattern = re.escape(self.base_prompt) + if read_entire_line: + pattern = f"{pattern}.*" + return self.read_until_pattern( + pattern=pattern, + re_flags=re_flags, + max_loops=max_loops, + read_timeout=read_timeout, + ) - """ - combined_pattern = re.escape(self.base_prompt) + def read_until_prompt_or_pattern( + self, + pattern: str = "", + read_timeout: float = 10.0, + read_entire_line: bool = False, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read until either self.base_prompt or pattern is detected.""" + prompt_pattern = re.escape(self.base_prompt) + if read_entire_line: + prompt_pattern = f"{prompt_pattern}.*" if pattern: - combined_pattern = r"({}|{})".format(combined_pattern, pattern) - return self._read_channel_expect(combined_pattern, re_flags=re_flags) + combined_pattern = r"(?:{}|{})".format(prompt_pattern, pattern) + else: + combined_pattern = prompt_pattern + return self.read_until_pattern( + pattern=combined_pattern, + re_flags=re_flags, + max_loops=max_loops, + read_timeout=read_timeout, + ) def serial_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:[Uu]ser:|sername|ogin)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): - self.telnet_login( + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:[Uu]ser:|sername|ogin)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: + return self.telnet_login( pri_prompt_terminator, alt_prompt_terminator, username_pattern, @@ -720,33 +809,28 @@

    Module netmiko.base_connection

    def telnet_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login|user name)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login|user name)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """Telnet login. Can be username/password or just password. :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt - :type pri_prompt_terminator: str :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt - :type alt_prompt_terminator: str :param username_pattern: Pattern used to identify the username prompt - :type username_pattern: str :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int :param max_loops: Controls the wait time in conjunction with the delay_factor - (default: 20) """ delay_factor = self.select_delay_factor(delay_factor) - # FIX: Cleanup in future versions of Netmiko + # Revert telnet_login back to old speeds/delays if delay_factor < 1: if not self._legacy_mode and self.fast_cli: delay_factor = 1 @@ -772,6 +856,7 @@

    Module netmiko.base_connection

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -791,6 +876,7 @@

    Module netmiko.base_connection

    time.sleep(0.5 * delay_factor) i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -806,10 +892,11 @@

    Module netmiko.base_connection

    return return_msg msg = f"Login failed: {self.host}" + assert self.remote_conn is not None self.remote_conn.close() raise NetmikoAuthenticationException(msg) - def _try_session_preparation(self): + def _try_session_preparation(self) -> None: """ In case of an exception happening during `session_preparation()` Netmiko should gracefully clean-up after itself. This might be challenging for library users @@ -822,7 +909,7 @@

    Module netmiko.base_connection

    self.disconnect() raise - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established @@ -830,31 +917,27 @@

    Module netmiko.base_connection

    early on in the session. In general, it should include: - self._test_channel_read() + self._test_channel_read(pattern=r"some_pattern") self.set_base_prompt() - self.disable_paging() self.set_terminal_width() - self.clear_buffer() + self.disable_paging() """ self._test_channel_read() self.set_base_prompt() self.set_terminal_width() self.disable_paging() - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def _use_ssh_config(self, dict_arg): + def _use_ssh_config(self, dict_arg: Dict[str, Any]) -> Dict[str, Any]: """Update SSH connection parameters based on contents of SSH config file. :param dict_arg: Dictionary of SSH connection parameters - :type dict_arg: dict """ connect_dict = dict_arg.copy() # Use SSHConfig to generate source content. + assert self.ssh_config_file is not None full_path = path.abspath(path.expanduser(self.ssh_config_file)) + source: Union[paramiko.config.SSHConfigDict, Dict[str, Any]] if path.exists(full_path): ssh_config_instance = paramiko.SSHConfig() with io.open(full_path, "rt", encoding="utf-8") as f: @@ -864,6 +947,7 @@

    Module netmiko.base_connection

    source = {} # Keys get normalized to lower-case + proxy: Optional[paramiko.proxy.ProxyCommand] if "proxycommand" in source: proxy = paramiko.ProxyCommand(source["proxycommand"]) elif "proxyjump" in source: @@ -892,7 +976,7 @@

    Module netmiko.base_connection

    return connect_dict - def _connect_params_dict(self): + def _connect_params_dict(self) -> Dict[str, Any]: """Generate dictionary of Paramiko connection parameters.""" conn_dict = { "hostname": self.host, @@ -904,6 +988,7 @@

    Module netmiko.base_connection

    "key_filename": self.key_file, "pkey": self.pkey, "passphrase": self.passphrase, + "disabled_algorithms": self.disabled_algorithms, "timeout": self.conn_timeout, "auth_timeout": self.auth_timeout, "banner_timeout": self.banner_timeout, @@ -916,17 +1001,13 @@

    Module netmiko.base_connection

    return conn_dict def _sanitize_output( - self, output, strip_command=False, command_string=None, strip_prompt=False - ): - """Strip out command echo, trailing router prompt and ANSI escape codes. - - :param output: Output from a remote network device - :type output: unicode string - - :param strip_command: - :type strip_command: - """ - output = self.normalize_linefeeds(output) + self, + output: str, + strip_command: bool = False, + command_string: Optional[str] = None, + strip_prompt: bool = False, + ) -> str: + """Strip out command echo and trailing router prompt.""" if strip_command and command_string: command_string = self.normalize_linefeeds(command_string) output = self.strip_command(command_string, output) @@ -934,7 +1015,7 @@

    Module netmiko.base_connection

    output = self.strip_prompt(output) return output - def establish_connection(self, width=511, height=1000): + def establish_connection(self, width: int = 511, height: int = 1000) -> None: """Establish SSH connection to the network device Timeout will generate a NetmikoTimeoutException @@ -946,16 +1027,21 @@

    Module netmiko.base_connection

    :param height: Specified height of the VT100 terminal window (default: 1000) :type height: int """ + self.channel: Channel if self.protocol == "telnet": self.remote_conn = telnetlib.Telnet( self.host, port=self.port, timeout=self.timeout ) + # Migrating communication to channel class + self.channel = TelnetChannel(conn=self.remote_conn, encoding=self.encoding) self.telnet_login() elif self.protocol == "serial": self.remote_conn = serial.Serial(**self.serial_settings) + self.channel = SerialChannel(conn=self.remote_conn, encoding=self.encoding) self.serial_login() elif self.protocol == "ssh": ssh_connect_params = self._connect_params_dict() + self.remote_conn_pre: Optional[paramiko.SSHClient] self.remote_conn_pre = self._build_ssh_client() # initiate SSH connection @@ -998,16 +1084,22 @@

    Module netmiko.base_connection

    msg += self.RETURN + str(auth_err) raise NetmikoAuthenticationException(msg) - except paramiko.ssh_exception.SSHException as no_session_err: + except paramiko.ssh_exception.SSHException as e: self.paramiko_cleanup() - if "No existing session" in str(no_session_err): + if "No existing session" in str(e): msg = ( "Paramiko: 'No existing session' error: " - "try increasing 'conn_timeout' to 10 seconds or larger." + "try increasing 'conn_timeout' to 15 seconds or larger." ) raise NetmikoTimeoutException(msg) else: - raise + msg = f""" +A paramiko SSHException occurred during connection creation: + +{str(e)} + +""" + raise NetmikoTimeoutException(msg) if self.verbose: print(f"SSH connection established to {self.host}:{self.port}") @@ -1019,24 +1111,29 @@

    Module netmiko.base_connection

    self.remote_conn.settimeout(self.blocking_timeout) if self.keepalive: + assert isinstance(self.remote_conn.transport, paramiko.Transport) self.remote_conn.transport.set_keepalive(self.keepalive) + + # Migrating communication to channel class + self.channel = SSHChannel(conn=self.remote_conn, encoding=self.encoding) + self.special_login_handler() if self.verbose: print("Interactive SSH session established") - return "" - # @m_exec_time - def _test_channel_read(self, count=40, pattern=""): + return None + + def _test_channel_read(self, count: int = 40, pattern: str = "") -> str: """Try to read the channel (generally post login) verify you receive data back. :param count: the number of times to check the channel for data - :type count: int :param pattern: Regular expression pattern used to determine end of channel read - :type pattern: str """ - def _increment_delay(main_delay, increment=1.1, maximum=8): + def _increment_delay( + main_delay: float, increment: float = 1.1, maximum: int = 8 + ) -> float: """Increment sleep time to a maximum value.""" main_delay = main_delay * increment if main_delay >= maximum: @@ -1045,30 +1142,26 @@

    Module netmiko.base_connection

    i = 0 delay_factor = self.select_delay_factor(delay_factor=0) + + if pattern: + return self.read_until_pattern(pattern=pattern, read_timeout=20) + main_delay = delay_factor * 0.1 time.sleep(main_delay * 10) new_data = "" while i <= count: - new_data += self._read_channel_timing() - if new_data and pattern: - if re.search(pattern, new_data): - break - elif new_data: - break - else: - self.write_channel(self.RETURN) + new_data += self.read_channel_timing() + if new_data: + return new_data + self.write_channel(self.RETURN) main_delay = _increment_delay(main_delay) time.sleep(main_delay) i += 1 - # check if data was ever present - if new_data: - return new_data - else: - raise NetmikoTimeoutException("Timed out waiting for data") + raise NetmikoTimeoutException("Timed out waiting for data") - def _build_ssh_client(self): + def _build_ssh_client(self) -> paramiko.SSHClient: """Prepare for Paramiko SSH connection.""" # Create instance of SSHClient object remote_conn_pre = paramiko.SSHClient() @@ -1083,7 +1176,7 @@

    Module netmiko.base_connection

    remote_conn_pre.set_missing_host_key_policy(self.key_policy) return remote_conn_pre - def select_delay_factor(self, delay_factor): + def select_delay_factor(self, delay_factor: float) -> float: """ Choose the greater of delay_factor or self.global_delay_factor (default). In fast_cli choose the lesser of delay_factor of self.global_delay_factor. @@ -1102,31 +1195,37 @@

    Module netmiko.base_connection

    else: return self.global_delay_factor - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """Handler for devices like WLC, Extreme ERS that throw up characters prior to login.""" pass def disable_paging( - self, command="terminal length 0", delay_factor=1, cmd_verify=True, pattern=None - ): + self, + command: str = "terminal length 0", + delay_factor: Optional[float] = None, + cmd_verify: bool = True, + pattern: Optional[str] = None, + ) -> str: """Disable paging default to a Cisco CLI method. :param command: Device command to disable pagination of output - :type command: str - :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + command = self.normalize_cmd(command) log.debug("In disable_paging") log.debug(f"Command: {command}") self.write_channel(command) # Make sure you read until you detect the command echo (avoid getting out of sync) if cmd_verify and self.global_cmd_verify is not False: - output = self.read_until_pattern(pattern=re.escape(command.strip())) + output = self.read_until_pattern( + pattern=re.escape(command.strip()), read_timeout=20 + ) elif pattern: - output = self.read_until_pattern(pattern=pattern) + output = self.read_until_pattern(pattern=pattern, read_timeout=20) else: output = self.read_until_prompt() log.debug(f"{output}") @@ -1134,24 +1233,29 @@

    Module netmiko.base_connection

    return output def set_terminal_width( - self, command="", delay_factor=1, cmd_verify=False, pattern=None - ): + self, + command: str = "", + delay_factor: Optional[float] = None, + cmd_verify: bool = False, + pattern: Optional[str] = None, + ) -> str: """CLI terminals try to automatically adjust the line based on the width of the terminal. This causes the output to get distorted when accessed programmatically. Set terminal width to 511 which works on a broad set of devices. :param command: Command string to send to the device - :type command: str - :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + if not command: return "" - delay_factor = self.select_delay_factor(delay_factor) command = self.normalize_cmd(command) self.write_channel(command) + # Avoid cmd_verify here as terminal width must be set before doing cmd_verify if cmd_verify and self.global_cmd_verify is not False: output = self.read_until_pattern(pattern=re.escape(command.strip())) @@ -1168,8 +1272,12 @@

    Module netmiko.base_connection

    reraise=True, ) def set_base_prompt( - self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 - ): + self, + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt Used as delimiter for stripping of trailing prompt in output. @@ -1181,206 +1289,216 @@

    Module netmiko.base_connection

    entering/exiting config mode. :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt - :type pri_prompt_terminator: str :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt - :type alt_prompt_terminator: str :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + + :param pattern: Regular expression pattern to search for in find_prompt() call """ - prompt = self.find_prompt(delay_factor=delay_factor) + if pattern is None: + if pri_prompt_terminator and alt_prompt_terminator: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + pattern = rf"({pri_term}|{alt_term})" + elif pri_prompt_terminator: + pattern = re.escape(pri_prompt_terminator) + elif alt_prompt_terminator: + pattern = re.escape(alt_prompt_terminator) + + if pattern: + prompt = self.find_prompt(delay_factor=delay_factor, pattern=pattern) + else: + prompt = self.find_prompt(delay_factor=delay_factor) + if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): raise ValueError(f"Router prompt not found: {repr(prompt)}") # Strip off trailing terminator self.base_prompt = prompt[:-1] return self.base_prompt - def find_prompt(self, delay_factor=1): + def find_prompt( + self, delay_factor: float = 1.0, pattern: Optional[str] = None + ) -> str: """Finds the current network device prompt, last line only. :param delay_factor: See __init__: global_delay_factor :type delay_factor: int + + :param pattern: Regular expression pattern to determine whether prompt is valid """ delay_factor = self.select_delay_factor(delay_factor) + sleep_time = delay_factor * 0.25 self.clear_buffer() self.write_channel(self.RETURN) - sleep_time = delay_factor * 0.1 - time.sleep(sleep_time) - - # Initial attempt to get prompt - prompt = self.read_channel().strip() - # Check if the only thing you received was a newline - count = 0 - while count <= 12 and not prompt: + if pattern: + try: + prompt = self.read_until_pattern(pattern=pattern) + except ReadTimeout: + pass + else: + # Initial read + time.sleep(sleep_time) prompt = self.read_channel().strip() - if not prompt: - self.write_channel(self.RETURN) - time.sleep(sleep_time) - if sleep_time <= 3: - # Double the sleep_time when it is small - sleep_time *= 2 - else: - sleep_time += 1 - count += 1 + + count = 0 + while count <= 12 and not prompt: + if not prompt: + self.write_channel(self.RETURN) + time.sleep(sleep_time) + prompt = self.read_channel().strip() + if sleep_time <= 3: + # Double the sleep_time when it is small + sleep_time *= 2 + else: + sleep_time += 1 + count += 1 # If multiple lines in the output take the last line - prompt = self.normalize_linefeeds(prompt) prompt = prompt.split(self.RESPONSE_RETURN)[-1] prompt = prompt.strip() + self.clear_buffer() if not prompt: raise ValueError(f"Unable to find prompt: {prompt}") - time.sleep(delay_factor * 0.1) - self.clear_buffer() log.debug(f"[find_prompt()]: prompt is {prompt}") return prompt - def clear_buffer(self, backoff=True): + def clear_buffer( + self, + backoff: bool = True, + backoff_max: float = 3.0, + delay_factor: Optional[float] = None, + ) -> str: """Read any data available in the channel.""" - sleep_time = 0.1 * self.global_delay_factor + + if delay_factor is None: + delay_factor = self.global_delay_factor + sleep_time = 0.1 * delay_factor + + output = "" for _ in range(10): time.sleep(sleep_time) data = self.read_channel() + data = self.strip_ansi_escape_codes(data) + output += data if not data: break # Double sleep time each time we detect data log.debug("Clear buffer detects data in the channel") if backoff: sleep_time *= 2 - sleep_time = 3 if sleep_time >= 3 else sleep_time + sleep_time = backoff_max if sleep_time >= backoff_max else sleep_time + return output + + def command_echo_read(self, cmd: str, read_timeout: float) -> str: + + # Make sure you read until you detect the command echo (avoid getting out of sync) + new_data = self.read_until_pattern( + pattern=re.escape(cmd), read_timeout=read_timeout + ) + + # There can be echoed prompts that haven't been cleared before the cmd echo + # this can later mess up the trailing prompt pattern detection. Clear this out. + lines = new_data.split(cmd) + if len(lines) == 2: + # lines[-1] should realistically just be the null string + new_data = f"{cmd}{lines[-1]}" + else: + # cmd exists in the output multiple times? Just retain the original output + pass + return new_data @select_cmd_verify def send_command_timing( self, - command_string, - delay_factor=1, - max_loops=150, - strip_prompt=True, - strip_command=True, - normalize=True, - use_textfsm=False, - textfsm_template=None, - use_ttp=False, - ttp_template=None, - use_genie=False, - cmd_verify=False, - cmd_echo=None, - ): + command_string: str, + last_read: float = 2.0, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + strip_prompt: bool = True, + strip_command: bool = True, + normalize: bool = True, + use_textfsm: bool = False, + textfsm_template: Optional[str] = None, + use_ttp: bool = False, + ttp_template: Optional[str] = None, + use_genie: bool = False, + cmd_verify: bool = False, + ) -> Union[str, List[Any], Dict[str, Any]]: """Execute command_string on the SSH channel using a delay-based mechanism. Generally used for show commands. :param command_string: The command to be executed on the remote device. - :type command_string: str - :param delay_factor: Multiplying factor used to adjust delays (default: 1). - :type delay_factor: int or float + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be - based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Remove the trailing router prompt from the output (default: True). - :type strip_prompt: bool :param strip_command: Remove the echo of the command from the output (default: True). - :type strip_command: bool :param normalize: Ensure the proper enter is sent at end of command (default: True). - :type normalize: bool :param use_textfsm: Process command output through TextFSM template (default: False). - :type use_textfsm: bool :param textfsm_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type textfsm_template: str :param use_ttp: Process command output through TTP template (default: False). - :type use_ttp: bool :param ttp_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type ttp_template: str :param use_genie: Process command output through PyATS/Genie parser (default: False). - :type use_genie: bool :param cmd_verify: Verify command echo before proceeding (default: False). - :type cmd_verify: bool - - :param cmd_echo: Deprecated (use cmd_verify instead) - :type cmd_echo: bool """ - - # For compatibility; remove cmd_echo in Netmiko 4.x.x - if cmd_echo is not None: - cmd_verify = cmd_echo + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) output = "" - delay_factor = self.select_delay_factor(delay_factor) - + new_data = "" if normalize: command_string = self.normalize_cmd(command_string) self.write_channel(command_string) cmd = command_string.strip() - # if cmd is just an "enter" skip this section if cmd and cmd_verify: - # Make sure you read until you detect the command echo (avoid getting out of sync) - new_data = self.read_until_pattern(pattern=re.escape(cmd)) - new_data = self.normalize_linefeeds(new_data) - - # Strip off everything before the command echo - if new_data.count(cmd) == 1: - new_data = new_data.split(cmd)[1:] - new_data = self.RESPONSE_RETURN.join(new_data) - new_data = new_data.lstrip() - output = f"{cmd}{self.RESPONSE_RETURN}{new_data}" - else: - # cmd is in the actual output (not just echoed) - output = new_data - - log.debug(f"send_command_timing current output: {output}") - - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops + new_data = self.command_echo_read(cmd=cmd, read_timeout=10) + output += new_data + output += self.read_channel_timing( + last_read=last_read, read_timeout=read_timeout ) + output = self._sanitize_output( output, strip_command=strip_command, command_string=command_string, strip_prompt=strip_prompt, ) + return_data = structured_data_converter( + command=command_string, + raw_data=output, + platform=self.device_type, + use_textfsm=use_textfsm, + use_ttp=use_ttp, + use_genie=use_genie, + textfsm_template=textfsm_template, + ttp_template=ttp_template, + ) + return return_data - # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie - if use_textfsm: - structured_output = get_structured_data( - output, - platform=self.device_type, - command=command_string.strip(), - template=textfsm_template, - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_ttp: - structured_output = get_structured_data_ttp(output, template=ttp_template) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_genie: - structured_output = get_structured_data_genie( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - - log.debug(f"send_command_timing final output: {output}") + def _send_command_timing_str(self, *args: Any, **kwargs: Any) -> str: + """Wrapper for `send_command_timing` method that always returns a + string""" + output = self.send_command_timing(*args, **kwargs) + assert isinstance(output, str) return output - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output. :param a_string: Returned string from device @@ -1388,12 +1506,13 @@

    Module netmiko.base_connection

    """ response_list = a_string.split(self.RESPONSE_RETURN) last_line = response_list[-1] + if self.base_prompt in last_line: return self.RESPONSE_RETURN.join(response_list[:-1]) else: return a_string - def _first_line_handler(self, data, search_pattern): + def _first_line_handler(self, data: str, search_pattern: str) -> Tuple[str, bool]: """ In certain situations the first line will get repainted which causes a false match on the terminating pattern. @@ -1420,126 +1539,151 @@

    Module netmiko.base_connection

    except IndexError: return (data, False) + def _prompt_handler(self, auto_find_prompt: bool) -> str: + if auto_find_prompt: + try: + prompt = self.find_prompt() + except ValueError: + prompt = self.base_prompt + else: + prompt = self.base_prompt + return re.escape(prompt.strip()) + @select_cmd_verify def send_command( self, - command_string, - expect_string=None, - delay_factor=1, - max_loops=500, - auto_find_prompt=True, - strip_prompt=True, - strip_command=True, - normalize=True, - use_textfsm=False, - textfsm_template=None, - use_ttp=False, - ttp_template=None, - use_genie=False, - cmd_verify=True, - ): + command_string: str, + expect_string: Optional[str] = None, + read_timeout: float = 10.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + auto_find_prompt: bool = True, + strip_prompt: bool = True, + strip_command: bool = True, + normalize: bool = True, + use_textfsm: bool = False, + textfsm_template: Optional[str] = None, + use_ttp: bool = False, + ttp_template: Optional[str] = None, + use_genie: bool = False, + cmd_verify: bool = True, + ) -> Union[str, List[Any], Dict[str, Any]]: """Execute command_string on the SSH channel using a pattern-based mechanism. Generally used for show commands. By default this method will keep waiting to receive data until the network device prompt is detected. The current network device prompt will be determined automatically. :param command_string: The command to be executed on the remote device. - :type command_string: str :param expect_string: Regular expression pattern to use for determining end of output. If left blank will default to being based on router prompt. - :type expect_string: str - :param delay_factor: Multiplying factor used to adjust delays (default: 1). - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be - based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Remove the trailing router prompt from the output (default: True). - :type strip_prompt: bool :param strip_command: Remove the echo of the command from the output (default: True). - :type strip_command: bool :param normalize: Ensure the proper enter is sent at end of command (default: True). - :type normalize: bool :param use_textfsm: Process command output through TextFSM template (default: False). - :type normalize: bool :param textfsm_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). :param use_ttp: Process command output through TTP template (default: False). - :type use_ttp: bool :param ttp_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type ttp_template: str :param use_genie: Process command output through PyATS/Genie parser (default: False). - :type normalize: bool :param cmd_verify: Verify command echo before proceeding (default: True). - :type cmd_verify: bool """ # Time to delay in each read loop - loop_delay = 0.2 + loop_delay = 0.025 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # and delay_factor arguments for backwards compatibility). - delay_factor = self.select_delay_factor(delay_factor) - if delay_factor == 1 and max_loops == 500: - # Default arguments are being used; use self.timeout instead - max_loops = int(self.timeout / loop_delay) - - # Find the current router prompt - if expect_string is None: - if auto_find_prompt: - try: - prompt = self.find_prompt(delay_factor=delay_factor) - except ValueError: - prompt = self.base_prompt + if self.read_timeout_override: + read_timeout = self.read_timeout_override + + if self.delay_factor_compat: + # For compatibility calculate the old equivalent read_timeout + # i.e. what it would have been in Netmiko 3.x + if delay_factor is None: + tmp_delay_factor = self.global_delay_factor else: - prompt = self.base_prompt - search_pattern = re.escape(prompt.strip()) + tmp_delay_factor = self.select_delay_factor(delay_factor) + compat_timeout = calc_old_timeout( + max_loops=max_loops, + delay_factor=tmp_delay_factor, + loop_delay=0.2, + old_timeout=self.timeout, + ) + msg = f"""\n +You have chosen to use Netmiko's delay_factor compatibility mode for +send_command. This will revert Netmiko to behave similarly to how it +did in Netmiko 3.x (i.e. to use delay_factor/global_delay_factor and +max_loops). + +Using these parameters Netmiko has calculated an effective read_timeout +of {compat_timeout} and will set the read_timeout to this value. + +Please convert your code to that new format i.e.: + + net_connect.send_command(cmd, read_timeout={compat_timeout}) + +And then disable delay_factor_compat. + +delay_factor_compat will be removed in Netmiko 5.x.\n""" + warnings.warn(msg, DeprecationWarning) + + # Override the read_timeout with Netmiko 3.x way :-( + read_timeout = compat_timeout + else: + # No need for two deprecation messages so only display this if not using + # delay_factor_compat + if delay_factor is not None or max_loops is not None: + msg = """\n +Netmiko 4.x has deprecated the use of delay_factor/max_loops with +send_command. You should convert all uses of delay_factor and max_loops +over to read_timeout=x where x is the total number of seconds to wait +before timing out.\n""" + warnings.warn(msg, DeprecationWarning) + + if expect_string is not None: search_pattern = expect_string + else: + search_pattern = self._prompt_handler(auto_find_prompt) if normalize: command_string = self.normalize_cmd(command_string) - time.sleep(delay_factor * loop_delay) - self.clear_buffer() + # Start the clock + start_time = time.time() self.write_channel(command_string) new_data = "" cmd = command_string.strip() - # if cmd is just an "enter" skip this section if cmd and cmd_verify: - # Make sure you read until you detect the command echo (avoid getting out of sync) - new_data = self.read_until_pattern(pattern=re.escape(cmd)) - new_data = self.normalize_linefeeds(new_data) - # Strip off everything before the command echo (to avoid false positives on the prompt) - if new_data.count(cmd) == 1: - new_data = new_data.split(cmd)[1:] - new_data = self.RESPONSE_RETURN.join(new_data) - new_data = new_data.lstrip() - new_data = f"{cmd}{self.RESPONSE_RETURN}{new_data}" + new_data = self.command_echo_read(cmd=cmd, read_timeout=10) - i = 1 + MAX_CHARS = 2_000_000 + DEQUE_SIZE = 20 output = "" - past_three_reads = deque(maxlen=3) + # Check only the past N-reads. This is for the case where the output is + # very large (i.e. searching a very large string for a pattern a whole bunch of times) + past_n_reads: Deque[str] = deque(maxlen=DEQUE_SIZE) first_line_processed = False - # Keep reading data until search_pattern is found or until max_loops is reached. - while i <= max_loops: + # Keep reading data until search_pattern is found or until read_timeout + while time.time() - start_time < read_timeout: if new_data: output += new_data - past_three_reads.append(new_data) + past_n_reads.append(new_data) # Case where we haven't processed the first_line yet (there is a potential issue # in the first line (in cases where the line is repainted). @@ -1552,19 +1696,30 @@

    Module netmiko.base_connection

    break else: - # Check if pattern is in the past three reads - if re.search(search_pattern, "".join(past_three_reads)): - break - - time.sleep(delay_factor * loop_delay) - i += 1 + if len(output) <= MAX_CHARS: + if re.search(search_pattern, output): + break + else: + # Switch to deque mode if output is greater than MAX_CHARS + # Check if pattern is in the past n reads + if re.search(search_pattern, "".join(past_n_reads)): + break + + time.sleep(loop_delay) new_data = self.read_channel() + else: # nobreak - raise IOError( - "Search pattern never detected in send_command: {}".format( - search_pattern - ) - ) + msg = f""" +Pattern not detected: {repr(search_pattern)} in output. + +Things you might try to fix this: +1. Explicitly set your pattern using the expect_string argument. +2. Increase the read_timeout to a larger value. + +You can also look at the Netmiko session_log or debug log for more information. + +""" + raise ReadTimeout(msg) output = self._sanitize_output( output, @@ -1572,45 +1727,98 @@

    Module netmiko.base_connection

    command_string=command_string, strip_prompt=strip_prompt, ) + return_val = structured_data_converter( + command=command_string, + raw_data=output, + platform=self.device_type, + use_textfsm=use_textfsm, + use_ttp=use_ttp, + use_genie=use_genie, + textfsm_template=textfsm_template, + ttp_template=ttp_template, + ) + return return_val - # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie - if use_textfsm: - structured_output = get_structured_data( - output, - platform=self.device_type, - command=command_string.strip(), - template=textfsm_template, - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_ttp: - structured_output = get_structured_data_ttp(output, template=ttp_template) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_genie: - structured_output = get_structured_data_genie( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output + def _send_command_str(self, *args: Any, **kwargs: Any) -> str: + """Wrapper for `send_command` method that always returns a string""" + output = self.send_command(*args, **kwargs) + assert isinstance(output, str) return output - def send_command_expect(self, *args, **kwargs): - """Support previous name of send_command method. + def send_command_expect( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: + """Support previous name of send_command method.""" + return self.send_command(*args, **kwargs) - :param args: Positional arguments to send to send_command() - :type args: list + def _multiline_kwargs(self, **kwargs: Any) -> Dict[str, Any]: + strip_prompt = kwargs.get("strip_prompt", False) + kwargs["strip_prompt"] = strip_prompt + strip_command = kwargs.get("strip_command", False) + kwargs["strip_command"] = strip_command + return kwargs - :param kwargs: Keyword arguments to send to send_command() - :type kwargs: dict + def send_multiline( + self, + commands: Sequence[Union[str, List[str]]], + multiline: bool = True, + **kwargs: Any, + ) -> str: """ - return self.send_command(*args, **kwargs) + commands should either be: + + commands = [[cmd1, expect1], [cmd2, expect2], ...]] + + Or + + commands = [cmd1, cmd2, cmd3, ...] + + Any expect_string that is a null-string will use pattern based on + device's prompt (unless expect_string argument is passed in via + kwargs. + + """ + output = "" + if multiline: + kwargs = self._multiline_kwargs(**kwargs) + + default_expect_string = kwargs.pop("expect_string", None) + if not default_expect_string: + auto_find_prompt = kwargs.get("auto_find_prompt", True) + default_expect_string = self._prompt_handler(auto_find_prompt) + + if commands and isinstance(commands[0], str): + # If list of commands just send directly using default_expect_string (probably prompt) + for cmd in commands: + cmd = str(cmd) + output += self._send_command_str( + cmd, expect_string=default_expect_string, **kwargs + ) + else: + # If list of lists, then first element is cmd and second element is expect_string + for cmd_item in commands: + assert not isinstance(cmd_item, str) + cmd, expect_string = cmd_item + if not expect_string: + expect_string = default_expect_string + output += self._send_command_str( + cmd, expect_string=expect_string, **kwargs + ) + return output + + def send_multiline_timing( + self, commands: Sequence[str], multiline: bool = True, **kwargs: Any + ) -> str: + if multiline: + kwargs = self._multiline_kwargs(**kwargs) + output = "" + for cmd in commands: + cmd = str(cmd) + output += self._send_command_timing_str(cmd, **kwargs) + return output @staticmethod - def strip_backspaces(output): + def strip_backspaces(output: str) -> str: """Strip any backspace characters out of the output. :param output: Output obtained from a remote network device. @@ -1619,7 +1827,7 @@

    Module netmiko.base_connection

    backspace_char = "\x08" return output.replace(backspace_char, "") - def strip_command(self, command_string, output): + def strip_command(self, command_string: str, output: str) -> str: """ Strip command_string from output string @@ -1648,7 +1856,7 @@

    Module netmiko.base_connection

    # command_string isn't there; do nothing return output - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Convert `\r\r\n`,`\r\n`, `\n\r` to `\n.` :param a_string: A string that may have non-normalized line feeds @@ -1663,7 +1871,7 @@

    Module netmiko.base_connection

    else: return a_string - def normalize_cmd(self, command): + def normalize_cmd(self, command: str) -> str: """Normalize CLI commands to have a single trailing newline. :param command: Command that may require line feed to be normalized @@ -1673,32 +1881,32 @@

    Module netmiko.base_connection

    command += self.RETURN return command - def check_enable_mode(self, check_string=""): + def check_enable_mode(self, check_string: str = "") -> bool: """Check if in enable mode. Return boolean. :param check_string: Identification of privilege mode from device :type check_string: str """ self.write_channel(self.RETURN) - output = self.read_until_prompt() + output = self.read_until_prompt(read_entire_line=True) return check_string in output def enable( - self, cmd="", pattern="ssword", enable_pattern=None, re_flags=re.IGNORECASE - ): + self, + cmd: str = "", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode. :param cmd: Device command to enter enable mode - :type cmd: str :param pattern: pattern to search for indicating device is waiting for password - :type pattern: str :param enable_pattern: pattern indicating you have entered enable mode - :type pattern: str :param re_flags: Regular expression flags used in conjunction with pattern - :type re_flags: int """ output = "" msg = ( @@ -1737,7 +1945,7 @@

    Module netmiko.base_connection

    raise ValueError(msg) return output - def exit_enable_mode(self, exit_command=""): + def exit_enable_mode(self, exit_command: str = "") -> str: """Exit enable mode. :param exit_command: Command that exits the session from privileged mode @@ -1751,7 +1959,7 @@

    Module netmiko.base_connection

    raise ValueError("Failed to exit enable mode.") return output - def check_config_mode(self, check_string="", pattern=""): + def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not. :param check_string: Identification of configuration mode from the device @@ -1763,12 +1971,14 @@

    Module netmiko.base_connection

    self.write_channel(self.RETURN) # You can encounter an issue here (on router name changes) prefer delay-based solution if not pattern: - output = self._read_channel_timing() + output = self.read_channel_timing() else: output = self.read_until_pattern(pattern=pattern) return check_string in output - def config_mode(self, config_command="", pattern="", re_flags=0): + def config_mode( + self, config_command: str = "", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter into config_mode. :param config_command: Configuration command to send to the device @@ -1788,13 +1998,15 @@

    Module netmiko.base_connection

    output += self.read_until_pattern( pattern=re.escape(config_command.strip()) ) - if not re.search(pattern, output, flags=re_flags): + if pattern: output += self.read_until_pattern(pattern=pattern, re_flags=re_flags) + else: + output += self.read_until_prompt(read_entire_line=True) if not self.check_config_mode(): raise ValueError("Failed to enter configuration mode.") return output - def exit_config_mode(self, exit_config="", pattern=""): + def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str: """Exit from configuration mode. :param exit_config: Command to exit configuration mode @@ -1811,14 +2023,18 @@

    Module netmiko.base_connection

    output += self.read_until_pattern( pattern=re.escape(exit_config.strip()) ) - if not re.search(pattern, output, flags=re.M): + if pattern: output += self.read_until_pattern(pattern=pattern) + else: + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") log.debug(f"exit_config_mode: {output}") return output - def send_config_from_file(self, config_file=None, **kwargs): + def send_config_from_file( + self, config_file: Union[str, bytes, "PathLike[Any]"], **kwargs: Any + ) -> str: """ Send configuration commands down the SSH channel from a file. @@ -1828,27 +2044,30 @@

    Module netmiko.base_connection

    **kwargs are passed to send_config_set method. :param config_file: Path to configuration file to be sent to the device - :type config_file: str :param kwargs: params to be sent to send_config_set method - :type kwargs: dict """ with io.open(config_file, "rt", encoding="utf-8") as cfg_file: - return self.send_config_set(cfg_file, **kwargs) + commands = cfg_file.readlines() + return self.send_config_set(commands, **kwargs) def send_config_set( self, - config_commands=None, - exit_config_mode=True, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - cmd_verify=True, - enter_config_mode=True, - error_pattern="", - ): + config_commands: Union[str, Sequence[str], TextIO, None] = None, + *, + exit_config_mode: bool = True, + read_timeout: Optional[float] = None, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + strip_prompt: bool = False, + strip_command: bool = False, + config_mode_command: Optional[str] = None, + cmd_verify: bool = True, + enter_config_mode: bool = True, + error_pattern: str = "", + terminator: str = r"#", + bypass_commands: Optional[str] = None, + ) -> str: """ Send configuration commands down the SSH channel. @@ -1858,37 +2077,64 @@

    Module netmiko.base_connection

    Automatically exits/enters configuration mode. :param config_commands: Multiple configuration commands to be sent to the device - :type config_commands: list or string :param exit_config_mode: Determines whether or not to exit config mode after complete - :type exit_config_mode: bool - :param delay_factor: Factor to adjust delays - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor (default: 150) - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Determines whether or not to strip the prompt - :type strip_prompt: bool :param strip_command: Determines whether or not to strip the command - :type strip_command: bool + + :param read_timeout: Absolute timer to send to read_channel_timing. Should be rarely needed. :param config_mode_command: The command to enter into config mode - :type config_mode_command: str :param cmd_verify: Whether or not to verify command echo for each command in config_set - :type cmd_verify: bool :param enter_config_mode: Do you enter config mode before sending config commands - :type exit_config_mode: bool :param error_pattern: Regular expression pattern to detect config errors in the output. - :type error_pattern: str + + :param terminator: Regular expression pattern to use as an alternate terminator in certain + situations. + + :param bypass_commands: Regular expression pattern indicating configuration commands + where cmd_verify is automatically disabled. """ - delay_factor = self.select_delay_factor(delay_factor) + + if self.global_cmd_verify is not None: + cmd_verify = self.global_cmd_verify + + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + + # Calculate an equivalent read_timeout (if using old settings) + # Eliminate in Netmiko 5.x + if read_timeout is None: + max_loops = 150 if max_loops is None else max_loops + delay_factor = 1.0 if delay_factor is None else delay_factor + + # If delay_factor has been set, then look at global_delay_factor + delay_factor = self.select_delay_factor(delay_factor) + + read_timeout = calc_old_timeout( + max_loops=max_loops, delay_factor=delay_factor, loop_delay=0.1 + ) + + if delay_factor is None: + delay_factor = self.select_delay_factor(0) + else: + delay_factor = self.select_delay_factor(delay_factor) + + if read_timeout is None: + read_timeout = 15 + else: + read_timeout = read_timeout + if config_commands is None: return "" elif isinstance(config_commands, str): @@ -1897,20 +2143,33 @@

    Module netmiko.base_connection

    if not hasattr(config_commands, "__iter__"): raise ValueError("Invalid argument passed into send_config_set") + if bypass_commands is None: + # Commands where cmd_verify is automatically disabled reg-ex logical-or + bypass_commands = r"^banner .*$" + + # Set bypass_commands="" to force no-bypass (usually for testing) + bypass_detected = False + if bypass_commands: + bypass_detected = any( + [True for cmd in config_commands if re.search(bypass_commands, cmd)] + ) + if bypass_detected: + cmd_verify = False + # Send config commands output = "" if enter_config_mode: - cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() - output += self.config_mode(*cfg_mode_args) + if config_mode_command: + output += self.config_mode(config_mode_command) + else: + output += self.config_mode() - # If error_pattern is perform output gathering line by line and not fast_cli mode. + # Perform output gathering line-by-line (legacy way) if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) elif not cmd_verify: for cmd in config_commands: @@ -1919,35 +2178,25 @@

    Module netmiko.base_connection

    # Gather the output incrementally due to error_pattern requirements if error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) if re.search(error_pattern, output, flags=re.M): msg = f"Invalid input detected at command: {cmd}" raise ConfigInvalidException(msg) # Standard output gathering (no error_pattern) if not error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Make sure command is echoed - new_output = self.read_until_pattern(pattern=re.escape(cmd.strip())) - output += new_output - - # We might capture next prompt in the original read - pattern = f"(?:{re.escape(self.base_prompt)}|#)" - if not re.search(pattern, new_output): - # Make sure trailing prompt comes back (after command) - # NX-OS has fast-buffering problem where it immediately echoes command - # Even though the device hasn't caught up with processing command. - new_output = self.read_until_pattern(pattern=pattern) - output += new_output + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + + # Read until next prompt or terminator (#); the .*$ forces read of entire line + pattern = f"(?:{re.escape(self.base_prompt)}.*$|{terminator}.*$)" + output += self.read_until_pattern(pattern=pattern, re_flags=re.M) if error_pattern: if re.search(error_pattern, output, flags=re.M): @@ -1960,7 +2209,7 @@

    Module netmiko.base_connection

    log.debug(f"{output}") return output - def strip_ansi_escape_codes(self, string_buffer): + def strip_ansi_escape_codes(self, string_buffer: str) -> str: """ Remove any ANSI (VT100) ESC codes from the output @@ -1981,10 +2230,11 @@

    Module netmiko.base_connection

    ESC[?6l Reset mode screen with options 640 x 200 monochrome (graphics) ESC[?7l Disable line wrapping ESC[2J Code erase display - ESC[00;32m Color Green (30 to 37 are different colors) more general pattern is - ESC[\d\d;\d\dm and ESC[\d\d;\d\d;\d\dm + ESC[00;32m Color Green (30 to 37 are different colors) ESC[6n Get cursor position ESC[1D Move cursor position leftward by x characters (1 in this case) + ESC[9999B Move cursor down N-lines (very large value is attempt to move to the + very bottom of the screen). HP ProCurve and Cisco SG300 require this (possible others). @@ -2006,7 +2256,8 @@

    Module netmiko.base_connection

    code_reset_graphics_mode = chr(27) + r"\[00m" code_erase_display = chr(27) + r"\[2J" code_erase_display_0 = chr(27) + r"\[J" - code_graphics_mode = chr(27) + r"\[\d\d;\d\dm" + code_graphics_mode = chr(27) + r"\[\dm" + code_graphics_mode1 = chr(27) + r"\[\d\d;\d\dm" code_graphics_mode2 = chr(27) + r"\[\d\d;\d\d;\d\dm" code_graphics_mode3 = chr(27) + r"\[(3|4)\dm" code_graphics_mode4 = chr(27) + r"\[(9|10)[0-7]m" @@ -2015,6 +2266,11 @@

    Module netmiko.base_connection

    code_attrs_off = chr(27) + r"\[0m" code_reverse = chr(27) + r"\[7m" code_cursor_left = chr(27) + r"\[\d+D" + code_cursor_forward = chr(27) + r"\[\d*C" + code_cursor_up = chr(27) + r"\[\d*A" + code_cursor_down = chr(27) + r"\[\d*B" + code_wrap_around = chr(27) + r"\[\?7h" + code_bracketed_paste_mode = chr(27) + r"\[\?2004h" code_set = [ code_position_cursor, @@ -2029,6 +2285,7 @@

    Module netmiko.base_connection

    code_reset_graphics_mode, code_erase_display, code_graphics_mode, + code_graphics_mode1, code_graphics_mode2, code_graphics_mode3, code_graphics_mode4, @@ -2039,6 +2296,11 @@

    Module netmiko.base_connection

    code_attrs_off, code_reverse, code_cursor_left, + code_cursor_up, + code_cursor_down, + code_cursor_forward, + code_wrap_around, + code_bracketed_paste_mode, ] output = string_buffer @@ -2057,24 +2319,27 @@

    Module netmiko.base_connection

    return output - def cleanup(self, command=""): + def cleanup(self, command: str = "") -> None: """Logout of the session on the network device plus any additional cleanup.""" pass - def paramiko_cleanup(self): + def paramiko_cleanup(self) -> None: """Cleanup Paramiko to try to gracefully handle SSH session ending.""" - self.remote_conn_pre.close() + if self.remote_conn_pre is not None: + self.remote_conn_pre.close() del self.remote_conn_pre - def disconnect(self): + def disconnect(self) -> None: """Try to gracefully close the session.""" try: self.cleanup() if self.protocol == "ssh": self.paramiko_cleanup() elif self.protocol == "telnet": + assert isinstance(self.remote_conn, telnetlib.Telnet) self.remote_conn.close() elif self.protocol == "serial": + assert isinstance(self.remote_conn, serial.Serial) self.remote_conn.close() except Exception: # There have been race conditions observed on disconnect. @@ -2082,31 +2347,25 @@

    Module netmiko.base_connection

    finally: self.remote_conn_pre = None self.remote_conn = None - self.close_session_log() + if self.session_log: + self.session_log.close() - def commit(self): + def commit(self) -> str: """Commit method for platforms that support this.""" raise AttributeError("Network device does not support 'commit()' method") - def save_config(self, *args, **kwargs): + def save_config( + self, cmd: str = "", confirm: bool = False, confirm_response: str = "" + ) -> str: """Not Implemented""" raise NotImplementedError - def open_session_log(self, filename, mode="write"): - """Open the session_log file.""" - if mode == "append": - self.session_log = open(filename, mode="a", encoding=self.encoding) - else: - self.session_log = open(filename, mode="w", encoding=self.encoding) - self._session_log_close = True - - def close_session_log(self): - """Close the session_log file (if it is a file that we opened).""" - if self.session_log is not None and self._session_log_close: - self.session_log.close() - self.session_log = None - - def run_ttp(self, template, res_kwargs={}, **kwargs): + def run_ttp( + self, + template: Union[str, bytes, "PathLike[Any]"], + res_kwargs: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> Any: """ Run TTP template parsing by using input parameters to collect devices output. @@ -2114,29 +2373,25 @@

    Module netmiko.base_connection

    :param template: template content, OS path to template or reference to template within TTP templates collection in ttp://path/to/template.txt format - :type template: str :param res_kwargs: ``**res_kwargs`` arguments to pass to TTP result method - :type res_kwargs: dict :param kwargs: any other ``**kwargs`` to use for TTP object instantiation - :type kwargs: dict TTP template must have inputs defined together with below parameters. :param method: name of Netmiko connection object method to call, default ``send_command`` - :type method: str :param kwargs: Netmiko connection object method arguments - :type kwargs: dict :param commands: list of commands to collect - :type commands: list Inputs' load could be of one of the supported formats and controlled by input's ``load`` attribute, supported values - python, yaml or json. For each input output collected from device and parsed accordingly. """ + if res_kwargs is None: + res_kwargs = {} return run_ttp_template( connection=self, template=template, res_kwargs=res_kwargs, **kwargs ) @@ -2151,13 +2406,67 @@

    Module netmiko.base_connection

    +

    Functions

    +
    +
    +def lock_channel(func) +
    +
    +
    +
    +Source code +
    def lock_channel(func: F) -> F:
    +    @functools.wraps(func)
    +    def wrapper_decorator(self: "BaseConnection", *args: Any, **kwargs: Any) -> Any:
    +        self._lock_netmiko_session()
    +        try:
    +            return_val = func(self, *args, **kwargs)
    +        finally:
    +            # Always unlock the channel, even on exception.
    +            self._unlock_netmiko_session()
    +        return return_val
    +
    +    return cast(F, wrapper_decorator)
    +
    +
    +
    +def log_writes(func) +
    +
    +

    Handle both session_log and log of writes.

    +
    +Source code +
    def log_writes(func: F) -> F:
    +    """Handle both session_log and log of writes."""
    +
    +    @functools.wraps(func)
    +    def wrapper_decorator(self: "BaseConnection", out_data: str) -> None:
    +        func(self, out_data)
    +        try:
    +            log.debug(
    +                "write_channel: {}".format(
    +                    str(write_bytes(out_data, encoding=self.encoding))
    +                )
    +            )
    +            if self.session_log:
    +                if self.session_log.fin or self.session_log.record_writes:
    +                    self.session_log.write(out_data)
    +        except UnicodeDecodeError:
    +            # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2)
    +            pass
    +        return None
    +
    +    return cast(F, wrapper_decorator)
    +
    +
    +

    Classes

    class BaseConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Defines vendor independent methods.

    @@ -2166,135 +2475,108 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class BaseConnection(object):
    +
    class BaseConnection:
         """
         Defines vendor independent methods.
     
    @@ -2303,183 +2585,165 @@ 

    Classes

    def __init__( self, - ip="", - host="", - username="", - password=None, - secret="", - port=None, - device_type="", - verbose=False, - global_delay_factor=1, - global_cmd_verify=None, - use_keys=False, - key_file=None, - pkey=None, - passphrase=None, - allow_agent=False, - ssh_strict=False, - system_host_keys=False, - alt_host_keys=False, - alt_key_file="", - ssh_config_file=None, + ip: str = "", + host: str = "", + username: str = "", + password: Optional[str] = None, + secret: str = "", + port: Optional[int] = None, + device_type: str = "", + verbose: bool = False, + global_delay_factor: float = 1.0, + global_cmd_verify: Optional[bool] = None, + use_keys: bool = False, + key_file: Optional[str] = None, + pkey: Optional[paramiko.PKey] = None, + passphrase: Optional[str] = None, + disabled_algorithms: Optional[Dict[str, Any]] = None, + allow_agent: bool = False, + ssh_strict: bool = False, + system_host_keys: bool = False, + alt_host_keys: bool = False, + alt_key_file: str = "", + ssh_config_file: Optional[str] = None, # # Connect timeouts # ssh-connect --> TCP conn (conn_timeout) --> SSH-banner (banner_timeout) # --> Auth response (auth_timeout) - conn_timeout=5, - auth_timeout=None, # Timeout to wait for authentication response - banner_timeout=15, # Timeout to wait for the banner to be presented (post TCP-connect) + conn_timeout: int = 10, + # Timeout to wait for authentication response + auth_timeout: Optional[int] = None, + banner_timeout: int = 15, # Timeout to wait for the banner to be presented # Other timeouts - blocking_timeout=20, # Read blocking timeout - timeout=100, # TCP connect timeout | overloaded to read-loop timeout - session_timeout=60, # Used for locking/sharing the connection - keepalive=0, - default_enter=None, - response_return=None, - serial_settings=None, - fast_cli=False, - _legacy_mode=True, - session_log=None, - session_log_record_writes=False, - session_log_file_mode="write", - allow_auto_change=False, - encoding="ascii", - sock=None, - auto_connect=True, - ): + blocking_timeout: int = 20, # Read blocking timeout + timeout: int = 100, # TCP connect timeout | overloaded to read-loop timeout + session_timeout: int = 60, # Used for locking/sharing the connection + read_timeout_override: Optional[float] = None, + keepalive: int = 0, + default_enter: Optional[str] = None, + response_return: Optional[str] = None, + serial_settings: Optional[Dict[str, Any]] = None, + fast_cli: bool = True, + _legacy_mode: bool = False, + session_log: Optional[SessionLog] = None, + session_log_record_writes: bool = False, + session_log_file_mode: str = "write", + allow_auto_change: bool = False, + encoding: str = "ascii", + sock: Optional[socket.socket] = None, + auto_connect: bool = True, + delay_factor_compat: bool = False, + ) -> None: """ Initialize attributes for establishing connection to target device. :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: \n). - :type default_enter: str :param response_return: Character(s) to use in normalized return data to represent enter key (default: \n) - :type response_return: str :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor to select smallest of global and specific. Sets default global_delay_factor to .1 - (default: False) - :type fast_cli: boolean + (default: True) :param session_log: File path or BufferedIOBase subclass object to write the session log to. - :type session_log: str :param session_log_record_writes: The session log generally only records channel reads due to eliminate command duplication due to command echo. You can enable this if you want to record both channel reads and channel writes in the log (default: False). - :type session_log_record_writes: boolean :param session_log_file_mode: "write" or "append" for session_log file mode (default: "write") - :type session_log_file_mode: str :param allow_auto_change: Allow automatic configuration changes for terminal settings. (default: False) - :type allow_auto_change: bool :param encoding: Encoding to be used when writing bytes to the output channel. (default: ascii) - :type encoding: str :param sock: An open socket or socket-like object (such as a `.Channel`) to use for communication to the target host (default: None). - :type sock: socket :param global_cmd_verify: Control whether command echo verification is enabled or disabled (default: None). Global attribute takes precedence over function `cmd_verify` argument. Value of `None` indicates to use function `cmd_verify` argument. - :type global_cmd_verify: bool|None :param auto_connect: Control whether Netmiko automatically establishes the connection as part of the object creation (default: True). - :type auto_connect: bool + + :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko + 3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be + eliminated in Netmiko 5.x (default: False). """ - self.remote_conn = None + + self.remote_conn: Union[ + None, telnetlib.Telnet, paramiko.Channel, serial.Serial + ] = None # Does the platform support a configuration mode self._config_mode = True + self._read_buffer = "" + self.delay_factor_compat = delay_factor_compat self.TELNET_RETURN = "\r\n" if default_enter is None: @@ -2517,24 +2781,46 @@

    Classes

    self.conn_timeout = conn_timeout self.session_timeout = session_timeout self.timeout = timeout + self.read_timeout_override = read_timeout_override self.keepalive = keepalive self.allow_auto_change = allow_auto_change self.encoding = encoding self.sock = sock - - # Netmiko will close the session_log if we open the file + self.fast_cli = fast_cli + self._legacy_mode = _legacy_mode + self.global_delay_factor = global_delay_factor + self.global_cmd_verify = global_cmd_verify + if self.fast_cli and self.global_delay_factor == 1: + self.global_delay_factor = 0.1 self.session_log = None - self.session_log_record_writes = session_log_record_writes self._session_log_close = False - # Ensures last write operations prior to disconnect are recorded. - self._session_log_fin = False + + # prevent logging secret data + no_log = {} + if self.password: + no_log["password"] = self.password + if self.secret: + no_log["secret"] = self.secret + log.addFilter(SecretsFilter(no_log=no_log)) + + # Netmiko will close the session_log if we open the file if session_log is not None: if isinstance(session_log, str): # If session_log is a string, open a file corresponding to string name. - self.open_session_log(filename=session_log, mode=session_log_file_mode) + self.session_log = SessionLog( + file_name=session_log, + file_mode=session_log_file_mode, + no_log=no_log, + record_writes=session_log_record_writes, + ) + self.session_log.open() elif isinstance(session_log, io.BufferedIOBase): # In-memory buffer or an already open file handle - self.session_log = session_log + self.session_log = SessionLog( + buffered_io=session_log, + no_log=no_log, + record_writes=session_log_record_writes, + ) else: raise ValueError( "session_log must be a path to a file, a file handle, " @@ -2560,13 +2846,6 @@

    Classes

    comm_port = check_serial_port(comm_port) self.serial_settings.update({"port": comm_port}) - self.fast_cli = fast_cli - self._legacy_mode = _legacy_mode - self.global_delay_factor = global_delay_factor - self.global_cmd_verify = global_cmd_verify - if self.fast_cli and self.global_delay_factor == 1: - self.global_delay_factor = 0.1 - # set in set_base_prompt method self.base_prompt = "" self._session_locker = Lock() @@ -2581,6 +2860,7 @@

    Classes

    else: self.protocol = "ssh" + self.key_policy: paramiko.client.MissingHostKeyPolicy if not ssh_strict: self.key_policy = paramiko.AutoAddPolicy() else: @@ -2597,6 +2877,7 @@

    Classes

    self.system_host_keys = system_host_keys self.alt_host_keys = alt_host_keys self.alt_key_file = alt_key_file + self.disabled_algorithms = disabled_algorithms or {} # For SSH proxy support self.ssh_config_file = ssh_config_file @@ -2605,25 +2886,30 @@

    Classes

    if auto_connect: self._open() - def _open(self): + def _open(self) -> None: """Decouple connection creation from __init__ for mocking.""" self._modify_connection_params() self.establish_connection() self._try_session_preparation() - def __enter__(self): + def __enter__(self) -> "BaseConnection": """Establish a session using a Context Manager.""" return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """Gracefully close connection on Context Manager exit.""" self.disconnect() - def _modify_connection_params(self): + def _modify_connection_params(self) -> None: """Modify connection parameters prior to SSH connection.""" pass - def _timeout_exceeded(self, start, msg="Timeout exceeded!"): + def _timeout_exceeded(self, start: float, msg: str = "Timeout exceeded!") -> bool: """Raise NetmikoTimeoutException if waiting too much in the serving queue. :param start: Initial start time to see if session lock timeout has been exceeded @@ -2640,7 +2926,7 @@

    Classes

    raise NetmikoTimeoutException(msg) return False - def _lock_netmiko_session(self, start=None): + def _lock_netmiko_session(self, start: Optional[float] = None) -> bool: """Try to acquire the Netmiko session lock. If not available, wait in the queue until the channel is available again. @@ -2656,68 +2942,33 @@

    Classes

    time.sleep(0.1) return True - def _unlock_netmiko_session(self): + def _unlock_netmiko_session(self) -> None: """ Release the channel at the end of the task. """ if self._session_locker.locked(): self._session_locker.release() - def _write_channel(self, out_data): - """Generic handler that will write to both SSH and telnet channel. + def _autodetect_fs(self, cmd: str = "", pattern: str = "") -> str: + raise NotImplementedError - :param out_data: data to be written to the channel - :type out_data: str (can be either unicode/byte string) - """ - if self.protocol == "ssh": - self.remote_conn.sendall(write_bytes(out_data, encoding=self.encoding)) - elif self.protocol == "telnet": - self.remote_conn.write(write_bytes(out_data, encoding=self.encoding)) - elif self.protocol == "serial": - self.remote_conn.write(write_bytes(out_data, encoding=self.encoding)) - self.remote_conn.flush() - else: - raise ValueError("Invalid protocol specified") - try: - log.debug( - "write_channel: {}".format( - write_bytes(out_data, encoding=self.encoding) - ) - ) - if self._session_log_fin or self.session_log_record_writes: - self._write_session_log(out_data) - except UnicodeDecodeError: - # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2) - pass + def _enter_shell(self) -> str: + raise NotImplementedError - def _write_session_log(self, data): - if self.session_log is not None and len(data) > 0: - # Hide the password and secret in the session_log - if self.password: - data = data.replace(self.password, "********") - if self.secret: - data = data.replace(self.secret, "********") - if isinstance(self.session_log, io.BufferedIOBase): - data = self.normalize_linefeeds(data) - self.session_log.write(write_bytes(data, encoding=self.encoding)) - else: - self.session_log.write(self.normalize_linefeeds(data)) - self.session_log.flush() + def _return_cli(self) -> str: + raise NotImplementedError - def write_channel(self, out_data): - """Generic handler that will write to both SSH and telnet channel. + @lock_channel + @log_writes + def write_channel(self, out_data: str) -> None: + """Generic method that will write data out the channel. :param out_data: data to be written to the channel - :type out_data: str (can be either unicode/byte string) + :type out_data: str """ - self._lock_netmiko_session() - try: - self._write_channel(out_data) - finally: - # Always unlock the SSH channel, even on exception. - self._unlock_netmiko_session() + self.channel.write_channel(out_data) - def is_alive(self): + def is_alive(self) -> bool: """Returns a boolean flag with the state of the connection.""" null = chr(0) if self.remote_conn is None: @@ -2729,9 +2980,11 @@

    Classes

    # IAC = Interpret as Command; it comes before the NOP. log.debug("Sending IAC + NOP") # Need to send multiple times to test connection - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) + assert isinstance(self.remote_conn, telnetlib.Telnet) + telnet_socket = self.remote_conn.get_socket() + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) return True except AttributeError: return False @@ -2741,203 +2994,236 @@

    Classes

    # Try sending ASCII null byte to maintain the connection alive log.debug("Sending the NULL byte") self.write_channel(null) - return self.remote_conn.transport.is_active() + assert isinstance(self.remote_conn, paramiko.Channel) + assert self.remote_conn.transport is not None + result = self.remote_conn.transport.is_active() + assert isinstance(result, bool) + return result except (socket.error, EOFError): log.error("Unable to send", exc_info=True) # If unable to send, we can tell for sure that the connection is unusable return False return False - def _read_channel(self): - """Generic handler that will read all the data from an SSH or telnet channel.""" - if self.protocol == "ssh": - output = "" - while True: - if self.remote_conn.recv_ready(): - outbuf = self.remote_conn.recv(MAX_BUFFER) - if len(outbuf) == 0: - raise EOFError("Channel stream closed by remote device.") - output += outbuf.decode("utf-8", "ignore") - else: - break - elif self.protocol == "telnet": - output = self.remote_conn.read_very_eager().decode("utf-8", "ignore") - elif self.protocol == "serial": - output = "" - while self.remote_conn.in_waiting > 0: - output += self.remote_conn.read(self.remote_conn.in_waiting).decode( - "utf-8", "ignore" - ) + @lock_channel + def read_channel(self) -> str: + """Generic handler that will read all the data from given channel.""" + new_data = self.channel.read_channel() + new_data = self.normalize_linefeeds(new_data) if self.ansi_escape_codes: - output = self.strip_ansi_escape_codes(output) - log.debug(f"read_channel: {output}") - self._write_session_log(output) + new_data = self.strip_ansi_escape_codes(new_data) + log.debug(f"read_channel: {new_data}") + if self.session_log: + self.session_log.write(new_data) + + # If data had been previously saved to the buffer, the prepend it to output + # do post read_channel so session_log/log doesn't record buffered data twice + if self._read_buffer: + output = self._read_buffer + new_data + self._read_buffer = "" + else: + output = new_data return output - def read_channel(self): - """Generic handler that will read all the data from an SSH or telnet channel.""" - output = "" - self._lock_netmiko_session() - try: - output = self._read_channel() - finally: - # Always unlock the SSH channel, even on exception. - self._unlock_netmiko_session() - return output + def read_until_pattern( + self, + pattern: str = "", + read_timeout: float = 10.0, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read channel until pattern is detected. - def _read_channel_expect(self, pattern="", re_flags=0, max_loops=150): - """Function that reads channel until pattern is detected. + Will return string up to and including pattern. - pattern takes a regular expression. + Returns ReadTimeout if pattern not detected in read_timeout seconds. - By default pattern will be self.base_prompt + :param pattern: Regular expression pattern used to identify that reading is done. - Note: this currently reads beyond pattern. In the case of SSH it reads MAX_BUFFER. - In the case of telnet it reads all non-blocking data. + :param read_timeout: maximum time to wait looking for pattern. Will raise ReadTimeout. + A read_timeout value of 0 will cause the loop to never timeout (i.e. it will keep + reading indefinitely until pattern is detected. - There are dependencies here like determining whether in config_mode that are actually - depending on reading beyond pattern. + :param re_flags: regex flags used in conjunction with pattern (defaults to no flags). - :param pattern: Regular expression pattern used to identify the command is done \ - (defaults to self.base_prompt) - :type pattern: str (regular expression) + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ + if max_loops is not None: + msg = """\n +Netmiko 4.x has deprecated the use of max_loops with read_until_pattern. +You should convert all uses of max_loops over to read_timeout=x +where x is the total number of seconds to wait before timing out.\n""" + warnings.warn(msg, DeprecationWarning) - :param re_flags: regex flags used in conjunction with pattern to search for prompt \ - (defaults to no flags) - :type re_flags: int + if self.read_timeout_override: + read_timeout = self.read_timeout_override - :param max_loops: max number of iterations to read the channel before raising exception. - Will default to be based upon self.timeout. - :type max_loops: int - """ output = "" - if not pattern: - pattern = re.escape(self.base_prompt) - log.debug(f"Pattern is: {pattern}") - - i = 1 - loop_delay = 0.1 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # argument for backwards compatibility). - if max_loops == 150: - max_loops = int(self.timeout / loop_delay) - while i < max_loops: - if self.protocol == "ssh": - try: - # If no data available will wait timeout seconds trying to read - self._lock_netmiko_session() - new_data = self.remote_conn.recv(MAX_BUFFER) - if len(new_data) == 0: - raise EOFError("Channel stream closed by remote device.") - new_data = new_data.decode("utf-8", "ignore") - if self.ansi_escape_codes: - new_data = self.strip_ansi_escape_codes(new_data) - log.debug(f"_read_channel_expect read_data: {new_data}") - output += new_data - self._write_session_log(new_data) - except socket.timeout: - raise NetmikoTimeoutException( - "Timed-out reading channel, data not available." - ) - finally: - self._unlock_netmiko_session() - elif self.protocol == "telnet" or "serial": - output += self.read_channel() + loop_delay = 0.01 + start_time = time.time() + # if read_timeout == 0 or 0.0 keep reading indefinitely + while (time.time() - start_time < read_timeout) or (not read_timeout): + output += self.read_channel() if re.search(pattern, output, flags=re_flags): + results = re.split(pattern, output, maxsplit=1, flags=re_flags) + + # The string matched by pattern must be retained in the output string. + # re.split will do this if capturing parentesis are used. + if len(results) == 2: + # no capturing parenthesis, convert and try again. + pattern = f"({pattern})" + results = re.split(pattern, output, maxsplit=1, flags=re_flags) + + if len(results) != 3: + # well, we tried + msg = f"""Unable to successfully split output based on pattern: +pattern={pattern} +output={repr(output)} +results={results} +""" + raise ReadException(msg) + + # Process such that everything before and including pattern is return. + # Everything else is retained in the _read_buffer + output, match_str, buffer = results + output = output + match_str + if buffer: + self._read_buffer += buffer log.debug(f"Pattern found: {pattern} {output}") return output - time.sleep(loop_delay * self.global_delay_factor) - i += 1 - raise NetmikoTimeoutException( - f"Timed-out reading channel, pattern not found in output: {pattern}" - ) + time.sleep(loop_delay) + + msg = f"""\n\nPattern not detected: {repr(pattern)} in output. - def _read_channel_timing(self, delay_factor=1, max_loops=150): +Things you might try to fix this: +1. Adjust the regex pattern to better identify the terminating string. Note, in +many situations the pattern is automatically based on the network device's prompt. +2. Increase the read_timeout to a larger value. + +You can also look at the Netmiko session_log or debug log for more information.\n\n""" + raise ReadTimeout(msg) + + def read_channel_timing( + self, + last_read: float = 2.0, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + ) -> str: """Read data on the channel based on timing delays. - Attempt to read channel max_loops number of times. If no data this will cause a 15 second - delay. + General pattern is keep reading until no new data is read. + Once no new data is read wait `last_read` amount of time (one last read). + As long as no new data, then return data. + + `read_timeout` is an absolute timer for how long to keep reading (which presupposes + we are still getting new data). - Once data is encountered read channel for another two seconds (2 * delay_factor) to make - sure reading of channel is complete. + Setting `read_timeout` to zero will cause read_channel_timing to never expire based + on an absolute timeout. It will only complete based on timeout based on their being + no new data. - :param delay_factor: multiplicative factor to adjust delay when reading channel (delays - get multiplied by this factor) - :type delay_factor: int or float + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: maximum number of loops to iterate through before returning channel data. - Will default to be based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ - # Time to delay in each read loop - loop_delay = 0.1 - final_delay = 2 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # and delay_factor arguments for backwards compatibility). - delay_factor = self.select_delay_factor(delay_factor) - if delay_factor == 1 and max_loops == 150: - max_loops = int(self.timeout / loop_delay) + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) - # FIX: Cleanup in future versions of Netmiko - if delay_factor < 1: - if not self._legacy_mode and self.fast_cli: - delay_factor = 1 + if self.read_timeout_override: + read_timeout = self.read_timeout_override + # Time to delay in each read loop + loop_delay = 0.1 channel_data = "" - i = 0 - while i <= max_loops: - time.sleep(loop_delay * delay_factor) + start_time = time.time() + + # Set read_timeout to 0 to never timeout + while (time.time() - start_time < read_timeout) or (not read_timeout): + time.sleep(loop_delay) new_data = self.read_channel() + # gather new output if new_data: channel_data += new_data - else: - # Safeguard to make sure really done - time.sleep(final_delay * delay_factor) + # if we have some output, but nothing new, then do the last read + elif channel_data != "": + # Make sure really done (i.e. no new data) + time.sleep(last_read) new_data = self.read_channel() if not new_data: break else: channel_data += new_data - i += 1 - return channel_data + else: + msg = f"""\n +read_channel_timing's absolute timer expired. - def read_until_prompt(self, *args, **kwargs): - """Read channel until self.base_prompt detected. Return ALL data available.""" - return self._read_channel_expect(*args, **kwargs) +The network device was continually outputting data for longer than {read_timeout} +seconds. - def read_until_pattern(self, *args, **kwargs): - """Read channel until pattern detected. Return ALL data available.""" - return self._read_channel_expect(*args, **kwargs) +If this is expected i.e. the command you are executing is continually emitting +data for a long period of time, then you can set 'read_timeout=x' seconds. If +you want Netmiko to keep reading indefinitely (i.e. to only stop when there is +no new data), then you can set 'read_timeout=0'. - def read_until_prompt_or_pattern(self, pattern="", re_flags=0): - """Read until either self.base_prompt or pattern is detected. +You can look at the Netmiko session_log or debug log for more information. - :param pattern: the pattern used to identify that the output is complete (i.e. stop \ - reading when pattern is detected). pattern will be combined with self.base_prompt to \ - terminate output reading when the first of self.base_prompt or pattern is detected. - :type pattern: regular expression string +""" + raise ReadTimeout(msg) + return channel_data - :param re_flags: regex flags used in conjunction with pattern to search for prompt \ - (defaults to no flags) - :type re_flags: int + def read_until_prompt( + self, + read_timeout: float = 10.0, + read_entire_line: bool = False, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read channel up to and including self.base_prompt.""" + pattern = re.escape(self.base_prompt) + if read_entire_line: + pattern = f"{pattern}.*" + return self.read_until_pattern( + pattern=pattern, + re_flags=re_flags, + max_loops=max_loops, + read_timeout=read_timeout, + ) - """ - combined_pattern = re.escape(self.base_prompt) + def read_until_prompt_or_pattern( + self, + pattern: str = "", + read_timeout: float = 10.0, + read_entire_line: bool = False, + re_flags: int = 0, + max_loops: Optional[int] = None, + ) -> str: + """Read until either self.base_prompt or pattern is detected.""" + prompt_pattern = re.escape(self.base_prompt) + if read_entire_line: + prompt_pattern = f"{prompt_pattern}.*" if pattern: - combined_pattern = r"({}|{})".format(combined_pattern, pattern) - return self._read_channel_expect(combined_pattern, re_flags=re_flags) + combined_pattern = r"(?:{}|{})".format(prompt_pattern, pattern) + else: + combined_pattern = prompt_pattern + return self.read_until_pattern( + pattern=combined_pattern, + re_flags=re_flags, + max_loops=max_loops, + read_timeout=read_timeout, + ) def serial_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:[Uu]ser:|sername|ogin)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): - self.telnet_login( + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:[Uu]ser:|sername|ogin)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: + return self.telnet_login( pri_prompt_terminator, alt_prompt_terminator, username_pattern, @@ -2948,33 +3234,28 @@

    Classes

    def telnet_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login|user name)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login|user name)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """Telnet login. Can be username/password or just password. :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt - :type pri_prompt_terminator: str :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt - :type alt_prompt_terminator: str :param username_pattern: Pattern used to identify the username prompt - :type username_pattern: str :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int :param max_loops: Controls the wait time in conjunction with the delay_factor - (default: 20) """ delay_factor = self.select_delay_factor(delay_factor) - # FIX: Cleanup in future versions of Netmiko + # Revert telnet_login back to old speeds/delays if delay_factor < 1: if not self._legacy_mode and self.fast_cli: delay_factor = 1 @@ -3000,6 +3281,7 @@

    Classes

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -3019,6 +3301,7 @@

    Classes

    time.sleep(0.5 * delay_factor) i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -3034,10 +3317,11 @@

    Classes

    return return_msg msg = f"Login failed: {self.host}" + assert self.remote_conn is not None self.remote_conn.close() raise NetmikoAuthenticationException(msg) - def _try_session_preparation(self): + def _try_session_preparation(self) -> None: """ In case of an exception happening during `session_preparation()` Netmiko should gracefully clean-up after itself. This might be challenging for library users @@ -3050,7 +3334,7 @@

    Classes

    self.disconnect() raise - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established @@ -3058,31 +3342,27 @@

    Classes

    early on in the session. In general, it should include: - self._test_channel_read() + self._test_channel_read(pattern=r"some_pattern") self.set_base_prompt() - self.disable_paging() self.set_terminal_width() - self.clear_buffer() + self.disable_paging() """ self._test_channel_read() self.set_base_prompt() self.set_terminal_width() self.disable_paging() - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def _use_ssh_config(self, dict_arg): + def _use_ssh_config(self, dict_arg: Dict[str, Any]) -> Dict[str, Any]: """Update SSH connection parameters based on contents of SSH config file. :param dict_arg: Dictionary of SSH connection parameters - :type dict_arg: dict """ connect_dict = dict_arg.copy() # Use SSHConfig to generate source content. + assert self.ssh_config_file is not None full_path = path.abspath(path.expanduser(self.ssh_config_file)) + source: Union[paramiko.config.SSHConfigDict, Dict[str, Any]] if path.exists(full_path): ssh_config_instance = paramiko.SSHConfig() with io.open(full_path, "rt", encoding="utf-8") as f: @@ -3092,6 +3372,7 @@

    Classes

    source = {} # Keys get normalized to lower-case + proxy: Optional[paramiko.proxy.ProxyCommand] if "proxycommand" in source: proxy = paramiko.ProxyCommand(source["proxycommand"]) elif "proxyjump" in source: @@ -3120,7 +3401,7 @@

    Classes

    return connect_dict - def _connect_params_dict(self): + def _connect_params_dict(self) -> Dict[str, Any]: """Generate dictionary of Paramiko connection parameters.""" conn_dict = { "hostname": self.host, @@ -3132,6 +3413,7 @@

    Classes

    "key_filename": self.key_file, "pkey": self.pkey, "passphrase": self.passphrase, + "disabled_algorithms": self.disabled_algorithms, "timeout": self.conn_timeout, "auth_timeout": self.auth_timeout, "banner_timeout": self.banner_timeout, @@ -3144,17 +3426,13 @@

    Classes

    return conn_dict def _sanitize_output( - self, output, strip_command=False, command_string=None, strip_prompt=False - ): - """Strip out command echo, trailing router prompt and ANSI escape codes. - - :param output: Output from a remote network device - :type output: unicode string - - :param strip_command: - :type strip_command: - """ - output = self.normalize_linefeeds(output) + self, + output: str, + strip_command: bool = False, + command_string: Optional[str] = None, + strip_prompt: bool = False, + ) -> str: + """Strip out command echo and trailing router prompt.""" if strip_command and command_string: command_string = self.normalize_linefeeds(command_string) output = self.strip_command(command_string, output) @@ -3162,7 +3440,7 @@

    Classes

    output = self.strip_prompt(output) return output - def establish_connection(self, width=511, height=1000): + def establish_connection(self, width: int = 511, height: int = 1000) -> None: """Establish SSH connection to the network device Timeout will generate a NetmikoTimeoutException @@ -3174,16 +3452,21 @@

    Classes

    :param height: Specified height of the VT100 terminal window (default: 1000) :type height: int """ + self.channel: Channel if self.protocol == "telnet": self.remote_conn = telnetlib.Telnet( self.host, port=self.port, timeout=self.timeout ) + # Migrating communication to channel class + self.channel = TelnetChannel(conn=self.remote_conn, encoding=self.encoding) self.telnet_login() elif self.protocol == "serial": self.remote_conn = serial.Serial(**self.serial_settings) + self.channel = SerialChannel(conn=self.remote_conn, encoding=self.encoding) self.serial_login() elif self.protocol == "ssh": ssh_connect_params = self._connect_params_dict() + self.remote_conn_pre: Optional[paramiko.SSHClient] self.remote_conn_pre = self._build_ssh_client() # initiate SSH connection @@ -3226,16 +3509,22 @@

    Classes

    msg += self.RETURN + str(auth_err) raise NetmikoAuthenticationException(msg) - except paramiko.ssh_exception.SSHException as no_session_err: + except paramiko.ssh_exception.SSHException as e: self.paramiko_cleanup() - if "No existing session" in str(no_session_err): + if "No existing session" in str(e): msg = ( "Paramiko: 'No existing session' error: " - "try increasing 'conn_timeout' to 10 seconds or larger." + "try increasing 'conn_timeout' to 15 seconds or larger." ) raise NetmikoTimeoutException(msg) else: - raise + msg = f""" +A paramiko SSHException occurred during connection creation: + +{str(e)} + +""" + raise NetmikoTimeoutException(msg) if self.verbose: print(f"SSH connection established to {self.host}:{self.port}") @@ -3247,24 +3536,29 @@

    Classes

    self.remote_conn.settimeout(self.blocking_timeout) if self.keepalive: + assert isinstance(self.remote_conn.transport, paramiko.Transport) self.remote_conn.transport.set_keepalive(self.keepalive) + + # Migrating communication to channel class + self.channel = SSHChannel(conn=self.remote_conn, encoding=self.encoding) + self.special_login_handler() if self.verbose: print("Interactive SSH session established") - return "" - # @m_exec_time - def _test_channel_read(self, count=40, pattern=""): + return None + + def _test_channel_read(self, count: int = 40, pattern: str = "") -> str: """Try to read the channel (generally post login) verify you receive data back. :param count: the number of times to check the channel for data - :type count: int :param pattern: Regular expression pattern used to determine end of channel read - :type pattern: str """ - def _increment_delay(main_delay, increment=1.1, maximum=8): + def _increment_delay( + main_delay: float, increment: float = 1.1, maximum: int = 8 + ) -> float: """Increment sleep time to a maximum value.""" main_delay = main_delay * increment if main_delay >= maximum: @@ -3273,30 +3567,26 @@

    Classes

    i = 0 delay_factor = self.select_delay_factor(delay_factor=0) + + if pattern: + return self.read_until_pattern(pattern=pattern, read_timeout=20) + main_delay = delay_factor * 0.1 time.sleep(main_delay * 10) new_data = "" while i <= count: - new_data += self._read_channel_timing() - if new_data and pattern: - if re.search(pattern, new_data): - break - elif new_data: - break - else: - self.write_channel(self.RETURN) + new_data += self.read_channel_timing() + if new_data: + return new_data + self.write_channel(self.RETURN) main_delay = _increment_delay(main_delay) time.sleep(main_delay) i += 1 - # check if data was ever present - if new_data: - return new_data - else: - raise NetmikoTimeoutException("Timed out waiting for data") + raise NetmikoTimeoutException("Timed out waiting for data") - def _build_ssh_client(self): + def _build_ssh_client(self) -> paramiko.SSHClient: """Prepare for Paramiko SSH connection.""" # Create instance of SSHClient object remote_conn_pre = paramiko.SSHClient() @@ -3311,7 +3601,7 @@

    Classes

    remote_conn_pre.set_missing_host_key_policy(self.key_policy) return remote_conn_pre - def select_delay_factor(self, delay_factor): + def select_delay_factor(self, delay_factor: float) -> float: """ Choose the greater of delay_factor or self.global_delay_factor (default). In fast_cli choose the lesser of delay_factor of self.global_delay_factor. @@ -3330,31 +3620,37 @@

    Classes

    else: return self.global_delay_factor - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """Handler for devices like WLC, Extreme ERS that throw up characters prior to login.""" pass def disable_paging( - self, command="terminal length 0", delay_factor=1, cmd_verify=True, pattern=None - ): + self, + command: str = "terminal length 0", + delay_factor: Optional[float] = None, + cmd_verify: bool = True, + pattern: Optional[str] = None, + ) -> str: """Disable paging default to a Cisco CLI method. :param command: Device command to disable pagination of output - :type command: str - :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + command = self.normalize_cmd(command) log.debug("In disable_paging") log.debug(f"Command: {command}") self.write_channel(command) # Make sure you read until you detect the command echo (avoid getting out of sync) if cmd_verify and self.global_cmd_verify is not False: - output = self.read_until_pattern(pattern=re.escape(command.strip())) + output = self.read_until_pattern( + pattern=re.escape(command.strip()), read_timeout=20 + ) elif pattern: - output = self.read_until_pattern(pattern=pattern) + output = self.read_until_pattern(pattern=pattern, read_timeout=20) else: output = self.read_until_prompt() log.debug(f"{output}") @@ -3362,24 +3658,29 @@

    Classes

    return output def set_terminal_width( - self, command="", delay_factor=1, cmd_verify=False, pattern=None - ): + self, + command: str = "", + delay_factor: Optional[float] = None, + cmd_verify: bool = False, + pattern: Optional[str] = None, + ) -> str: """CLI terminals try to automatically adjust the line based on the width of the terminal. This causes the output to get distorted when accessed programmatically. Set terminal width to 511 which works on a broad set of devices. :param command: Command string to send to the device - :type command: str - :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. """ + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + if not command: return "" - delay_factor = self.select_delay_factor(delay_factor) command = self.normalize_cmd(command) self.write_channel(command) + # Avoid cmd_verify here as terminal width must be set before doing cmd_verify if cmd_verify and self.global_cmd_verify is not False: output = self.read_until_pattern(pattern=re.escape(command.strip())) @@ -3396,8 +3697,12 @@

    Classes

    reraise=True, ) def set_base_prompt( - self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 - ): + self, + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt Used as delimiter for stripping of trailing prompt in output. @@ -3409,206 +3714,216 @@

    Classes

    entering/exiting config mode. :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt - :type pri_prompt_terminator: str :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt - :type alt_prompt_terminator: str :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + + :param pattern: Regular expression pattern to search for in find_prompt() call """ - prompt = self.find_prompt(delay_factor=delay_factor) + if pattern is None: + if pri_prompt_terminator and alt_prompt_terminator: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + pattern = rf"({pri_term}|{alt_term})" + elif pri_prompt_terminator: + pattern = re.escape(pri_prompt_terminator) + elif alt_prompt_terminator: + pattern = re.escape(alt_prompt_terminator) + + if pattern: + prompt = self.find_prompt(delay_factor=delay_factor, pattern=pattern) + else: + prompt = self.find_prompt(delay_factor=delay_factor) + if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): raise ValueError(f"Router prompt not found: {repr(prompt)}") # Strip off trailing terminator self.base_prompt = prompt[:-1] return self.base_prompt - def find_prompt(self, delay_factor=1): + def find_prompt( + self, delay_factor: float = 1.0, pattern: Optional[str] = None + ) -> str: """Finds the current network device prompt, last line only. :param delay_factor: See __init__: global_delay_factor :type delay_factor: int + + :param pattern: Regular expression pattern to determine whether prompt is valid """ delay_factor = self.select_delay_factor(delay_factor) + sleep_time = delay_factor * 0.25 self.clear_buffer() self.write_channel(self.RETURN) - sleep_time = delay_factor * 0.1 - time.sleep(sleep_time) - - # Initial attempt to get prompt - prompt = self.read_channel().strip() - # Check if the only thing you received was a newline - count = 0 - while count <= 12 and not prompt: + if pattern: + try: + prompt = self.read_until_pattern(pattern=pattern) + except ReadTimeout: + pass + else: + # Initial read + time.sleep(sleep_time) prompt = self.read_channel().strip() - if not prompt: - self.write_channel(self.RETURN) - time.sleep(sleep_time) - if sleep_time <= 3: - # Double the sleep_time when it is small - sleep_time *= 2 - else: - sleep_time += 1 - count += 1 + + count = 0 + while count <= 12 and not prompt: + if not prompt: + self.write_channel(self.RETURN) + time.sleep(sleep_time) + prompt = self.read_channel().strip() + if sleep_time <= 3: + # Double the sleep_time when it is small + sleep_time *= 2 + else: + sleep_time += 1 + count += 1 # If multiple lines in the output take the last line - prompt = self.normalize_linefeeds(prompt) prompt = prompt.split(self.RESPONSE_RETURN)[-1] prompt = prompt.strip() + self.clear_buffer() if not prompt: raise ValueError(f"Unable to find prompt: {prompt}") - time.sleep(delay_factor * 0.1) - self.clear_buffer() log.debug(f"[find_prompt()]: prompt is {prompt}") return prompt - def clear_buffer(self, backoff=True): + def clear_buffer( + self, + backoff: bool = True, + backoff_max: float = 3.0, + delay_factor: Optional[float] = None, + ) -> str: """Read any data available in the channel.""" - sleep_time = 0.1 * self.global_delay_factor + + if delay_factor is None: + delay_factor = self.global_delay_factor + sleep_time = 0.1 * delay_factor + + output = "" for _ in range(10): time.sleep(sleep_time) data = self.read_channel() + data = self.strip_ansi_escape_codes(data) + output += data if not data: break # Double sleep time each time we detect data log.debug("Clear buffer detects data in the channel") if backoff: sleep_time *= 2 - sleep_time = 3 if sleep_time >= 3 else sleep_time + sleep_time = backoff_max if sleep_time >= backoff_max else sleep_time + return output + + def command_echo_read(self, cmd: str, read_timeout: float) -> str: + + # Make sure you read until you detect the command echo (avoid getting out of sync) + new_data = self.read_until_pattern( + pattern=re.escape(cmd), read_timeout=read_timeout + ) + + # There can be echoed prompts that haven't been cleared before the cmd echo + # this can later mess up the trailing prompt pattern detection. Clear this out. + lines = new_data.split(cmd) + if len(lines) == 2: + # lines[-1] should realistically just be the null string + new_data = f"{cmd}{lines[-1]}" + else: + # cmd exists in the output multiple times? Just retain the original output + pass + return new_data @select_cmd_verify def send_command_timing( self, - command_string, - delay_factor=1, - max_loops=150, - strip_prompt=True, - strip_command=True, - normalize=True, - use_textfsm=False, - textfsm_template=None, - use_ttp=False, - ttp_template=None, - use_genie=False, - cmd_verify=False, - cmd_echo=None, - ): + command_string: str, + last_read: float = 2.0, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + strip_prompt: bool = True, + strip_command: bool = True, + normalize: bool = True, + use_textfsm: bool = False, + textfsm_template: Optional[str] = None, + use_ttp: bool = False, + ttp_template: Optional[str] = None, + use_genie: bool = False, + cmd_verify: bool = False, + ) -> Union[str, List[Any], Dict[str, Any]]: """Execute command_string on the SSH channel using a delay-based mechanism. Generally used for show commands. :param command_string: The command to be executed on the remote device. - :type command_string: str - :param delay_factor: Multiplying factor used to adjust delays (default: 1). - :type delay_factor: int or float + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be - based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Remove the trailing router prompt from the output (default: True). - :type strip_prompt: bool :param strip_command: Remove the echo of the command from the output (default: True). - :type strip_command: bool :param normalize: Ensure the proper enter is sent at end of command (default: True). - :type normalize: bool :param use_textfsm: Process command output through TextFSM template (default: False). - :type use_textfsm: bool :param textfsm_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type textfsm_template: str :param use_ttp: Process command output through TTP template (default: False). - :type use_ttp: bool :param ttp_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type ttp_template: str :param use_genie: Process command output through PyATS/Genie parser (default: False). - :type use_genie: bool :param cmd_verify: Verify command echo before proceeding (default: False). - :type cmd_verify: bool - - :param cmd_echo: Deprecated (use cmd_verify instead) - :type cmd_echo: bool """ - - # For compatibility; remove cmd_echo in Netmiko 4.x.x - if cmd_echo is not None: - cmd_verify = cmd_echo + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) output = "" - delay_factor = self.select_delay_factor(delay_factor) - + new_data = "" if normalize: command_string = self.normalize_cmd(command_string) self.write_channel(command_string) cmd = command_string.strip() - # if cmd is just an "enter" skip this section if cmd and cmd_verify: - # Make sure you read until you detect the command echo (avoid getting out of sync) - new_data = self.read_until_pattern(pattern=re.escape(cmd)) - new_data = self.normalize_linefeeds(new_data) - - # Strip off everything before the command echo - if new_data.count(cmd) == 1: - new_data = new_data.split(cmd)[1:] - new_data = self.RESPONSE_RETURN.join(new_data) - new_data = new_data.lstrip() - output = f"{cmd}{self.RESPONSE_RETURN}{new_data}" - else: - # cmd is in the actual output (not just echoed) - output = new_data - - log.debug(f"send_command_timing current output: {output}") - - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops + new_data = self.command_echo_read(cmd=cmd, read_timeout=10) + output += new_data + output += self.read_channel_timing( + last_read=last_read, read_timeout=read_timeout ) + output = self._sanitize_output( output, strip_command=strip_command, command_string=command_string, strip_prompt=strip_prompt, ) + return_data = structured_data_converter( + command=command_string, + raw_data=output, + platform=self.device_type, + use_textfsm=use_textfsm, + use_ttp=use_ttp, + use_genie=use_genie, + textfsm_template=textfsm_template, + ttp_template=ttp_template, + ) + return return_data - # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie - if use_textfsm: - structured_output = get_structured_data( - output, - platform=self.device_type, - command=command_string.strip(), - template=textfsm_template, - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_ttp: - structured_output = get_structured_data_ttp(output, template=ttp_template) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_genie: - structured_output = get_structured_data_genie( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - - log.debug(f"send_command_timing final output: {output}") + def _send_command_timing_str(self, *args: Any, **kwargs: Any) -> str: + """Wrapper for `send_command_timing` method that always returns a + string""" + output = self.send_command_timing(*args, **kwargs) + assert isinstance(output, str) return output - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output. :param a_string: Returned string from device @@ -3616,12 +3931,13 @@

    Classes

    """ response_list = a_string.split(self.RESPONSE_RETURN) last_line = response_list[-1] + if self.base_prompt in last_line: return self.RESPONSE_RETURN.join(response_list[:-1]) else: return a_string - def _first_line_handler(self, data, search_pattern): + def _first_line_handler(self, data: str, search_pattern: str) -> Tuple[str, bool]: """ In certain situations the first line will get repainted which causes a false match on the terminating pattern. @@ -3648,126 +3964,151 @@

    Classes

    except IndexError: return (data, False) + def _prompt_handler(self, auto_find_prompt: bool) -> str: + if auto_find_prompt: + try: + prompt = self.find_prompt() + except ValueError: + prompt = self.base_prompt + else: + prompt = self.base_prompt + return re.escape(prompt.strip()) + @select_cmd_verify def send_command( self, - command_string, - expect_string=None, - delay_factor=1, - max_loops=500, - auto_find_prompt=True, - strip_prompt=True, - strip_command=True, - normalize=True, - use_textfsm=False, - textfsm_template=None, - use_ttp=False, - ttp_template=None, - use_genie=False, - cmd_verify=True, - ): + command_string: str, + expect_string: Optional[str] = None, + read_timeout: float = 10.0, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + auto_find_prompt: bool = True, + strip_prompt: bool = True, + strip_command: bool = True, + normalize: bool = True, + use_textfsm: bool = False, + textfsm_template: Optional[str] = None, + use_ttp: bool = False, + ttp_template: Optional[str] = None, + use_genie: bool = False, + cmd_verify: bool = True, + ) -> Union[str, List[Any], Dict[str, Any]]: """Execute command_string on the SSH channel using a pattern-based mechanism. Generally used for show commands. By default this method will keep waiting to receive data until the network device prompt is detected. The current network device prompt will be determined automatically. :param command_string: The command to be executed on the remote device. - :type command_string: str :param expect_string: Regular expression pattern to use for determining end of output. If left blank will default to being based on router prompt. - :type expect_string: str - :param delay_factor: Multiplying factor used to adjust delays (default: 1). - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be - based upon self.timeout. - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Remove the trailing router prompt from the output (default: True). - :type strip_prompt: bool :param strip_command: Remove the echo of the command from the output (default: True). - :type strip_command: bool :param normalize: Ensure the proper enter is sent at end of command (default: True). - :type normalize: bool :param use_textfsm: Process command output through TextFSM template (default: False). - :type normalize: bool :param textfsm_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). :param use_ttp: Process command output through TTP template (default: False). - :type use_ttp: bool :param ttp_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None). - :type ttp_template: str :param use_genie: Process command output through PyATS/Genie parser (default: False). - :type normalize: bool :param cmd_verify: Verify command echo before proceeding (default: True). - :type cmd_verify: bool """ # Time to delay in each read loop - loop_delay = 0.2 + loop_delay = 0.025 - # Default to making loop time be roughly equivalent to self.timeout (support old max_loops - # and delay_factor arguments for backwards compatibility). - delay_factor = self.select_delay_factor(delay_factor) - if delay_factor == 1 and max_loops == 500: - # Default arguments are being used; use self.timeout instead - max_loops = int(self.timeout / loop_delay) - - # Find the current router prompt - if expect_string is None: - if auto_find_prompt: - try: - prompt = self.find_prompt(delay_factor=delay_factor) - except ValueError: - prompt = self.base_prompt + if self.read_timeout_override: + read_timeout = self.read_timeout_override + + if self.delay_factor_compat: + # For compatibility calculate the old equivalent read_timeout + # i.e. what it would have been in Netmiko 3.x + if delay_factor is None: + tmp_delay_factor = self.global_delay_factor else: - prompt = self.base_prompt - search_pattern = re.escape(prompt.strip()) + tmp_delay_factor = self.select_delay_factor(delay_factor) + compat_timeout = calc_old_timeout( + max_loops=max_loops, + delay_factor=tmp_delay_factor, + loop_delay=0.2, + old_timeout=self.timeout, + ) + msg = f"""\n +You have chosen to use Netmiko's delay_factor compatibility mode for +send_command. This will revert Netmiko to behave similarly to how it +did in Netmiko 3.x (i.e. to use delay_factor/global_delay_factor and +max_loops). + +Using these parameters Netmiko has calculated an effective read_timeout +of {compat_timeout} and will set the read_timeout to this value. + +Please convert your code to that new format i.e.: + + net_connect.send_command(cmd, read_timeout={compat_timeout}) + +And then disable delay_factor_compat. + +delay_factor_compat will be removed in Netmiko 5.x.\n""" + warnings.warn(msg, DeprecationWarning) + + # Override the read_timeout with Netmiko 3.x way :-( + read_timeout = compat_timeout + else: + # No need for two deprecation messages so only display this if not using + # delay_factor_compat + if delay_factor is not None or max_loops is not None: + msg = """\n +Netmiko 4.x has deprecated the use of delay_factor/max_loops with +send_command. You should convert all uses of delay_factor and max_loops +over to read_timeout=x where x is the total number of seconds to wait +before timing out.\n""" + warnings.warn(msg, DeprecationWarning) + + if expect_string is not None: search_pattern = expect_string + else: + search_pattern = self._prompt_handler(auto_find_prompt) if normalize: command_string = self.normalize_cmd(command_string) - time.sleep(delay_factor * loop_delay) - self.clear_buffer() + # Start the clock + start_time = time.time() self.write_channel(command_string) new_data = "" cmd = command_string.strip() - # if cmd is just an "enter" skip this section if cmd and cmd_verify: - # Make sure you read until you detect the command echo (avoid getting out of sync) - new_data = self.read_until_pattern(pattern=re.escape(cmd)) - new_data = self.normalize_linefeeds(new_data) - # Strip off everything before the command echo (to avoid false positives on the prompt) - if new_data.count(cmd) == 1: - new_data = new_data.split(cmd)[1:] - new_data = self.RESPONSE_RETURN.join(new_data) - new_data = new_data.lstrip() - new_data = f"{cmd}{self.RESPONSE_RETURN}{new_data}" + new_data = self.command_echo_read(cmd=cmd, read_timeout=10) - i = 1 + MAX_CHARS = 2_000_000 + DEQUE_SIZE = 20 output = "" - past_three_reads = deque(maxlen=3) + # Check only the past N-reads. This is for the case where the output is + # very large (i.e. searching a very large string for a pattern a whole bunch of times) + past_n_reads: Deque[str] = deque(maxlen=DEQUE_SIZE) first_line_processed = False - # Keep reading data until search_pattern is found or until max_loops is reached. - while i <= max_loops: + # Keep reading data until search_pattern is found or until read_timeout + while time.time() - start_time < read_timeout: if new_data: output += new_data - past_three_reads.append(new_data) + past_n_reads.append(new_data) # Case where we haven't processed the first_line yet (there is a potential issue # in the first line (in cases where the line is repainted). @@ -3780,19 +4121,30 @@

    Classes

    break else: - # Check if pattern is in the past three reads - if re.search(search_pattern, "".join(past_three_reads)): - break - - time.sleep(delay_factor * loop_delay) - i += 1 + if len(output) <= MAX_CHARS: + if re.search(search_pattern, output): + break + else: + # Switch to deque mode if output is greater than MAX_CHARS + # Check if pattern is in the past n reads + if re.search(search_pattern, "".join(past_n_reads)): + break + + time.sleep(loop_delay) new_data = self.read_channel() + else: # nobreak - raise IOError( - "Search pattern never detected in send_command: {}".format( - search_pattern - ) - ) + msg = f""" +Pattern not detected: {repr(search_pattern)} in output. + +Things you might try to fix this: +1. Explicitly set your pattern using the expect_string argument. +2. Increase the read_timeout to a larger value. + +You can also look at the Netmiko session_log or debug log for more information. + +""" + raise ReadTimeout(msg) output = self._sanitize_output( output, @@ -3800,45 +4152,98 @@

    Classes

    command_string=command_string, strip_prompt=strip_prompt, ) + return_val = structured_data_converter( + command=command_string, + raw_data=output, + platform=self.device_type, + use_textfsm=use_textfsm, + use_ttp=use_ttp, + use_genie=use_genie, + textfsm_template=textfsm_template, + ttp_template=ttp_template, + ) + return return_val - # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie - if use_textfsm: - structured_output = get_structured_data( - output, - platform=self.device_type, - command=command_string.strip(), - template=textfsm_template, - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_ttp: - structured_output = get_structured_data_ttp(output, template=ttp_template) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output - if use_genie: - structured_output = get_structured_data_genie( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, str): - return structured_output + def _send_command_str(self, *args: Any, **kwargs: Any) -> str: + """Wrapper for `send_command` method that always returns a string""" + output = self.send_command(*args, **kwargs) + assert isinstance(output, str) return output - def send_command_expect(self, *args, **kwargs): - """Support previous name of send_command method. + def send_command_expect( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: + """Support previous name of send_command method.""" + return self.send_command(*args, **kwargs) + + def _multiline_kwargs(self, **kwargs: Any) -> Dict[str, Any]: + strip_prompt = kwargs.get("strip_prompt", False) + kwargs["strip_prompt"] = strip_prompt + strip_command = kwargs.get("strip_command", False) + kwargs["strip_command"] = strip_command + return kwargs + + def send_multiline( + self, + commands: Sequence[Union[str, List[str]]], + multiline: bool = True, + **kwargs: Any, + ) -> str: + """ + commands should either be: + + commands = [[cmd1, expect1], [cmd2, expect2], ...]] + + Or - :param args: Positional arguments to send to send_command() - :type args: list + commands = [cmd1, cmd2, cmd3, ...] + + Any expect_string that is a null-string will use pattern based on + device's prompt (unless expect_string argument is passed in via + kwargs. - :param kwargs: Keyword arguments to send to send_command() - :type kwargs: dict """ - return self.send_command(*args, **kwargs) + output = "" + if multiline: + kwargs = self._multiline_kwargs(**kwargs) + + default_expect_string = kwargs.pop("expect_string", None) + if not default_expect_string: + auto_find_prompt = kwargs.get("auto_find_prompt", True) + default_expect_string = self._prompt_handler(auto_find_prompt) + + if commands and isinstance(commands[0], str): + # If list of commands just send directly using default_expect_string (probably prompt) + for cmd in commands: + cmd = str(cmd) + output += self._send_command_str( + cmd, expect_string=default_expect_string, **kwargs + ) + else: + # If list of lists, then first element is cmd and second element is expect_string + for cmd_item in commands: + assert not isinstance(cmd_item, str) + cmd, expect_string = cmd_item + if not expect_string: + expect_string = default_expect_string + output += self._send_command_str( + cmd, expect_string=expect_string, **kwargs + ) + return output + + def send_multiline_timing( + self, commands: Sequence[str], multiline: bool = True, **kwargs: Any + ) -> str: + if multiline: + kwargs = self._multiline_kwargs(**kwargs) + output = "" + for cmd in commands: + cmd = str(cmd) + output += self._send_command_timing_str(cmd, **kwargs) + return output @staticmethod - def strip_backspaces(output): + def strip_backspaces(output: str) -> str: """Strip any backspace characters out of the output. :param output: Output obtained from a remote network device. @@ -3847,7 +4252,7 @@

    Classes

    backspace_char = "\x08" return output.replace(backspace_char, "") - def strip_command(self, command_string, output): + def strip_command(self, command_string: str, output: str) -> str: """ Strip command_string from output string @@ -3876,7 +4281,7 @@

    Classes

    # command_string isn't there; do nothing return output - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Convert `\r\r\n`,`\r\n`, `\n\r` to `\n.` :param a_string: A string that may have non-normalized line feeds @@ -3891,7 +4296,7 @@

    Classes

    else: return a_string - def normalize_cmd(self, command): + def normalize_cmd(self, command: str) -> str: """Normalize CLI commands to have a single trailing newline. :param command: Command that may require line feed to be normalized @@ -3901,32 +4306,32 @@

    Classes

    command += self.RETURN return command - def check_enable_mode(self, check_string=""): + def check_enable_mode(self, check_string: str = "") -> bool: """Check if in enable mode. Return boolean. :param check_string: Identification of privilege mode from device :type check_string: str """ self.write_channel(self.RETURN) - output = self.read_until_prompt() + output = self.read_until_prompt(read_entire_line=True) return check_string in output def enable( - self, cmd="", pattern="ssword", enable_pattern=None, re_flags=re.IGNORECASE - ): + self, + cmd: str = "", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode. :param cmd: Device command to enter enable mode - :type cmd: str :param pattern: pattern to search for indicating device is waiting for password - :type pattern: str :param enable_pattern: pattern indicating you have entered enable mode - :type pattern: str :param re_flags: Regular expression flags used in conjunction with pattern - :type re_flags: int """ output = "" msg = ( @@ -3965,7 +4370,7 @@

    Classes

    raise ValueError(msg) return output - def exit_enable_mode(self, exit_command=""): + def exit_enable_mode(self, exit_command: str = "") -> str: """Exit enable mode. :param exit_command: Command that exits the session from privileged mode @@ -3979,7 +4384,7 @@

    Classes

    raise ValueError("Failed to exit enable mode.") return output - def check_config_mode(self, check_string="", pattern=""): + def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not. :param check_string: Identification of configuration mode from the device @@ -3991,12 +4396,14 @@

    Classes

    self.write_channel(self.RETURN) # You can encounter an issue here (on router name changes) prefer delay-based solution if not pattern: - output = self._read_channel_timing() + output = self.read_channel_timing() else: output = self.read_until_pattern(pattern=pattern) return check_string in output - def config_mode(self, config_command="", pattern="", re_flags=0): + def config_mode( + self, config_command: str = "", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter into config_mode. :param config_command: Configuration command to send to the device @@ -4016,13 +4423,15 @@

    Classes

    output += self.read_until_pattern( pattern=re.escape(config_command.strip()) ) - if not re.search(pattern, output, flags=re_flags): + if pattern: output += self.read_until_pattern(pattern=pattern, re_flags=re_flags) + else: + output += self.read_until_prompt(read_entire_line=True) if not self.check_config_mode(): raise ValueError("Failed to enter configuration mode.") return output - def exit_config_mode(self, exit_config="", pattern=""): + def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str: """Exit from configuration mode. :param exit_config: Command to exit configuration mode @@ -4039,14 +4448,18 @@

    Classes

    output += self.read_until_pattern( pattern=re.escape(exit_config.strip()) ) - if not re.search(pattern, output, flags=re.M): + if pattern: output += self.read_until_pattern(pattern=pattern) + else: + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") log.debug(f"exit_config_mode: {output}") return output - def send_config_from_file(self, config_file=None, **kwargs): + def send_config_from_file( + self, config_file: Union[str, bytes, "PathLike[Any]"], **kwargs: Any + ) -> str: """ Send configuration commands down the SSH channel from a file. @@ -4056,27 +4469,30 @@

    Classes

    **kwargs are passed to send_config_set method. :param config_file: Path to configuration file to be sent to the device - :type config_file: str :param kwargs: params to be sent to send_config_set method - :type kwargs: dict """ with io.open(config_file, "rt", encoding="utf-8") as cfg_file: - return self.send_config_set(cfg_file, **kwargs) + commands = cfg_file.readlines() + return self.send_config_set(commands, **kwargs) def send_config_set( self, - config_commands=None, - exit_config_mode=True, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - cmd_verify=True, - enter_config_mode=True, - error_pattern="", - ): + config_commands: Union[str, Sequence[str], TextIO, None] = None, + *, + exit_config_mode: bool = True, + read_timeout: Optional[float] = None, + delay_factor: Optional[float] = None, + max_loops: Optional[int] = None, + strip_prompt: bool = False, + strip_command: bool = False, + config_mode_command: Optional[str] = None, + cmd_verify: bool = True, + enter_config_mode: bool = True, + error_pattern: str = "", + terminator: str = r"#", + bypass_commands: Optional[str] = None, + ) -> str: """ Send configuration commands down the SSH channel. @@ -4086,37 +4502,64 @@

    Classes

    Automatically exits/enters configuration mode. :param config_commands: Multiple configuration commands to be sent to the device - :type config_commands: list or string :param exit_config_mode: Determines whether or not to exit config mode after complete - :type exit_config_mode: bool - :param delay_factor: Factor to adjust delays - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor (default: 150) - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Determines whether or not to strip the prompt - :type strip_prompt: bool :param strip_command: Determines whether or not to strip the command - :type strip_command: bool + + :param read_timeout: Absolute timer to send to read_channel_timing. Should be rarely needed. :param config_mode_command: The command to enter into config mode - :type config_mode_command: str :param cmd_verify: Whether or not to verify command echo for each command in config_set - :type cmd_verify: bool :param enter_config_mode: Do you enter config mode before sending config commands - :type exit_config_mode: bool :param error_pattern: Regular expression pattern to detect config errors in the output. - :type error_pattern: str + + :param terminator: Regular expression pattern to use as an alternate terminator in certain + situations. + + :param bypass_commands: Regular expression pattern indicating configuration commands + where cmd_verify is automatically disabled. """ - delay_factor = self.select_delay_factor(delay_factor) + + if self.global_cmd_verify is not None: + cmd_verify = self.global_cmd_verify + + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + + # Calculate an equivalent read_timeout (if using old settings) + # Eliminate in Netmiko 5.x + if read_timeout is None: + max_loops = 150 if max_loops is None else max_loops + delay_factor = 1.0 if delay_factor is None else delay_factor + + # If delay_factor has been set, then look at global_delay_factor + delay_factor = self.select_delay_factor(delay_factor) + + read_timeout = calc_old_timeout( + max_loops=max_loops, delay_factor=delay_factor, loop_delay=0.1 + ) + + if delay_factor is None: + delay_factor = self.select_delay_factor(0) + else: + delay_factor = self.select_delay_factor(delay_factor) + + if read_timeout is None: + read_timeout = 15 + else: + read_timeout = read_timeout + if config_commands is None: return "" elif isinstance(config_commands, str): @@ -4125,20 +4568,33 @@

    Classes

    if not hasattr(config_commands, "__iter__"): raise ValueError("Invalid argument passed into send_config_set") + if bypass_commands is None: + # Commands where cmd_verify is automatically disabled reg-ex logical-or + bypass_commands = r"^banner .*$" + + # Set bypass_commands="" to force no-bypass (usually for testing) + bypass_detected = False + if bypass_commands: + bypass_detected = any( + [True for cmd in config_commands if re.search(bypass_commands, cmd)] + ) + if bypass_detected: + cmd_verify = False + # Send config commands output = "" if enter_config_mode: - cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() - output += self.config_mode(*cfg_mode_args) + if config_mode_command: + output += self.config_mode(config_mode_command) + else: + output += self.config_mode() - # If error_pattern is perform output gathering line by line and not fast_cli mode. + # Perform output gathering line-by-line (legacy way) if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) elif not cmd_verify: for cmd in config_commands: @@ -4147,35 +4603,25 @@

    Classes

    # Gather the output incrementally due to error_pattern requirements if error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) if re.search(error_pattern, output, flags=re.M): msg = f"Invalid input detected at command: {cmd}" raise ConfigInvalidException(msg) # Standard output gathering (no error_pattern) if not error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Make sure command is echoed - new_output = self.read_until_pattern(pattern=re.escape(cmd.strip())) - output += new_output - - # We might capture next prompt in the original read - pattern = f"(?:{re.escape(self.base_prompt)}|#)" - if not re.search(pattern, new_output): - # Make sure trailing prompt comes back (after command) - # NX-OS has fast-buffering problem where it immediately echoes command - # Even though the device hasn't caught up with processing command. - new_output = self.read_until_pattern(pattern=pattern) - output += new_output + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + + # Read until next prompt or terminator (#); the .*$ forces read of entire line + pattern = f"(?:{re.escape(self.base_prompt)}.*$|{terminator}.*$)" + output += self.read_until_pattern(pattern=pattern, re_flags=re.M) if error_pattern: if re.search(error_pattern, output, flags=re.M): @@ -4188,7 +4634,7 @@

    Classes

    log.debug(f"{output}") return output - def strip_ansi_escape_codes(self, string_buffer): + def strip_ansi_escape_codes(self, string_buffer: str) -> str: """ Remove any ANSI (VT100) ESC codes from the output @@ -4209,10 +4655,11 @@

    Classes

    ESC[?6l Reset mode screen with options 640 x 200 monochrome (graphics) ESC[?7l Disable line wrapping ESC[2J Code erase display - ESC[00;32m Color Green (30 to 37 are different colors) more general pattern is - ESC[\d\d;\d\dm and ESC[\d\d;\d\d;\d\dm + ESC[00;32m Color Green (30 to 37 are different colors) ESC[6n Get cursor position ESC[1D Move cursor position leftward by x characters (1 in this case) + ESC[9999B Move cursor down N-lines (very large value is attempt to move to the + very bottom of the screen). HP ProCurve and Cisco SG300 require this (possible others). @@ -4234,7 +4681,8 @@

    Classes

    code_reset_graphics_mode = chr(27) + r"\[00m" code_erase_display = chr(27) + r"\[2J" code_erase_display_0 = chr(27) + r"\[J" - code_graphics_mode = chr(27) + r"\[\d\d;\d\dm" + code_graphics_mode = chr(27) + r"\[\dm" + code_graphics_mode1 = chr(27) + r"\[\d\d;\d\dm" code_graphics_mode2 = chr(27) + r"\[\d\d;\d\d;\d\dm" code_graphics_mode3 = chr(27) + r"\[(3|4)\dm" code_graphics_mode4 = chr(27) + r"\[(9|10)[0-7]m" @@ -4243,6 +4691,11 @@

    Classes

    code_attrs_off = chr(27) + r"\[0m" code_reverse = chr(27) + r"\[7m" code_cursor_left = chr(27) + r"\[\d+D" + code_cursor_forward = chr(27) + r"\[\d*C" + code_cursor_up = chr(27) + r"\[\d*A" + code_cursor_down = chr(27) + r"\[\d*B" + code_wrap_around = chr(27) + r"\[\?7h" + code_bracketed_paste_mode = chr(27) + r"\[\?2004h" code_set = [ code_position_cursor, @@ -4257,6 +4710,7 @@

    Classes

    code_reset_graphics_mode, code_erase_display, code_graphics_mode, + code_graphics_mode1, code_graphics_mode2, code_graphics_mode3, code_graphics_mode4, @@ -4267,6 +4721,11 @@

    Classes

    code_attrs_off, code_reverse, code_cursor_left, + code_cursor_up, + code_cursor_down, + code_cursor_forward, + code_wrap_around, + code_bracketed_paste_mode, ] output = string_buffer @@ -4285,24 +4744,27 @@

    Classes

    return output - def cleanup(self, command=""): + def cleanup(self, command: str = "") -> None: """Logout of the session on the network device plus any additional cleanup.""" pass - def paramiko_cleanup(self): + def paramiko_cleanup(self) -> None: """Cleanup Paramiko to try to gracefully handle SSH session ending.""" - self.remote_conn_pre.close() + if self.remote_conn_pre is not None: + self.remote_conn_pre.close() del self.remote_conn_pre - def disconnect(self): + def disconnect(self) -> None: """Try to gracefully close the session.""" try: self.cleanup() if self.protocol == "ssh": self.paramiko_cleanup() elif self.protocol == "telnet": + assert isinstance(self.remote_conn, telnetlib.Telnet) self.remote_conn.close() elif self.protocol == "serial": + assert isinstance(self.remote_conn, serial.Serial) self.remote_conn.close() except Exception: # There have been race conditions observed on disconnect. @@ -4310,31 +4772,25 @@

    Classes

    finally: self.remote_conn_pre = None self.remote_conn = None - self.close_session_log() + if self.session_log: + self.session_log.close() - def commit(self): + def commit(self) -> str: """Commit method for platforms that support this.""" raise AttributeError("Network device does not support 'commit()' method") - def save_config(self, *args, **kwargs): + def save_config( + self, cmd: str = "", confirm: bool = False, confirm_response: str = "" + ) -> str: """Not Implemented""" raise NotImplementedError - def open_session_log(self, filename, mode="write"): - """Open the session_log file.""" - if mode == "append": - self.session_log = open(filename, mode="a", encoding=self.encoding) - else: - self.session_log = open(filename, mode="w", encoding=self.encoding) - self._session_log_close = True - - def close_session_log(self): - """Close the session_log file (if it is a file that we opened).""" - if self.session_log is not None and self._session_log_close: - self.session_log.close() - self.session_log = None - - def run_ttp(self, template, res_kwargs={}, **kwargs): + def run_ttp( + self, + template: Union[str, bytes, "PathLike[Any]"], + res_kwargs: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> Any: """ Run TTP template parsing by using input parameters to collect devices output. @@ -4342,29 +4798,25 @@

    Classes

    :param template: template content, OS path to template or reference to template within TTP templates collection in ttp://path/to/template.txt format - :type template: str :param res_kwargs: ``**res_kwargs`` arguments to pass to TTP result method - :type res_kwargs: dict :param kwargs: any other ``**kwargs`` to use for TTP object instantiation - :type kwargs: dict TTP template must have inputs defined together with below parameters. :param method: name of Netmiko connection object method to call, default ``send_command`` - :type method: str :param kwargs: Netmiko connection object method arguments - :type kwargs: dict :param commands: list of commands to collect - :type commands: list Inputs' load could be of one of the supported formats and controlled by input's ``load`` attribute, supported values - python, yaml or json. For each input output collected from device and parsed accordingly. """ + if res_kwargs is None: + res_kwargs = {} return run_ttp_template( connection=self, template=template, res_kwargs=res_kwargs, **kwargs )
    @@ -4404,7 +4856,7 @@

    Static methods

    Source code
    @staticmethod
    -def strip_backspaces(output):
    +def strip_backspaces(output: str) -> str:
         """Strip any backspace characters out of the output.
     
         :param output: Output obtained from a remote network device.
    @@ -4428,7 +4880,7 @@ 

    Methods

    :type pattern: str

    Source code -
    def check_config_mode(self, check_string="", pattern=""):
    +
    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode or not.
     
         :param check_string: Identification of configuration mode from the device
    @@ -4440,7 +4892,7 @@ 

    Methods

    self.write_channel(self.RETURN) # You can encounter an issue here (on router name changes) prefer delay-based solution if not pattern: - output = self._read_channel_timing() + output = self.read_channel_timing() else: output = self.read_until_pattern(pattern=pattern) return check_string in output
    @@ -4455,14 +4907,14 @@

    Methods

    :type check_string: str

    Source code -
    def check_enable_mode(self, check_string=""):
    +
    def check_enable_mode(self, check_string: str = "") -> bool:
         """Check if in enable mode. Return boolean.
     
         :param check_string: Identification of privilege mode from device
         :type check_string: str
         """
         self.write_channel(self.RETURN)
    -    output = self.read_until_prompt()
    +    output = self.read_until_prompt(read_entire_line=True)
         return check_string in output
    @@ -4473,45 +4925,70 @@

    Methods

    Logout of the session on the network device plus any additional cleanup.

    Source code -
    def cleanup(self, command=""):
    +
    def cleanup(self, command: str = "") -> None:
         """Logout of the session on the network device plus any additional cleanup."""
         pass
    -def clear_buffer(self, backoff=True) +def clear_buffer(self, backoff=True, backoff_max=3.0, delay_factor=None)

    Read any data available in the channel.

    Source code -
    def clear_buffer(self, backoff=True):
    +
    def clear_buffer(
    +    self,
    +    backoff: bool = True,
    +    backoff_max: float = 3.0,
    +    delay_factor: Optional[float] = None,
    +) -> str:
         """Read any data available in the channel."""
    -    sleep_time = 0.1 * self.global_delay_factor
    +
    +    if delay_factor is None:
    +        delay_factor = self.global_delay_factor
    +    sleep_time = 0.1 * delay_factor
    +
    +    output = ""
         for _ in range(10):
             time.sleep(sleep_time)
             data = self.read_channel()
    +        data = self.strip_ansi_escape_codes(data)
    +        output += data
             if not data:
                 break
             # Double sleep time each time we detect data
             log.debug("Clear buffer detects data in the channel")
             if backoff:
                 sleep_time *= 2
    -            sleep_time = 3 if sleep_time >= 3 else sleep_time
    + sleep_time = backoff_max if sleep_time >= backoff_max else sleep_time + return output
    -
    -def close_session_log(self) +
    +def command_echo_read(self, cmd, read_timeout)
    -

    Close the session_log file (if it is a file that we opened).

    +
    Source code -
    def close_session_log(self):
    -    """Close the session_log file (if it is a file that we opened)."""
    -    if self.session_log is not None and self._session_log_close:
    -        self.session_log.close()
    -        self.session_log = None
    +
    def command_echo_read(self, cmd: str, read_timeout: float) -> str:
    +
    +    # Make sure you read until you detect the command echo (avoid getting out of sync)
    +    new_data = self.read_until_pattern(
    +        pattern=re.escape(cmd), read_timeout=read_timeout
    +    )
    +
    +    # There can be echoed prompts that haven't been cleared before the cmd echo
    +    # this can later mess up the trailing prompt pattern detection. Clear this out.
    +    lines = new_data.split(cmd)
    +    if len(lines) == 2:
    +        # lines[-1] should realistically just be the null string
    +        new_data = f"{cmd}{lines[-1]}"
    +    else:
    +        # cmd exists in the output multiple times? Just retain the original output
    +        pass
    +    return new_data
    @@ -4521,7 +4998,7 @@

    Methods

    Commit method for platforms that support this.

    Source code -
    def commit(self):
    +
    def commit(self) -> str:
         """Commit method for platforms that support this."""
         raise AttributeError("Network device does not support 'commit()' method")
    @@ -4539,7 +5016,9 @@

    Methods

    :type re_flags: RegexFlag

    Source code -
    def config_mode(self, config_command="", pattern="", re_flags=0):
    +
    def config_mode(
    +    self, config_command: str = "", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter into config_mode.
     
         :param config_command: Configuration command to send to the device
    @@ -4559,45 +5038,51 @@ 

    Methods

    output += self.read_until_pattern( pattern=re.escape(config_command.strip()) ) - if not re.search(pattern, output, flags=re_flags): + if pattern: output += self.read_until_pattern(pattern=pattern, re_flags=re_flags) + else: + output += self.read_until_prompt(read_entire_line=True) if not self.check_config_mode(): raise ValueError("Failed to enter configuration mode.") return output
    -def disable_paging(self, command='terminal length 0', delay_factor=1, cmd_verify=True, pattern=None) +def disable_paging(self, command='terminal length 0', delay_factor=None, cmd_verify=True, pattern=None)

    Disable paging default to a Cisco CLI method.

    -

    :param command: Device command to disable pagination of output -:type command: str

    -

    :param delay_factor: See init: global_delay_factor -:type delay_factor: int

    +

    :param command: Device command to disable pagination of output

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code
    def disable_paging(
    -    self, command="terminal length 0", delay_factor=1, cmd_verify=True, pattern=None
    -):
    +    self,
    +    command: str = "terminal length 0",
    +    delay_factor: Optional[float] = None,
    +    cmd_verify: bool = True,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Disable paging default to a Cisco CLI method.
     
         :param command: Device command to disable pagination of output
    -    :type command: str
     
    -    :param delay_factor: See __init__: global_delay_factor
    -    :type delay_factor: int
    +    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
         """
    -    delay_factor = self.select_delay_factor(delay_factor)
    +    if delay_factor is not None:
    +        warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning)
    +
         command = self.normalize_cmd(command)
         log.debug("In disable_paging")
         log.debug(f"Command: {command}")
         self.write_channel(command)
         # Make sure you read until you detect the command echo (avoid getting out of sync)
         if cmd_verify and self.global_cmd_verify is not False:
    -        output = self.read_until_pattern(pattern=re.escape(command.strip()))
    +        output = self.read_until_pattern(
    +            pattern=re.escape(command.strip()), read_timeout=20
    +        )
         elif pattern:
    -        output = self.read_until_pattern(pattern=pattern)
    +        output = self.read_until_pattern(pattern=pattern, read_timeout=20)
         else:
             output = self.read_until_prompt()
         log.debug(f"{output}")
    @@ -4612,15 +5097,17 @@ 

    Methods

    Try to gracefully close the session.

    Source code -
    def disconnect(self):
    +
    def disconnect(self) -> None:
         """Try to gracefully close the session."""
         try:
             self.cleanup()
             if self.protocol == "ssh":
                 self.paramiko_cleanup()
             elif self.protocol == "telnet":
    +            assert isinstance(self.remote_conn, telnetlib.Telnet)
                 self.remote_conn.close()
             elif self.protocol == "serial":
    +            assert isinstance(self.remote_conn, serial.Serial)
                 self.remote_conn.close()
         except Exception:
             # There have been race conditions observed on disconnect.
    @@ -4628,7 +5115,8 @@ 

    Methods

    finally: self.remote_conn_pre = None self.remote_conn = None - self.close_session_log()
    + if self.session_log: + self.session_log.close()
    @@ -4636,32 +5124,28 @@

    Methods

    Enter enable mode.

    -

    :param cmd: Device command to enter enable mode -:type cmd: str

    -

    :param pattern: pattern to search for indicating device is waiting for password -:type pattern: str

    -

    :param enable_pattern: pattern indicating you have entered enable mode -:type pattern: str

    -

    :param re_flags: Regular expression flags used in conjunction with pattern -:type re_flags: int

    +

    :param cmd: Device command to enter enable mode

    +

    :param pattern: pattern to search for indicating device is waiting for password

    +

    :param enable_pattern: pattern indicating you have entered enable mode

    +

    :param re_flags: Regular expression flags used in conjunction with pattern

    Source code
    def enable(
    -    self, cmd="", pattern="ssword", enable_pattern=None, re_flags=re.IGNORECASE
    -):
    +    self,
    +    cmd: str = "",
    +    pattern: str = "ssword",
    +    enable_pattern: Optional[str] = None,
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
         """Enter enable mode.
     
         :param cmd: Device command to enter enable mode
    -    :type cmd: str
     
         :param pattern: pattern to search for indicating device is waiting for password
    -    :type pattern: str
     
         :param enable_pattern: pattern indicating you have entered enable mode
    -    :type pattern: str
     
         :param re_flags: Regular expression flags used in conjunction with pattern
    -    :type re_flags: int
         """
         output = ""
         msg = (
    @@ -4714,7 +5198,7 @@ 

    Methods

    :type height: int

    Source code -
        def establish_connection(self, width=511, height=1000):
    +
        def establish_connection(self, width: int = 511, height: int = 1000) -> None:
             """Establish SSH connection to the network device
     
             Timeout will generate a NetmikoTimeoutException
    @@ -4726,16 +5210,21 @@ 

    Methods

    :param height: Specified height of the VT100 terminal window (default: 1000) :type height: int """ + self.channel: Channel if self.protocol == "telnet": self.remote_conn = telnetlib.Telnet( self.host, port=self.port, timeout=self.timeout ) + # Migrating communication to channel class + self.channel = TelnetChannel(conn=self.remote_conn, encoding=self.encoding) self.telnet_login() elif self.protocol == "serial": self.remote_conn = serial.Serial(**self.serial_settings) + self.channel = SerialChannel(conn=self.remote_conn, encoding=self.encoding) self.serial_login() elif self.protocol == "ssh": ssh_connect_params = self._connect_params_dict() + self.remote_conn_pre: Optional[paramiko.SSHClient] self.remote_conn_pre = self._build_ssh_client() # initiate SSH connection @@ -4778,16 +5267,22 @@

    Methods

    msg += self.RETURN + str(auth_err) raise NetmikoAuthenticationException(msg) - except paramiko.ssh_exception.SSHException as no_session_err: + except paramiko.ssh_exception.SSHException as e: self.paramiko_cleanup() - if "No existing session" in str(no_session_err): + if "No existing session" in str(e): msg = ( "Paramiko: 'No existing session' error: " - "try increasing 'conn_timeout' to 10 seconds or larger." + "try increasing 'conn_timeout' to 15 seconds or larger." ) raise NetmikoTimeoutException(msg) else: - raise + msg = f""" +A paramiko SSHException occurred during connection creation: + +{str(e)} + +""" + raise NetmikoTimeoutException(msg) if self.verbose: print(f"SSH connection established to {self.host}:{self.port}") @@ -4799,11 +5294,17 @@

    Methods

    self.remote_conn.settimeout(self.blocking_timeout) if self.keepalive: + assert isinstance(self.remote_conn.transport, paramiko.Transport) self.remote_conn.transport.set_keepalive(self.keepalive) + + # Migrating communication to channel class + self.channel = SSHChannel(conn=self.remote_conn, encoding=self.encoding) + self.special_login_handler() if self.verbose: print("Interactive SSH session established") - return ""
    + + return None
    @@ -4817,7 +5318,7 @@

    Methods

    :type pattern: str

    Source code -
    def exit_config_mode(self, exit_config="", pattern=""):
    +
    def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str:
         """Exit from configuration mode.
     
         :param exit_config: Command to exit configuration mode
    @@ -4834,8 +5335,10 @@ 

    Methods

    output += self.read_until_pattern( pattern=re.escape(exit_config.strip()) ) - if not re.search(pattern, output, flags=re.M): + if pattern: output += self.read_until_pattern(pattern=pattern) + else: + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") log.debug(f"exit_config_mode: {output}") @@ -4851,7 +5354,7 @@

    Methods

    :type exit_command: str

    Source code -
    def exit_enable_mode(self, exit_command=""):
    +
    def exit_enable_mode(self, exit_command: str = "") -> str:
         """Exit enable mode.
     
         :param exit_command: Command that exits the session from privileged mode
    @@ -4867,51 +5370,59 @@ 

    Methods

    -def find_prompt(self, delay_factor=1) +def find_prompt(self, delay_factor=1.0, pattern=None)

    Finds the current network device prompt, last line only.

    :param delay_factor: See init: global_delay_factor -:type delay_factor: int

    +:type delay_factor: int

    +

    :param pattern: Regular expression pattern to determine whether prompt is valid

    Source code -
    def find_prompt(self, delay_factor=1):
    +
    def find_prompt(
    +    self, delay_factor: float = 1.0, pattern: Optional[str] = None
    +) -> str:
         """Finds the current network device prompt, last line only.
     
         :param delay_factor: See __init__: global_delay_factor
         :type delay_factor: int
    +
    +    :param pattern: Regular expression pattern to determine whether prompt is valid
         """
         delay_factor = self.select_delay_factor(delay_factor)
    +    sleep_time = delay_factor * 0.25
         self.clear_buffer()
         self.write_channel(self.RETURN)
    -    sleep_time = delay_factor * 0.1
    -    time.sleep(sleep_time)
     
    -    # Initial attempt to get prompt
    -    prompt = self.read_channel().strip()
    -
    -    # Check if the only thing you received was a newline
    -    count = 0
    -    while count <= 12 and not prompt:
    +    if pattern:
    +        try:
    +            prompt = self.read_until_pattern(pattern=pattern)
    +        except ReadTimeout:
    +            pass
    +    else:
    +        # Initial read
    +        time.sleep(sleep_time)
             prompt = self.read_channel().strip()
    -        if not prompt:
    -            self.write_channel(self.RETURN)
    -            time.sleep(sleep_time)
    -            if sleep_time <= 3:
    -                # Double the sleep_time when it is small
    -                sleep_time *= 2
    -            else:
    -                sleep_time += 1
    -        count += 1
    +
    +        count = 0
    +        while count <= 12 and not prompt:
    +            if not prompt:
    +                self.write_channel(self.RETURN)
    +                time.sleep(sleep_time)
    +                prompt = self.read_channel().strip()
    +                if sleep_time <= 3:
    +                    # Double the sleep_time when it is small
    +                    sleep_time *= 2
    +                else:
    +                    sleep_time += 1
    +            count += 1
     
         # If multiple lines in the output take the last line
    -    prompt = self.normalize_linefeeds(prompt)
         prompt = prompt.split(self.RESPONSE_RETURN)[-1]
         prompt = prompt.strip()
    +    self.clear_buffer()
         if not prompt:
             raise ValueError(f"Unable to find prompt: {prompt}")
    -    time.sleep(delay_factor * 0.1)
    -    self.clear_buffer()
         log.debug(f"[find_prompt()]: prompt is {prompt}")
         return prompt
    @@ -4923,7 +5434,7 @@

    Methods

    Returns a boolean flag with the state of the connection.

    Source code -
    def is_alive(self):
    +
    def is_alive(self) -> bool:
         """Returns a boolean flag with the state of the connection."""
         null = chr(0)
         if self.remote_conn is None:
    @@ -4935,9 +5446,11 @@ 

    Methods

    # IAC = Interpret as Command; it comes before the NOP. log.debug("Sending IAC + NOP") # Need to send multiple times to test connection - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) - self.remote_conn.sock.sendall(telnetlib.IAC + telnetlib.NOP) + assert isinstance(self.remote_conn, telnetlib.Telnet) + telnet_socket = self.remote_conn.get_socket() + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) + telnet_socket.sendall(telnetlib.IAC + telnetlib.NOP) return True except AttributeError: return False @@ -4947,7 +5460,11 @@

    Methods

    # Try sending ASCII null byte to maintain the connection alive log.debug("Sending the NULL byte") self.write_channel(null) - return self.remote_conn.transport.is_active() + assert isinstance(self.remote_conn, paramiko.Channel) + assert self.remote_conn.transport is not None + result = self.remote_conn.transport.is_active() + assert isinstance(result, bool) + return result except (socket.error, EOFError): log.error("Unable to send", exc_info=True) # If unable to send, we can tell for sure that the connection is unusable @@ -4964,7 +5481,7 @@

    Methods

    :type command: str

    Source code -
    def normalize_cmd(self, command):
    +
    def normalize_cmd(self, command: str) -> str:
         """Normalize CLI commands to have a single trailing newline.
     
         :param command: Command that may require line feed to be normalized
    @@ -4990,7 +5507,7 @@ 

    Methods

    Source code -
    def normalize_linefeeds(self, a_string):
    +
    def normalize_linefeeds(self, a_string: str) -> str:
         """Convert `\r\r\n`,`\r\n`, `\n\r` to `\n.`
     
         :param a_string: A string that may have non-normalized line feeds
    @@ -5006,22 +5523,6 @@ 

    Methods

    return a_string
    -
    -def open_session_log(self, filename, mode='write') -
    -
    -

    Open the session_log file.

    -
    -Source code -
    def open_session_log(self, filename, mode="write"):
    -    """Open the session_log file."""
    -    if mode == "append":
    -        self.session_log = open(filename, mode="a", encoding=self.encoding)
    -    else:
    -        self.session_log = open(filename, mode="w", encoding=self.encoding)
    -    self._session_log_close = True
    -
    -
    def paramiko_cleanup(self)
    @@ -5029,9 +5530,10 @@

    Methods

    Cleanup Paramiko to try to gracefully handle SSH session ending.

    Source code -
    def paramiko_cleanup(self):
    +
    def paramiko_cleanup(self) -> None:
         """Cleanup Paramiko to try to gracefully handle SSH session ending."""
    -    self.remote_conn_pre.close()
    +    if self.remote_conn_pre is not None:
    +        self.remote_conn_pre.close()
         del self.remote_conn_pre
    @@ -5039,105 +5541,295 @@

    Methods

    def read_channel(self)
    -

    Generic handler that will read all the data from an SSH or telnet channel.

    +

    Generic handler that will read all the data from given channel.

    Source code -
    def read_channel(self):
    -    """Generic handler that will read all the data from an SSH or telnet channel."""
    -    output = ""
    -    self._lock_netmiko_session()
    -    try:
    -        output = self._read_channel()
    -    finally:
    -        # Always unlock the SSH channel, even on exception.
    -        self._unlock_netmiko_session()
    +
    @lock_channel
    +def read_channel(self) -> str:
    +    """Generic handler that will read all the data from given channel."""
    +    new_data = self.channel.read_channel()
    +    new_data = self.normalize_linefeeds(new_data)
    +    if self.ansi_escape_codes:
    +        new_data = self.strip_ansi_escape_codes(new_data)
    +    log.debug(f"read_channel: {new_data}")
    +    if self.session_log:
    +        self.session_log.write(new_data)
    +
    +    # If data had been previously saved to the buffer, the prepend it to output
    +    # do post read_channel so session_log/log doesn't record buffered data twice
    +    if self._read_buffer:
    +        output = self._read_buffer + new_data
    +        self._read_buffer = ""
    +    else:
    +        output = new_data
         return output
    -
    -def read_until_pattern(self, *args, **kwargs) +
    +def read_channel_timing(self, last_read=2.0, read_timeout=120.0, delay_factor=None, max_loops=None)
    -

    Read channel until pattern detected. Return ALL data available.

    +

    Read data on the channel based on timing delays.

    +

    General pattern is keep reading until no new data is read. +Once no new data is read wait last_read amount of time (one last read). +As long as no new data, then return data.

    +

    read_timeout is an absolute timer for how long to keep reading (which presupposes +we are still getting new data).

    +

    Setting read_timeout to zero will cause read_channel_timing to never expire based +on an absolute timeout. It will only complete based on timeout based on their being +no new data.

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code -
    def read_until_pattern(self, *args, **kwargs):
    -    """Read channel until pattern detected. Return ALL data available."""
    -    return self._read_channel_expect(*args, **kwargs)
    -
    -
    +
        def read_channel_timing(
    +        self,
    +        last_read: float = 2.0,
    +        read_timeout: float = 120.0,
    +        delay_factor: Optional[float] = None,
    +        max_loops: Optional[int] = None,
    +    ) -> str:
    +        """Read data on the channel based on timing delays.
    +
    +        General pattern is keep reading until no new data is read.
    +        Once no new data is read wait `last_read` amount of time (one last read).
    +        As long as no new data, then return data.
    +
    +        `read_timeout` is an absolute timer for how long to keep reading (which presupposes
    +        we are still getting new data).
    +
    +        Setting `read_timeout` to zero will cause read_channel_timing to never expire based
    +        on an absolute timeout. It will only complete based on timeout based on their being
    +        no new data.
    +
    +        :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
    +
    +        :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
    +        """
    +
    +        if delay_factor is not None or max_loops is not None:
    +            warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning)
    +
    +        if self.read_timeout_override:
    +            read_timeout = self.read_timeout_override
    +
    +        # Time to delay in each read loop
    +        loop_delay = 0.1
    +        channel_data = ""
    +        start_time = time.time()
    +
    +        # Set read_timeout to 0 to never timeout
    +        while (time.time() - start_time < read_timeout) or (not read_timeout):
    +            time.sleep(loop_delay)
    +            new_data = self.read_channel()
    +            # gather new output
    +            if new_data:
    +                channel_data += new_data
    +            # if we have some output, but nothing new, then do the last read
    +            elif channel_data != "":
    +                # Make sure really done (i.e. no new data)
    +                time.sleep(last_read)
    +                new_data = self.read_channel()
    +                if not new_data:
    +                    break
    +                else:
    +                    channel_data += new_data
    +        else:
    +            msg = f"""\n
    +read_channel_timing's absolute timer expired.
    +
    +The network device was continually outputting data for longer than {read_timeout}
    +seconds.
    +
    +If this is expected i.e. the command you are executing is continually emitting
    +data for a long period of time, then you can set 'read_timeout=x' seconds. If
    +you want Netmiko to keep reading indefinitely (i.e. to only stop when there is
    +no new data), then you can set 'read_timeout=0'.
    +
    +You can look at the Netmiko session_log or debug log for more information.
    +
    +"""
    +            raise ReadTimeout(msg)
    +        return channel_data
    + + +
    +def read_until_pattern(self, pattern='', read_timeout=10.0, re_flags=0, max_loops=None) +
    +
    +

    Read channel until pattern is detected.

    +

    Will return string up to and including pattern.

    +

    Returns ReadTimeout if pattern not detected in read_timeout seconds.

    +

    :param pattern: Regular expression pattern used to identify that reading is done.

    +

    :param read_timeout: maximum time to wait looking for pattern. Will raise ReadTimeout. +A read_timeout value of 0 will cause the loop to never timeout (i.e. it will keep +reading indefinitely until pattern is detected.

    +

    :param re_flags: regex flags used in conjunction with pattern (defaults to no flags).

    +

    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +
    +Source code +
        def read_until_pattern(
    +        self,
    +        pattern: str = "",
    +        read_timeout: float = 10.0,
    +        re_flags: int = 0,
    +        max_loops: Optional[int] = None,
    +    ) -> str:
    +        """Read channel until pattern is detected.
    +
    +        Will return string up to and including pattern.
    +
    +        Returns ReadTimeout if pattern not detected in read_timeout seconds.
    +
    +        :param pattern: Regular expression pattern used to identify that reading is done.
    +
    +        :param read_timeout: maximum time to wait looking for pattern. Will raise ReadTimeout.
    +            A read_timeout value of 0 will cause the loop to never timeout (i.e. it will keep
    +            reading indefinitely until pattern is detected.
    +
    +        :param re_flags: regex flags used in conjunction with pattern (defaults to no flags).
    +
    +        :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
    +        """
    +        if max_loops is not None:
    +            msg = """\n
    +Netmiko 4.x has deprecated the use of max_loops with read_until_pattern.
    +You should convert all uses of max_loops over to read_timeout=x
    +where x is the total number of seconds to wait before timing out.\n"""
    +            warnings.warn(msg, DeprecationWarning)
    +
    +        if self.read_timeout_override:
    +            read_timeout = self.read_timeout_override
    +
    +        output = ""
    +        loop_delay = 0.01
    +        start_time = time.time()
    +        # if read_timeout == 0 or 0.0 keep reading indefinitely
    +        while (time.time() - start_time < read_timeout) or (not read_timeout):
    +            output += self.read_channel()
    +            if re.search(pattern, output, flags=re_flags):
    +                results = re.split(pattern, output, maxsplit=1, flags=re_flags)
    +
    +                # The string matched by pattern must be retained in the output string.
    +                # re.split will do this if capturing parentesis are used.
    +                if len(results) == 2:
    +                    # no capturing parenthesis, convert and try again.
    +                    pattern = f"({pattern})"
    +                    results = re.split(pattern, output, maxsplit=1, flags=re_flags)
    +
    +                if len(results) != 3:
    +                    # well, we tried
    +                    msg = f"""Unable to successfully split output based on pattern:
    +pattern={pattern}
    +output={repr(output)}
    +results={results}
    +"""
    +                    raise ReadException(msg)
    +
    +                # Process such that everything before and including pattern is return.
    +                # Everything else is retained in the _read_buffer
    +                output, match_str, buffer = results
    +                output = output + match_str
    +                if buffer:
    +                    self._read_buffer += buffer
    +                log.debug(f"Pattern found: {pattern} {output}")
    +                return output
    +            time.sleep(loop_delay)
    +
    +        msg = f"""\n\nPattern not detected: {repr(pattern)} in output.
    +
    +Things you might try to fix this:
    +1. Adjust the regex pattern to better identify the terminating string. Note, in
    +many situations the pattern is automatically based on the network device's prompt.
    +2. Increase the read_timeout to a larger value.
    +
    +You can also look at the Netmiko session_log or debug log for more information.\n\n"""
    +        raise ReadTimeout(msg)
    +
    +
    -def read_until_prompt(self, *args, **kwargs) +def read_until_prompt(self, read_timeout=10.0, read_entire_line=False, re_flags=0, max_loops=None)
    -

    Read channel until self.base_prompt detected. Return ALL data available.

    +

    Read channel up to and including self.base_prompt.

    Source code -
    def read_until_prompt(self, *args, **kwargs):
    -    """Read channel until self.base_prompt detected. Return ALL data available."""
    -    return self._read_channel_expect(*args, **kwargs)
    +
    def read_until_prompt(
    +    self,
    +    read_timeout: float = 10.0,
    +    read_entire_line: bool = False,
    +    re_flags: int = 0,
    +    max_loops: Optional[int] = None,
    +) -> str:
    +    """Read channel up to and including self.base_prompt."""
    +    pattern = re.escape(self.base_prompt)
    +    if read_entire_line:
    +        pattern = f"{pattern}.*"
    +    return self.read_until_pattern(
    +        pattern=pattern,
    +        re_flags=re_flags,
    +        max_loops=max_loops,
    +        read_timeout=read_timeout,
    +    )
    -def read_until_prompt_or_pattern(self, pattern='', re_flags=0) +def read_until_prompt_or_pattern(self, pattern='', read_timeout=10.0, read_entire_line=False, re_flags=0, max_loops=None)
    -

    Read until either self.base_prompt or pattern is detected.

    -

    :param pattern: the pattern used to identify that the output is complete (i.e. stop -reading when pattern is detected). pattern will be combined with self.base_prompt to -terminate output reading when the first of self.base_prompt or pattern is detected. -:type pattern: regular expression string

    -

    :param re_flags: regex flags used in conjunction with pattern to search for prompt -(defaults to no flags) -:type re_flags: int

    +

    Read until either self.base_prompt or pattern is detected.

    Source code -
    def read_until_prompt_or_pattern(self, pattern="", re_flags=0):
    -    """Read until either self.base_prompt or pattern is detected.
    -
    -    :param pattern: the pattern used to identify that the output is complete (i.e. stop \
    -    reading when pattern is detected). pattern will be combined with self.base_prompt to \
    -    terminate output reading when the first of self.base_prompt or pattern is detected.
    -    :type pattern: regular expression string
    -
    -    :param re_flags: regex flags used in conjunction with pattern to search for prompt \
    -    (defaults to no flags)
    -    :type re_flags: int
    -
    -    """
    -    combined_pattern = re.escape(self.base_prompt)
    +
    def read_until_prompt_or_pattern(
    +    self,
    +    pattern: str = "",
    +    read_timeout: float = 10.0,
    +    read_entire_line: bool = False,
    +    re_flags: int = 0,
    +    max_loops: Optional[int] = None,
    +) -> str:
    +    """Read until either self.base_prompt or pattern is detected."""
    +    prompt_pattern = re.escape(self.base_prompt)
    +    if read_entire_line:
    +        prompt_pattern = f"{prompt_pattern}.*"
         if pattern:
    -        combined_pattern = r"({}|{})".format(combined_pattern, pattern)
    -    return self._read_channel_expect(combined_pattern, re_flags=re_flags)
    + combined_pattern = r"(?:{}|{})".format(prompt_pattern, pattern) + else: + combined_pattern = prompt_pattern + return self.read_until_pattern( + pattern=combined_pattern, + re_flags=re_flags, + max_loops=max_loops, + read_timeout=read_timeout, + )
    -def run_ttp(self, template, res_kwargs={}, **kwargs) +def run_ttp(self, template, res_kwargs=None, **kwargs)

    Run TTP template parsing by using input parameters to collect devices output.

    :param template: template content, OS path to template or reference to template within TTP templates collection in -ttp://path/to/template.txt format -:type template: str

    -

    :param res_kwargs: **res_kwargs arguments to pass to TTP result method -:type res_kwargs: dict

    -

    :param kwargs: any other **kwargs to use for TTP object instantiation -:type kwargs: dict

    +ttp://path/to/template.txt format

    +

    :param res_kwargs: **res_kwargs arguments to pass to TTP result method

    +

    :param kwargs: any other **kwargs to use for TTP object instantiation

    TTP template must have inputs defined together with below parameters.

    -

    :param method: name of Netmiko connection object method to call, default send_command -:type method: str

    -

    :param kwargs: Netmiko connection object method arguments -:type kwargs: dict

    -

    :param commands: list of commands to collect -:type commands: list

    +

    :param method: name of Netmiko connection object method to call, default send_command

    +

    :param kwargs: Netmiko connection object method arguments

    +

    :param commands: list of commands to collect

    Inputs' load could be of one of the supported formats and controlled by input's load attribute, supported values - python, yaml or json. For each input output collected from device and parsed accordingly.

    Source code -
    def run_ttp(self, template, res_kwargs={}, **kwargs):
    +
    def run_ttp(
    +    self,
    +    template: Union[str, bytes, "PathLike[Any]"],
    +    res_kwargs: Optional[Dict[str, Any]] = None,
    +    **kwargs: Any,
    +) -> Any:
         """
         Run TTP template parsing by using input parameters to collect
         devices output.
    @@ -5145,42 +5837,40 @@ 

    Methods

    :param template: template content, OS path to template or reference to template within TTP templates collection in ttp://path/to/template.txt format - :type template: str :param res_kwargs: ``**res_kwargs`` arguments to pass to TTP result method - :type res_kwargs: dict :param kwargs: any other ``**kwargs`` to use for TTP object instantiation - :type kwargs: dict TTP template must have inputs defined together with below parameters. :param method: name of Netmiko connection object method to call, default ``send_command`` - :type method: str :param kwargs: Netmiko connection object method arguments - :type kwargs: dict :param commands: list of commands to collect - :type commands: list Inputs' load could be of one of the supported formats and controlled by input's ``load`` attribute, supported values - python, yaml or json. For each input output collected from device and parsed accordingly. """ + if res_kwargs is None: + res_kwargs = {} return run_ttp_template( connection=self, template=template, res_kwargs=res_kwargs, **kwargs )
    -def save_config(self, *args, **kwargs) +def save_config(self, cmd='', confirm=False, confirm_response='')

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(
    +    self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -5195,7 +5885,7 @@

    Methods

    :type delay_factor: int

    Source code -
    def select_delay_factor(self, delay_factor):
    +
    def select_delay_factor(self, delay_factor: float) -> float:
         """
         Choose the greater of delay_factor or self.global_delay_factor (default).
         In fast_cli choose the lesser of delay_factor of self.global_delay_factor.
    @@ -5216,429 +5906,356 @@ 

    Methods

    -def send_command(self, command_string, expect_string=None, delay_factor=1, max_loops=500, auto_find_prompt=True, strip_prompt=True, strip_command=True, normalize=True, use_textfsm=False, textfsm_template=None, use_ttp=False, ttp_template=None, use_genie=False, cmd_verify=True) +def send_command(self, command_string, expect_string=None, read_timeout=10.0, delay_factor=None, max_loops=None, auto_find_prompt=True, strip_prompt=True, strip_command=True, normalize=True, use_textfsm=False, textfsm_template=None, use_ttp=False, ttp_template=None, use_genie=False, cmd_verify=True)

    Execute command_string on the SSH channel using a pattern-based mechanism. Generally used for show commands. By default this method will keep waiting to receive data until the network device prompt is detected. The current network device prompt will be determined automatically.

    -

    :param command_string: The command to be executed on the remote device. -:type command_string: str

    +

    :param command_string: The command to be executed on the remote device.

    :param expect_string: Regular expression pattern to use for determining end of output. -If left blank will default to being based on router prompt. -:type expect_string: str

    -

    :param delay_factor: Multiplying factor used to adjust delays (default: 1). -:type delay_factor: int

    -

    :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be -based upon self.timeout. -:type max_loops: int

    -

    :param strip_prompt: Remove the trailing router prompt from the output (default: True). -:type strip_prompt: bool

    -

    :param strip_command: Remove the echo of the command from the output (default: True). -:type strip_command: bool

    -

    :param normalize: Ensure the proper enter is sent at end of command (default: True). -:type normalize: bool

    -

    :param use_textfsm: Process command output through TextFSM template (default: False). -:type normalize: bool

    +If left blank will default to being based on router prompt.

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param strip_prompt: Remove the trailing router prompt from the output (default: True).

    +

    :param strip_command: Remove the echo of the command from the output (default: True).

    +

    :param normalize: Ensure the proper enter is sent at end of command (default: True).

    +

    :param use_textfsm: Process command output through TextFSM template (default: False).

    :param textfsm_template: Name of template to parse output with; can be fully qualified path, relative path, or name of file in current directory. (default: None).

    -

    :param use_ttp: Process command output through TTP template (default: False). -:type use_ttp: bool

    +

    :param use_ttp: Process command output through TTP template (default: False).

    :param ttp_template: Name of template to parse output with; can be fully qualified -path, relative path, or name of file in current directory. (default: None). -:type ttp_template: str

    -

    :param use_genie: Process command output through PyATS/Genie parser (default: False). -:type normalize: bool

    -

    :param cmd_verify: Verify command echo before proceeding (default: True). -:type cmd_verify: bool

    +path, relative path, or name of file in current directory. (default: None).

    +

    :param use_genie: Process command output through PyATS/Genie parser (default: False).

    +

    :param cmd_verify: Verify command echo before proceeding (default: True).

    Source code -
    @select_cmd_verify
    -def send_command(
    -    self,
    -    command_string,
    -    expect_string=None,
    -    delay_factor=1,
    -    max_loops=500,
    -    auto_find_prompt=True,
    -    strip_prompt=True,
    -    strip_command=True,
    -    normalize=True,
    -    use_textfsm=False,
    -    textfsm_template=None,
    -    use_ttp=False,
    -    ttp_template=None,
    -    use_genie=False,
    -    cmd_verify=True,
    -):
    -    """Execute command_string on the SSH channel using a pattern-based mechanism. Generally
    -    used for show commands. By default this method will keep waiting to receive data until the
    -    network device prompt is detected. The current network device prompt will be determined
    -    automatically.
    +
        @select_cmd_verify
    +    def send_command(
    +        self,
    +        command_string: str,
    +        expect_string: Optional[str] = None,
    +        read_timeout: float = 10.0,
    +        delay_factor: Optional[float] = None,
    +        max_loops: Optional[int] = None,
    +        auto_find_prompt: bool = True,
    +        strip_prompt: bool = True,
    +        strip_command: bool = True,
    +        normalize: bool = True,
    +        use_textfsm: bool = False,
    +        textfsm_template: Optional[str] = None,
    +        use_ttp: bool = False,
    +        ttp_template: Optional[str] = None,
    +        use_genie: bool = False,
    +        cmd_verify: bool = True,
    +    ) -> Union[str, List[Any], Dict[str, Any]]:
    +        """Execute command_string on the SSH channel using a pattern-based mechanism. Generally
    +        used for show commands. By default this method will keep waiting to receive data until the
    +        network device prompt is detected. The current network device prompt will be determined
    +        automatically.
     
    -    :param command_string: The command to be executed on the remote device.
    -    :type command_string: str
    +        :param command_string: The command to be executed on the remote device.
    +
    +        :param expect_string: Regular expression pattern to use for determining end of output.
    +            If left blank will default to being based on router prompt.
     
    -    :param expect_string: Regular expression pattern to use for determining end of output.
    -        If left blank will default to being based on router prompt.
    -    :type expect_string: str
    +        :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
     
    -    :param delay_factor: Multiplying factor used to adjust delays (default: 1).
    -    :type delay_factor: int
    +        :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
     
    -    :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be
    -        based upon self.timeout.
    -    :type max_loops: int
    +        :param strip_prompt: Remove the trailing router prompt from the output (default: True).
     
    -    :param strip_prompt: Remove the trailing router prompt from the output (default: True).
    -    :type strip_prompt: bool
    +        :param strip_command: Remove the echo of the command from the output (default: True).
     
    -    :param strip_command: Remove the echo of the command from the output (default: True).
    -    :type strip_command: bool
    +        :param normalize: Ensure the proper enter is sent at end of command (default: True).
     
    -    :param normalize: Ensure the proper enter is sent at end of command (default: True).
    -    :type normalize: bool
    +        :param use_textfsm: Process command output through TextFSM template (default: False).
     
    -    :param use_textfsm: Process command output through TextFSM template (default: False).
    -    :type normalize: bool
    +        :param textfsm_template: Name of template to parse output with; can be fully qualified
    +            path, relative path, or name of file in current directory. (default: None).
     
    -    :param textfsm_template: Name of template to parse output with; can be fully qualified
    -        path, relative path, or name of file in current directory. (default: None).
    +        :param use_ttp: Process command output through TTP template (default: False).
     
    -    :param use_ttp: Process command output through TTP template (default: False).
    -    :type use_ttp: bool
    +        :param ttp_template: Name of template to parse output with; can be fully qualified
    +            path, relative path, or name of file in current directory. (default: None).
     
    -    :param ttp_template: Name of template to parse output with; can be fully qualified
    -        path, relative path, or name of file in current directory. (default: None).
    -    :type ttp_template: str
    +        :param use_genie: Process command output through PyATS/Genie parser (default: False).
     
    -    :param use_genie: Process command output through PyATS/Genie parser (default: False).
    -    :type normalize: bool
    +        :param cmd_verify: Verify command echo before proceeding (default: True).
    +        """
     
    -    :param cmd_verify: Verify command echo before proceeding (default: True).
    -    :type cmd_verify: bool
    -    """
    +        # Time to delay in each read loop
    +        loop_delay = 0.025
     
    -    # Time to delay in each read loop
    -    loop_delay = 0.2
    +        if self.read_timeout_override:
    +            read_timeout = self.read_timeout_override
     
    -    # Default to making loop time be roughly equivalent to self.timeout (support old max_loops
    -    # and delay_factor arguments for backwards compatibility).
    -    delay_factor = self.select_delay_factor(delay_factor)
    -    if delay_factor == 1 and max_loops == 500:
    -        # Default arguments are being used; use self.timeout instead
    -        max_loops = int(self.timeout / loop_delay)
    +        if self.delay_factor_compat:
    +            # For compatibility calculate the old equivalent read_timeout
    +            # i.e. what it would have been in Netmiko 3.x
    +            if delay_factor is None:
    +                tmp_delay_factor = self.global_delay_factor
    +            else:
    +                tmp_delay_factor = self.select_delay_factor(delay_factor)
    +            compat_timeout = calc_old_timeout(
    +                max_loops=max_loops,
    +                delay_factor=tmp_delay_factor,
    +                loop_delay=0.2,
    +                old_timeout=self.timeout,
    +            )
    +            msg = f"""\n
    +You have chosen to use Netmiko's delay_factor compatibility mode for
    +send_command. This will revert Netmiko to behave similarly to how it
    +did in Netmiko 3.x (i.e. to use delay_factor/global_delay_factor and
    +max_loops).
    +
    +Using these parameters Netmiko has calculated an effective read_timeout
    +of {compat_timeout} and will set the read_timeout to this value.
    +
    +Please convert your code to that new format i.e.:
    +
    +    net_connect.send_command(cmd, read_timeout={compat_timeout})
    +
    +And then disable delay_factor_compat.
    +
    +delay_factor_compat will be removed in Netmiko 5.x.\n"""
    +            warnings.warn(msg, DeprecationWarning)
    +
    +            # Override the read_timeout with Netmiko 3.x way :-(
    +            read_timeout = compat_timeout
     
    -    # Find the current router prompt
    -    if expect_string is None:
    -        if auto_find_prompt:
    -            try:
    -                prompt = self.find_prompt(delay_factor=delay_factor)
    -            except ValueError:
    -                prompt = self.base_prompt
             else:
    -            prompt = self.base_prompt
    -        search_pattern = re.escape(prompt.strip())
    -    else:
    -        search_pattern = expect_string
    +            # No need for two deprecation messages so only display this if not using
    +            # delay_factor_compat
    +            if delay_factor is not None or max_loops is not None:
    +                msg = """\n
    +Netmiko 4.x has deprecated the use of delay_factor/max_loops with
    +send_command. You should convert all uses of delay_factor and max_loops
    +over to read_timeout=x where x is the total number of seconds to wait
    +before timing out.\n"""
    +                warnings.warn(msg, DeprecationWarning)
    +
    +        if expect_string is not None:
    +            search_pattern = expect_string
    +        else:
    +            search_pattern = self._prompt_handler(auto_find_prompt)
     
    -    if normalize:
    -        command_string = self.normalize_cmd(command_string)
    +        if normalize:
    +            command_string = self.normalize_cmd(command_string)
     
    -    time.sleep(delay_factor * loop_delay)
    -    self.clear_buffer()
    -    self.write_channel(command_string)
    -    new_data = ""
    +        # Start the clock
    +        start_time = time.time()
    +        self.write_channel(command_string)
    +        new_data = ""
     
    -    cmd = command_string.strip()
    -    # if cmd is just an "enter" skip this section
    -    if cmd and cmd_verify:
    -        # Make sure you read until you detect the command echo (avoid getting out of sync)
    -        new_data = self.read_until_pattern(pattern=re.escape(cmd))
    -        new_data = self.normalize_linefeeds(new_data)
    -        # Strip off everything before the command echo (to avoid false positives on the prompt)
    -        if new_data.count(cmd) == 1:
    -            new_data = new_data.split(cmd)[1:]
    -            new_data = self.RESPONSE_RETURN.join(new_data)
    -            new_data = new_data.lstrip()
    -            new_data = f"{cmd}{self.RESPONSE_RETURN}{new_data}"
    +        cmd = command_string.strip()
    +        if cmd and cmd_verify:
    +            new_data = self.command_echo_read(cmd=cmd, read_timeout=10)
     
    -    i = 1
    -    output = ""
    -    past_three_reads = deque(maxlen=3)
    -    first_line_processed = False
    +        MAX_CHARS = 2_000_000
    +        DEQUE_SIZE = 20
    +        output = ""
    +        # Check only the past N-reads. This is for the case where the output is
    +        # very large (i.e. searching a very large string for a pattern a whole bunch of times)
    +        past_n_reads: Deque[str] = deque(maxlen=DEQUE_SIZE)
    +        first_line_processed = False
     
    -    # Keep reading data until search_pattern is found or until max_loops is reached.
    -    while i <= max_loops:
    -        if new_data:
    -            output += new_data
    -            past_three_reads.append(new_data)
    -
    -            # Case where we haven't processed the first_line yet (there is a potential issue
    -            # in the first line (in cases where the line is repainted).
    -            if not first_line_processed:
    -                output, first_line_processed = self._first_line_handler(
    -                    output, search_pattern
    -                )
    -                # Check if we have already found our pattern
    -                if re.search(search_pattern, output):
    -                    break
    +        # Keep reading data until search_pattern is found or until read_timeout
    +        while time.time() - start_time < read_timeout:
    +            if new_data:
    +                output += new_data
    +                past_n_reads.append(new_data)
     
    -            else:
    -                # Check if pattern is in the past three reads
    -                if re.search(search_pattern, "".join(past_three_reads)):
    -                    break
    +                # Case where we haven't processed the first_line yet (there is a potential issue
    +                # in the first line (in cases where the line is repainted).
    +                if not first_line_processed:
    +                    output, first_line_processed = self._first_line_handler(
    +                        output, search_pattern
    +                    )
    +                    # Check if we have already found our pattern
    +                    if re.search(search_pattern, output):
    +                        break
     
    -        time.sleep(delay_factor * loop_delay)
    -        i += 1
    -        new_data = self.read_channel()
    -    else:  # nobreak
    -        raise IOError(
    -            "Search pattern never detected in send_command: {}".format(
    -                search_pattern
    -            )
    -        )
    +                else:
    +                    if len(output) <= MAX_CHARS:
    +                        if re.search(search_pattern, output):
    +                            break
    +                    else:
    +                        # Switch to deque mode if output is greater than MAX_CHARS
    +                        # Check if pattern is in the past n reads
    +                        if re.search(search_pattern, "".join(past_n_reads)):
    +                            break
    +
    +            time.sleep(loop_delay)
    +            new_data = self.read_channel()
     
    -    output = self._sanitize_output(
    -        output,
    -        strip_command=strip_command,
    -        command_string=command_string,
    -        strip_prompt=strip_prompt,
    -    )
    +        else:  # nobreak
    +            msg = f"""
    +Pattern not detected: {repr(search_pattern)} in output.
    +
    +Things you might try to fix this:
    +1. Explicitly set your pattern using the expect_string argument.
    +2. Increase the read_timeout to a larger value.
    +
    +You can also look at the Netmiko session_log or debug log for more information.
     
    -    # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie
    -    if use_textfsm:
    -        structured_output = get_structured_data(
    +"""
    +            raise ReadTimeout(msg)
    +
    +        output = self._sanitize_output(
                 output,
    -            platform=self.device_type,
    -            command=command_string.strip(),
    -            template=textfsm_template,
    +            strip_command=strip_command,
    +            command_string=command_string,
    +            strip_prompt=strip_prompt,
             )
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -    if use_ttp:
    -        structured_output = get_structured_data_ttp(output, template=ttp_template)
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -    if use_genie:
    -        structured_output = get_structured_data_genie(
    -            output, platform=self.device_type, command=command_string.strip()
    +        return_val = structured_data_converter(
    +            command=command_string,
    +            raw_data=output,
    +            platform=self.device_type,
    +            use_textfsm=use_textfsm,
    +            use_ttp=use_ttp,
    +            use_genie=use_genie,
    +            textfsm_template=textfsm_template,
    +            ttp_template=ttp_template,
             )
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -    return output
    + return return_val
    def send_command_expect(self, *args, **kwargs)
    -

    Support previous name of send_command method.

    -

    :param args: Positional arguments to send to send_command() -:type args: list

    -

    :param kwargs: Keyword arguments to send to send_command() -:type kwargs: dict

    +

    Support previous name of send_command method.

    Source code -
    def send_command_expect(self, *args, **kwargs):
    -    """Support previous name of send_command method.
    -
    -    :param args: Positional arguments to send to send_command()
    -    :type args: list
    -
    -    :param kwargs: Keyword arguments to send to send_command()
    -    :type kwargs: dict
    -    """
    +
    def send_command_expect(
    +    self, *args: Any, **kwargs: Any
    +) -> Union[str, List[Any], Dict[str, Any]]:
    +    """Support previous name of send_command method."""
         return self.send_command(*args, **kwargs)
    -def send_command_timing(self, command_string, delay_factor=1, max_loops=150, strip_prompt=True, strip_command=True, normalize=True, use_textfsm=False, textfsm_template=None, use_ttp=False, ttp_template=None, use_genie=False, cmd_verify=False, cmd_echo=None) +def send_command_timing(self, command_string, last_read=2.0, read_timeout=120.0, delay_factor=None, max_loops=None, strip_prompt=True, strip_command=True, normalize=True, use_textfsm=False, textfsm_template=None, use_ttp=False, ttp_template=None, use_genie=False, cmd_verify=False)

    Execute command_string on the SSH channel using a delay-based mechanism. Generally used for show commands.

    -

    :param command_string: The command to be executed on the remote device. -:type command_string: str

    -

    :param delay_factor: Multiplying factor used to adjust delays (default: 1). -:type delay_factor: int or float

    -

    :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be -based upon self.timeout. -:type max_loops: int

    -

    :param strip_prompt: Remove the trailing router prompt from the output (default: True). -:type strip_prompt: bool

    -

    :param strip_command: Remove the echo of the command from the output (default: True). -:type strip_command: bool

    -

    :param normalize: Ensure the proper enter is sent at end of command (default: True). -:type normalize: bool

    -

    :param use_textfsm: Process command output through TextFSM template (default: False). -:type use_textfsm: bool

    +

    :param command_string: The command to be executed on the remote device.

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param strip_prompt: Remove the trailing router prompt from the output (default: True).

    +

    :param strip_command: Remove the echo of the command from the output (default: True).

    +

    :param normalize: Ensure the proper enter is sent at end of command (default: True).

    +

    :param use_textfsm: Process command output through TextFSM template (default: False).

    :param textfsm_template: Name of template to parse output with; can be fully qualified -path, relative path, or name of file in current directory. (default: None). -:type textfsm_template: str

    -

    :param use_ttp: Process command output through TTP template (default: False). -:type use_ttp: bool

    +path, relative path, or name of file in current directory. (default: None).

    +

    :param use_ttp: Process command output through TTP template (default: False).

    :param ttp_template: Name of template to parse output with; can be fully qualified -path, relative path, or name of file in current directory. (default: None). -:type ttp_template: str

    -

    :param use_genie: Process command output through PyATS/Genie parser (default: False). -:type use_genie: bool

    -

    :param cmd_verify: Verify command echo before proceeding (default: False). -:type cmd_verify: bool

    -

    :param cmd_echo: Deprecated (use cmd_verify instead) -:type cmd_echo: bool

    +path, relative path, or name of file in current directory. (default: None).

    +

    :param use_genie: Process command output through PyATS/Genie parser (default: False).

    +

    :param cmd_verify: Verify command echo before proceeding (default: False).

    Source code
    @select_cmd_verify
     def send_command_timing(
         self,
    -    command_string,
    -    delay_factor=1,
    -    max_loops=150,
    -    strip_prompt=True,
    -    strip_command=True,
    -    normalize=True,
    -    use_textfsm=False,
    -    textfsm_template=None,
    -    use_ttp=False,
    -    ttp_template=None,
    -    use_genie=False,
    -    cmd_verify=False,
    -    cmd_echo=None,
    -):
    +    command_string: str,
    +    last_read: float = 2.0,
    +    read_timeout: float = 120.0,
    +    delay_factor: Optional[float] = None,
    +    max_loops: Optional[int] = None,
    +    strip_prompt: bool = True,
    +    strip_command: bool = True,
    +    normalize: bool = True,
    +    use_textfsm: bool = False,
    +    textfsm_template: Optional[str] = None,
    +    use_ttp: bool = False,
    +    ttp_template: Optional[str] = None,
    +    use_genie: bool = False,
    +    cmd_verify: bool = False,
    +) -> Union[str, List[Any], Dict[str, Any]]:
         """Execute command_string on the SSH channel using a delay-based mechanism. Generally
         used for show commands.
     
         :param command_string: The command to be executed on the remote device.
    -    :type command_string: str
     
    -    :param delay_factor: Multiplying factor used to adjust delays (default: 1).
    -    :type delay_factor: int or float
    +    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
     
    -    :param max_loops: Controls wait time in conjunction with delay_factor. Will default to be
    -        based upon self.timeout.
    -    :type max_loops: int
    +    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
     
         :param strip_prompt: Remove the trailing router prompt from the output (default: True).
    -    :type strip_prompt: bool
     
         :param strip_command: Remove the echo of the command from the output (default: True).
    -    :type strip_command: bool
     
         :param normalize: Ensure the proper enter is sent at end of command (default: True).
    -    :type normalize: bool
     
         :param use_textfsm: Process command output through TextFSM template (default: False).
    -    :type use_textfsm: bool
     
         :param textfsm_template: Name of template to parse output with; can be fully qualified
             path, relative path, or name of file in current directory. (default: None).
    -    :type textfsm_template: str
     
         :param use_ttp: Process command output through TTP template (default: False).
    -    :type use_ttp: bool
     
         :param ttp_template: Name of template to parse output with; can be fully qualified
             path, relative path, or name of file in current directory. (default: None).
    -    :type ttp_template: str
     
         :param use_genie: Process command output through PyATS/Genie parser (default: False).
    -    :type use_genie: bool
     
         :param cmd_verify: Verify command echo before proceeding (default: False).
    -    :type cmd_verify: bool
    -
    -    :param cmd_echo: Deprecated (use cmd_verify instead)
    -    :type cmd_echo: bool
         """
    -
    -    # For compatibility; remove cmd_echo in Netmiko 4.x.x
    -    if cmd_echo is not None:
    -        cmd_verify = cmd_echo
    +    if delay_factor is not None or max_loops is not None:
    +        warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning)
     
         output = ""
    -    delay_factor = self.select_delay_factor(delay_factor)
    -
    +    new_data = ""
         if normalize:
             command_string = self.normalize_cmd(command_string)
         self.write_channel(command_string)
     
         cmd = command_string.strip()
    -    # if cmd is just an "enter" skip this section
         if cmd and cmd_verify:
    -        # Make sure you read until you detect the command echo (avoid getting out of sync)
    -        new_data = self.read_until_pattern(pattern=re.escape(cmd))
    -        new_data = self.normalize_linefeeds(new_data)
    -
    -        # Strip off everything before the command echo
    -        if new_data.count(cmd) == 1:
    -            new_data = new_data.split(cmd)[1:]
    -            new_data = self.RESPONSE_RETURN.join(new_data)
    -            new_data = new_data.lstrip()
    -            output = f"{cmd}{self.RESPONSE_RETURN}{new_data}"
    -        else:
    -            # cmd is in the actual output (not just echoed)
    -            output = new_data
    -
    -    log.debug(f"send_command_timing current output: {output}")
    -
    -    output += self._read_channel_timing(
    -        delay_factor=delay_factor, max_loops=max_loops
    +        new_data = self.command_echo_read(cmd=cmd, read_timeout=10)
    +    output += new_data
    +    output += self.read_channel_timing(
    +        last_read=last_read, read_timeout=read_timeout
         )
    +
         output = self._sanitize_output(
             output,
             strip_command=strip_command,
             command_string=command_string,
             strip_prompt=strip_prompt,
         )
    -
    -    # If both TextFSM, TTP and Genie are set, try TextFSM then TTP then Genie
    -    if use_textfsm:
    -        structured_output = get_structured_data(
    -            output,
    -            platform=self.device_type,
    -            command=command_string.strip(),
    -            template=textfsm_template,
    -        )
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -    if use_ttp:
    -        structured_output = get_structured_data_ttp(output, template=ttp_template)
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -    if use_genie:
    -        structured_output = get_structured_data_genie(
    -            output, platform=self.device_type, command=command_string.strip()
    -        )
    -        # If we have structured data; return it.
    -        if not isinstance(structured_output, str):
    -            return structured_output
    -
    -    log.debug(f"send_command_timing final output: {output}")
    -    return output
    + return_data = structured_data_converter( + command=command_string, + raw_data=output, + platform=self.device_type, + use_textfsm=use_textfsm, + use_ttp=use_ttp, + use_genie=use_genie, + textfsm_template=textfsm_template, + ttp_template=ttp_template, + ) + return return_data
    -def send_config_from_file(self, config_file=None, **kwargs) +def send_config_from_file(self, config_file, **kwargs)

    Send configuration commands down the SSH channel from a file.

    The file is processed line-by-line and each command is sent down the SSH channel.

    **kwargs are passed to send_config_set method.

    -

    :param config_file: Path to configuration file to be sent to the device -:type config_file: str

    -

    :param kwargs: params to be sent to send_config_set method -:type kwargs: dict

    +

    :param config_file: Path to configuration file to be sent to the device

    +

    :param kwargs: params to be sent to send_config_set method

    Source code -
    def send_config_from_file(self, config_file=None, **kwargs):
    +
    def send_config_from_file(
    +    self, config_file: Union[str, bytes, "PathLike[Any]"], **kwargs: Any
    +) -> str:
         """
         Send configuration commands down the SSH channel from a file.
     
    @@ -5648,59 +6265,57 @@ 

    Methods

    **kwargs are passed to send_config_set method. :param config_file: Path to configuration file to be sent to the device - :type config_file: str :param kwargs: params to be sent to send_config_set method - :type kwargs: dict """ with io.open(config_file, "rt", encoding="utf-8") as cfg_file: - return self.send_config_set(cfg_file, **kwargs)
    + commands = cfg_file.readlines() + return self.send_config_set(commands, **kwargs)
    -def send_config_set(self, config_commands=None, exit_config_mode=True, delay_factor=1, max_loops=150, strip_prompt=False, strip_command=False, config_mode_command=None, cmd_verify=True, enter_config_mode=True, error_pattern='') +def send_config_set(self, config_commands=None, *, exit_config_mode=True, read_timeout=None, delay_factor=None, max_loops=None, strip_prompt=False, strip_command=False, config_mode_command=None, cmd_verify=True, enter_config_mode=True, error_pattern='', terminator='#', bypass_commands=None)

    Send configuration commands down the SSH channel.

    config_commands is an iterable containing all of the configuration commands. The commands will be executed one after the other.

    Automatically exits/enters configuration mode.

    -

    :param config_commands: Multiple configuration commands to be sent to the device -:type config_commands: list or string

    -

    :param exit_config_mode: Determines whether or not to exit config mode after complete -:type exit_config_mode: bool

    -

    :param delay_factor: Factor to adjust delays -:type delay_factor: int

    -

    :param max_loops: Controls wait time in conjunction with delay_factor (default: 150) -:type max_loops: int

    -

    :param strip_prompt: Determines whether or not to strip the prompt -:type strip_prompt: bool

    -

    :param strip_command: Determines whether or not to strip the command -:type strip_command: bool

    -

    :param config_mode_command: The command to enter into config mode -:type config_mode_command: str

    -

    :param cmd_verify: Whether or not to verify command echo for each command in config_set -:type cmd_verify: bool

    -

    :param enter_config_mode: Do you enter config mode before sending config commands -:type exit_config_mode: bool

    +

    :param config_commands: Multiple configuration commands to be sent to the device

    +

    :param exit_config_mode: Determines whether or not to exit config mode after complete

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    +

    :param strip_prompt: Determines whether or not to strip the prompt

    +

    :param strip_command: Determines whether or not to strip the command

    +

    :param read_timeout: Absolute timer to send to read_channel_timing. Should be rarely needed.

    +

    :param config_mode_command: The command to enter into config mode

    +

    :param cmd_verify: Whether or not to verify command echo for each command in config_set

    +

    :param enter_config_mode: Do you enter config mode before sending config commands

    :param error_pattern: Regular expression pattern to detect config errors in the -output. -:type error_pattern: str

    +output.

    +

    :param terminator: Regular expression pattern to use as an alternate terminator in certain +situations.

    +

    :param bypass_commands: Regular expression pattern indicating configuration commands +where cmd_verify is automatically disabled.

    Source code
    def send_config_set(
         self,
    -    config_commands=None,
    -    exit_config_mode=True,
    -    delay_factor=1,
    -    max_loops=150,
    -    strip_prompt=False,
    -    strip_command=False,
    -    config_mode_command=None,
    -    cmd_verify=True,
    -    enter_config_mode=True,
    -    error_pattern="",
    -):
    +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +    *,
    +    exit_config_mode: bool = True,
    +    read_timeout: Optional[float] = None,
    +    delay_factor: Optional[float] = None,
    +    max_loops: Optional[int] = None,
    +    strip_prompt: bool = False,
    +    strip_command: bool = False,
    +    config_mode_command: Optional[str] = None,
    +    cmd_verify: bool = True,
    +    enter_config_mode: bool = True,
    +    error_pattern: str = "",
    +    terminator: str = r"#",
    +    bypass_commands: Optional[str] = None,
    +) -> str:
         """
         Send configuration commands down the SSH channel.
     
    @@ -5710,37 +6325,64 @@ 

    Methods

    Automatically exits/enters configuration mode. :param config_commands: Multiple configuration commands to be sent to the device - :type config_commands: list or string :param exit_config_mode: Determines whether or not to exit config mode after complete - :type exit_config_mode: bool - :param delay_factor: Factor to adjust delays - :type delay_factor: int + :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - :param max_loops: Controls wait time in conjunction with delay_factor (default: 150) - :type max_loops: int + :param max_loops: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. :param strip_prompt: Determines whether or not to strip the prompt - :type strip_prompt: bool :param strip_command: Determines whether or not to strip the command - :type strip_command: bool + + :param read_timeout: Absolute timer to send to read_channel_timing. Should be rarely needed. :param config_mode_command: The command to enter into config mode - :type config_mode_command: str :param cmd_verify: Whether or not to verify command echo for each command in config_set - :type cmd_verify: bool :param enter_config_mode: Do you enter config mode before sending config commands - :type exit_config_mode: bool :param error_pattern: Regular expression pattern to detect config errors in the output. - :type error_pattern: str + + :param terminator: Regular expression pattern to use as an alternate terminator in certain + situations. + + :param bypass_commands: Regular expression pattern indicating configuration commands + where cmd_verify is automatically disabled. """ - delay_factor = self.select_delay_factor(delay_factor) + + if self.global_cmd_verify is not None: + cmd_verify = self.global_cmd_verify + + if delay_factor is not None or max_loops is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + + # Calculate an equivalent read_timeout (if using old settings) + # Eliminate in Netmiko 5.x + if read_timeout is None: + max_loops = 150 if max_loops is None else max_loops + delay_factor = 1.0 if delay_factor is None else delay_factor + + # If delay_factor has been set, then look at global_delay_factor + delay_factor = self.select_delay_factor(delay_factor) + + read_timeout = calc_old_timeout( + max_loops=max_loops, delay_factor=delay_factor, loop_delay=0.1 + ) + + if delay_factor is None: + delay_factor = self.select_delay_factor(0) + else: + delay_factor = self.select_delay_factor(delay_factor) + + if read_timeout is None: + read_timeout = 15 + else: + read_timeout = read_timeout + if config_commands is None: return "" elif isinstance(config_commands, str): @@ -5749,20 +6391,33 @@

    Methods

    if not hasattr(config_commands, "__iter__"): raise ValueError("Invalid argument passed into send_config_set") + if bypass_commands is None: + # Commands where cmd_verify is automatically disabled reg-ex logical-or + bypass_commands = r"^banner .*$" + + # Set bypass_commands="" to force no-bypass (usually for testing) + bypass_detected = False + if bypass_commands: + bypass_detected = any( + [True for cmd in config_commands if re.search(bypass_commands, cmd)] + ) + if bypass_detected: + cmd_verify = False + # Send config commands output = "" if enter_config_mode: - cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() - output += self.config_mode(*cfg_mode_args) + if config_mode_command: + output += self.config_mode(config_mode_command) + else: + output += self.config_mode() - # If error_pattern is perform output gathering line by line and not fast_cli mode. + # Perform output gathering line-by-line (legacy way) if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) elif not cmd_verify: for cmd in config_commands: @@ -5771,35 +6426,25 @@

    Methods

    # Gather the output incrementally due to error_pattern requirements if error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) if re.search(error_pattern, output, flags=re.M): msg = f"Invalid input detected at command: {cmd}" raise ConfigInvalidException(msg) # Standard output gathering (no error_pattern) if not error_pattern: - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) + output += self.read_channel_timing(read_timeout=read_timeout) else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Make sure command is echoed - new_output = self.read_until_pattern(pattern=re.escape(cmd.strip())) - output += new_output - - # We might capture next prompt in the original read - pattern = f"(?:{re.escape(self.base_prompt)}|#)" - if not re.search(pattern, new_output): - # Make sure trailing prompt comes back (after command) - # NX-OS has fast-buffering problem where it immediately echoes command - # Even though the device hasn't caught up with processing command. - new_output = self.read_until_pattern(pattern=pattern) - output += new_output + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + + # Read until next prompt or terminator (#); the .*$ forces read of entire line + pattern = f"(?:{re.escape(self.base_prompt)}.*$|{terminator}.*$)" + output += self.read_until_pattern(pattern=pattern, re_flags=re.M) if error_pattern: if re.search(error_pattern, output, flags=re.M): @@ -5813,8 +6458,89 @@

    Methods

    return output
    +
    +def send_multiline(self, commands, multiline=True, **kwargs) +
    +
    +

    commands should either be:

    +

    commands = [[cmd1, expect1], [cmd2, expect2], …]]

    +

    Or

    +

    commands = [cmd1, cmd2, cmd3, …]

    +

    Any expect_string that is a null-string will use pattern based on +device's prompt (unless expect_string argument is passed in via +kwargs.

    +
    +Source code +
    def send_multiline(
    +    self,
    +    commands: Sequence[Union[str, List[str]]],
    +    multiline: bool = True,
    +    **kwargs: Any,
    +) -> str:
    +    """
    +    commands should either be:
    +
    +    commands = [[cmd1, expect1], [cmd2, expect2], ...]]
    +
    +    Or
    +
    +    commands = [cmd1, cmd2, cmd3, ...]
    +
    +    Any expect_string that is a null-string will use pattern based on
    +    device's prompt (unless expect_string argument is passed in via
    +    kwargs.
    +
    +    """
    +    output = ""
    +    if multiline:
    +        kwargs = self._multiline_kwargs(**kwargs)
    +
    +    default_expect_string = kwargs.pop("expect_string", None)
    +    if not default_expect_string:
    +        auto_find_prompt = kwargs.get("auto_find_prompt", True)
    +        default_expect_string = self._prompt_handler(auto_find_prompt)
    +
    +    if commands and isinstance(commands[0], str):
    +        # If list of commands just send directly using default_expect_string (probably prompt)
    +        for cmd in commands:
    +            cmd = str(cmd)
    +            output += self._send_command_str(
    +                cmd, expect_string=default_expect_string, **kwargs
    +            )
    +    else:
    +        # If list of lists, then first element is cmd and second element is expect_string
    +        for cmd_item in commands:
    +            assert not isinstance(cmd_item, str)
    +            cmd, expect_string = cmd_item
    +            if not expect_string:
    +                expect_string = default_expect_string
    +            output += self._send_command_str(
    +                cmd, expect_string=expect_string, **kwargs
    +            )
    +    return output
    +
    +
    +
    +def send_multiline_timing(self, commands, multiline=True, **kwargs) +
    +
    +
    +
    +Source code +
    def send_multiline_timing(
    +    self, commands: Sequence[str], multiline: bool = True, **kwargs: Any
    +) -> str:
    +    if multiline:
    +        kwargs = self._multiline_kwargs(**kwargs)
    +    output = ""
    +    for cmd in commands:
    +        cmd = str(cmd)
    +        output += self._send_command_timing_str(cmd, **kwargs)
    +    return output
    +
    +
    -def serial_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:[Uu]ser:|sername|ogin)', pwd_pattern='assword', delay_factor=1, max_loops=20) +def serial_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:[Uu]ser:|sername|ogin)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)
    @@ -5822,14 +6548,14 @@

    Methods

    Source code
    def serial_login(
         self,
    -    pri_prompt_terminator=r"#\s*$",
    -    alt_prompt_terminator=r">\s*$",
    -    username_pattern=r"(?:[Uu]ser:|sername|ogin)",
    -    pwd_pattern=r"assword",
    -    delay_factor=1,
    -    max_loops=20,
    -):
    -    self.telnet_login(
    +    pri_prompt_terminator: str = r"#\s*$",
    +    alt_prompt_terminator: str = r">\s*$",
    +    username_pattern: str = r"(?:[Uu]ser:|sername|ogin)",
    +    pwd_pattern: str = r"assword",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 20,
    +) -> str:
    +    return self.telnet_login(
             pri_prompt_terminator,
             alt_prompt_terminator,
             username_pattern,
    @@ -5847,14 +6573,13 @@ 

    Methods

    This method handles some differences that occur between various devices early on in the session.

    In general, it should include: -self._test_channel_read() +self._test_channel_read(pattern=r"some_pattern") self.set_base_prompt() -self.disable_paging() self.set_terminal_width() -self.clear_buffer()

    +self.disable_paging()

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established
     
    @@ -5862,24 +6587,19 @@ 

    Methods

    early on in the session. In general, it should include: - self._test_channel_read() + self._test_channel_read(pattern=r"some_pattern") self.set_base_prompt() - self.disable_paging() self.set_terminal_width() - self.clear_buffer() + self.disable_paging() """ self._test_channel_read() self.set_base_prompt() self.set_terminal_width() - self.disable_paging() - - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer()
    + self.disable_paging()
    -def set_base_prompt(self, pri_prompt_terminator='#', alt_prompt_terminator='>', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='#', alt_prompt_terminator='>', delay_factor=1.0, pattern=None)

    Sets self.base_prompt

    @@ -5888,12 +6608,10 @@

    Methods

    devices this will be set to router hostname (i.e. prompt without > or #).

    This will be set on entering user exec or privileged exec on Cisco, but not when entering/exiting config mode.

    -

    :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt -:type pri_prompt_terminator: str

    -

    :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt -:type alt_prompt_terminator: str

    -

    :param delay_factor: See init: global_delay_factor -:type delay_factor: int

    +

    :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt

    +

    :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt

    +

    :param delay_factor: See init: global_delay_factor

    +

    :param pattern: Regular expression pattern to search for in find_prompt() call

    Source code
    @retry(
    @@ -5902,8 +6620,12 @@ 

    Methods

    reraise=True, ) def set_base_prompt( - self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 -): + self, + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, +) -> str: """Sets self.base_prompt Used as delimiter for stripping of trailing prompt in output. @@ -5915,15 +6637,28 @@

    Methods

    entering/exiting config mode. :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt - :type pri_prompt_terminator: str :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt - :type alt_prompt_terminator: str :param delay_factor: See __init__: global_delay_factor - :type delay_factor: int + + :param pattern: Regular expression pattern to search for in find_prompt() call """ - prompt = self.find_prompt(delay_factor=delay_factor) + if pattern is None: + if pri_prompt_terminator and alt_prompt_terminator: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + pattern = rf"({pri_term}|{alt_term})" + elif pri_prompt_terminator: + pattern = re.escape(pri_prompt_terminator) + elif alt_prompt_terminator: + pattern = re.escape(alt_prompt_terminator) + + if pattern: + prompt = self.find_prompt(delay_factor=delay_factor, pattern=pattern) + else: + prompt = self.find_prompt(delay_factor=delay_factor) + if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): raise ValueError(f"Router prompt not found: {repr(prompt)}") # Strip off trailing terminator @@ -5932,37 +6667,40 @@

    Methods

    -def set_terminal_width(self, command='', delay_factor=1, cmd_verify=False, pattern=None) +def set_terminal_width(self, command='', delay_factor=None, cmd_verify=False, pattern=None)

    CLI terminals try to automatically adjust the line based on the width of the terminal. This causes the output to get distorted when accessed programmatically.

    Set terminal width to 511 which works on a broad set of devices.

    -

    :param command: Command string to send to the device -:type command: str

    -

    :param delay_factor: See init: global_delay_factor -:type delay_factor: int

    +

    :param command: Command string to send to the device

    +

    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code
    def set_terminal_width(
    -    self, command="", delay_factor=1, cmd_verify=False, pattern=None
    -):
    +    self,
    +    command: str = "",
    +    delay_factor: Optional[float] = None,
    +    cmd_verify: bool = False,
    +    pattern: Optional[str] = None,
    +) -> str:
         """CLI terminals try to automatically adjust the line based on the width of the terminal.
         This causes the output to get distorted when accessed programmatically.
     
         Set terminal width to 511 which works on a broad set of devices.
     
         :param command: Command string to send to the device
    -    :type command: str
     
    -    :param delay_factor: See __init__: global_delay_factor
    -    :type delay_factor: int
    +    :param delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
         """
    +    if delay_factor is not None:
    +        warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning)
    +
         if not command:
             return ""
    -    delay_factor = self.select_delay_factor(delay_factor)
         command = self.normalize_cmd(command)
         self.write_channel(command)
    +
         # Avoid cmd_verify here as terminal width must be set before doing cmd_verify
         if cmd_verify and self.global_cmd_verify is not False:
             output = self.read_until_pattern(pattern=re.escape(command.strip()))
    @@ -5974,13 +6712,13 @@ 

    Methods

    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Handler for devices like WLC, Extreme ERS that throw up characters prior to login.

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """Handler for devices like WLC, Extreme ERS that throw up characters prior to login."""
         pass
    @@ -6015,18 +6753,20 @@

    Methods

    ESC[2J Code erase display ESC[00;32m -Color Green (30 to 37 are different colors) more general pattern is -ESC[\d\d;\d\dm and ESC[\d\d;\d\d;\d\dm +Color Green (30 to 37 are different colors) ESC[6n Get cursor position ESC[1D -Move cursor position leftward by x characters (1 in this case)

    +Move cursor position leftward by x characters (1 in this case) +ESC[9999B +Move cursor down N-lines (very large value is attempt to move to the +very bottom of the screen).

    HP ProCurve and Cisco SG300 require this (possible others).

    :param string_buffer: The string to be processed to remove ANSI escape codes :type string_buffer: str

    Source code -
    def strip_ansi_escape_codes(self, string_buffer):
    +
    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
         """
         Remove any ANSI (VT100) ESC codes from the output
     
    @@ -6047,10 +6787,11 @@ 

    Methods

    ESC[?6l Reset mode screen with options 640 x 200 monochrome (graphics) ESC[?7l Disable line wrapping ESC[2J Code erase display - ESC[00;32m Color Green (30 to 37 are different colors) more general pattern is - ESC[\d\d;\d\dm and ESC[\d\d;\d\d;\d\dm + ESC[00;32m Color Green (30 to 37 are different colors) ESC[6n Get cursor position ESC[1D Move cursor position leftward by x characters (1 in this case) + ESC[9999B Move cursor down N-lines (very large value is attempt to move to the + very bottom of the screen). HP ProCurve and Cisco SG300 require this (possible others). @@ -6072,7 +6813,8 @@

    Methods

    code_reset_graphics_mode = chr(27) + r"\[00m" code_erase_display = chr(27) + r"\[2J" code_erase_display_0 = chr(27) + r"\[J" - code_graphics_mode = chr(27) + r"\[\d\d;\d\dm" + code_graphics_mode = chr(27) + r"\[\dm" + code_graphics_mode1 = chr(27) + r"\[\d\d;\d\dm" code_graphics_mode2 = chr(27) + r"\[\d\d;\d\d;\d\dm" code_graphics_mode3 = chr(27) + r"\[(3|4)\dm" code_graphics_mode4 = chr(27) + r"\[(9|10)[0-7]m" @@ -6081,6 +6823,11 @@

    Methods

    code_attrs_off = chr(27) + r"\[0m" code_reverse = chr(27) + r"\[7m" code_cursor_left = chr(27) + r"\[\d+D" + code_cursor_forward = chr(27) + r"\[\d*C" + code_cursor_up = chr(27) + r"\[\d*A" + code_cursor_down = chr(27) + r"\[\d*B" + code_wrap_around = chr(27) + r"\[\?7h" + code_bracketed_paste_mode = chr(27) + r"\[\?2004h" code_set = [ code_position_cursor, @@ -6095,6 +6842,7 @@

    Methods

    code_reset_graphics_mode, code_erase_display, code_graphics_mode, + code_graphics_mode1, code_graphics_mode2, code_graphics_mode3, code_graphics_mode4, @@ -6105,6 +6853,11 @@

    Methods

    code_attrs_off, code_reverse, code_cursor_left, + code_cursor_up, + code_cursor_down, + code_cursor_forward, + code_wrap_around, + code_bracketed_paste_mode, ] output = string_buffer @@ -6136,7 +6889,7 @@

    Methods

    :type output: str

    Source code -
    def strip_command(self, command_string, output):
    +
    def strip_command(self, command_string: str, output: str) -> str:
         """
         Strip command_string from output string
     
    @@ -6175,7 +6928,7 @@ 

    Methods

    :type a_string: str

    Source code -
    def strip_prompt(self, a_string):
    +
    def strip_prompt(self, a_string: str) -> str:
         """Strip the trailing router prompt from the output.
     
         :param a_string: Returned string from device
    @@ -6183,6 +6936,7 @@ 

    Methods

    """ response_list = a_string.split(self.RESPONSE_RETURN) last_line = response_list[-1] + if self.base_prompt in last_line: return self.RESPONSE_RETURN.join(response_list[:-1]) else: @@ -6190,51 +6944,41 @@

    Methods

    -def telnet_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login|user name)', pwd_pattern='assword', delay_factor=1, max_loops=20) +def telnet_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login|user name)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)

    Telnet login. Can be username/password or just password.

    -

    :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt -:type pri_prompt_terminator: str

    -

    :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt -:type alt_prompt_terminator: str

    -

    :param username_pattern: Pattern used to identify the username prompt -:type username_pattern: str

    -

    :param delay_factor: See init: global_delay_factor -:type delay_factor: int

    -

    :param max_loops: Controls the wait time in conjunction with the delay_factor -(default: 20)

    +

    :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt

    +

    :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt

    +

    :param username_pattern: Pattern used to identify the username prompt

    +

    :param delay_factor: See init: global_delay_factor

    +

    :param max_loops: Controls the wait time in conjunction with the delay_factor

    Source code
    def telnet_login(
         self,
    -    pri_prompt_terminator=r"#\s*$",
    -    alt_prompt_terminator=r">\s*$",
    -    username_pattern=r"(?:user:|username|login|user name)",
    -    pwd_pattern=r"assword",
    -    delay_factor=1,
    -    max_loops=20,
    -):
    +    pri_prompt_terminator: str = r"#\s*$",
    +    alt_prompt_terminator: str = r">\s*$",
    +    username_pattern: str = r"(?:user:|username|login|user name)",
    +    pwd_pattern: str = r"assword",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 20,
    +) -> str:
         """Telnet login. Can be username/password or just password.
     
         :param pri_prompt_terminator: Primary trailing delimiter for identifying a device prompt
    -    :type pri_prompt_terminator: str
     
         :param alt_prompt_terminator: Alternate trailing delimiter for identifying a device prompt
    -    :type alt_prompt_terminator: str
     
         :param username_pattern: Pattern used to identify the username prompt
    -    :type username_pattern: str
     
         :param delay_factor: See __init__: global_delay_factor
    -    :type delay_factor: int
     
         :param max_loops: Controls the wait time in conjunction with the delay_factor
    -    (default: 20)
         """
         delay_factor = self.select_delay_factor(delay_factor)
     
    -    # FIX: Cleanup in future versions of Netmiko
    +    # Revert telnet_login back to old speeds/delays
         if delay_factor < 1:
             if not self._legacy_mode and self.fast_cli:
                 delay_factor = 1
    @@ -6260,6 +7004,7 @@ 

    Methods

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -6279,6 +7024,7 @@

    Methods

    time.sleep(0.5 * delay_factor) i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -6294,6 +7040,7 @@

    Methods

    return return_msg msg = f"Login failed: {self.host}" + assert self.remote_conn is not None self.remote_conn.close() raise NetmikoAuthenticationException(msg)
    @@ -6302,30 +7049,79 @@

    Methods

    def write_channel(self, out_data)
    -

    Generic handler that will write to both SSH and telnet channel.

    +

    Generic method that will write data out the channel.

    :param out_data: data to be written to the channel -:type out_data: str (can be either unicode/byte string)

    +:type out_data: str

    Source code -
    def write_channel(self, out_data):
    -    """Generic handler that will write to both SSH and telnet channel.
    +
    @lock_channel
    +@log_writes
    +def write_channel(self, out_data: str) -> None:
    +    """Generic method that will write data out the channel.
     
         :param out_data: data to be written to the channel
    -    :type out_data: str (can be either unicode/byte string)
    +    :type out_data: str
         """
    -    self._lock_netmiko_session()
    -    try:
    -        self._write_channel(out_data)
    -    finally:
    -        # Always unlock the SSH channel, even on exception.
    -        self._unlock_netmiko_session()
    + self.channel.write_channel(out_data)
    +
    +
    +
    + +
    +class SecretsFilter +(no_log=None) +
    +
    +

    Filter instances are used to perform arbitrary filtering of LogRecords.

    +

    Loggers and Handlers can optionally use Filter instances to filter +records as desired. The base filter class only allows events which are +below a certain point in the logger hierarchy. For example, a filter +initialized with "A.B" will allow events logged by loggers "A.B", +"A.B.C", "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If +initialized with the empty string, all events are passed.

    +

    Initialize a filter.

    +

    Initialize with the name of the logger which, together with its +children, will have its events allowed through the filter. If no +name is specified, allow every event.

    +
    +Source code +
    class SecretsFilter(logging.Filter):
    +    def __init__(self, no_log: Optional[Dict[Any, str]] = None) -> None:
    +        self.no_log = no_log
    +
    +    def filter(self, record: logging.LogRecord) -> bool:
    +        """Removes secrets (no_log) from messages"""
    +        if self.no_log:
    +            for hidden_data in self.no_log.values():
    +                record.msg = record.msg.replace(hidden_data, "********")
    +        return True
    +
    +

    Ancestors

    +
      +
    • logging.Filter
    • +
    +

    Methods

    +
    +
    +def filter(self, record) +
    +
    +

    Removes secrets (no_log) from messages

    +
    +Source code +
    def filter(self, record: logging.LogRecord) -> bool:
    +    """Removes secrets (no_log) from messages"""
    +    if self.no_log:
    +        for hidden_data in self.no_log.values():
    +            record.msg = record.msg.replace(hidden_data, "********")
    +    return True
    class TelnetConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Defines vendor independent methods.

    @@ -6334,131 +7130,104 @@

    Methods

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -6477,7 +7246,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -6490,9 +7258,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -6504,6 +7272,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -6532,6 +7301,12 @@

    Index

  • netmiko
  • +
  • Functions

    + +
  • Classes

    diff --git a/docs/netmiko/broadcom/broadcom_icos_ssh.html b/docs/netmiko/broadcom/broadcom_icos_ssh.html index f4965990e..381e7153d 100644 --- a/docs/netmiko/broadcom/broadcom_icos_ssh.html +++ b/docs/netmiko/broadcom/broadcom_icos_ssh.html @@ -22,8 +22,7 @@

    Module netmiko.broadcom.broadcom_icos_ssh

    Source code -
    import time
    -from netmiko.cisco_base_connection import CiscoSSHConnection
    +
    from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
     class BroadcomIcosSSH(CiscoSSHConnection):
    @@ -32,35 +31,40 @@ 

    Module netmiko.broadcom.broadcom_icos_ssh

    Syntax its almost identical to Cisco IOS in most cases """ - def session_preparation(self): - self._test_channel_read() + def session_preparation(self) -> None: + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() self.set_base_prompt() self.set_terminal_width() self.disable_paging() - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -78,7 +82,7 @@

    Classes

    class BroadcomIcosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implements support for Broadcom Icos devices. @@ -87,131 +91,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -221,35 +198,40 @@

    Classes

    Syntax its almost identical to Cisco IOS in most cases """ - def session_preparation(self): - self._test_channel_read() + def session_preparation(self) -> None: + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() self.set_base_prompt() self.set_terminal_width() self.disable_paging() - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -264,37 +246,41 @@

    Ancestors

    Methods

    -def check_config_mode(self, check_string=')#') +def check_config_mode(self, check_string=')#', pattern='')

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string=")#"):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode or not."""
    -    return super().check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string, pattern=pattern)
    -def config_mode(self, config_command='configure') +def config_mode(self, config_command='configure', pattern='', re_flags=0)

    Enter configuration mode.

    Source code -
    def config_mode(self, config_command="configure"):
    +
    def config_mode(
    +    self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    -def exit_config_mode(self, exit_config='exit') +def exit_config_mode(self, exit_config='exit', pattern='')

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="exit"):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
         """Exit configuration mode."""
         return super().exit_config_mode(exit_config=exit_config)
    @@ -306,7 +292,7 @@

    Methods

    Exit enable mode.

    Source code -
    def exit_enable_mode(self, exit_command="exit"):
    +
    def exit_enable_mode(self, exit_command: str = "exit") -> str:
         """Exit enable mode."""
         return super().exit_enable_mode(exit_command=exit_command)
    @@ -318,7 +304,12 @@

    Methods

    Saves configuration.

    Source code -
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "write memory",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves configuration."""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -333,7 +324,6 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • disable_paging
  • disconnect
  • @@ -343,9 +333,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -356,6 +346,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/broadcom/index.html b/docs/netmiko/broadcom/index.html index 9d0ad8181..f5a71b448 100644 --- a/docs/netmiko/broadcom/index.html +++ b/docs/netmiko/broadcom/index.html @@ -46,7 +46,7 @@

    Classes

    class BroadcomIcosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implements support for Broadcom Icos devices. @@ -55,131 +55,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -189,35 +162,40 @@

    Classes

    Syntax its almost identical to Cisco IOS in most cases """ - def session_preparation(self): - self._test_channel_read() + def session_preparation(self) -> None: + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.enable() self.set_base_prompt() self.set_terminal_width() self.disable_paging() - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -232,37 +210,41 @@

    Ancestors

    Methods

    -def check_config_mode(self, check_string=')#') +def check_config_mode(self, check_string=')#', pattern='')

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string=")#"):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode or not."""
    -    return super().check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string, pattern=pattern)
    -def config_mode(self, config_command='configure') +def config_mode(self, config_command='configure', pattern='', re_flags=0)

    Enter configuration mode.

    Source code -
    def config_mode(self, config_command="configure"):
    +
    def config_mode(
    +    self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    -def exit_config_mode(self, exit_config='exit') +def exit_config_mode(self, exit_config='exit', pattern='')

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="exit"):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
         """Exit configuration mode."""
         return super().exit_config_mode(exit_config=exit_config)
    @@ -274,7 +256,7 @@

    Methods

    Exit enable mode.

    Source code -
    def exit_enable_mode(self, exit_command="exit"):
    +
    def exit_enable_mode(self, exit_command: str = "exit") -> str:
         """Exit enable mode."""
         return super().exit_enable_mode(exit_command=exit_command)
    @@ -286,7 +268,12 @@

    Methods

    Saves configuration.

    Source code -
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "write memory",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves configuration."""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -301,7 +288,6 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • disable_paging
  • disconnect
  • @@ -311,9 +297,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -324,6 +310,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/brocade/brocade_fos_ssh.html b/docs/netmiko/brocade/brocade_fos_ssh.html index a4233c5ff..74842c86d 100644 --- a/docs/netmiko/brocade/brocade_fos_ssh.html +++ b/docs/netmiko/brocade/brocade_fos_ssh.html @@ -22,48 +22,23 @@

    Module netmiko.brocade.brocade_fos_ssh

    Source code -
    import time
    -import re
    +
    from typing import Any
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    -class BrocadeFOSSSH(CiscoSSHConnection):
    +class BrocadeFOSSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Brocade Fabric OS support"""
     
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
             return super().__init__(**kwargs)
     
    -    def session_preparation(self):
    -        self._test_channel_read()
    -        self.set_base_prompt()
    -
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, check_string=">"):
    -        """No enable mode. Always return True."""
    -        return True
    -
    -    def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE):
    -        """No Enable Mode."""
    -        return ""
    -
    -    def exit_enable_mode(self, exit_command=""):
    -        """No Enable Mode."""
    -        return ""
    -
    -    def check_config_mode(self, check_string="", pattern=""):
    -        return True
    -
    -    def config_mode(self, config_command="", pattern="", re_flags=0):
    -        """No config mode."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config="", pattern="#"):
    -        return ""
    + def session_preparation(self) -> None: + self._test_channel_read(pattern=r">") + self.set_base_prompt()
    @@ -80,254 +55,52 @@

    Classes

    (**kwargs)
    -

    Brocade Fabric OS support

    -
        Initialize attributes for establishing connection to target device.
    -
    -    :param ip: IP address of target device. Not required if `host` is
    -        provided.
    -    :type ip: str
    -
    -    :param host: Hostname of target device. Not required if `ip` is
    -            provided.
    -    :type host: str
    -
    -    :param username: Username to authenticate against target device if
    -            required.
    -    :type username: str
    -
    -    :param password: Password to authenticate against target device if
    -            required.
    -    :type password: str
    -
    -    :param secret: The enable password if target device requires one.
    -    :type secret: str
    -
    -    :param port: The destination port used to connect to the target
    -            device.
    -    :type port: int or None
    -
    -    :param device_type: Class selection based on device type.
    -    :type device_type: str
    -
    -    :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
    -
    -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
    -
    -    :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
    -
    -    :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
    -
    -    :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
    -
    -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    -            decryption if not specified.
    -    :type passphrase: str
    -
    -    :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
    -
    -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    -            means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
    -
    -    :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    -            alt_key_file.
    -    :type alt_host_keys: bool
    -
    -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
    -
    -    :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
    -
    -    :param timeout: Connection timeout.
    -    :type timeout: float
    -
    -    :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
    -
    -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
    -
    -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
    -
    -    :param 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).
    -    :type keepalive: int
    -
    -    :param default_enter: Character(s) to send to correspond to enter key (default:
    -
    -

    ). -:type default_enter: str

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

    ) -:type response_return: str

    -
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    -            to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    -
    -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
    -
    -    :param session_log_record_writes: The session log generally only records channel reads due
    -            to eliminate command duplication due to command echo. You can enable this if you
    -            want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
    -
    -    :param session_log_file_mode: "write" or "append" for session_log file mode
    -            (default: "write")
    -    :type session_log_file_mode: str
    -
    -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    -            (default: False)
    -    :type allow_auto_change: bool
    -
    -    :param encoding: Encoding to be used when writing bytes to the output channel.
    -            (default: ascii)
    -    :type encoding: str
    -
    -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    -            communication to the target host (default: None).
    -    :type sock: socket
    -
    -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    -            (default: None). Global attribute takes precedence over function `cmd_verify`
    -            argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
    -
    -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    -            part of the object creation (default: True).
    -    :type auto_connect: bool
    -
    +

    Brocade Fabric OS support

    Source code -
    class BrocadeFOSSSH(CiscoSSHConnection):
    +
    class BrocadeFOSSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Brocade Fabric OS support"""
     
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
             return super().__init__(**kwargs)
     
    -    def session_preparation(self):
    -        self._test_channel_read()
    -        self.set_base_prompt()
    -
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, check_string=">"):
    -        """No enable mode. Always return True."""
    -        return True
    -
    -    def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE):
    -        """No Enable Mode."""
    -        return ""
    -
    -    def exit_enable_mode(self, exit_command=""):
    -        """No Enable Mode."""
    -        return ""
    -
    -    def check_config_mode(self, check_string="", pattern=""):
    -        return True
    -
    -    def config_mode(self, config_command="", pattern="", re_flags=0):
    -        """No config mode."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config="", pattern="#"):
    -        return ""
    + def session_preparation(self) -> None: + self._test_channel_read(pattern=r">") + self.set_base_prompt()

    Ancestors

    -

    Methods

    -
    -
    -def check_enable_mode(self, check_string='>') -
    -
    -

    No enable mode. Always return True.

    -
    -Source code -
    def check_enable_mode(self, check_string=">"):
    -    """No enable mode. Always return True."""
    -    return True
    -
    -
    -
    -def config_mode(self, config_command='', pattern='', re_flags=0) -
    -
    -

    No config mode.

    -
    -Source code -
    def config_mode(self, config_command="", pattern="", re_flags=0):
    -    """No config mode."""
    -    return ""
    -
    -
    -
    -def enable(self, cmd='', pattern='', enable_pattern=None, re_flags=) -
    -
    -

    No Enable Mode.

    -
    -Source code -
    def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE):
    -    """No Enable Mode."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, exit_command='') -
    -
    -

    No Enable Mode.

    -
    -Source code -
    def exit_enable_mode(self, exit_command=""):
    -    """No Enable Mode."""
    -    return ""
    -
    -
    -

    Inherited members

    • CiscoSSHConnection:
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -339,6 +112,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -371,12 +145,6 @@

        Index

        diff --git a/docs/netmiko/brocade/index.html b/docs/netmiko/brocade/index.html index 4df5e4f46..2fddb4882 100644 --- a/docs/netmiko/brocade/index.html +++ b/docs/netmiko/brocade/index.html @@ -48,254 +48,52 @@

        Classes

        (**kwargs)
        -

        Brocade Fabric OS support

        -
            Initialize attributes for establishing connection to target device.
        -
        -    :param ip: IP address of target device. Not required if `host` is
        -        provided.
        -    :type ip: str
        -
        -    :param host: Hostname of target device. Not required if `ip` is
        -            provided.
        -    :type host: str
        -
        -    :param username: Username to authenticate against target device if
        -            required.
        -    :type username: str
        -
        -    :param password: Password to authenticate against target device if
        -            required.
        -    :type password: str
        -
        -    :param secret: The enable password if target device requires one.
        -    :type secret: str
        -
        -    :param port: The destination port used to connect to the target
        -            device.
        -    :type port: int or None
        -
        -    :param device_type: Class selection based on device type.
        -    :type device_type: str
        -
        -    :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
        -
        -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
        -
        -    :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
        -
        -    :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
        -
        -    :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
        -
        -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
        -            decryption if not specified.
        -    :type passphrase: str
        -
        -    :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
        -
        -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
        -            means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
        -
        -    :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
        -            alt_key_file.
        -    :type alt_host_keys: bool
        -
        -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
        -
        -    :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
        -
        -    :param timeout: Connection timeout.
        -    :type timeout: float
        -
        -    :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
        -
        -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
        -
        -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
        -
        -    :param 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).
        -    :type keepalive: int
        -
        -    :param default_enter: Character(s) to send to correspond to enter key (default:
        -
        -

        ). -:type default_enter: str

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

        ) -:type response_return: str

        -
            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
        -            to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        -
        -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
        -
        -    :param session_log_record_writes: The session log generally only records channel reads due
        -            to eliminate command duplication due to command echo. You can enable this if you
        -            want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
        -
        -    :param session_log_file_mode: "write" or "append" for session_log file mode
        -            (default: "write")
        -    :type session_log_file_mode: str
        -
        -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
        -            (default: False)
        -    :type allow_auto_change: bool
        -
        -    :param encoding: Encoding to be used when writing bytes to the output channel.
        -            (default: ascii)
        -    :type encoding: str
        -
        -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
        -            communication to the target host (default: None).
        -    :type sock: socket
        -
        -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
        -            (default: None). Global attribute takes precedence over function `cmd_verify`
        -            argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
        -
        -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
        -            part of the object creation (default: True).
        -    :type auto_connect: bool
        -
        +

        Brocade Fabric OS support

        Source code -
        class BrocadeFOSSSH(CiscoSSHConnection):
        +
        class BrocadeFOSSSH(NoEnable, NoConfig, CiscoSSHConnection):
             """Brocade Fabric OS support"""
         
        -    def __init__(self, **kwargs):
        +    def __init__(self, **kwargs: Any) -> None:
                 if kwargs.get("default_enter") is None:
                     kwargs["default_enter"] = "\r"
                 return super().__init__(**kwargs)
         
        -    def session_preparation(self):
        -        self._test_channel_read()
        -        self.set_base_prompt()
        -
        -        # Clear the read buffer
        -        time.sleep(0.3 * self.global_delay_factor)
        -        self.clear_buffer()
        -
        -    def check_enable_mode(self, check_string=">"):
        -        """No enable mode. Always return True."""
        -        return True
        -
        -    def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE):
        -        """No Enable Mode."""
        -        return ""
        -
        -    def exit_enable_mode(self, exit_command=""):
        -        """No Enable Mode."""
        -        return ""
        -
        -    def check_config_mode(self, check_string="", pattern=""):
        -        return True
        -
        -    def config_mode(self, config_command="", pattern="", re_flags=0):
        -        """No config mode."""
        -        return ""
        -
        -    def exit_config_mode(self, exit_config="", pattern="#"):
        -        return ""
        + def session_preparation(self) -> None: + self._test_channel_read(pattern=r">") + self.set_base_prompt()

        Ancestors

        -

        Methods

        -
        -
        -def check_enable_mode(self, check_string='>') -
        -
        -

        No enable mode. Always return True.

        -
        -Source code -
        def check_enable_mode(self, check_string=">"):
        -    """No enable mode. Always return True."""
        -    return True
        -
        -
        -
        -def config_mode(self, config_command='', pattern='', re_flags=0) -
        -
        -

        No config mode.

        -
        -Source code -
        def config_mode(self, config_command="", pattern="", re_flags=0):
        -    """No config mode."""
        -    return ""
        -
        -
        -
        -def enable(self, cmd='', pattern='', enable_pattern=None, re_flags=) -
        -
        -

        No Enable Mode.

        -
        -Source code -
        def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE):
        -    """No Enable Mode."""
        -    return ""
        -
        -
        -
        -def exit_enable_mode(self, exit_command='') -
        -
        -

        No Enable Mode.

        -
        -Source code -
        def exit_enable_mode(self, exit_command=""):
        -    """No Enable Mode."""
        -    return ""
        -
        -
        -

        Inherited members

        • CiscoSSHConnection:
          • check_config_mode
          • +
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • +
          • config_mode
          • disable_paging
          • disconnect
          • +
          • enable
          • establish_connection
          • exit_config_mode
          • +
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -307,6 +105,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -344,12 +143,6 @@

            Index

            diff --git a/docs/netmiko/calix/calix_b6.html b/docs/netmiko/calix/calix_b6.html index b8742242d..0f2cf600e 100644 --- a/docs/netmiko/calix/calix_b6.html +++ b/docs/netmiko/calix/calix_b6.html @@ -24,71 +24,79 @@

            Module netmiko.calix.calix_b6

            Source code
            """Calix B6 SSH Driver for Netmiko"""
            +from typing import Any
             import time
             from os import path
             
             from paramiko import SSHClient
             
             from netmiko.cisco_base_connection import CiscoSSHConnection
            -
            -
            -class SSHClient_noauth(SSHClient):
            -    """Set noauth when manually handling SSH authentication."""
            -
            -    def _auth(self, username, *args):
            -        self._transport.auth_none(username)
            -        return
            +from netmiko.ssh_auth import SSHClient_noauth
            +from netmiko.exceptions import NetmikoTimeoutException
             
             
             class CalixB6Base(CiscoSSHConnection):
                 """Common methods for Calix B6, both SSH and Telnet."""
             
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     default_enter = kwargs.get("default_enter")
                     kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                     super().__init__(*args, **kwargs)
             
            -    def session_preparation(self):
            +    def session_preparation(self) -> Any:
                     """Prepare the session after the connection has been established."""
                     self.ansi_escape_codes = True
            -        self._test_channel_read()
            +        self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
                     self.set_terminal_width(command="terminal width 511", pattern="terminal")
                     self.disable_paging()
            -        # Clear the read buffer
            -        time.sleep(0.3 * self.global_delay_factor)
            -        self.clear_buffer()
             
            -    def special_login_handler(self, delay_factor=1):
            +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
                     """
                     Calix B6 presents with the following on login:
             
                     login as:
                     Password: ****
                     """
            -        delay_factor = self.select_delay_factor(delay_factor)
            -        i = 0
            -        time.sleep(delay_factor * 0.25)
            -        output = ""
            -        while i <= 12:
            -            output = self.read_channel()
            +        new_data = ""
            +        time.sleep(0.1)
            +        start = time.time()
            +        login_timeout = 20
            +        while time.time() - start < login_timeout:
            +            output = self.read_channel() if not new_data else new_data
            +            new_data = ""
                         if output:
                             if "login as:" in output:
            +                    assert isinstance(self.username, str)
                                 self.write_channel(self.username + self.RETURN)
                             elif "Password:" in output:
            +                    assert isinstance(self.password, str)
                                 self.write_channel(self.password + self.RETURN)
                                 break
            -                time.sleep(delay_factor * 0.5)
            +                time.sleep(0.1)
                         else:
            -                self.write_channel(self.RETURN)
            -                time.sleep(delay_factor * 1)
            -            i += 1
            -
            -    def check_config_mode(self, check_string=")#", pattern=""):
            +                # No new data...sleep longer
            +                time.sleep(0.5)
            +                new_data = self.read_channel()
            +                # If still no data, send an <enter>
            +                if not new_data:
            +                    self.write_channel(self.RETURN)
            +        else:  # no-break
            +            msg = """
            +Login process failed to Calix B6 device. Unable to login in {login_timeout} seconds.
            +"""
            +            raise NetmikoTimeoutException(msg)
            +
            +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
                     """Checks if the device is in configuration mode"""
                     return super().check_config_mode(check_string=check_string)
             
            -    def save_config(self, cmd="copy run start", confirm=False, confirm_response=""):
            +    def save_config(
            +        self,
            +        cmd: str = "copy run start",
            +        confirm: bool = False,
            +        confirm_response: str = "",
            +    ) -> str:
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
                     )
            @@ -101,12 +109,12 @@ 

            Module netmiko.calix.calix_b6

            the username/password. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection.""" # Create instance of SSHClient object # If not using SSH keys, we use noauth if not self.use_keys: - remote_conn_pre = SSHClient_noauth() + remote_conn_pre: SSHClient = SSHClient_noauth() else: remote_conn_pre = SSHClient() @@ -146,183 +154,169 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
    Source code
    class CalixB6Base(CiscoSSHConnection):
         """Common methods for Calix B6, both SSH and Telnet."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> Any:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.set_terminal_width(command="terminal width 511", pattern="terminal")
             self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def special_login_handler(self, delay_factor=1):
    +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
             """
             Calix B6 presents with the following on login:
     
             login as:
             Password: ****
             """
    -        delay_factor = self.select_delay_factor(delay_factor)
    -        i = 0
    -        time.sleep(delay_factor * 0.25)
    -        output = ""
    -        while i <= 12:
    -            output = self.read_channel()
    +        new_data = ""
    +        time.sleep(0.1)
    +        start = time.time()
    +        login_timeout = 20
    +        while time.time() - start < login_timeout:
    +            output = self.read_channel() if not new_data else new_data
    +            new_data = ""
                 if output:
                     if "login as:" in output:
    +                    assert isinstance(self.username, str)
                         self.write_channel(self.username + self.RETURN)
                     elif "Password:" in output:
    +                    assert isinstance(self.password, str)
                         self.write_channel(self.password + self.RETURN)
                         break
    -                time.sleep(delay_factor * 0.5)
    +                time.sleep(0.1)
                 else:
    -                self.write_channel(self.RETURN)
    -                time.sleep(delay_factor * 1)
    -            i += 1
    -
    -    def check_config_mode(self, check_string=")#", pattern=""):
    +                # No new data...sleep longer
    +                time.sleep(0.5)
    +                new_data = self.read_channel()
    +                # If still no data, send an <enter>
    +                if not new_data:
    +                    self.write_channel(self.RETURN)
    +        else:  # no-break
    +            msg = """
    +Login process failed to Calix B6 device. Unable to login in {login_timeout} seconds.
    +"""
    +            raise NetmikoTimeoutException(msg)
    +
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
             """Checks if the device is in configuration mode"""
             return super().check_config_mode(check_string=check_string)
     
    -    def save_config(self, cmd="copy run start", confirm=False, confirm_response=""):
    +    def save_config(
    +        self,
    +        cmd: str = "copy run start",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
             )
    @@ -347,7 +341,7 @@

    Methods

    Checks if the device is in configuration mode

    Source code -
    def check_config_mode(self, check_string=")#", pattern=""):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode"""
         return super().check_config_mode(check_string=check_string)
    @@ -359,20 +353,17 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> Any:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.set_terminal_width(command="terminal width 511", pattern="terminal")
    -    self.disable_paging()
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging()
    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Calix B6 presents with the following on login:

    @@ -380,30 +371,41 @@

    Methods

    Password: ****

    Source code -
    def special_login_handler(self, delay_factor=1):
    -    """
    -    Calix B6 presents with the following on login:
    +
        def special_login_handler(self, delay_factor: float = 1.0) -> None:
    +        """
    +        Calix B6 presents with the following on login:
     
    -    login as:
    -    Password: ****
    -    """
    -    delay_factor = self.select_delay_factor(delay_factor)
    -    i = 0
    -    time.sleep(delay_factor * 0.25)
    -    output = ""
    -    while i <= 12:
    -        output = self.read_channel()
    -        if output:
    -            if "login as:" in output:
    -                self.write_channel(self.username + self.RETURN)
    -            elif "Password:" in output:
    -                self.write_channel(self.password + self.RETURN)
    -                break
    -            time.sleep(delay_factor * 0.5)
    -        else:
    -            self.write_channel(self.RETURN)
    -            time.sleep(delay_factor * 1)
    -        i += 1
    + login as: + Password: **** + """ + new_data = "" + time.sleep(0.1) + start = time.time() + login_timeout = 20 + while time.time() - start < login_timeout: + output = self.read_channel() if not new_data else new_data + new_data = "" + if output: + if "login as:" in output: + assert isinstance(self.username, str) + self.write_channel(self.username + self.RETURN) + elif "Password:" in output: + assert isinstance(self.password, str) + self.write_channel(self.password + self.RETURN) + break + time.sleep(0.1) + else: + # No new data...sleep longer + time.sleep(0.5) + new_data = self.read_channel() + # If still no data, send an <enter> + if not new_data: + self.write_channel(self.RETURN) + else: # no-break + msg = """ +Login process failed to Calix B6 device. Unable to login in {login_timeout} seconds. +""" + raise NetmikoTimeoutException(msg)
    @@ -414,9 +416,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -427,9 +428,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -441,6 +442,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • strip_ansi_escape_codes
  • @@ -465,131 +467,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -600,12 +575,12 @@

    Inherited members

    the username/password. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection.""" # Create instance of SSHClient object # If not using SSH keys, we use noauth if not self.use_keys: - remote_conn_pre = SSHClient_noauth() + remote_conn_pre: SSHClient = SSHClient_noauth() else: remote_conn_pre = SSHClient() @@ -634,9 +609,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -647,9 +621,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -661,6 +635,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -685,131 +660,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -833,9 +781,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -846,9 +793,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -860,6 +807,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -874,27 +822,6 @@

    Inherited members

  • -
    -class SSHClient_noauth -
    -
    -

    Set noauth when manually handling SSH authentication.

    -

    Create a new SSHClient.

    -
    -Source code -
    class SSHClient_noauth(SSHClient):
    -    """Set noauth when manually handling SSH authentication."""
    -
    -    def _auth(self, username, *args):
    -        self._transport.auth_none(username)
    -        return
    -
    -

    Ancestors

    -
      -
    • paramiko.client.SSHClient
    • -
    • paramiko.util.ClosingContextManager
    • -
    -
    @@ -925,9 +852,6 @@

    CalixB6Telnet

    -
  • -

    SSHClient_noauth

    -
  • diff --git a/docs/netmiko/calix/index.html b/docs/netmiko/calix/index.html index 16f1c1cc8..254b35f05 100644 --- a/docs/netmiko/calix/index.html +++ b/docs/netmiko/calix/index.html @@ -55,131 +55,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -190,12 +163,12 @@

    Classes

    the username/password. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection.""" # Create instance of SSHClient object # If not using SSH keys, we use noauth if not self.use_keys: - remote_conn_pre = SSHClient_noauth() + remote_conn_pre: SSHClient = SSHClient_noauth() else: remote_conn_pre = SSHClient() @@ -224,9 +197,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -237,9 +209,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -251,6 +223,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -275,131 +248,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -423,9 +369,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -436,9 +381,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -450,6 +395,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/cdot/cdot_cros_ssh.html b/docs/netmiko/cdot/cdot_cros_ssh.html index 4ad2f6f79..b476d4ebf 100644 --- a/docs/netmiko/cdot/cdot_cros_ssh.html +++ b/docs/netmiko/cdot/cdot_cros_ssh.html @@ -27,42 +27,62 @@

    Module netmiko.cdot.cdot_cros_ssh

    # CROS = CDOT Router OS # Script: cros_ssh.py # Author: Maloy Ghosh <mghosh@cdot.in> +# Updated by Kirk Byers # # Purpose: Provide basic SSH connection to CROS based router products -from netmiko.cisco_base_connection import CiscoBaseConnection +from typing import Optional, Union, Sequence, TextIO, Any import time +import warnings +from netmiko.no_enable import NoEnable +from netmiko.cisco_base_connection import CiscoBaseConnection +from netmiko.base_connection import DELAY_FACTOR_DEPR_SIMPLE_MSG -class CdotCrosSSH(CiscoBaseConnection): +class CdotCrosSSH(NoEnable, CiscoBaseConnection): """Implement methods for interacting with CROS network devices.""" - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" - self._test_channel_read() + self._test_channel_read(pattern=r"[#\$]") self.set_base_prompt() self._disable_complete_on_space() + self.set_terminal_width(command="screen-width 511", pattern=r"screen.width 511") self.disable_paging(command="screen-length 0") - self.set_terminal_width(command="screen-width 511") - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() return - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """CROS requires you not exit from configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def check_config_mode(self, check_string=")#", pattern=r"[#\$]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[#\$]" + ) -> bool: """Checks if device is in configuration mode""" return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="config", pattern=""): + def config_mode( + self, config_command: str = "config", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def commit(self, comment="", delay_factor=1, and_quit=True): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + and_quit: bool = True, + ) -> str: """ Commit the candidate configuration. @@ -74,9 +94,12 @@

    Module netmiko.cdot.cdot_cros_ssh

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) command_string = "commit" commit_marker = ["Commit complete", "No modifications to commit"] @@ -87,11 +110,11 @@

    Module netmiko.cdot.cdot_cros_ssh

    command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=True, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if not (any(x in output for x in commit_marker)): @@ -100,19 +123,7 @@

    Module netmiko.cdot.cdot_cros_ssh

    self.exit_config_mode() return output - def check_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return True - - def enable(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def _disable_complete_on_space(self): + def _disable_complete_on_space(self) -> str: """ CROS tries to auto complete commands when you type a "space" character. @@ -139,7 +150,7 @@

    Classes

    class CdotCrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with CROS network devices.

    @@ -147,163 +158,151 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CdotCrosSSH(CiscoBaseConnection):
    +
    class CdotCrosSSH(NoEnable, CiscoBaseConnection):
         """Implement methods for interacting with CROS network devices."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[#\$]")
             self.set_base_prompt()
             self._disable_complete_on_space()
    +        self.set_terminal_width(command="screen-width 511", pattern=r"screen.width 511")
             self.disable_paging(command="screen-length 0")
    -        self.set_terminal_width(command="screen-width 511")
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
             return
     
    -    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = False,
    +        **kwargs: Any,
    +    ) -> str:
             """CROS requires you not exit from configuration mode."""
             return super().send_config_set(
                 config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
             )
     
    -    def check_config_mode(self, check_string=")#", pattern=r"[#\$]"):
    +    def check_config_mode(
    +        self, check_string: str = ")#", pattern: str = r"[#\$]"
    +    ) -> bool:
             """Checks if device is in configuration mode"""
             return super().check_config_mode(check_string=check_string, pattern=pattern)
     
    -    def config_mode(self, config_command="config", pattern=""):
    +    def config_mode(
    +        self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +    ) -> str:
             """Enter configuration mode."""
    -        return super().config_mode(config_command=config_command, pattern=pattern)
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
     
    -    def commit(self, comment="", delay_factor=1, and_quit=True):
    +    def commit(
    +        self,
    +        comment: str = "",
    +        read_timeout: float = 120.0,
    +        delay_factor: Optional[float] = None,
    +        and_quit: bool = True,
    +    ) -> str:
             """
             Commit the candidate configuration.
     
    @@ -315,9 +314,12 @@ 

    Classes

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) command_string = "commit" commit_marker = ["Commit complete", "No modifications to commit"] @@ -328,11 +330,11 @@

    Classes

    command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=True, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if not (any(x in output for x in commit_marker)): @@ -341,19 +343,7 @@

    Classes

    self.exit_config_mode() return output - def check_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return True - - def enable(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def _disable_complete_on_space(self): + def _disable_complete_on_space(self) -> str: """ CROS tries to auto complete commands when you type a "space" character. @@ -370,6 +360,7 @@

    Classes

    Ancestors

    @@ -382,25 +373,15 @@

    Methods

    Checks if device is in configuration mode

    Source code -
    def check_config_mode(self, check_string=")#", pattern=r"[#\$]"):
    +
    def check_config_mode(
    +    self, check_string: str = ")#", pattern: str = r"[#\$]"
    +) -> bool:
         """Checks if device is in configuration mode"""
         return super().check_config_mode(check_string=check_string, pattern=pattern)
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return True
    -
    -
    -def commit(self, comment='', delay_factor=1, and_quit=True) +def commit(self, comment='', read_timeout=120.0, delay_factor=None, and_quit=True)

    Commit the candidate configuration.

    @@ -409,10 +390,17 @@

    Methods

    default: command_string = commit comment: -command_string = commit comment

    +command_string = commit comment

    +

    delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code -
    def commit(self, comment="", delay_factor=1, and_quit=True):
    +
    def commit(
    +    self,
    +    comment: str = "",
    +    read_timeout: float = 120.0,
    +    delay_factor: Optional[float] = None,
    +    and_quit: bool = True,
    +) -> str:
         """
         Commit the candidate configuration.
     
    @@ -424,9 +412,12 @@ 

    Methods

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) command_string = "commit" commit_marker = ["Commit complete", "No modifications to commit"] @@ -437,11 +428,11 @@

    Methods

    command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=True, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if not (any(x in output for x in commit_marker)): @@ -452,39 +443,19 @@

    Methods

    -def config_mode(self, config_command='config', pattern='') +def config_mode(self, config_command='config', pattern='', re_flags=0)

    Enter configuration mode.

    Source code -
    def config_mode(self, config_command="config", pattern=""):
    +
    def config_mode(
    +    self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command, pattern=pattern)
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return ""
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    @@ -494,7 +465,12 @@

    Methods

    CROS requires you not exit from configuration mode.

    Source code -
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
    +
    def send_config_set(
    +    self,
    +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +    exit_config_mode: bool = False,
    +    **kwargs: Any,
    +) -> str:
         """CROS requires you not exit from configuration mode."""
         return super().send_config_set(
             config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    @@ -508,15 +484,13 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[#\$]")
         self.set_base_prompt()
         self._disable_complete_on_space()
    +    self.set_terminal_width(command="screen-width 511", pattern=r"screen.width 511")
         self.disable_paging(command="screen-length 0")
    -    self.set_terminal_width(command="screen-width 511")
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
         return
    @@ -525,20 +499,22 @@

    Inherited members

    • CiscoBaseConnection:
        +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -549,6 +525,7 @@

        Inherited members

      • send_command_expect
      • send_command_timing
      • send_config_from_file
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -580,13 +557,10 @@

        Index

        • CdotCrosSSH

          -
            + diff --git a/docs/netmiko/cdot/index.html b/docs/netmiko/cdot/index.html index 4f80bf97e..3237ca26a 100644 --- a/docs/netmiko/cdot/index.html +++ b/docs/netmiko/cdot/index.html @@ -45,7 +45,7 @@

            Classes

            class CdotCrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Implement methods for interacting with CROS network devices.

            @@ -53,163 +53,151 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CdotCrosSSH(CiscoBaseConnection):
    +
    class CdotCrosSSH(NoEnable, CiscoBaseConnection):
         """Implement methods for interacting with CROS network devices."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[#\$]")
             self.set_base_prompt()
             self._disable_complete_on_space()
    +        self.set_terminal_width(command="screen-width 511", pattern=r"screen.width 511")
             self.disable_paging(command="screen-length 0")
    -        self.set_terminal_width(command="screen-width 511")
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
             return
     
    -    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = False,
    +        **kwargs: Any,
    +    ) -> str:
             """CROS requires you not exit from configuration mode."""
             return super().send_config_set(
                 config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
             )
     
    -    def check_config_mode(self, check_string=")#", pattern=r"[#\$]"):
    +    def check_config_mode(
    +        self, check_string: str = ")#", pattern: str = r"[#\$]"
    +    ) -> bool:
             """Checks if device is in configuration mode"""
             return super().check_config_mode(check_string=check_string, pattern=pattern)
     
    -    def config_mode(self, config_command="config", pattern=""):
    +    def config_mode(
    +        self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +    ) -> str:
             """Enter configuration mode."""
    -        return super().config_mode(config_command=config_command, pattern=pattern)
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
     
    -    def commit(self, comment="", delay_factor=1, and_quit=True):
    +    def commit(
    +        self,
    +        comment: str = "",
    +        read_timeout: float = 120.0,
    +        delay_factor: Optional[float] = None,
    +        and_quit: bool = True,
    +    ) -> str:
             """
             Commit the candidate configuration.
     
    @@ -221,9 +209,12 @@ 

    Classes

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) command_string = "commit" commit_marker = ["Commit complete", "No modifications to commit"] @@ -234,11 +225,11 @@

    Classes

    command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=True, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if not (any(x in output for x in commit_marker)): @@ -247,19 +238,7 @@

    Classes

    self.exit_config_mode() return output - def check_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return True - - def enable(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on CROS.""" - return "" - - def _disable_complete_on_space(self): + def _disable_complete_on_space(self) -> str: """ CROS tries to auto complete commands when you type a "space" character. @@ -276,6 +255,7 @@

    Classes

    Ancestors

    @@ -288,25 +268,15 @@

    Methods

    Checks if device is in configuration mode

    Source code -
    def check_config_mode(self, check_string=")#", pattern=r"[#\$]"):
    +
    def check_config_mode(
    +    self, check_string: str = ")#", pattern: str = r"[#\$]"
    +) -> bool:
         """Checks if device is in configuration mode"""
         return super().check_config_mode(check_string=check_string, pattern=pattern)
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return True
    -
    -
    -def commit(self, comment='', delay_factor=1, and_quit=True) +def commit(self, comment='', read_timeout=120.0, delay_factor=None, and_quit=True)

    Commit the candidate configuration.

    @@ -315,10 +285,17 @@

    Methods

    default: command_string = commit comment: -command_string = commit comment

    +command_string = commit comment

    +

    delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code -
    def commit(self, comment="", delay_factor=1, and_quit=True):
    +
    def commit(
    +    self,
    +    comment: str = "",
    +    read_timeout: float = 120.0,
    +    delay_factor: Optional[float] = None,
    +    and_quit: bool = True,
    +) -> str:
         """
         Commit the candidate configuration.
     
    @@ -330,9 +307,12 @@ 

    Methods

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) command_string = "commit" commit_marker = ["Commit complete", "No modifications to commit"] @@ -343,11 +323,11 @@

    Methods

    command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=True, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if not (any(x in output for x in commit_marker)): @@ -358,39 +338,19 @@

    Methods

    -def config_mode(self, config_command='config', pattern='') +def config_mode(self, config_command='config', pattern='', re_flags=0)

    Enter configuration mode.

    Source code -
    def config_mode(self, config_command="config", pattern=""):
    +
    def config_mode(
    +    self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command, pattern=pattern)
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on CROS.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on CROS."""
    -    return ""
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    @@ -400,7 +360,12 @@

    Methods

    CROS requires you not exit from configuration mode.

    Source code -
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
    +
    def send_config_set(
    +    self,
    +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +    exit_config_mode: bool = False,
    +    **kwargs: Any,
    +) -> str:
         """CROS requires you not exit from configuration mode."""
         return super().send_config_set(
             config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    @@ -414,15 +379,13 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[#\$]")
         self.set_base_prompt()
         self._disable_complete_on_space()
    +    self.set_terminal_width(command="screen-width 511", pattern=r"screen.width 511")
         self.disable_paging(command="screen-length 0")
    -    self.set_terminal_width(command="screen-width 511")
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
         return
    @@ -431,20 +394,22 @@

    Inherited members

    • CiscoBaseConnection:
        +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -455,6 +420,7 @@

        Inherited members

      • send_command_expect
      • send_command_timing
      • send_config_from_file
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -491,13 +457,10 @@

        Index

        • CdotCrosSSH

          -
            + diff --git a/docs/netmiko/centec/centec_os.html b/docs/netmiko/centec/centec_os.html index 4b1c21a02..2c7233d15 100644 --- a/docs/netmiko/centec/centec_os.html +++ b/docs/netmiko/centec/centec_os.html @@ -25,20 +25,18 @@

            Module netmiko.centec.centec_os

            Source code
            """Centec OS Support"""
             from netmiko.cisco_base_connection import CiscoBaseConnection
            -import time
             
             
             class CentecOSBase(CiscoBaseConnection):
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
                     self.disable_paging()
            -        # Clear the read buffer
            -        time.sleep(0.3 * self.global_delay_factor)
            -        self.clear_buffer()
             
            -    def save_config(self, cmd="write", confirm=False, confirm_response=""):
            +    def save_config(
            +        self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
            +    ) -> str:
                     """Save config: write"""
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
            @@ -66,7 +64,7 @@ 

            Classes

            class CentecOSBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Base Class for cisco-like behavior.

            @@ -74,145 +72,117 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class CentecOSBase(CiscoBaseConnection):
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
                     self.disable_paging()
            -        # Clear the read buffer
            -        time.sleep(0.3 * self.global_delay_factor)
            -        self.clear_buffer()
             
            -    def save_config(self, cmd="write", confirm=False, confirm_response=""):
            +    def save_config(
            +        self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
            +    ) -> str:
                     """Save config: write"""
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
            @@ -237,7 +207,9 @@ 

            Methods

            Save config: write

            Source code -
            def save_config(self, cmd="write", confirm=False, confirm_response=""):
            +
            def save_config(
            +    self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
            +) -> str:
                 """Save config: write"""
                 return super().save_config(
                     cmd=cmd, confirm=confirm, confirm_response=confirm_response
            @@ -251,14 +223,11 @@ 

            Methods

            Prepare the session after the connection has been established.

            Source code -
            def session_preparation(self):
            +
            def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
            -    self.disable_paging()
            -    # Clear the read buffer
            -    time.sleep(0.3 * self.global_delay_factor)
            -    self.clear_buffer()
            + self.disable_paging()
    @@ -270,9 +239,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -283,9 +251,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -296,6 +264,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -311,7 +280,7 @@

    Inherited members

    class CentecOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -319,131 +288,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -465,9 +407,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -478,9 +419,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -492,6 +433,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -508,7 +450,7 @@

    Inherited members

    class CentecOSTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -516,131 +458,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -662,9 +577,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -675,9 +589,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -689,6 +603,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/centec/index.html b/docs/netmiko/centec/index.html index bdd6aa767..ae0adcdc8 100644 --- a/docs/netmiko/centec/index.html +++ b/docs/netmiko/centec/index.html @@ -45,7 +45,7 @@

    Classes

    class CentecOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -53,131 +53,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -199,9 +172,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -212,9 +184,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -226,6 +198,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -242,7 +215,7 @@

    Inherited members

    class CentecOSTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -250,131 +223,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -396,9 +342,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -409,9 +354,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -423,6 +368,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/channel.html b/docs/netmiko/channel.html new file mode 100644 index 000000000..4ca1f8906 --- /dev/null +++ b/docs/netmiko/channel.html @@ -0,0 +1,540 @@ + + + + + + +netmiko.channel API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.channel

    +
    +
    +
    +Source code +
    from typing import Any, Optional
    +from abc import ABC, abstractmethod
    +import paramiko
    +import telnetlib
    +import serial
    +
    +from netmiko.utilities import write_bytes
    +from netmiko.netmiko_globals import MAX_BUFFER
    +from netmiko.exceptions import ReadException, WriteException
    +
    +
    +class Channel(ABC):
    +    @abstractmethod
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
    +        """Create the object."""
    +        pass
    +
    +    # @abstractmethod
    +    # def __repr__(self) -> str:
    +    #     """String representation of the object."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def open(self, width: int = 511, height: int = 1000) -> None:
    +    #     """Create the underlying connection."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def close(self) -> None:
    +    #     """Close the underlying connection."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def login(self) -> None:
    +    #     """Handle the channel login process for any channel that requires it."""
    +    #     pass
    +
    +    @abstractmethod
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        pass
    +
    +    @abstractmethod
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        pass
    +
    +    @abstractmethod
    +    def write_channel(self, out_data: str) -> None:
    +        """Write data down the channel."""
    +        pass
    +
    +    # @abstractmethod
    +    # def is_alive(self) -> bool:
    +    #     """Is the channel alive."""
    +    #     pass
    +
    +
    +class SSHChannel(Channel):
    +    def __init__(self, conn: Optional[paramiko.Channel], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.sendall(write_bytes(out_data, encoding=self.encoding))
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        if self.remote_conn.recv_ready():
    +            outbuf = self.remote_conn.recv(MAX_BUFFER)
    +            if len(outbuf) == 0:
    +                raise ReadException("Channel stream closed by remote device.")
    +            output += outbuf.decode("utf-8", "ignore")
    +        return output
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        while True:
    +            new_output = self.read_buffer()
    +            output += new_output
    +            if new_output == "":
    +                break
    +        return output
    +
    +
    +class TelnetChannel(Channel):
    +    def __init__(self, conn: Optional[telnetlib.Telnet], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.write(write_bytes(out_data, encoding=self.encoding))
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        raise NotImplementedError
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        return self.remote_conn.read_very_eager().decode("utf-8", "ignore")
    +
    +
    +class SerialChannel(Channel):
    +    def __init__(self, conn: Optional[serial.Serial], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.write(write_bytes(out_data, encoding=self.encoding))
    +        self.remote_conn.flush()
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        if self.remote_conn.in_waiting > 0:
    +            output = self.remote_conn.read(self.remote_conn.in_waiting).decode(
    +                "utf-8", "ignore"
    +            )
    +            assert isinstance(output, str)
    +            return output
    +        else:
    +            return ""
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        while self.remote_conn.in_waiting > 0:
    +            output += self.read_buffer()
    +        return output
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class Channel +(*args, **kwargs) +
    +
    +

    Helper class that provides a standard way to create an ABC using +inheritance.

    +

    Create the object.

    +
    +Source code +
    class Channel(ABC):
    +    @abstractmethod
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
    +        """Create the object."""
    +        pass
    +
    +    # @abstractmethod
    +    # def __repr__(self) -> str:
    +    #     """String representation of the object."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def open(self, width: int = 511, height: int = 1000) -> None:
    +    #     """Create the underlying connection."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def close(self) -> None:
    +    #     """Close the underlying connection."""
    +    #     pass
    +    #
    +    # @abstractmethod
    +    # def login(self) -> None:
    +    #     """Handle the channel login process for any channel that requires it."""
    +    #     pass
    +
    +    @abstractmethod
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        pass
    +
    +    @abstractmethod
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        pass
    +
    +    @abstractmethod
    +    def write_channel(self, out_data: str) -> None:
    +        """Write data down the channel."""
    +        pass
    +
    +

    Ancestors

    +
      +
    • abc.ABC
    • +
    +

    Subclasses

    + +

    Methods

    +
    +
    +def read_buffer(self) +
    +
    +

    Single read of available data.

    +
    +Source code +
    @abstractmethod
    +def read_buffer(self) -> str:
    +    """Single read of available data."""
    +    pass
    +
    +
    +
    +def read_channel(self) +
    +
    +

    Read all of the available data from the channel.

    +
    +Source code +
    @abstractmethod
    +def read_channel(self) -> str:
    +    """Read all of the available data from the channel."""
    +    pass
    +
    +
    +
    +def write_channel(self, out_data) +
    +
    +

    Write data down the channel.

    +
    +Source code +
    @abstractmethod
    +def write_channel(self, out_data: str) -> None:
    +    """Write data down the channel."""
    +    pass
    +
    +
    +
    +
    +
    +class SSHChannel +(conn, encoding) +
    +
    +

    Helper class that provides a standard way to create an ABC using +inheritance.

    +

    Placeholder init method so that reading and writing can be moved to the +channel class.

    +
    +Source code +
    class SSHChannel(Channel):
    +    def __init__(self, conn: Optional[paramiko.Channel], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.sendall(write_bytes(out_data, encoding=self.encoding))
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        if self.remote_conn.recv_ready():
    +            outbuf = self.remote_conn.recv(MAX_BUFFER)
    +            if len(outbuf) == 0:
    +                raise ReadException("Channel stream closed by remote device.")
    +            output += outbuf.decode("utf-8", "ignore")
    +        return output
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        while True:
    +            new_output = self.read_buffer()
    +            output += new_output
    +            if new_output == "":
    +                break
    +        return output
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +class SerialChannel +(conn, encoding) +
    +
    +

    Helper class that provides a standard way to create an ABC using +inheritance.

    +

    Placeholder init method so that reading and writing can be moved to the +channel class.

    +
    +Source code +
    class SerialChannel(Channel):
    +    def __init__(self, conn: Optional[serial.Serial], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.write(write_bytes(out_data, encoding=self.encoding))
    +        self.remote_conn.flush()
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        if self.remote_conn.in_waiting > 0:
    +            output = self.remote_conn.read(self.remote_conn.in_waiting).decode(
    +                "utf-8", "ignore"
    +            )
    +            assert isinstance(output, str)
    +            return output
    +        else:
    +            return ""
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        output = ""
    +        while self.remote_conn.in_waiting > 0:
    +            output += self.read_buffer()
    +        return output
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +class TelnetChannel +(conn, encoding) +
    +
    +

    Helper class that provides a standard way to create an ABC using +inheritance.

    +

    Placeholder init method so that reading and writing can be moved to the +channel class.

    +
    +Source code +
    class TelnetChannel(Channel):
    +    def __init__(self, conn: Optional[telnetlib.Telnet], encoding: str) -> None:
    +        """
    +        Placeholder __init__ method so that reading and writing can be moved to the
    +        channel class.
    +        """
    +        self.remote_conn = conn
    +        # FIX: move encoding to GlobalState object?
    +        self.encoding = encoding
    +
    +    def write_channel(self, out_data: str) -> None:
    +        if self.remote_conn is None:
    +            raise WriteException(
    +                "Attempt to write data, but there is no active channel."
    +            )
    +        self.remote_conn.write(write_bytes(out_data, encoding=self.encoding))
    +
    +    def read_buffer(self) -> str:
    +        """Single read of available data."""
    +        raise NotImplementedError
    +
    +    def read_channel(self) -> str:
    +        """Read all of the available data from the channel."""
    +        if self.remote_conn is None:
    +            raise ReadException("Attempt to read, but there is no active channel.")
    +        return self.remote_conn.read_very_eager().decode("utf-8", "ignore")
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/checkpoint/checkpoint_gaia_ssh.html b/docs/netmiko/checkpoint/checkpoint_gaia_ssh.html index bf196d8fc..d414540aa 100644 --- a/docs/netmiko/checkpoint/checkpoint_gaia_ssh.html +++ b/docs/netmiko/checkpoint/checkpoint_gaia_ssh.html @@ -22,39 +22,29 @@

    Module netmiko.checkpoint.checkpoint_gaia_ssh

    Source code -
    import time
    +
    from netmiko.no_config import NoConfig
     from netmiko.base_connection import BaseConnection
     
     
    -class CheckPointGaiaSSH(BaseConnection):
    +class CheckPointGaiaSSH(NoConfig, BaseConnection):
         """
         Implements methods for communicating with Check Point Gaia
         firewalls.
         """
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established.
     
             Set the base prompt for interaction ('>').
             """
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging(command="set clienv rows 0")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def config_mode(self, config_command=""):
    -        """No config mode for Check Point devices."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config=""):
    -        """No config mode for Check Point devices."""
    -        return ""
    -
    -    def save_config(self, *args, **kwargs):
    -        """Not Implemented"""
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             raise NotImplementedError
    @@ -69,7 +59,7 @@

    Classes

    class CheckPointGaiaSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implements methods for communicating with Check Point Gaia @@ -78,195 +68,135 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CheckPointGaiaSSH(BaseConnection):
    +
    class CheckPointGaiaSSH(NoConfig, BaseConnection):
         """
         Implements methods for communicating with Check Point Gaia
         firewalls.
         """
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established.
     
             Set the base prompt for interaction ('>').
             """
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging(command="set clienv rows 0")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def config_mode(self, config_command=""):
    -        """No config mode for Check Point devices."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config=""):
    -        """No config mode for Check Point devices."""
    -        return ""
     
    -    def save_config(self, *args, **kwargs):
    -        """Not Implemented"""
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             raise NotImplementedError

    Ancestors

    Methods

    -
    -def config_mode(self, config_command='') -
    -
    -

    No config mode for Check Point devices.

    -
    -Source code -
    def config_mode(self, config_command=""):
    -    """No config mode for Check Point devices."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, exit_config='') -
    -
    -

    No config mode for Check Point devices.

    -
    -Source code -
    def exit_config_mode(self, exit_config=""):
    -    """No config mode for Check Point devices."""
    -    return ""
    -
    -
    def session_preparation(self)
    @@ -275,18 +205,15 @@

    Methods

    Set the base prompt for interaction ('>').

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established.
     
         Set the base prompt for interaction ('>').
         """
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
    -    self.disable_paging(command="set clienv rows 0")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="set clienv rows 0")
    @@ -298,20 +225,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • establish_connection
  • +
  • exit_config_mode
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -323,6 +251,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -355,8 +284,6 @@

    Index

  • CheckPointGaiaSSH

  • diff --git a/docs/netmiko/checkpoint/index.html b/docs/netmiko/checkpoint/index.html index 51284305d..284a19e0b 100644 --- a/docs/netmiko/checkpoint/index.html +++ b/docs/netmiko/checkpoint/index.html @@ -45,7 +45,7 @@

    Classes

    class CheckPointGaiaSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implements methods for communicating with Check Point Gaia @@ -54,195 +54,135 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CheckPointGaiaSSH(BaseConnection):
    +
    class CheckPointGaiaSSH(NoConfig, BaseConnection):
         """
         Implements methods for communicating with Check Point Gaia
         firewalls.
         """
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established.
     
             Set the base prompt for interaction ('>').
             """
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging(command="set clienv rows 0")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def config_mode(self, config_command=""):
    -        """No config mode for Check Point devices."""
    -        return ""
     
    -    def exit_config_mode(self, exit_config=""):
    -        """No config mode for Check Point devices."""
    -        return ""
    -
    -    def save_config(self, *args, **kwargs):
    -        """Not Implemented"""
    +    def save_config(
    +        self, cmd: str = "", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             raise NotImplementedError

    Ancestors

    Methods

    -
    -def config_mode(self, config_command='') -
    -
    -

    No config mode for Check Point devices.

    -
    -Source code -
    def config_mode(self, config_command=""):
    -    """No config mode for Check Point devices."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, exit_config='') -
    -
    -

    No config mode for Check Point devices.

    -
    -Source code -
    def exit_config_mode(self, exit_config=""):
    -    """No config mode for Check Point devices."""
    -    return ""
    -
    -
    def session_preparation(self)
    @@ -251,18 +191,15 @@

    Methods

    Set the base prompt for interaction ('>').

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established.
     
         Set the base prompt for interaction ('>').
         """
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
    -    self.disable_paging(command="set clienv rows 0")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="set clienv rows 0")
    @@ -274,20 +211,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • establish_connection
  • +
  • exit_config_mode
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -299,6 +237,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -336,8 +275,6 @@

    Index

  • CheckPointGaiaSSH

  • diff --git a/docs/netmiko/ciena/ciena_saos.html b/docs/netmiko/ciena/ciena_saos.html index 4e33c21ad..f8de7150f 100644 --- a/docs/netmiko/ciena/ciena_saos.html +++ b/docs/netmiko/ciena/ciena_saos.html @@ -24,70 +24,49 @@

    Module netmiko.ciena.ciena_saos

    Source code
    """Ciena SAOS support."""
    -import time
    +from typing import Optional, Any
     import re
     import os
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
     from netmiko.base_connection import BaseConnection
     from netmiko.scp_handler import BaseFileTransfer
     
     
    -class CienaSaosBase(BaseConnection):
    +class CienaSaosBase(NoEnable, NoConfig, BaseConnection):
         """
         Ciena SAOS support.
     
         Implements methods for interacting Ciena Saos devices.
    -
    -    Disables enable(), check_enable_mode(), config_mode() and
    -    check_config_mode()
         """
     
    -    def session_preparation(self):
    -        self._test_channel_read()
    +    def session_preparation(self) -> None:
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging(command="system shell session set more off")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def _enter_shell(self):
    +    def _enter_shell(self) -> str:
             """Enter the Bourne Shell."""
    -        output = self.send_command("diag shell", expect_string=r"[$#>]")
    +        output = self._send_command_str("diag shell", expect_string=r"[$#>]")
             if "SHELL PARSER FAILURE" in output:
                 msg = "SCP support on Ciena SAOS requires 'diag shell' permissions"
                 raise ValueError(msg)
             return output
     
    -    def _return_cli(self):
    +    def _return_cli(self) -> str:
             """Return to the Ciena SAOS CLI."""
    -        return self.send_command("exit", expect_string=r"[>]")
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return True
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return ""
    -
    -    def check_config_mode(self, check_string=">", pattern=""):
    -        """No config mode on Ciena SAOS."""
    -        return False
    +        return self._send_command_str("exit", expect_string=r"[>]")
     
    -    def config_mode(self, config_command=""):
    -        """No config mode on Ciena SAOS."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config=""):
    -        """No config mode on Ciena SAOS."""
    -        return ""
    -
    -    def save_config(self, cmd="configuration save", confirm=False, confirm_response=""):
    +    def save_config(
    +        self,
    +        cmd: str = "configuration save",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Saves Config."""
    -        return self.send_command(command_string=cmd)
    +        return super().save_config(
    +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
    +        )
     
     
     class CienaSaosSSH(CienaSaosBase):
    @@ -95,7 +74,7 @@ 

    Module netmiko.ciena.ciena_saos

    class CienaSaosTelnet(CienaSaosBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs) @@ -106,14 +85,14 @@

    Module netmiko.ciena.ciena_saos

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="", - direction="put", - **kwargs, - ): - if file_system == "": + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + **kwargs: Any, + ) -> None: + if file_system is None: file_system = f"/tmp/users/{ssh_conn.username}" return super().__init__( ssh_conn=ssh_conn, @@ -124,7 +103,7 @@

    Module netmiko.ciena.ciena_saos

    **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """ Return space available on Ciena SAOS @@ -134,7 +113,7 @@

    Module netmiko.ciena.ciena_saos

    tmpfs 1048576 648 1047928 0% /tmp """ remote_cmd = f"file vols -P {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) remote_output = remote_output.strip() err_msg = ( f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" @@ -164,12 +143,12 @@

    Module netmiko.ciena.ciena_saos

    return int(space_avail) * 1024 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"file ls {self.file_system}/{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = re.escape(f"{self.file_system}/{self.dest_file}") if "ERROR" in remote_out: return False @@ -179,8 +158,12 @@

    Module netmiko.ciena.ciena_saos

    raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -193,7 +176,7 @@

    Module netmiko.ciena.ciena_saos

    if not remote_cmd: remote_cmd = f"file ls -l {remote_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "No such file or directory" in remote_out: raise IOError("Unable to find file on remote system") @@ -211,7 +194,7 @@

    Module netmiko.ciena.ciena_saos

    "Search pattern not found for remote file size during SCP transfer." ) - def remote_md5(self, base_cmd="", remote_file=None): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: """Calculate remote MD5 and returns the hash. This command can be CPU intensive on the remote device. @@ -227,17 +210,17 @@

    Module netmiko.ciena.ciena_saos

    remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" self.ssh_ctl_chan._enter_shell() - dest_md5 = self.ssh_ctl_chan.send_command( + dest_md5 = self.ssh_ctl_chan._send_command_str( remote_md5_cmd, expect_string=r"[$#>]" ) self.ssh_ctl_chan._return_cli() dest_md5 = self.process_md5(dest_md5, pattern=r"([0-9a-f]+)\s+") return dest_md5 - def enable_scp(self, cmd="system server scp enable"): + def enable_scp(self, cmd: str = "system server scp enable") -> None: return super().enable_scp(cmd=cmd) - def disable_scp(self, cmd="system server scp disable"): + def disable_scp(self, cmd: str = "system server scp disable") -> None: return super().disable_scp(cmd=cmd)
    @@ -252,205 +235,155 @@

    Classes

    class CienaSaosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Ciena SAOS support.

    Implements methods for interacting Ciena Saos devices.

    -

    Disables enable(), check_enable_mode(), config_mode() and -check_config_mode()

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CienaSaosBase(BaseConnection):
    +
    class CienaSaosBase(NoEnable, NoConfig, BaseConnection):
         """
         Ciena SAOS support.
     
         Implements methods for interacting Ciena Saos devices.
    -
    -    Disables enable(), check_enable_mode(), config_mode() and
    -    check_config_mode()
         """
     
    -    def session_preparation(self):
    -        self._test_channel_read()
    +    def session_preparation(self) -> None:
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
             self.disable_paging(command="system shell session set more off")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
     
    -    def _enter_shell(self):
    +    def _enter_shell(self) -> str:
             """Enter the Bourne Shell."""
    -        output = self.send_command("diag shell", expect_string=r"[$#>]")
    +        output = self._send_command_str("diag shell", expect_string=r"[$#>]")
             if "SHELL PARSER FAILURE" in output:
                 msg = "SCP support on Ciena SAOS requires 'diag shell' permissions"
                 raise ValueError(msg)
             return output
     
    -    def _return_cli(self):
    +    def _return_cli(self) -> str:
             """Return to the Ciena SAOS CLI."""
    -        return self.send_command("exit", expect_string=r"[>]")
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return True
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Ciena SAOS."""
    -        return ""
    +        return self._send_command_str("exit", expect_string=r"[>]")
     
    -    def check_config_mode(self, check_string=">", pattern=""):
    -        """No config mode on Ciena SAOS."""
    -        return False
    -
    -    def config_mode(self, config_command=""):
    -        """No config mode on Ciena SAOS."""
    -        return ""
    -
    -    def exit_config_mode(self, exit_config=""):
    -        """No config mode on Ciena SAOS."""
    -        return ""
    -
    -    def save_config(self, cmd="configuration save", confirm=False, confirm_response=""):
    +    def save_config(
    +        self,
    +        cmd: str = "configuration save",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Saves Config."""
    -        return self.send_command(command_string=cmd)
    + return super().save_config( + cmd=cmd, confirm=confirm, confirm_response=confirm_response + )

    Ancestors

    Subclasses

    @@ -460,78 +393,6 @@

    Subclasses

    Methods

    -
    -def check_config_mode(self, check_string='>', pattern='') -
    -
    -

    No config mode on Ciena SAOS.

    -
    -Source code -
    def check_config_mode(self, check_string=">", pattern=""):
    -    """No config mode on Ciena SAOS."""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Ciena SAOS.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Ciena SAOS."""
    -    return True
    -
    -
    -
    -def config_mode(self, config_command='') -
    -
    -

    No config mode on Ciena SAOS.

    -
    -Source code -
    def config_mode(self, config_command=""):
    -    """No config mode on Ciena SAOS."""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on Ciena SAOS.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on Ciena SAOS."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, exit_config='') -
    -
    -

    No config mode on Ciena SAOS.

    -
    -Source code -
    def exit_config_mode(self, exit_config=""):
    -    """No config mode on Ciena SAOS."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Ciena SAOS.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Ciena SAOS."""
    -    return ""
    -
    -
    def save_config(self, cmd='configuration save', confirm=False, confirm_response='')
    @@ -539,9 +400,16 @@

    Methods

    Saves Config.

    Source code -
    def save_config(self, cmd="configuration save", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "configuration save",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config."""
    -    return self.send_command(command_string=cmd)
    + return super().save_config( + cmd=cmd, confirm=confirm, confirm_response=confirm_response + )
    @@ -549,20 +417,25 @@

    Inherited members

    class CienaSaosFileTransfer -(ssh_conn, source_file, dest_file, file_system='', direction='put', **kwargs) +(ssh_conn, source_file, dest_file, file_system=None, direction='put', **kwargs)

    Ciena SAOS SCP File Transfer driver.

    @@ -600,14 +474,14 @@

    Inherited members

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="", - direction="put", - **kwargs, - ): - if file_system == "": + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + **kwargs: Any, + ) -> None: + if file_system is None: file_system = f"/tmp/users/{ssh_conn.username}" return super().__init__( ssh_conn=ssh_conn, @@ -618,7 +492,7 @@

    Inherited members

    **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """ Return space available on Ciena SAOS @@ -628,7 +502,7 @@

    Inherited members

    tmpfs 1048576 648 1047928 0% /tmp """ remote_cmd = f"file vols -P {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) remote_output = remote_output.strip() err_msg = ( f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" @@ -658,12 +532,12 @@

    Inherited members

    return int(space_avail) * 1024 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"file ls {self.file_system}/{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = re.escape(f"{self.file_system}/{self.dest_file}") if "ERROR" in remote_out: return False @@ -673,8 +547,12 @@

    Inherited members

    raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -687,7 +565,7 @@

    Inherited members

    if not remote_cmd: remote_cmd = f"file ls -l {remote_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "No such file or directory" in remote_out: raise IOError("Unable to find file on remote system") @@ -705,7 +583,7 @@

    Inherited members

    "Search pattern not found for remote file size during SCP transfer." ) - def remote_md5(self, base_cmd="", remote_file=None): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: """Calculate remote MD5 and returns the hash. This command can be CPU intensive on the remote device. @@ -721,17 +599,17 @@

    Inherited members

    remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" self.ssh_ctl_chan._enter_shell() - dest_md5 = self.ssh_ctl_chan.send_command( + dest_md5 = self.ssh_ctl_chan._send_command_str( remote_md5_cmd, expect_string=r"[$#>]" ) self.ssh_ctl_chan._return_cli() dest_md5 = self.process_md5(dest_md5, pattern=r"([0-9a-f]+)\s+") return dest_md5 - def enable_scp(self, cmd="system server scp enable"): + def enable_scp(self, cmd: str = "system server scp enable") -> None: return super().enable_scp(cmd=cmd) - def disable_scp(self, cmd="system server scp disable"): + def disable_scp(self, cmd: str = "system server scp disable") -> None: return super().disable_scp(cmd=cmd)

    Ancestors

    @@ -756,7 +634,7 @@

    Methods

    0% /tmp

    Source code -
    def remote_space_available(self, search_pattern=""):
    +
    def remote_space_available(self, search_pattern: str = "") -> int:
         """
         Return space available on Ciena SAOS
     
    @@ -766,7 +644,7 @@ 

    Methods

    tmpfs 1048576 648 1047928 0% /tmp """ remote_cmd = f"file vols -P {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) remote_output = remote_output.strip() err_msg = ( f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" @@ -824,142 +702,113 @@

    Inherited members

    class CienaSaosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Ciena SAOS support.

    Implements methods for interacting Ciena Saos devices.

    -

    Disables enable(), check_enable_mode(), config_mode() and -check_config_mode()

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -969,32 +818,33 @@

    Inherited members

    Ancestors

    Inherited members

    • CienaSaosBase:
        -
      • check_config_mode
      • -
      • check_enable_mode
      • +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • -
      • enable
      • +
      • enable
      • establish_connection
      • -
      • exit_config_mode
      • -
      • exit_enable_mode
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1006,6 +856,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -1027,142 +878,113 @@

        Inherited members

        Ciena SAOS support.

        Implements methods for interacting Ciena Saos devices.

        -

        Disables enable(), check_enable_mode(), config_mode() and -check_config_mode()

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class CienaSaosTelnet(CienaSaosBase):
        -    def __init__(self, *args, **kwargs):
        +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                 default_enter = kwargs.get("default_enter")
                 kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                 super().__init__(*args, **kwargs)
        @@ -1170,32 +992,33 @@

        Inherited members

        Ancestors

        Inherited members

        • CienaSaosBase:
            -
          • check_config_mode
          • -
          • check_enable_mode
          • +
          • check_config_mode
          • +
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • -
          • enable
          • +
          • enable
          • establish_connection
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • +
          • exit_config_mode
          • +
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -1207,6 +1030,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -1239,13 +1063,7 @@

            Index

            • CienaSaosBase

              -
                -
              • check_config_mode
              • -
              • check_enable_mode
              • -
              • config_mode
              • -
              • enable
              • -
              • exit_config_mode
              • -
              • exit_enable_mode
              • + diff --git a/docs/netmiko/ciena/index.html b/docs/netmiko/ciena/index.html index 608b89c15..f38b15400 100644 --- a/docs/netmiko/ciena/index.html +++ b/docs/netmiko/ciena/index.html @@ -49,7 +49,7 @@

                Classes

                class CienaSaosFileTransfer -(ssh_conn, source_file, dest_file, file_system='', direction='put', **kwargs) +(ssh_conn, source_file, dest_file, file_system=None, direction='put', **kwargs)

                Ciena SAOS SCP File Transfer driver.

                @@ -60,14 +60,14 @@

                Classes

                def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="", - direction="put", - **kwargs, - ): - if file_system == "": + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + **kwargs: Any, + ) -> None: + if file_system is None: file_system = f"/tmp/users/{ssh_conn.username}" return super().__init__( ssh_conn=ssh_conn, @@ -78,7 +78,7 @@

                Classes

                **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """ Return space available on Ciena SAOS @@ -88,7 +88,7 @@

                Classes

                tmpfs 1048576 648 1047928 0% /tmp """ remote_cmd = f"file vols -P {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) remote_output = remote_output.strip() err_msg = ( f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" @@ -118,12 +118,12 @@

                Classes

                return int(space_avail) * 1024 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"file ls {self.file_system}/{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = re.escape(f"{self.file_system}/{self.dest_file}") if "ERROR" in remote_out: return False @@ -133,8 +133,12 @@

                Classes

                raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -147,7 +151,7 @@

                Classes

                if not remote_cmd: remote_cmd = f"file ls -l {remote_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "No such file or directory" in remote_out: raise IOError("Unable to find file on remote system") @@ -165,7 +169,7 @@

                Classes

                "Search pattern not found for remote file size during SCP transfer." ) - def remote_md5(self, base_cmd="", remote_file=None): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: """Calculate remote MD5 and returns the hash. This command can be CPU intensive on the remote device. @@ -181,17 +185,17 @@

                Classes

                remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" self.ssh_ctl_chan._enter_shell() - dest_md5 = self.ssh_ctl_chan.send_command( + dest_md5 = self.ssh_ctl_chan._send_command_str( remote_md5_cmd, expect_string=r"[$#>]" ) self.ssh_ctl_chan._return_cli() dest_md5 = self.process_md5(dest_md5, pattern=r"([0-9a-f]+)\s+") return dest_md5 - def enable_scp(self, cmd="system server scp enable"): + def enable_scp(self, cmd: str = "system server scp enable") -> None: return super().enable_scp(cmd=cmd) - def disable_scp(self, cmd="system server scp disable"): + def disable_scp(self, cmd: str = "system server scp disable") -> None: return super().disable_scp(cmd=cmd)

        Ancestors

        @@ -216,7 +220,7 @@

        Methods

        0% /tmp

        Source code -
        def remote_space_available(self, search_pattern=""):
        +
        def remote_space_available(self, search_pattern: str = "") -> int:
             """
             Return space available on Ciena SAOS
         
        @@ -226,7 +230,7 @@ 

        Methods

        tmpfs 1048576 648 1047928 0% /tmp """ remote_cmd = f"file vols -P {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) remote_output = remote_output.strip() err_msg = ( f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" @@ -284,142 +288,113 @@

        Inherited members

        class CienaSaosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Ciena SAOS support.

        Implements methods for interacting Ciena Saos devices.

        -

        Disables enable(), check_enable_mode(), config_mode() and -check_config_mode()

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -429,32 +404,33 @@

        Inherited members

        Ancestors

        Inherited members

        • CienaSaosBase:
            -
          • check_config_mode
          • -
          • check_enable_mode
          • +
          • check_config_mode
          • +
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • -
          • enable
          • +
          • enable
          • establish_connection
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • +
          • exit_config_mode
          • +
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -466,6 +442,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -487,142 +464,113 @@

            Inherited members

            Ciena SAOS support.

            Implements methods for interacting Ciena Saos devices.

            -

            Disables enable(), check_enable_mode(), config_mode() and -check_config_mode()

                Initialize attributes for establishing connection to target device.
             
                 :param ip: IP address of target device. Not required if `host` is
                     provided.
            -    :type ip: str
             
                 :param host: Hostname of target device. Not required if `ip` is
                         provided.
            -    :type host: str
             
                 :param username: Username to authenticate against target device if
                         required.
            -    :type username: str
             
                 :param password: Password to authenticate against target device if
                         required.
            -    :type password: str
             
                 :param secret: The enable password if target device requires one.
            -    :type secret: str
             
                 :param port: The destination port used to connect to the target
                         device.
            -    :type port: int or None
             
                 :param device_type: Class selection based on device type.
            -    :type device_type: str
             
                 :param verbose: Enable additional messages to standard output.
            -    :type verbose: bool
             
                 :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
            -    :type global_delay_factor: int
             
                 :param use_keys: Connect to target device using SSH keys.
            -    :type use_keys: bool
             
                 :param key_file: Filename path of the SSH key file to use.
            -    :type key_file: str
             
                 :param pkey: SSH key object to use.
            -    :type pkey: paramiko.PKey
             
                 :param passphrase: Passphrase to use for encrypted key; password will be used for key
                         decryption if not specified.
            -    :type passphrase: str
            +
            +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
            +            documentation for a description of the expected format.
             
                 :param allow_agent: Enable use of SSH key-agent.
            -    :type allow_agent: bool
             
                 :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                         means unknown SSH host keys will be accepted).
            -    :type ssh_strict: bool
             
                 :param system_host_keys: Load host keys from the users known_hosts file.
            -    :type system_host_keys: bool
            +
                 :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                         alt_key_file.
            -    :type alt_host_keys: bool
             
                 :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
            -    :type alt_key_file: str
             
                 :param ssh_config_file: File name of OpenSSH configuration file.
            -    :type ssh_config_file: str
             
                 :param timeout: Connection timeout.
            -    :type timeout: float
             
                 :param session_timeout: Set a timeout for parallel requests.
            -    :type session_timeout: float
             
                 :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
            -    :type auth_timeout: float
             
                 :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
            -    :type banner_timeout: float
             
                 :param 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).
            -    :type keepalive: int
             
                 :param default_enter: Character(s) to send to correspond to enter key (default:
             
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class CienaSaosTelnet(CienaSaosBase):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     default_enter = kwargs.get("default_enter")
                     kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                     super().__init__(*args, **kwargs)
            @@ -630,32 +578,33 @@

            Inherited members

            Ancestors

            Inherited members

            • CienaSaosBase:
                -
              • check_config_mode
              • -
              • check_enable_mode
              • +
              • check_config_mode
              • +
              • check_enable_mode
              • cleanup
              • clear_buffer
              • -
              • close_session_log
              • commit
              • -
              • config_mode
              • +
              • config_mode
              • disable_paging
              • disconnect
              • -
              • enable
              • +
              • enable
              • establish_connection
              • -
              • exit_config_mode
              • -
              • exit_enable_mode
              • +
              • exit_config_mode
              • +
              • exit_enable_mode
              • find_prompt
              • is_alive
              • normalize_cmd
              • normalize_linefeeds
              • -
              • open_session_log
              • paramiko_cleanup
              • read_channel
              • +
              • read_channel_timing
              • read_until_pattern
              • read_until_prompt
              • read_until_prompt_or_pattern
              • @@ -667,6 +616,7 @@

                Inherited members

              • send_command_timing
              • send_config_from_file
              • send_config_set
              • +
              • send_multiline
              • session_preparation
              • set_base_prompt
              • set_terminal_width
              • diff --git a/docs/netmiko/cisco/cisco_asa_ssh.html b/docs/netmiko/cisco/cisco_asa_ssh.html index c352342c4..4754f10fe 100644 --- a/docs/netmiko/cisco/cisco_asa_ssh.html +++ b/docs/netmiko/cisco/cisco_asa_ssh.html @@ -24,22 +24,21 @@

                Module netmiko.cisco.cisco_asa_ssh

                Source code
                """Subclass specific to Cisco ASA."""
                +from typing import Any, Union, List, Dict, Optional
                 import re
                 import time
                 from netmiko.cisco_base_connection import CiscoSSHConnection, CiscoFileTransfer
                -from netmiko.ssh_exception import NetmikoAuthenticationException
                +from netmiko.exceptions import NetmikoAuthenticationException
                 
                 
                 class CiscoAsaSSH(CiscoSSHConnection):
                     """Subclass specific to Cisco ASA."""
                 
                -    def __init__(self, *args, **kwargs):
                -        kwargs.setdefault("fast_cli", True)
                -        kwargs.setdefault("_legacy_mode", False)
                +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                         kwargs.setdefault("allow_auto_change", True)
                         return super().__init__(*args, **kwargs)
                 
                -    def session_preparation(self):
                +    def session_preparation(self) -> None:
                         """Prepare the session after the connection has been established."""
                 
                         # Make sure the ASA is ready
                @@ -67,21 +66,25 @@ 

                Module netmiko.cisco.cisco_asa_ssh

                self.set_base_prompt() - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[>\#]" + ) -> bool: return super().check_config_mode(check_string=check_string, pattern=pattern) def enable( self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = r"\#", + re_flags: int = re.IGNORECASE, + ) -> str: return super().enable( cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags ) - def send_command_timing(self, *args, **kwargs): + def send_command_timing( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -95,7 +98,9 @@

                Module netmiko.cisco.cisco_asa_ssh

                self.set_base_prompt() return output - def send_command(self, *args, **kwargs): + def send_command( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -117,11 +122,7 @@

                Module netmiko.cisco.cisco_asa_ssh

                return output - def send_command_expect(self, *args, **kwargs): - """Backwards compaitibility.""" - return self.send_command(*args, **kwargs) - - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """ Cisco ASA in multi-context mode needs to have the base prompt updated (if you switch contexts i.e. 'changeto') @@ -135,8 +136,10 @@

                Module netmiko.cisco.cisco_asa_ssh

                # strip off (conf.* from base_prompt self.base_prompt = match.group(1) return self.base_prompt + else: + return cur_base_prompt - def asa_login(self): + def asa_login(self) -> None: """ Handle ASA reaching privilege level 15 using login @@ -156,8 +159,10 @@

                Module netmiko.cisco.cisco_asa_ssh

                time.sleep(0.5 * delay_factor) output = self.read_channel() if "sername" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "ssword" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) elif "#" in output: return @@ -168,13 +173,15 @@

                Module netmiko.cisco.cisco_asa_ssh

                msg = "Unable to enter enable mode!" raise NetmikoAuthenticationException(msg) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Cisco ASA needed that extra \r\n\r""" newline = re.compile("(\r\n\r|\r\r\r\n|\r\r\n|\r\n|\n\r)") a_string = newline.sub(self.RESPONSE_RETURN, a_string) @@ -253,144 +260,115 @@

                Inherited members

                :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                -

                ). -:type default_enter: str

                +

                ).

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

                ) -:type response_return: str

                +

                )

                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                             to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                +            (default: True)
                 
                     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                 
                     :param session_log_record_writes: The session log generally only records channel reads due
                             to eliminate command duplication due to command echo. You can enable this if you
                             want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                 
                     :param session_log_file_mode: "write" or "append" for session_log file mode
                             (default: "write")
                -    :type session_log_file_mode: str
                 
                     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                             (default: False)
                -    :type allow_auto_change: bool
                 
                     :param encoding: Encoding to be used when writing bytes to the output channel.
                             (default: ascii)
                -    :type encoding: str
                 
                     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                             communication to the target host (default: None).
                -    :type sock: socket
                 
                     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                             (default: None). Global attribute takes precedence over function `cmd_verify`
                             argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                 
                     :param auto_connect: Control whether Netmiko automatically establishes the connection as
                             part of the object creation (default: True).
                -    :type auto_connect: bool
                +
                +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                +            eliminated in Netmiko 5.x (default: False).
                 
                Source code
                class CiscoAsaSSH(CiscoSSHConnection):
                     """Subclass specific to Cisco ASA."""
                 
                -    def __init__(self, *args, **kwargs):
                -        kwargs.setdefault("fast_cli", True)
                -        kwargs.setdefault("_legacy_mode", False)
                +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                         kwargs.setdefault("allow_auto_change", True)
                         return super().__init__(*args, **kwargs)
                 
                -    def session_preparation(self):
                +    def session_preparation(self) -> None:
                         """Prepare the session after the connection has been established."""
                 
                         # Make sure the ASA is ready
                @@ -418,21 +396,25 @@ 

                Inherited members

                self.set_base_prompt() - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[>\#]" + ) -> bool: return super().check_config_mode(check_string=check_string, pattern=pattern) def enable( self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = r"\#", + re_flags: int = re.IGNORECASE, + ) -> str: return super().enable( cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags ) - def send_command_timing(self, *args, **kwargs): + def send_command_timing( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -446,7 +428,9 @@

                Inherited members

                self.set_base_prompt() return output - def send_command(self, *args, **kwargs): + def send_command( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -468,11 +452,7 @@

                Inherited members

                return output - def send_command_expect(self, *args, **kwargs): - """Backwards compaitibility.""" - return self.send_command(*args, **kwargs) - - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """ Cisco ASA in multi-context mode needs to have the base prompt updated (if you switch contexts i.e. 'changeto') @@ -486,8 +466,10 @@

                Inherited members

                # strip off (conf.* from base_prompt self.base_prompt = match.group(1) return self.base_prompt + else: + return cur_base_prompt - def asa_login(self): + def asa_login(self) -> None: """ Handle ASA reaching privilege level 15 using login @@ -507,8 +489,10 @@

                Inherited members

                time.sleep(0.5 * delay_factor) output = self.read_channel() if "sername" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "ssword" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) elif "#" in output: return @@ -519,13 +503,15 @@

                Inherited members

                msg = "Unable to enter enable mode!" raise NetmikoAuthenticationException(msg) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Cisco ASA needed that extra \r\n\r""" newline = re.compile("(\r\n\r|\r\r\r\n|\r\r\n|\r\n|\n\r)") a_string = newline.sub(self.RESPONSE_RETURN, a_string) @@ -554,7 +540,7 @@

                Methods

                level 15 after 10 loops.

                Source code -
                def asa_login(self):
                +
                def asa_login(self) -> None:
                     """
                     Handle ASA reaching privilege level 15 using login
                 
                @@ -574,8 +560,10 @@ 

                Methods

                time.sleep(0.5 * delay_factor) output = self.read_channel() if "sername" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "ssword" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) elif "#" in output: return @@ -594,7 +582,7 @@

                Methods

                Cisco ASA needed that extra

                Source code -
                def normalize_linefeeds(self, a_string):
                +
                def normalize_linefeeds(self, a_string: str) -> str:
                     """Cisco ASA needed that extra \r\n\r"""
                     newline = re.compile("(\r\n\r|\r\r\r\n|\r\r\n|\r\n|\n\r)")
                     a_string = newline.sub(self.RESPONSE_RETURN, a_string)
                @@ -612,7 +600,9 @@ 

                Methods

                Saves Config

                Source code -
                def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
                +
                def save_config(
                +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
                +) -> str:
                     """Saves Config"""
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
                @@ -627,7 +617,9 @@ 

                Methods

                updated after each context change.

                Source code -
                def send_command(self, *args, **kwargs):
                +
                def send_command(
                +    self, *args: Any, **kwargs: Any
                +) -> Union[str, List[Any], Dict[str, Any]]:
                     """
                     If the ASA is in multi-context mode, then the base_prompt needs to be
                     updated after each context change.
                @@ -650,18 +642,6 @@ 

                Methods

                return output
            -
            -def send_command_expect(self, *args, **kwargs) -
            -
            -

            Backwards compaitibility.

            -
            -Source code -
            def send_command_expect(self, *args, **kwargs):
            -    """Backwards compaitibility."""
            -    return self.send_command(*args, **kwargs)
            -
            -
            def send_command_timing(self, *args, **kwargs)
            @@ -670,7 +650,9 @@

            Methods

            updated after each context change.

            Source code -
            def send_command_timing(self, *args, **kwargs):
            +
            def send_command_timing(
            +    self, *args: Any, **kwargs: Any
            +) -> Union[str, List[Any], Dict[str, Any]]:
                 """
                 If the ASA is in multi-context mode, then the base_prompt needs to be
                 updated after each context change.
            @@ -692,7 +674,7 @@ 

            Methods

            Prepare the session after the connection has been established.

            Source code -
            def session_preparation(self):
            +
            def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
             
                 # Make sure the ASA is ready
            @@ -731,7 +713,7 @@ 

            Methods

            happens the trailing '(config*' needs stripped off.

            Source code -
            def set_base_prompt(self, *args, **kwargs):
            +
            def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
                 """
                 Cisco ASA in multi-context mode needs to have the base prompt updated
                 (if you switch contexts i.e. 'changeto')
            @@ -744,7 +726,9 @@ 

            Methods

            if match: # strip off (conf.* from base_prompt self.base_prompt = match.group(1) - return self.base_prompt
            + return self.base_prompt + else: + return cur_base_prompt
        @@ -756,9 +740,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -768,16 +751,18 @@

        Inherited members

      • find_prompt
      • is_alive
      • normalize_cmd
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • run_ttp
      • select_delay_factor
      • +
      • send_command_expect
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_terminal_width
      • special_login_handler
      • strip_ansi_escape_codes
      • @@ -816,7 +801,6 @@

        normalize_linefeeds
      • save_config
      • send_command
      • -
      • send_command_expect
      • send_command_timing
      • session_preparation
      • set_base_prompt
      • diff --git a/docs/netmiko/cisco/cisco_ftd_ssh.html b/docs/netmiko/cisco/cisco_ftd_ssh.html index d882b2366..847ee71f7 100644 --- a/docs/netmiko/cisco/cisco_ftd_ssh.html +++ b/docs/netmiko/cisco/cisco_ftd_ssh.html @@ -24,31 +24,26 @@

        Module netmiko.cisco.cisco_ftd_ssh

        Source code
        """Subclass specific to Cisco FTD."""
        +from typing import Any
        +from netmiko.no_enable import NoEnable
        +from netmiko.no_config import NoConfig
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
         
        -class CiscoFtdSSH(CiscoSSHConnection):
        +class CiscoFtdSSH(NoEnable, NoConfig, CiscoSSHConnection):
             """Subclass specific to Cisco FTD."""
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
        -        self._test_channel_read()
        +        self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
         
        -    def send_config_set(self, *args, **kwargs):
        +    def send_config_set(self, *args: Any, **kwargs: Any) -> str:
                 """Canot change config on FTD via ssh"""
                 raise NotImplementedError
         
        -    def enable(self, *args, **kwargs):
        -        """No enable mode on firepower ssh"""
        -        return ""
        -
        -    def config_mode(self, *args, **kwargs):
        -        """No config mode on firepower ssh"""
        -        return ""
        -
        -    def check_config_mode(self, *args, **kwargs):
        -        """No config mode on firepower ssh"""
        +    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
        +        """Canot change config on FTD via ssh"""
                 return False
        @@ -63,7 +58,7 @@

        Classes

        class CiscoFtdSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Subclass specific to Cisco FTD.

        @@ -71,160 +66,127 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code -
        class CiscoFtdSSH(CiscoSSHConnection):
        +
        class CiscoFtdSSH(NoEnable, NoConfig, CiscoSSHConnection):
             """Subclass specific to Cisco FTD."""
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
        -        self._test_channel_read()
        +        self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
         
        -    def send_config_set(self, *args, **kwargs):
        +    def send_config_set(self, *args: Any, **kwargs: Any) -> str:
                 """Canot change config on FTD via ssh"""
                 raise NotImplementedError
         
        -    def enable(self, *args, **kwargs):
        -        """No enable mode on firepower ssh"""
        -        return ""
        -
        -    def config_mode(self, *args, **kwargs):
        -        """No config mode on firepower ssh"""
        -        return ""
        -
        -    def check_config_mode(self, *args, **kwargs):
        -        """No config mode on firepower ssh"""
        +    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
        +        """Canot change config on FTD via ssh"""
                 return False

        Ancestors

          +
        • NoEnable
        • +
        • NoConfig
        • CiscoSSHConnection
        • CiscoBaseConnection
        • BaseConnection
        • @@ -232,41 +194,17 @@

          Ancestors

          Methods

          -def check_config_mode(self, *args, **kwargs) +def check_config_mode(self, check_string='', pattern='')
          -

          No config mode on firepower ssh

          +

          Canot change config on FTD via ssh

          Source code -
          def check_config_mode(self, *args, **kwargs):
          -    """No config mode on firepower ssh"""
          +
          def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
          +    """Canot change config on FTD via ssh"""
               return False
          -
          -def config_mode(self, *args, **kwargs) -
          -
          -

          No config mode on firepower ssh

          -
          -Source code -
          def config_mode(self, *args, **kwargs):
          -    """No config mode on firepower ssh"""
          -    return ""
          -
          -
          -
          -def enable(self, *args, **kwargs) -
          -
          -

          No enable mode on firepower ssh

          -
          -Source code -
          def enable(self, *args, **kwargs):
          -    """No enable mode on firepower ssh"""
          -    return ""
          -
          -
          def send_config_set(self, *args, **kwargs)
          @@ -274,7 +212,7 @@

          Methods

          Canot change config on FTD via ssh

          Source code -
          def send_config_set(self, *args, **kwargs):
          +
          def send_config_set(self, *args: Any, **kwargs: Any) -> str:
               """Canot change config on FTD via ssh"""
               raise NotImplementedError
          @@ -286,9 +224,9 @@

          Methods

          Prepare the session after the connection has been established.

          Source code -
          def session_preparation(self):
          +
          def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
          -    self._test_channel_read()
          +    self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
        @@ -300,10 +238,11 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • exit_enable_mode
      • @@ -311,9 +250,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -324,6 +263,7 @@

        Inherited members

      • send_command_expect
      • send_command_timing
      • send_config_from_file
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -357,8 +297,6 @@

        Index

        CiscoFtdSSH

        diff --git a/docs/netmiko/cisco/cisco_ios.html b/docs/netmiko/cisco/cisco_ios.html index aa49abe6a..1e6f961ec 100644 --- a/docs/netmiko/cisco/cisco_ios.html +++ b/docs/netmiko/cisco/cisco_ios.html @@ -22,32 +22,29 @@

        Module netmiko.cisco.cisco_ios

        Source code -
        import time
        +
        from typing import Any, Optional, Callable, Type
        +from types import TracebackType
        +import time
         import re
         import os
         import hashlib
         import io
         
         from netmiko.cisco_base_connection import CiscoBaseConnection, CiscoFileTransfer
        +from netmiko.base_connection import BaseConnection
         
         
         class CiscoIosBase(CiscoBaseConnection):
             """Common Methods for IOS (both SSH and telnet)."""
         
        -    def __init__(self, *args, **kwargs):
        -        # Cisco-IOS defaults to fast_cli=True and legacy_mode=False
        -        kwargs.setdefault("fast_cli", True)
        -        kwargs.setdefault("_legacy_mode", False)
        -        return super().__init__(*args, **kwargs)
        -
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 cmd = "terminal width 511"
                 self.set_terminal_width(command=cmd, pattern=cmd)
                 self.disable_paging()
                 self.set_base_prompt()
         
        -    def check_config_mode(self, check_string=")#", pattern="#"):
        +    def check_config_mode(self, check_string: str = ")#", pattern: str = r"#") -> bool:
                 """
                 Checks if the device is in configuration mode or not.
         
        @@ -55,7 +52,9 @@ 

        Module netmiko.cisco.cisco_ios

        """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using Copy Run Start""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -91,16 +90,24 @@

        Module netmiko.cisco.cisco_ios

        def __init__( self, - ssh_conn, - source_file=None, - dest_file=None, - file_system=None, - direction="put", - source_config=None, - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str = "", + dest_file: str = "", + file_system: Optional[str] = None, + direction: str = "put", + source_config: Optional[str] = None, + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: + + if not dest_file: + raise ValueError( + "Destination file must be specified for InlineTransfer operations." + ) + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for InLineTransfer") if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -117,13 +124,12 @@

        Module netmiko.cisco.cisco_ios

        self.progress4 = progress4 self.ssh_ctl_chan = ssh_conn + self.source_file = source_file if source_file: - self.source_file = source_file self.source_config = None self.source_md5 = self.file_md5(source_file) self.file_size = os.stat(source_file).st_size elif source_config: - self.source_file = None self.source_config = source_config self.source_md5 = self.config_md5(source_config) self.file_size = len(source_config.encode("UTF-8")) @@ -138,12 +144,12 @@

        Module netmiko.cisco.cisco_ios

        self.socket_timeout = socket_timeout @staticmethod - def _read_file(file_name): + def _read_file(file_name: str) -> str: with io.open(file_name, "rt", encoding="utf-8") as f: return f.read() @staticmethod - def _tcl_newline_rationalize(tcl_string): + def _tcl_newline_rationalize(tcl_string: str) -> str: r""" When using put inside a TCL {} section the newline is considered a new TCL statement and causes a missing curly-brace message. Convert "\n" to "\r". TCL @@ -158,17 +164,22 @@

        Module netmiko.cisco.cisco_ios

        raise ValueError(msg) return tmp_string - def __enter__(self): + def __enter__(self) -> "InLineTransfer": self._enter_tcl_mode() return self - def __exit__(self, exc_type, exc_value, traceback): - _ = self._exit_tcl_mode() # noqa + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: + self._exit_tcl_mode() - def _enter_tcl_mode(self): + def _enter_tcl_mode(self) -> str: TCL_ENTER = "tclsh" cmd_failed = ['Translating "tclsh"', "% Unknown command", "% Bad IP address"] - output = self.ssh_ctl_chan.send_command( + output = self.ssh_ctl_chan._send_command_str( TCL_ENTER, expect_string=r"\(tcl\)#", strip_prompt=False, @@ -179,7 +190,7 @@

        Module netmiko.cisco.cisco_ios

        raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output - def _exit_tcl_mode(self): + def _exit_tcl_mode(self) -> str: TCL_EXIT = "tclquit" self.ssh_ctl_chan.write_channel("\r") time.sleep(1) @@ -190,29 +201,33 @@

        Module netmiko.cisco.cisco_ios

        output += self.ssh_ctl_chan.read_channel() return output - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: raise NotImplementedError - def close_scp_chan(self): + def close_scp_chan(self) -> None: raise NotImplementedError - def local_space_available(self): + def local_space_available(self) -> bool: raise NotImplementedError - def file_md5(self, file_name): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file.""" + if add_newline is True: + raise ValueError( + "add_newline argument is not supported for inline transfers." + ) file_contents = self._read_file(file_name) file_contents = file_contents + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def config_md5(self, source_config): + def config_md5(self, source_config: str) -> str: """Compute MD5 hash of text.""" file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def put_file(self): + def put_file(self) -> None: curlybrace = r"{" TCL_FILECMD_ENTER = 'puts [open "{}{}" w+] {}'.format( self.file_system, self.dest_file, curlybrace @@ -234,21 +249,21 @@

        Module netmiko.cisco.cisco_ios

        self.ssh_ctl_chan.write_channel(TCL_FILECMD_EXIT + "\r") # This operation can be slow (depends on the size of the file) - max_loops = 400 + read_timeout = 100 sleep_time = 4 if self.file_size >= 2500: - max_loops = 1500 + read_timeout = 300 sleep_time = 12 elif self.file_size >= 7500: - max_loops = 3000 + read_timeout = 600 sleep_time = 25 # Initial delay time.sleep(sleep_time) # File paste and TCL_FILECMD_exit should be indicated by "router(tcl)#" - output = self.ssh_ctl_chan._read_channel_expect( - pattern=r"\(tcl\)", max_loops=max_loops + output = self.ssh_ctl_chan.read_until_pattern( + pattern=r"\(tcl\).*$", re_flags=re.M, read_timeout=read_timeout ) # The file doesn't write until tclquit @@ -257,16 +272,20 @@

        Module netmiko.cisco.cisco_ios

        time.sleep(1) # Read all data remaining from the TCLSH session - output += self.ssh_ctl_chan._read_channel_expect(max_loops=max_loops) - return output + pattern = rf"tclquit.*{self.ssh_ctl_chan.base_prompt}.*$" + re_flags = re.DOTALL | re.M + output += self.ssh_ctl_chan.read_until_pattern( + pattern=pattern, re_flags=re_flags, read_timeout=read_timeout + ) + return None - def get_file(self): + def get_file(self) -> None: raise NotImplementedError - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError
        @@ -281,7 +300,7 @@

        Classes

        class CiscoIosBase -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Common Methods for IOS (both SSH and telnet).

        @@ -289,151 +308,118 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class CiscoIosBase(CiscoBaseConnection):
             """Common Methods for IOS (both SSH and telnet)."""
         
        -    def __init__(self, *args, **kwargs):
        -        # Cisco-IOS defaults to fast_cli=True and legacy_mode=False
        -        kwargs.setdefault("fast_cli", True)
        -        kwargs.setdefault("_legacy_mode", False)
        -        return super().__init__(*args, **kwargs)
        -
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 cmd = "terminal width 511"
                 self.set_terminal_width(command=cmd, pattern=cmd)
                 self.disable_paging()
                 self.set_base_prompt()
         
        -    def check_config_mode(self, check_string=")#", pattern="#"):
        +    def check_config_mode(self, check_string: str = ")#", pattern: str = r"#") -> bool:
                 """
                 Checks if the device is in configuration mode or not.
         
        @@ -441,7 +427,9 @@ 

        Classes

        """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using Copy Run Start""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -469,7 +457,9 @@

        Methods

        Saves Config Using Copy Run Start

        Source code -
        def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
        +) -> str:
             """Saves Config Using Copy Run Start"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -483,7 +473,7 @@ 

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             cmd = "terminal width 511"
             self.set_terminal_width(command=cmd, pattern=cmd)
        @@ -500,9 +490,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -513,9 +502,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -526,6 +515,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -588,7 +578,7 @@

        Inherited members

        class CiscoIosSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Cisco IOS SSH driver.

        @@ -596,131 +586,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -743,9 +706,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -756,9 +718,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -770,6 +732,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -786,7 +749,7 @@

        Inherited members

        class CiscoIosSerial -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Cisco IOS Serial driver.

        @@ -794,131 +757,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -941,9 +877,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -954,9 +889,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -968,6 +903,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -984,7 +920,7 @@

        Inherited members

        class CiscoIosTelnet -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Cisco IOS Telnet driver.

        @@ -992,131 +928,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -1139,9 +1048,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -1152,9 +1060,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1166,6 +1074,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -1182,7 +1091,7 @@

        Inherited members

        class InLineTransfer -(ssh_conn, source_file=None, dest_file=None, file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None) +(ssh_conn, source_file='', dest_file='', file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None, hash_supported=True)

        Use TCL on Cisco IOS to directly transfer file.

        @@ -1193,16 +1102,24 @@

        Inherited members

        def __init__( self, - ssh_conn, - source_file=None, - dest_file=None, - file_system=None, - direction="put", - source_config=None, - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str = "", + dest_file: str = "", + file_system: Optional[str] = None, + direction: str = "put", + source_config: Optional[str] = None, + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: + + if not dest_file: + raise ValueError( + "Destination file must be specified for InlineTransfer operations." + ) + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for InLineTransfer") if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -1219,13 +1136,12 @@

        Inherited members

        self.progress4 = progress4 self.ssh_ctl_chan = ssh_conn + self.source_file = source_file if source_file: - self.source_file = source_file self.source_config = None self.source_md5 = self.file_md5(source_file) self.file_size = os.stat(source_file).st_size elif source_config: - self.source_file = None self.source_config = source_config self.source_md5 = self.config_md5(source_config) self.file_size = len(source_config.encode("UTF-8")) @@ -1240,12 +1156,12 @@

        Inherited members

        self.socket_timeout = socket_timeout @staticmethod - def _read_file(file_name): + def _read_file(file_name: str) -> str: with io.open(file_name, "rt", encoding="utf-8") as f: return f.read() @staticmethod - def _tcl_newline_rationalize(tcl_string): + def _tcl_newline_rationalize(tcl_string: str) -> str: r""" When using put inside a TCL {} section the newline is considered a new TCL statement and causes a missing curly-brace message. Convert "\n" to "\r". TCL @@ -1260,17 +1176,22 @@

        Inherited members

        raise ValueError(msg) return tmp_string - def __enter__(self): + def __enter__(self) -> "InLineTransfer": self._enter_tcl_mode() return self - def __exit__(self, exc_type, exc_value, traceback): - _ = self._exit_tcl_mode() # noqa + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: + self._exit_tcl_mode() - def _enter_tcl_mode(self): + def _enter_tcl_mode(self) -> str: TCL_ENTER = "tclsh" cmd_failed = ['Translating "tclsh"', "% Unknown command", "% Bad IP address"] - output = self.ssh_ctl_chan.send_command( + output = self.ssh_ctl_chan._send_command_str( TCL_ENTER, expect_string=r"\(tcl\)#", strip_prompt=False, @@ -1281,7 +1202,7 @@

        Inherited members

        raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output - def _exit_tcl_mode(self): + def _exit_tcl_mode(self) -> str: TCL_EXIT = "tclquit" self.ssh_ctl_chan.write_channel("\r") time.sleep(1) @@ -1292,29 +1213,33 @@

        Inherited members

        output += self.ssh_ctl_chan.read_channel() return output - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: raise NotImplementedError - def close_scp_chan(self): + def close_scp_chan(self) -> None: raise NotImplementedError - def local_space_available(self): + def local_space_available(self) -> bool: raise NotImplementedError - def file_md5(self, file_name): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file.""" + if add_newline is True: + raise ValueError( + "add_newline argument is not supported for inline transfers." + ) file_contents = self._read_file(file_name) file_contents = file_contents + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def config_md5(self, source_config): + def config_md5(self, source_config: str) -> str: """Compute MD5 hash of text.""" file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def put_file(self): + def put_file(self) -> None: curlybrace = r"{" TCL_FILECMD_ENTER = 'puts [open "{}{}" w+] {}'.format( self.file_system, self.dest_file, curlybrace @@ -1336,21 +1261,21 @@

        Inherited members

        self.ssh_ctl_chan.write_channel(TCL_FILECMD_EXIT + "\r") # This operation can be slow (depends on the size of the file) - max_loops = 400 + read_timeout = 100 sleep_time = 4 if self.file_size >= 2500: - max_loops = 1500 + read_timeout = 300 sleep_time = 12 elif self.file_size >= 7500: - max_loops = 3000 + read_timeout = 600 sleep_time = 25 # Initial delay time.sleep(sleep_time) # File paste and TCL_FILECMD_exit should be indicated by "router(tcl)#" - output = self.ssh_ctl_chan._read_channel_expect( - pattern=r"\(tcl\)", max_loops=max_loops + output = self.ssh_ctl_chan.read_until_pattern( + pattern=r"\(tcl\).*$", re_flags=re.M, read_timeout=read_timeout ) # The file doesn't write until tclquit @@ -1359,16 +1284,20 @@

        Inherited members

        time.sleep(1) # Read all data remaining from the TCLSH session - output += self.ssh_ctl_chan._read_channel_expect(max_loops=max_loops) - return output + pattern = rf"tclquit.*{self.ssh_ctl_chan.base_prompt}.*$" + re_flags = re.DOTALL | re.M + output += self.ssh_ctl_chan.read_until_pattern( + pattern=pattern, re_flags=re_flags, read_timeout=read_timeout + ) + return None - def get_file(self): + def get_file(self) -> None: raise NotImplementedError - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -1386,26 +1315,30 @@

    Methods

    Compute MD5 hash of text.

    Source code -
    def config_md5(self, source_config):
    +
    def config_md5(self, source_config: str) -> str:
         """Compute MD5 hash of text."""
         file_contents = source_config + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    -def file_md5(self, file_name) +def file_md5(self, file_name, add_newline=False)

    Compute MD5 hash of file.

    Source code -
    def file_md5(self, file_name):
    +
    def file_md5(self, file_name: str, add_newline: bool = False) -> str:
         """Compute MD5 hash of file."""
    +    if add_newline is True:
    +        raise ValueError(
    +            "add_newline argument is not supported for inline transfers."
    +        )
         file_contents = self._read_file(file_name)
         file_contents = file_contents + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    diff --git a/docs/netmiko/cisco/cisco_nxos_ssh.html b/docs/netmiko/cisco/cisco_nxos_ssh.html index 372985221..72011f5e0 100644 --- a/docs/netmiko/cisco/cisco_nxos_ssh.html +++ b/docs/netmiko/cisco/cisco_nxos_ssh.html @@ -22,20 +22,16 @@

    Module netmiko.cisco.cisco_nxos_ssh

    Source code -
    import re
    +
    from typing import Any, Optional, Callable
    +import re
     import os
    +from netmiko.base_connection import BaseConnection
     from netmiko.cisco_base_connection import CiscoSSHConnection
     from netmiko.cisco_base_connection import CiscoFileTransfer
     
     
     class CiscoNxosSSH(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        # Cisco NX-OS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
             # NX-OS has an issue where it echoes the command even though it hasn't returned the prompt
    @@ -46,46 +42,45 @@ 

    Module netmiko.cisco.cisco_nxos_ssh

    self.disable_paging() self.set_base_prompt() - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Convert '\r\n' or '\r\r\n' to '\n, and remove extra '\r's in the text.""" newline = re.compile(r"(\r\r\n\r|\r\r\n|\r\n)") # NX-OS fix for incorrect MD5 on 9K (due to strange <enter> patterns on NX-OS) return newline.sub(self.RESPONSE_RETURN, a_string).replace("\r", "\n") - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """Checks if the device is in configuration mode or not.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() + output = "" if confirm: - output = self.send_command_timing( + output += self._send_command_timing_str( command_string=cmd, strip_prompt=False, strip_command=False ) if confirm_response: - output += self.send_command_timing( + output += self._send_command_timing_str( confirm_response, strip_prompt=False, strip_command=False ) else: # Send enter by default - output += self.send_command_timing( + output += self._send_command_timing_str( self.RETURN, strip_prompt=False, strip_command=False ) else: # NX-OS is very slow on save_config ensure it waits long enough. - # FIX: this is a hack as delay_factor will be set to .1 via fast_cli=True in - # send_command so increase max_loops. - output = self.send_command( + output += self._send_command_str( command_string=cmd, strip_prompt=False, strip_command=False, - max_loops=5000, + read_timeout=100, ) return output @@ -95,20 +90,24 @@

    Module netmiko.cisco.cisco_nxos_ssh

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="bootflash:", - direction="put", - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: str = "bootflash:", + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for NX-OS") + if file_system: self.file_system = file_system else: @@ -127,12 +126,12 @@

    Module netmiko.cisco.cisco_nxos_ssh

    self.progress = progress self.progress4 = progress4 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"dir {self.file_system}{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: return False @@ -142,19 +141,25 @@

    Module netmiko.cisco.cisco_nxos_ssh

    raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Invalid value for file transfer direction.") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Invalid value for file transfer direction.") if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if re.search("no such file or directory", remote_out, flags=re.I): raise IOError("Unable to find file on remote system") # Match line containing file name @@ -169,23 +174,27 @@

    Module netmiko.cisco.cisco_nxos_ssh

    raise IOError("Unable to find file on remote system") @staticmethod - def process_md5(md5_output, pattern=r"= (.*)"): + def process_md5(md5_output: str, pattern: str = r"= (.*)") -> str: """Not needed on NX-OS.""" raise NotImplementedError - def remote_md5(self, base_cmd="show file", remote_file=None): + def remote_md5( + self, base_cmd: str = "show file", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}{remote_file} md5sum" - return self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500).strip() + output = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + output = output.strip() + return output - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError
    @@ -200,7 +209,7 @@

    Classes

    class CiscoNxosFileTransfer -(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0, progress=None, progress4=None) +(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0, progress=None, progress4=None, hash_supported=True)

    Cisco NXOS SCP File Transfer driver.

    @@ -211,20 +220,24 @@

    Classes

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="bootflash:", - direction="put", - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: str = "bootflash:", + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for NX-OS") + if file_system: self.file_system = file_system else: @@ -243,12 +256,12 @@

    Classes

    self.progress = progress self.progress4 = progress4 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"dir {self.file_system}{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: return False @@ -258,19 +271,25 @@

    Classes

    raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Invalid value for file transfer direction.") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Invalid value for file transfer direction.") if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if re.search("no such file or directory", remote_out, flags=re.I): raise IOError("Unable to find file on remote system") # Match line containing file name @@ -285,23 +304,27 @@

    Classes

    raise IOError("Unable to find file on remote system") @staticmethod - def process_md5(md5_output, pattern=r"= (.*)"): + def process_md5(md5_output: str, pattern: str = r"= (.*)") -> str: """Not needed on NX-OS.""" raise NotImplementedError - def remote_md5(self, base_cmd="show file", remote_file=None): + def remote_md5( + self, base_cmd: str = "show file", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}{remote_file} md5sum" - return self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500).strip() + output = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + output = output.strip() + return output - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -319,7 +342,7 @@

    Static methods

    Source code
    @staticmethod
    -def process_md5(md5_output, pattern=r"= (.*)"):
    +def process_md5(md5_output: str, pattern: str = r"= (.*)") -> str:
         """Not needed on NX-OS."""
         raise NotImplementedError
    @@ -351,7 +374,7 @@

    Inherited members

    class CiscoNxosSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -359,142 +382,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoNxosSSH(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        # Cisco NX-OS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
             # NX-OS has an issue where it echoes the command even though it hasn't returned the prompt
    @@ -505,46 +495,45 @@ 

    Inherited members

    self.disable_paging() self.set_base_prompt() - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Convert '\r\n' or '\r\r\n' to '\n, and remove extra '\r's in the text.""" newline = re.compile(r"(\r\r\n\r|\r\r\n|\r\n)") # NX-OS fix for incorrect MD5 on 9K (due to strange <enter> patterns on NX-OS) return newline.sub(self.RESPONSE_RETURN, a_string).replace("\r", "\n") - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """Checks if the device is in configuration mode or not.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() + output = "" if confirm: - output = self.send_command_timing( + output += self._send_command_timing_str( command_string=cmd, strip_prompt=False, strip_command=False ) if confirm_response: - output += self.send_command_timing( + output += self._send_command_timing_str( confirm_response, strip_prompt=False, strip_command=False ) else: # Send enter by default - output += self.send_command_timing( + output += self._send_command_timing_str( self.RETURN, strip_prompt=False, strip_command=False ) else: # NX-OS is very slow on save_config ensure it waits long enough. - # FIX: this is a hack as delay_factor will be set to .1 via fast_cli=True in - # send_command so increase max_loops. - output = self.send_command( + output += self._send_command_str( command_string=cmd, strip_prompt=False, strip_command=False, - max_loops=5000, + read_timeout=100, ) return output
    @@ -563,7 +552,7 @@

    Methods

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string=")#", pattern="#"):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
         """Checks if the device is in configuration mode or not."""
         return super().check_config_mode(check_string=check_string, pattern=pattern)
    @@ -579,7 +568,7 @@

    Methods

    's in the text.

    Source code -
    def normalize_linefeeds(self, a_string):
    +
    def normalize_linefeeds(self, a_string: str) -> str:
         """Convert '\r\n' or '\r\r\n' to '\n, and remove extra '\r's in the text."""
         newline = re.compile(r"(\r\r\n\r|\r\r\n|\r\n)")
         # NX-OS fix for incorrect MD5 on 9K (due to strange <enter> patterns on NX-OS)
    @@ -593,7 +582,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
         # NX-OS has an issue where it echoes the command even though it hasn't returned the prompt
    @@ -613,9 +602,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -625,9 +613,9 @@

    Inherited members

  • find_prompt
  • is_alive
  • normalize_cmd
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -639,6 +627,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • diff --git a/docs/netmiko/cisco/cisco_s300.html b/docs/netmiko/cisco/cisco_s300.html index c53e768c4..af25013d5 100644 --- a/docs/netmiko/cisco/cisco_s300.html +++ b/docs/netmiko/cisco/cisco_s300.html @@ -22,11 +22,10 @@

    Module netmiko.cisco.cisco_s300

    Source code -
    import time
    -from netmiko.cisco_base_connection import CiscoSSHConnection
    +
    from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    -class CiscoS300SSH(CiscoSSHConnection):
    +class CiscoS300Base(CiscoSSHConnection):
         """
         Support for Cisco SG300 series of devices.
     
    @@ -36,20 +35,36 @@ 

    Module netmiko.cisco.cisco_s300

    ip ssh password-auth """ - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.set_terminal_width(command="terminal width 511", pattern="terminal") self.disable_paging(command="terminal datadump") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - def save_config(self, cmd="write memory", confirm=True, confirm_response="Y"): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = True, + confirm_response: str = "Y", + ) -> str: return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response - )
    + ) + + +class CiscoS300SSH(CiscoS300Base): + pass + + +class CiscoS300Telnet(CiscoS300Base): + """ + Support for Cisco SG300 series of devices, with telnet. + Note: can be used with Sx200 series, with telnet enabled. + """ + + pass
    @@ -61,9 +76,9 @@

    Module netmiko.cisco.cisco_s300

    Classes

    -
    -class CiscoS300SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +
    +class CiscoS300Base +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Support for Cisco SG300 series of devices.

    @@ -74,135 +89,108 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CiscoS300SSH(CiscoSSHConnection):
    +
    class CiscoS300Base(CiscoSSHConnection):
         """
         Support for Cisco SG300 series of devices.
     
    @@ -212,17 +200,20 @@ 

    Classes

    ip ssh password-auth """ - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.set_terminal_width(command="terminal width 511", pattern="terminal") self.disable_paging(command="terminal datadump") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - def save_config(self, cmd="write memory", confirm=True, confirm_response="Y"): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = True, + confirm_response: str = "Y", + ) -> str: return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -233,24 +224,27 @@

    Ancestors

  • CiscoBaseConnection
  • BaseConnection
  • +

    Subclasses

    +

    Methods

    -
    +
    def session_preparation(self)

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.set_terminal_width(command="terminal width 511", pattern="terminal")
    -    self.disable_paging(command="terminal datadump")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    + self.disable_paging(command="terminal datadump")
    @@ -262,9 +256,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -275,9 +268,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -289,6 +282,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -302,6 +296,355 @@

    Inherited members

    +
    +class CiscoS300SSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Support for Cisco SG300 series of devices.

    +

    Note, must configure the following to disable SG300 from prompting for username twice:

    +

    configure terminal +ip ssh password-auth

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class CiscoS300SSH(CiscoS300Base):
    +    pass
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +class CiscoS300Telnet +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Support for Cisco SG300 series of devices, with telnet. +Note: can be used with Sx200 series, with telnet enabled.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class CiscoS300Telnet(CiscoS300Base):
    +    """
    +    Support for Cisco SG300 series of devices, with telnet.
    +    Note: can be used with Sx200 series, with telnet enabled.
    +    """
    +
    +    pass
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    @@ -319,11 +662,17 @@

    Index

  • Classes

  • diff --git a/docs/netmiko/cisco/cisco_tp_tcce.html b/docs/netmiko/cisco/cisco_tp_tcce.html index ed73e9eec..0a7569cbd 100644 --- a/docs/netmiko/cisco/cisco_tp_tcce.html +++ b/docs/netmiko/cisco/cisco_tp_tcce.html @@ -25,7 +25,8 @@

    Module netmiko.cisco.cisco_tp_tcce

    CiscoTpTcCeSSH Class Class to manage Cisco Telepresence Endpoint on TC/CE software release. Also working for Cisco Expressway/VCS

    -

    Written by Ahmad Barrin

    +

    Written by Ahmad Barrin +Updated by Kirk Byers

    Source code
    """
    @@ -34,23 +35,25 @@ 

    Module netmiko.cisco.cisco_tp_tcce

    Expressway/VCS Written by Ahmad Barrin +Updated by Kirk Byers """ +from typing import Any, Union, List, Dict import time import re from netmiko.cisco_base_connection import CiscoSSHConnection class CiscoTpTcCeSSH(CiscoSSHConnection): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs) - def disable_paging(self, *args, **kwargs): + def disable_paging(self, *args: Any, **kwargs: Any) -> str: """Paging is disabled by default.""" return "" - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established @@ -62,6 +65,8 @@

    Module netmiko.cisco.cisco_tp_tcce

    self.disable_paging() self.set_terminal_width() """ + # Could not work out what the CLI looked like. It would be good to switch to + # a pattern on the _test_channel_read() call. self._test_channel_read() self.set_base_prompt() self.set_terminal_width() @@ -70,16 +75,16 @@

    Module netmiko.cisco.cisco_tp_tcce

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """Use 'OK' as base_prompt.""" self.base_prompt = "OK" return self.base_prompt - def find_prompt(self, *args, **kwargs): + def find_prompt(self, *args: Any, **kwargs: Any) -> str: """Use 'OK' as standard prompt.""" return "OK" - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output.""" expect_string = r"^(OK|ERROR|Command not recognized\.)$" response_list = a_string.split(self.RESPONSE_RETURN) @@ -89,7 +94,9 @@

    Module netmiko.cisco.cisco_tp_tcce

    else: return a_string - def send_command(self, *args, **kwargs): + def send_command( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ Send command to network device retrieve output until router_prompt or expect_string @@ -108,7 +115,7 @@

    Module netmiko.cisco.cisco_tp_tcce

    output = super().send_command(*args, **kwargs) return output - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError
    @@ -132,145 +139,118 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoTpTcCeSSH(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Paging is disabled by default."""
             return ""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established
     
    @@ -282,6 +262,8 @@ 

    Classes

    self.disable_paging() self.set_terminal_width() """ + # Could not work out what the CLI looked like. It would be good to switch to + # a pattern on the _test_channel_read() call. self._test_channel_read() self.set_base_prompt() self.set_terminal_width() @@ -290,16 +272,16 @@

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """Use 'OK' as base_prompt.""" self.base_prompt = "OK" return self.base_prompt - def find_prompt(self, *args, **kwargs): + def find_prompt(self, *args: Any, **kwargs: Any) -> str: """Use 'OK' as standard prompt.""" return "OK" - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output.""" expect_string = r"^(OK|ERROR|Command not recognized\.)$" response_list = a_string.split(self.RESPONSE_RETURN) @@ -309,7 +291,9 @@

    Classes

    else: return a_string - def send_command(self, *args, **kwargs): + def send_command( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ Send command to network device retrieve output until router_prompt or expect_string @@ -328,7 +312,7 @@

    Classes

    output = super().send_command(*args, **kwargs) return output - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError
    @@ -347,7 +331,7 @@

    Methods

    Paging is disabled by default.

    Source code -
    def disable_paging(self, *args, **kwargs):
    +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
         """Paging is disabled by default."""
         return ""
    @@ -359,7 +343,7 @@

    Methods

    Use 'OK' as standard prompt.

    Source code -
    def find_prompt(self, *args, **kwargs):
    +
    def find_prompt(self, *args: Any, **kwargs: Any) -> str:
         """Use 'OK' as standard prompt."""
         return "OK"
    @@ -371,7 +355,7 @@

    Methods

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -385,7 +369,9 @@

    Methods

    detected. The current network device prompt will be determined automatically.

    Source code -
    def send_command(self, *args, **kwargs):
    +
    def send_command(
    +    self, *args: Any, **kwargs: Any
    +) -> Union[str, List[Any], Dict[str, Any]]:
         """
         Send command to network device retrieve output until router_prompt or expect_string
     
    @@ -418,7 +404,7 @@ 

    Methods

    self.set_terminal_width()

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established
     
    @@ -430,6 +416,8 @@ 

    Methods

    self.disable_paging() self.set_terminal_width() """ + # Could not work out what the CLI looked like. It would be good to switch to + # a pattern on the _test_channel_read() call. self._test_channel_read() self.set_base_prompt() self.set_terminal_width() @@ -446,7 +434,7 @@

    Methods

    Use 'OK' as base_prompt.

    Source code -
    def set_base_prompt(self, *args, **kwargs):
    +
    def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
         """Use 'OK' as base_prompt."""
         self.base_prompt = "OK"
         return self.base_prompt
    @@ -459,7 +447,7 @@

    Methods

    Strip the trailing router prompt from the output.

    Source code -
    def strip_prompt(self, a_string):
    +
    def strip_prompt(self, a_string: str) -> str:
         """Strip the trailing router prompt from the output."""
         expect_string = r"^(OK|ERROR|Command not recognized\.)$"
         response_list = a_string.split(self.RESPONSE_RETURN)
    @@ -479,9 +467,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disconnect
  • enable
  • establish_connection
  • @@ -490,9 +477,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -502,6 +489,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_terminal_width
  • special_login_handler
  • strip_ansi_escape_codes
  • diff --git a/docs/netmiko/cisco/cisco_viptela.html b/docs/netmiko/cisco/cisco_viptela.html new file mode 100644 index 000000000..49afd7fa4 --- /dev/null +++ b/docs/netmiko/cisco/cisco_viptela.html @@ -0,0 +1,471 @@ + + + + + + +netmiko.cisco.cisco_viptela API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.cisco.cisco_viptela

    +
    +
    +

    Subclass specific to Cisco Viptela.

    +
    +Source code +
    """Subclass specific to Cisco Viptela."""
    +from typing import Union, Sequence, TextIO, Any
    +import re
    +
    +from netmiko.cisco_base_connection import CiscoSSHConnection
    +
    +
    +class CiscoViptelaSSH(CiscoSSHConnection):
    +    """Subclass specific to Cisco Viptela."""
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>#]")
    +        self.set_base_prompt()
    +        self.disable_paging(command="paginate false")
    +
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
    +        """Checks if the device is in configuration mode or not."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def commit(self, confirm: bool = False, confirm_response: str = "") -> str:
    +        cmd = "commit"
    +        return super().save_config(
    +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
    +        )
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "conf terminal",
    +        pattern: str = "",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = False,
    +        **kwargs: Any,
    +    ) -> str:
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#") -> str:
    +        """
    +        Exit from configuration mode.
    +
    +        Viptela might have the following in the output (if no 'commit()' occurred.
    +
    +        Uncommitted changes found, commit them? [yes/no/CANCEL]
    +        """
    +        output = ""
    +        if self.check_config_mode():
    +            self.write_channel(self.normalize_cmd(exit_config))
    +            # Make sure you read until you detect the command echo (avoid getting out of sync)
    +            if self.global_cmd_verify is not False:
    +                output += self.read_until_pattern(
    +                    pattern=re.escape(exit_config.strip())
    +                )
    +            if not re.search(pattern, output, flags=re.M):
    +                uncommit_pattern = r"Uncommitted changes found"
    +                new_pattern = f"({pattern}|{uncommit_pattern})"
    +                output += self.read_until_pattern(pattern=new_pattern)
    +                # Do not save 'uncommited changes'
    +                if uncommit_pattern in output:
    +                    self.write_channel(self.normalize_cmd("no"))
    +                    output += self.read_until_pattern(pattern=pattern)
    +
    +            if self.check_config_mode():
    +                raise ValueError("Failed to exit configuration mode")
    +        return output
    +
    +    def save_config(
    +        self, cmd: str = "commit", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
    +        """Saves Config"""
    +        raise NotImplementedError
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class CiscoViptelaSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Subclass specific to Cisco Viptela.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class CiscoViptelaSSH(CiscoSSHConnection):
    +    """Subclass specific to Cisco Viptela."""
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>#]")
    +        self.set_base_prompt()
    +        self.disable_paging(command="paginate false")
    +
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
    +        """Checks if the device is in configuration mode or not."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def commit(self, confirm: bool = False, confirm_response: str = "") -> str:
    +        cmd = "commit"
    +        return super().save_config(
    +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
    +        )
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "conf terminal",
    +        pattern: str = "",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = False,
    +        **kwargs: Any,
    +    ) -> str:
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#") -> str:
    +        """
    +        Exit from configuration mode.
    +
    +        Viptela might have the following in the output (if no 'commit()' occurred.
    +
    +        Uncommitted changes found, commit them? [yes/no/CANCEL]
    +        """
    +        output = ""
    +        if self.check_config_mode():
    +            self.write_channel(self.normalize_cmd(exit_config))
    +            # Make sure you read until you detect the command echo (avoid getting out of sync)
    +            if self.global_cmd_verify is not False:
    +                output += self.read_until_pattern(
    +                    pattern=re.escape(exit_config.strip())
    +                )
    +            if not re.search(pattern, output, flags=re.M):
    +                uncommit_pattern = r"Uncommitted changes found"
    +                new_pattern = f"({pattern}|{uncommit_pattern})"
    +                output += self.read_until_pattern(pattern=new_pattern)
    +                # Do not save 'uncommited changes'
    +                if uncommit_pattern in output:
    +                    self.write_channel(self.normalize_cmd("no"))
    +                    output += self.read_until_pattern(pattern=pattern)
    +
    +            if self.check_config_mode():
    +                raise ValueError("Failed to exit configuration mode")
    +        return output
    +
    +    def save_config(
    +        self, cmd: str = "commit", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
    +        """Saves Config"""
    +        raise NotImplementedError
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string=')#', pattern='#') +
    +
    +

    Checks if the device is in configuration mode or not.

    +
    +Source code +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
    +    """Checks if the device is in configuration mode or not."""
    +    return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def exit_config_mode(self, exit_config='end', pattern='#') +
    +
    +

    Exit from configuration mode.

    +

    Viptela might have the following in the output (if no 'commit()' occurred.

    +

    Uncommitted changes found, commit them? [yes/no/CANCEL]

    +
    +Source code +
    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#") -> str:
    +    """
    +    Exit from configuration mode.
    +
    +    Viptela might have the following in the output (if no 'commit()' occurred.
    +
    +    Uncommitted changes found, commit them? [yes/no/CANCEL]
    +    """
    +    output = ""
    +    if self.check_config_mode():
    +        self.write_channel(self.normalize_cmd(exit_config))
    +        # Make sure you read until you detect the command echo (avoid getting out of sync)
    +        if self.global_cmd_verify is not False:
    +            output += self.read_until_pattern(
    +                pattern=re.escape(exit_config.strip())
    +            )
    +        if not re.search(pattern, output, flags=re.M):
    +            uncommit_pattern = r"Uncommitted changes found"
    +            new_pattern = f"({pattern}|{uncommit_pattern})"
    +            output += self.read_until_pattern(pattern=new_pattern)
    +            # Do not save 'uncommited changes'
    +            if uncommit_pattern in output:
    +                self.write_channel(self.normalize_cmd("no"))
    +                output += self.read_until_pattern(pattern=pattern)
    +
    +        if self.check_config_mode():
    +            raise ValueError("Failed to exit configuration mode")
    +    return output
    +
    +
    +
    +def save_config(self, cmd='commit', confirm=False, confirm_response='') +
    +
    +

    Saves Config

    +
    +Source code +
    def save_config(
    +    self, cmd: str = "commit", confirm: bool = False, confirm_response: str = ""
    +) -> str:
    +    """Saves Config"""
    +    raise NotImplementedError
    +
    +
    +
    +def session_preparation(self) +
    +
    +

    Prepare the session after the connection has been established.

    +
    +Source code +
    def session_preparation(self) -> None:
    +    """Prepare the session after the connection has been established."""
    +    self._test_channel_read(pattern=r"[>#]")
    +    self.set_base_prompt()
    +    self.disable_paging(command="paginate false")
    +
    +
    +
    +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/cisco/cisco_wlc_ssh.html b/docs/netmiko/cisco/cisco_wlc_ssh.html index 4a0973d99..8016ec807 100644 --- a/docs/netmiko/cisco/cisco_wlc_ssh.html +++ b/docs/netmiko/cisco/cisco_wlc_ssh.html @@ -24,24 +24,25 @@

    Module netmiko.cisco.cisco_wlc_ssh

    Source code
    """Netmiko Cisco WLC support."""
    +from typing import Any, Union, Sequence, TextIO
     import time
     import re
     import socket
     
    -from netmiko.ssh_exception import NetmikoAuthenticationException
    +from netmiko.exceptions import NetmikoAuthenticationException
     from netmiko.base_connection import BaseConnection
     
     
     class CiscoWlcSSH(BaseConnection):
         """Netmiko Cisco WLC support."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             # WLC/AireOS has an issue where you can get "No Existing Session" with
             # the default conn_timeout (so increase conn_timeout to 10-seconds).
             kwargs.setdefault("conn_timeout", 10)
             return super().__init__(*args, **kwargs)
     
    -    def special_login_handler(self, delay_factor=1):
    +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
             """WLC presents with the following on login (in certain OS versions)
     
             login as: user
    @@ -60,17 +61,19 @@ 

    Module netmiko.cisco.cisco_wlc_ssh

    output = self.read_channel() if output: if "login as" in output or "User:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) else: - self.write_channel(self.RETURN) + # no output read, sleep and go for one more round of read channel time.sleep(delay_factor * 1.5) i += 1 - def send_command_w_enter(self, *args, **kwargs): + def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str: """ For 'show run-config' Cisco WLC adds a 'Press Enter to continue...' message Even though pagination is disabled @@ -84,7 +87,7 @@

    Module netmiko.cisco.cisco_wlc_ssh

    # If no delay_factor use 1 for default value delay_factor = kwargs.get("delay_factor", 1) kwargs["delay_factor"] = self.select_delay_factor(delay_factor) - output = self.send_command_timing(*args, **kwargs) + output = self._send_command_timing_str(*args, **kwargs) if "Press any key" in output or "Press Enter to" in output: new_args = list(args) @@ -96,7 +99,7 @@

    Module netmiko.cisco.cisco_wlc_ssh

    kwargs["max_loops"] = 150 # Send an 'enter' - output = self.send_command_timing(*new_args, **kwargs) + output += self._send_command_timing_str(*new_args, **kwargs) # WLC has excessive delay after this appears on screen if "802.11b Advanced Configuration" in output: @@ -122,13 +125,30 @@

    Module netmiko.cisco.cisco_wlc_ssh

    output = self.strip_prompt(output) return output - def session_preparation(self): + def send_command_w_yes(self, *args: Any, **kwargs: Any) -> str: + """ + For 'show interface summary' Cisco WLC adds a + 'Would you like to display the next 15 entries?' message + Even though pagination is disabled + Arguments are the same as send_command_timing() method + """ + output = self._send_command_timing_str(*args, **kwargs) + if "(y/n)" in output: + output += self._send_command_timing_str("y") + strip_prompt = kwargs.get("strip_prompt", True) + if strip_prompt: + # Had to strip trailing prompt twice. + output = self.strip_prompt(output) + output = self.strip_prompt(output) + return output + + def session_preparation(self) -> None: """ Prepare the session after the connection has been established Cisco WLC uses "config paging disable" to disable paging """ - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") try: self.set_base_prompt() @@ -137,11 +157,8 @@

    Module netmiko.cisco.cisco_wlc_ssh

    raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - def cleanup(self, command="logout"): + def cleanup(self, command: str = "logout") -> None: """Reset WLC back to normal paging and gracefully close session.""" self.send_command_timing("config paging enable") @@ -177,31 +194,33 @@

    Module netmiko.cisco.cisco_wlc_ssh

    break count += 1 - def check_config_mode(self, check_string="config", pattern=""): + def check_config_mode( + self, check_string: str = "config", pattern: str = "" + ) -> bool: """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) return super().check_config_mode(check_string, pattern) - def config_mode(self, config_command="config", pattern=""): + def config_mode( + self, config_command: str = "config", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter into config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) - return super().config_mode(config_command, pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=""): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) return super().exit_config_mode(exit_config, pattern) def send_config_set( self, - config_commands=None, - exit_config_mode=False, - enter_config_mode=False, - **kwargs, - ): + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + enter_config_mode: bool = False, + **kwargs: Any, + ) -> str: return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, @@ -209,19 +228,24 @@

    Module netmiko.cisco.cisco_wlc_ssh

    **kwargs, ) - def save_config(self, cmd="save config", confirm=True, confirm_response="y"): + def save_config( + self, + cmd: str = "save config", + confirm: bool = True, + confirm_response: str = "y", + ) -> str: """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self._send_command_timing_str(command_string=cmd) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self._send_command_timing_str(confirm_response) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self._send_command_timing_str(self.RETURN) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) return output
    @@ -244,144 +268,117 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoWlcSSH(BaseConnection):
         """Netmiko Cisco WLC support."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             # WLC/AireOS has an issue where you can get "No Existing Session" with
             # the default conn_timeout (so increase conn_timeout to 10-seconds).
             kwargs.setdefault("conn_timeout", 10)
             return super().__init__(*args, **kwargs)
     
    -    def special_login_handler(self, delay_factor=1):
    +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
             """WLC presents with the following on login (in certain OS versions)
     
             login as: user
    @@ -400,17 +397,19 @@ 

    Classes

    output = self.read_channel() if output: if "login as" in output or "User:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) else: - self.write_channel(self.RETURN) + # no output read, sleep and go for one more round of read channel time.sleep(delay_factor * 1.5) i += 1 - def send_command_w_enter(self, *args, **kwargs): + def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str: """ For 'show run-config' Cisco WLC adds a 'Press Enter to continue...' message Even though pagination is disabled @@ -424,7 +423,7 @@

    Classes

    # If no delay_factor use 1 for default value delay_factor = kwargs.get("delay_factor", 1) kwargs["delay_factor"] = self.select_delay_factor(delay_factor) - output = self.send_command_timing(*args, **kwargs) + output = self._send_command_timing_str(*args, **kwargs) if "Press any key" in output or "Press Enter to" in output: new_args = list(args) @@ -436,7 +435,7 @@

    Classes

    kwargs["max_loops"] = 150 # Send an 'enter' - output = self.send_command_timing(*new_args, **kwargs) + output += self._send_command_timing_str(*new_args, **kwargs) # WLC has excessive delay after this appears on screen if "802.11b Advanced Configuration" in output: @@ -462,13 +461,30 @@

    Classes

    output = self.strip_prompt(output) return output - def session_preparation(self): + def send_command_w_yes(self, *args: Any, **kwargs: Any) -> str: + """ + For 'show interface summary' Cisco WLC adds a + 'Would you like to display the next 15 entries?' message + Even though pagination is disabled + Arguments are the same as send_command_timing() method + """ + output = self._send_command_timing_str(*args, **kwargs) + if "(y/n)" in output: + output += self._send_command_timing_str("y") + strip_prompt = kwargs.get("strip_prompt", True) + if strip_prompt: + # Had to strip trailing prompt twice. + output = self.strip_prompt(output) + output = self.strip_prompt(output) + return output + + def session_preparation(self) -> None: """ Prepare the session after the connection has been established Cisco WLC uses "config paging disable" to disable paging """ - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") try: self.set_base_prompt() @@ -477,11 +493,8 @@

    Classes

    raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - def cleanup(self, command="logout"): + def cleanup(self, command: str = "logout") -> None: """Reset WLC back to normal paging and gracefully close session.""" self.send_command_timing("config paging enable") @@ -517,31 +530,33 @@

    Classes

    break count += 1 - def check_config_mode(self, check_string="config", pattern=""): + def check_config_mode( + self, check_string: str = "config", pattern: str = "" + ) -> bool: """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) return super().check_config_mode(check_string, pattern) - def config_mode(self, config_command="config", pattern=""): + def config_mode( + self, config_command: str = "config", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter into config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) - return super().config_mode(config_command, pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=""): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) return super().exit_config_mode(exit_config, pattern) def send_config_set( self, - config_commands=None, - exit_config_mode=False, - enter_config_mode=False, - **kwargs, - ): + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + enter_config_mode: bool = False, + **kwargs: Any, + ) -> str: return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, @@ -549,19 +564,24 @@

    Classes

    **kwargs, ) - def save_config(self, cmd="save config", confirm=True, confirm_response="y"): + def save_config( + self, + cmd: str = "save config", + confirm: bool = True, + confirm_response: str = "y", + ) -> str: """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self._send_command_timing_str(command_string=cmd) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self._send_command_timing_str(confirm_response) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self._send_command_timing_str(self.RETURN) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) return output

    Ancestors

    @@ -577,7 +597,9 @@

    Methods

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string="config", pattern=""):
    +
    def check_config_mode(
    +    self, check_string: str = "config", pattern: str = ""
    +) -> bool:
         """Checks if the device is in configuration mode or not."""
         if not pattern:
             pattern = re.escape(self.base_prompt)
    @@ -591,7 +613,7 @@ 

    Methods

    Reset WLC back to normal paging and gracefully close session.

    Source code -
    def cleanup(self, command="logout"):
    +
    def cleanup(self, command: str = "logout") -> None:
         """Reset WLC back to normal paging and gracefully close session."""
         self.send_command_timing("config paging enable")
     
    @@ -629,17 +651,19 @@ 

    Methods

    -def config_mode(self, config_command='config', pattern='') +def config_mode(self, config_command='config', pattern='', re_flags=0)

    Enter into config_mode.

    Source code -
    def config_mode(self, config_command="config", pattern=""):
    +
    def config_mode(
    +    self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter into config_mode."""
    -    if not pattern:
    -        pattern = re.escape(self.base_prompt)
    -    return super().config_mode(config_command, pattern)
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    @@ -649,10 +673,8 @@

    Methods

    Exit config_mode.

    Source code -
    def exit_config_mode(self, exit_config="exit", pattern=""):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
         """Exit config_mode."""
    -    if not pattern:
    -        pattern = re.escape(self.base_prompt)
         return super().exit_config_mode(exit_config, pattern)
    @@ -663,19 +685,24 @@

    Methods

    Saves Config.

    Source code -
    def save_config(self, cmd="save config", confirm=True, confirm_response="y"):
    +
    def save_config(
    +    self,
    +    cmd: str = "save config",
    +    confirm: bool = True,
    +    confirm_response: str = "y",
    +) -> str:
         """Saves Config."""
         self.enable()
         if confirm:
    -        output = self.send_command_timing(command_string=cmd)
    +        output = self._send_command_timing_str(command_string=cmd)
             if confirm_response:
    -            output += self.send_command_timing(confirm_response)
    +            output += self._send_command_timing_str(confirm_response)
             else:
                 # Send enter by default
    -            output += self.send_command_timing(self.RETURN)
    +            output += self._send_command_timing_str(self.RETURN)
         else:
             # Some devices are slow so match on trailing-prompt if you can
    -        output = self.send_command(command_string=cmd)
    +        output = self._send_command_str(command_string=cmd)
         return output
    @@ -690,7 +717,7 @@

    Methods

    Arguments are the same as send_command_timing() method

    Source code -
    def send_command_w_enter(self, *args, **kwargs):
    +
    def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str:
         """
         For 'show run-config' Cisco WLC adds a 'Press Enter to continue...' message
         Even though pagination is disabled
    @@ -704,7 +731,7 @@ 

    Methods

    # If no delay_factor use 1 for default value delay_factor = kwargs.get("delay_factor", 1) kwargs["delay_factor"] = self.select_delay_factor(delay_factor) - output = self.send_command_timing(*args, **kwargs) + output = self._send_command_timing_str(*args, **kwargs) if "Press any key" in output or "Press Enter to" in output: new_args = list(args) @@ -716,7 +743,7 @@

    Methods

    kwargs["max_loops"] = 150 # Send an 'enter' - output = self.send_command_timing(*new_args, **kwargs) + output += self._send_command_timing_str(*new_args, **kwargs) # WLC has excessive delay after this appears on screen if "802.11b Advanced Configuration" in output: @@ -743,6 +770,34 @@

    Methods

    return output
    +
    +def send_command_w_yes(self, *args, **kwargs) +
    +
    +

    For 'show interface summary' Cisco WLC adds a +'Would you like to display the next 15 entries?' message +Even though pagination is disabled +Arguments are the same as send_command_timing() method

    +
    +Source code +
    def send_command_w_yes(self, *args: Any, **kwargs: Any) -> str:
    +    """
    +    For 'show interface summary' Cisco WLC adds a
    +    'Would you like to display the next 15 entries?' message
    +    Even though pagination is disabled
    +    Arguments are the same as send_command_timing() method
    +    """
    +    output = self._send_command_timing_str(*args, **kwargs)
    +    if "(y/n)" in output:
    +        output += self._send_command_timing_str("y")
    +    strip_prompt = kwargs.get("strip_prompt", True)
    +    if strip_prompt:
    +        # Had to strip trailing prompt twice.
    +        output = self.strip_prompt(output)
    +        output = self.strip_prompt(output)
    +    return output
    +
    +
    def session_preparation(self)
    @@ -751,13 +806,13 @@

    Methods

    Cisco WLC uses "config paging disable" to disable paging

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established
     
         Cisco WLC uses "config paging disable" to disable paging
         """
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
     
         try:
             self.set_base_prompt()
    @@ -765,14 +820,11 @@ 

    Methods

    msg = f"Authentication failed: {self.host}" raise NetmikoAuthenticationException(msg) - self.disable_paging(command="config paging disable") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer()
    + self.disable_paging(command="config paging disable")
    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    WLC presents with the following on login (in certain OS versions)

    @@ -782,7 +834,7 @@

    Methods

    Password:****

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """WLC presents with the following on login (in certain OS versions)
     
         login as: user
    @@ -801,13 +853,15 @@ 

    Methods

    output = self.read_channel() if output: if "login as" in output or "User:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) else: - self.write_channel(self.RETURN) + # no output read, sleep and go for one more round of read channel time.sleep(delay_factor * 1.5) i += 1
    @@ -819,7 +873,6 @@

    Inherited members

    diff --git a/docs/netmiko/cisco/cisco_xr.html b/docs/netmiko/cisco/cisco_xr.html index 19f1538f1..d93a0dee1 100644 --- a/docs/netmiko/cisco/cisco_xr.html +++ b/docs/netmiko/cisco/cisco_xr.html @@ -22,22 +22,19 @@

    Module netmiko.cisco.cisco_xr

    Source code -
    import re
    +
    from typing import Optional, Any, Union, Sequence, TextIO
    +import re
    +import warnings
    +from netmiko.base_connection import DELAY_FACTOR_DEPR_SIMPLE_MSG
     from netmiko.cisco_base_connection import CiscoBaseConnection, CiscoFileTransfer
     
     
     class CiscoXrBase(CiscoBaseConnection):
    -    def __init__(self, *args, **kwargs):
    -        # Cisco NX-OS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def establish_connection(self):
    +    def establish_connection(self, width: int = 511, height: int = 511) -> None:
             """Establish SSH connection to the network device"""
    -        super().establish_connection(width=511, height=511)
    +        super().establish_connection(width=width, height=height)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             # IOS-XR has an issue where it echoes the command even though it hasn't returned the prompt
             self._test_channel_read(pattern=r"[>#]")
    @@ -47,15 +44,26 @@ 

    Module netmiko.cisco.cisco_xr

    self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """IOS-XR requires you not exit from configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def commit( - self, confirm=False, confirm_delay=None, comment="", label="", delay_factor=1 - ): + self, + confirm: bool = False, + confirm_delay: Optional[int] = None, + comment: str = "", + label: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -68,6 +76,8 @@

    Module netmiko.cisco.cisco_xr

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + supported combinations label and confirm: command_string = commit label <label> confirmed <confirm_delay> @@ -89,7 +99,8 @@

    Module netmiko.cisco.cisco_xr

    Exit of configuration mode with pending changes will cause the changes to be discarded and an exception to be generated. """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if confirm and not confirm_delay: raise ValueError("Invalid arguments supplied to XR commit") if confirm_delay and not confirm: @@ -120,24 +131,40 @@

    Module netmiko.cisco.cisco_xr

    # Enter config mode (if necessary) output = self.config_mode() - output += self.send_command_expect( + + # IOS-XR might do this: + # This could be a few minutes if your config is large. Confirm? [y/n][confirm] + new_data = self._send_command_str( command_string, + expect_string=r"(#|onfirm)", strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) + if "onfirm" in new_data: + output += new_data + new_data = self._send_command_str( + "y", + expect_string=r"#", + strip_prompt=False, + strip_command=False, + read_timeout=read_timeout, + ) + output += new_data if error_marker in output: raise ValueError(f"Commit failed with the following errors:\n\n{output}") if alt_error_marker in output: # Other commits occurred, don't proceed with commit - output += self.send_command_timing( - "no", strip_prompt=False, strip_command=False, delay_factor=delay_factor + output += self._send_command_timing_str( + "no", strip_prompt=False, strip_command=False ) raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def check_config_mode(self, check_string=")#", pattern=r"[#\$]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[#\$]" + ) -> bool: """Checks if the device is in configuration mode or not. IOS-XR, unfortunately, does this: @@ -150,7 +177,7 @@

    Module netmiko.cisco.cisco_xr

    output = output.replace("(admin)", "") return check_string in output - def exit_config_mode(self, exit_config="end", pattern=""): + def exit_config_mode(self, exit_config: str = "end", pattern: str = "") -> str: """Exit configuration mode.""" output = "" if self.check_config_mode(): @@ -172,7 +199,7 @@

    Module netmiko.cisco.cisco_xr

    raise ValueError("Failed to exit configuration mode") return output - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented (use commit() method)""" raise NotImplementedError @@ -192,7 +219,8 @@

    Module netmiko.cisco.cisco_xr

    class CiscoXrFileTransfer(CiscoFileTransfer): """Cisco IOS-XR SCP File Transfer driver.""" - def process_md5(self, md5_output, pattern=r"^([a-fA-F0-9]+)$"): + @staticmethod + def process_md5(md5_output: str, pattern: str = r"^([a-fA-F0-9]+)$") -> str: """ IOS-XR defaults with timestamps enabled @@ -206,7 +234,9 @@

    Module netmiko.cisco.cisco_xr

    else: raise ValueError(f"Invalid output from MD5 command: {md5_output}") - def remote_md5(self, base_cmd="show md5 file", remote_file=None): + def remote_md5( + self, base_cmd: str = "show md5 file", remote_file: Optional[str] = None + ) -> str: """ IOS-XR for MD5 requires this extra leading / @@ -219,14 +249,14 @@

    Module netmiko.cisco.cisco_xr

    remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here remote_md5_cmd = f"{base_cmd} /{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError
    @@ -241,7 +271,7 @@

    Classes

    class CiscoXrBase -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -249,146 +279,113 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoXrBase(CiscoBaseConnection):
    -    def __init__(self, *args, **kwargs):
    -        # Cisco NX-OS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def establish_connection(self):
    +    def establish_connection(self, width: int = 511, height: int = 511) -> None:
             """Establish SSH connection to the network device"""
    -        super().establish_connection(width=511, height=511)
    +        super().establish_connection(width=width, height=height)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             # IOS-XR has an issue where it echoes the command even though it hasn't returned the prompt
             self._test_channel_read(pattern=r"[>#]")
    @@ -398,15 +395,26 @@ 

    Classes

    self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """IOS-XR requires you not exit from configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def commit( - self, confirm=False, confirm_delay=None, comment="", label="", delay_factor=1 - ): + self, + confirm: bool = False, + confirm_delay: Optional[int] = None, + comment: str = "", + label: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -419,6 +427,8 @@

    Classes

    comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + supported combinations label and confirm: command_string = commit label <label> confirmed <confirm_delay> @@ -440,7 +450,8 @@

    Classes

    Exit of configuration mode with pending changes will cause the changes to be discarded and an exception to be generated. """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if confirm and not confirm_delay: raise ValueError("Invalid arguments supplied to XR commit") if confirm_delay and not confirm: @@ -471,24 +482,40 @@

    Classes

    # Enter config mode (if necessary) output = self.config_mode() - output += self.send_command_expect( + + # IOS-XR might do this: + # This could be a few minutes if your config is large. Confirm? [y/n][confirm] + new_data = self._send_command_str( command_string, + expect_string=r"(#|onfirm)", strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) + if "onfirm" in new_data: + output += new_data + new_data = self._send_command_str( + "y", + expect_string=r"#", + strip_prompt=False, + strip_command=False, + read_timeout=read_timeout, + ) + output += new_data if error_marker in output: raise ValueError(f"Commit failed with the following errors:\n\n{output}") if alt_error_marker in output: # Other commits occurred, don't proceed with commit - output += self.send_command_timing( - "no", strip_prompt=False, strip_command=False, delay_factor=delay_factor + output += self._send_command_timing_str( + "no", strip_prompt=False, strip_command=False ) raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def check_config_mode(self, check_string=")#", pattern=r"[#\$]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[#\$]" + ) -> bool: """Checks if the device is in configuration mode or not. IOS-XR, unfortunately, does this: @@ -501,7 +528,7 @@

    Classes

    output = output.replace("(admin)", "") return check_string in output - def exit_config_mode(self, exit_config="end", pattern=""): + def exit_config_mode(self, exit_config: str = "end", pattern: str = "") -> str: """Exit configuration mode.""" output = "" if self.check_config_mode(): @@ -523,7 +550,7 @@

    Classes

    raise ValueError("Failed to exit configuration mode") return output - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented (use commit() method)""" raise NotImplementedError
    @@ -548,7 +575,9 @@

    Methods

    RP/0/RSP0/CPU0:BNG(admin)#

    Source code -
    def check_config_mode(self, check_string=")#", pattern=r"[#\$]"):
    +
    def check_config_mode(
    +    self, check_string: str = ")#", pattern: str = r"[#\$]"
    +) -> bool:
         """Checks if the device is in configuration mode or not.
     
         IOS-XR, unfortunately, does this:
    @@ -563,7 +592,7 @@ 

    Methods

    -def commit(self, confirm=False, confirm_delay=None, comment='', label='', delay_factor=1) +def commit(self, confirm=False, confirm_delay=None, comment='', label='', read_timeout=120.0, delay_factor=None)

    Commit the candidate configuration.

    @@ -575,6 +604,7 @@

    Methods

    command_string = commit label
    -def establish_connection(self) +def establish_connection(self, width=511, height=511)

    Establish SSH connection to the network device

    Source code -
    def establish_connection(self):
    +
    def establish_connection(self, width: int = 511, height: int = 511) -> None:
         """Establish SSH connection to the network device"""
    -    super().establish_connection(width=511, height=511)
    + super().establish_connection(width=width, height=height)
    @@ -697,7 +750,7 @@

    Methods

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="end", pattern=""):
    +
    def exit_config_mode(self, exit_config: str = "end", pattern: str = "") -> str:
         """Exit configuration mode."""
         output = ""
         if self.check_config_mode():
    @@ -727,7 +780,7 @@ 

    Methods

    Not Implemented (use commit() method)

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented (use commit() method)"""
         raise NotImplementedError
    @@ -739,7 +792,12 @@

    Methods

    IOS-XR requires you not exit from configuration mode.

    Source code -
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
    +
    def send_config_set(
    +    self,
    +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +    exit_config_mode: bool = False,
    +    **kwargs: Any,
    +) -> str:
         """IOS-XR requires you not exit from configuration mode."""
         return super().send_config_set(
             config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    @@ -753,7 +811,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         # IOS-XR has an issue where it echoes the command even though it hasn't returned the prompt
         self._test_channel_read(pattern=r"[>#]")
    @@ -772,8 +830,7 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -782,9 +839,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -794,6 +851,7 @@

    Inherited members

  • send_command_expect
  • send_command_timing
  • send_config_from_file
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -818,7 +876,8 @@

    Inherited members

    class CiscoXrFileTransfer(CiscoFileTransfer):
         """Cisco IOS-XR SCP File Transfer driver."""
     
    -    def process_md5(self, md5_output, pattern=r"^([a-fA-F0-9]+)$"):
    +    @staticmethod
    +    def process_md5(md5_output: str, pattern: str = r"^([a-fA-F0-9]+)$") -> str:
             """
             IOS-XR defaults with timestamps enabled
     
    @@ -832,7 +891,9 @@ 

    Inherited members

    else: raise ValueError(f"Invalid output from MD5 command: {md5_output}") - def remote_md5(self, base_cmd="show md5 file", remote_file=None): + def remote_md5( + self, base_cmd: str = "show md5 file", remote_file: Optional[str] = None + ) -> str: """ IOS-XR for MD5 requires this extra leading / @@ -845,14 +906,14 @@

    Inherited members

    remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here remote_md5_cmd = f"{base_cmd} /{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -860,10 +921,10 @@

    Ancestors

  • CiscoFileTransfer
  • BaseFileTransfer
  • -

    Methods

    +

    Static methods

    -def process_md5(self, md5_output, pattern='^([a-fA-F0-9]+)$') +def process_md5(md5_output, pattern='^([a-fA-F0-9]+)$')

    IOS-XR defaults with timestamps enabled

    @@ -873,7 +934,8 @@

    show md5 file /bootflash:/boot/g c84843f0030efd44b01343fdb8c2e801

    Source code -
    def process_md5(self, md5_output, pattern=r"^([a-fA-F0-9]+)$"):
    +
    @staticmethod
    +def process_md5(md5_output: str, pattern: str = r"^([a-fA-F0-9]+)$") -> str:
         """
         IOS-XR defaults with timestamps enabled
     
    @@ -888,6 +950,9 @@ 

    show md5 file /bootflash:/boot/g raise ValueError(f"Invalid output from MD5 command: {md5_output}")

    +
    +

    Methods

    +
    def remote_md5(self, base_cmd='show md5 file', remote_file=None)
    @@ -896,7 +961,9 @@

    show md5 file /bootflash:/boot/g

    show md5 file /bootflash:/boot/grub/grub.cfg

    Source code -
    def remote_md5(self, base_cmd="show md5 file", remote_file=None):
    +
    def remote_md5(
    +    self, base_cmd: str = "show md5 file", remote_file: Optional[str] = None
    +) -> str:
         """
         IOS-XR for MD5 requires this extra leading /
     
    @@ -909,7 +976,7 @@ 

    show md5 file /bootflash:/boot/g remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here remote_md5_cmd = f"{base_cmd} /{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5

    @@ -940,7 +1007,7 @@

    Inherited members

    class CiscoXrSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco XR SSH driver.

    @@ -948,131 +1015,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:

    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1095,9 +1135,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1108,9 +1147,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1122,6 +1161,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1138,7 +1178,7 @@

    Inherited members

    class CiscoXrTelnet -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco XR Telnet driver.

    @@ -1146,131 +1186,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1293,9 +1306,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1306,9 +1318,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1320,6 +1332,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/cisco/index.html b/docs/netmiko/cisco/index.html index be5e9fe1b..5b928666c 100644 --- a/docs/netmiko/cisco/index.html +++ b/docs/netmiko/cisco/index.html @@ -36,7 +36,9 @@

    Module netmiko.cisco

    from netmiko.cisco.cisco_xr import CiscoXrSSH, CiscoXrTelnet, CiscoXrFileTransfer from netmiko.cisco.cisco_wlc_ssh import CiscoWlcSSH from netmiko.cisco.cisco_s300 import CiscoS300SSH +from netmiko.cisco.cisco_s300 import CiscoS300Telnet from netmiko.cisco.cisco_tp_tcce import CiscoTpTcCeSSH +from netmiko.cisco.cisco_viptela import CiscoViptelaSSH __all__ = [ "CiscoIosSSH", @@ -48,7 +50,9 @@

    Module netmiko.cisco

    "CiscoXrTelnet", "CiscoWlcSSH", "CiscoS300SSH", + "CiscoS300Telnet", "CiscoTpTcCeSSH", + "CiscoViptelaSSH", "CiscoIosBase", "CiscoIosFileTransfer", "InLineTransfer", @@ -88,6 +92,10 @@

    Sub-modules

    Class to manage Cisco Telepresence Endpoint on TC/CE software release. Also working for Cisco Expressway/VCS …

    +
    netmiko.cisco.cisco_viptela
    +
    +

    Subclass specific to Cisco Viptela.

    +
    netmiko.cisco.cisco_wlc_ssh

    Netmiko Cisco WLC support.

    @@ -158,144 +166,115 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoAsaSSH(CiscoSSHConnection):
         """Subclass specific to Cisco ASA."""
     
    -    def __init__(self, *args, **kwargs):
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             kwargs.setdefault("allow_auto_change", True)
             return super().__init__(*args, **kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
     
             # Make sure the ASA is ready
    @@ -323,21 +302,25 @@ 

    Inherited members

    self.set_base_prompt() - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + def check_config_mode( + self, check_string: str = ")#", pattern: str = r"[>\#]" + ) -> bool: return super().check_config_mode(check_string=check_string, pattern=pattern) def enable( self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = r"\#", + re_flags: int = re.IGNORECASE, + ) -> str: return super().enable( cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags ) - def send_command_timing(self, *args, **kwargs): + def send_command_timing( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -351,7 +334,9 @@

    Inherited members

    self.set_base_prompt() return output - def send_command(self, *args, **kwargs): + def send_command( + self, *args: Any, **kwargs: Any + ) -> Union[str, List[Any], Dict[str, Any]]: """ If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. @@ -373,11 +358,7 @@

    Inherited members

    return output - def send_command_expect(self, *args, **kwargs): - """Backwards compaitibility.""" - return self.send_command(*args, **kwargs) - - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """ Cisco ASA in multi-context mode needs to have the base prompt updated (if you switch contexts i.e. 'changeto') @@ -391,8 +372,10 @@

    Inherited members

    # strip off (conf.* from base_prompt self.base_prompt = match.group(1) return self.base_prompt + else: + return cur_base_prompt - def asa_login(self): + def asa_login(self) -> None: """ Handle ASA reaching privilege level 15 using login @@ -412,8 +395,10 @@

    Inherited members

    time.sleep(0.5 * delay_factor) output = self.read_channel() if "sername" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "ssword" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) elif "#" in output: return @@ -424,13 +409,15 @@

    Inherited members

    msg = "Unable to enter enable mode!" raise NetmikoAuthenticationException(msg) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Cisco ASA needed that extra \r\n\r""" newline = re.compile("(\r\n\r|\r\r\r\n|\r\r\n|\r\n|\n\r)") a_string = newline.sub(self.RESPONSE_RETURN, a_string) @@ -459,7 +446,7 @@

    Methods

    level 15 after 10 loops.

    Source code -
    def asa_login(self):
    +
    def asa_login(self) -> None:
         """
         Handle ASA reaching privilege level 15 using login
     
    @@ -479,8 +466,10 @@ 

    Methods

    time.sleep(0.5 * delay_factor) output = self.read_channel() if "sername" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "ssword" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) elif "#" in output: return @@ -499,7 +488,7 @@

    Methods

    Cisco ASA needed that extra

    Source code -
    def normalize_linefeeds(self, a_string):
    +
    def normalize_linefeeds(self, a_string: str) -> str:
         """Cisco ASA needed that extra \r\n\r"""
         newline = re.compile("(\r\n\r|\r\r\r\n|\r\r\n|\r\n|\n\r)")
         a_string = newline.sub(self.RESPONSE_RETURN, a_string)
    @@ -517,7 +506,9 @@ 

    Methods

    Saves Config

    Source code -
    def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Saves Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -532,7 +523,9 @@ 

    Methods

    updated after each context change.

    Source code -
    def send_command(self, *args, **kwargs):
    +
    def send_command(
    +    self, *args: Any, **kwargs: Any
    +) -> Union[str, List[Any], Dict[str, Any]]:
         """
         If the ASA is in multi-context mode, then the base_prompt needs to be
         updated after each context change.
    @@ -555,18 +548,6 @@ 

    Methods

    return output
    -
    -def send_command_expect(self, *args, **kwargs) -
    -
    -

    Backwards compaitibility.

    -
    -Source code -
    def send_command_expect(self, *args, **kwargs):
    -    """Backwards compaitibility."""
    -    return self.send_command(*args, **kwargs)
    -
    -
    def send_command_timing(self, *args, **kwargs)
    @@ -575,7 +556,9 @@

    Methods

    updated after each context change.

    Source code -
    def send_command_timing(self, *args, **kwargs):
    +
    def send_command_timing(
    +    self, *args: Any, **kwargs: Any
    +) -> Union[str, List[Any], Dict[str, Any]]:
         """
         If the ASA is in multi-context mode, then the base_prompt needs to be
         updated after each context change.
    @@ -597,7 +580,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
     
         # Make sure the ASA is ready
    @@ -636,7 +619,7 @@ 

    Methods

    happens the trailing '(config*' needs stripped off.

    Source code -
    def set_base_prompt(self, *args, **kwargs):
    +
    def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
         """
         Cisco ASA in multi-context mode needs to have the base prompt updated
         (if you switch contexts i.e. 'changeto')
    @@ -649,7 +632,9 @@ 

    Methods

    if match: # strip off (conf.* from base_prompt self.base_prompt = match.group(1) - return self.base_prompt
    + return self.base_prompt + else: + return cur_base_prompt
    @@ -661,9 +646,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -673,16 +657,18 @@

    Inherited members

  • find_prompt
  • is_alive
  • normalize_cmd
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • run_ttp
  • select_delay_factor
  • +
  • send_command_expect
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_terminal_width
  • special_login_handler
  • strip_ansi_escape_codes
  • @@ -697,7 +683,7 @@

    Inherited members

    class CiscoFtdSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Subclass specific to Cisco FTD.

    @@ -705,160 +691,127 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CiscoFtdSSH(CiscoSSHConnection):
    +
    class CiscoFtdSSH(NoEnable, NoConfig, CiscoSSHConnection):
         """Subclass specific to Cisco FTD."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
     
    -    def send_config_set(self, *args, **kwargs):
    +    def send_config_set(self, *args: Any, **kwargs: Any) -> str:
             """Canot change config on FTD via ssh"""
             raise NotImplementedError
     
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on firepower ssh"""
    -        return ""
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on firepower ssh"""
    -        return ""
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on firepower ssh"""
    +    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
    +        """Canot change config on FTD via ssh"""
             return False

    Ancestors

      +
    • NoEnable
    • +
    • NoConfig
    • CiscoSSHConnection
    • CiscoBaseConnection
    • BaseConnection
    • @@ -866,41 +819,17 @@

      Ancestors

      Methods

      -def check_config_mode(self, *args, **kwargs) +def check_config_mode(self, check_string='', pattern='')
      -

      No config mode on firepower ssh

      +

      Canot change config on FTD via ssh

      Source code -
      def check_config_mode(self, *args, **kwargs):
      -    """No config mode on firepower ssh"""
      +
      def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
      +    """Canot change config on FTD via ssh"""
           return False
      -
      -def config_mode(self, *args, **kwargs) -
      -
      -

      No config mode on firepower ssh

      -
      -Source code -
      def config_mode(self, *args, **kwargs):
      -    """No config mode on firepower ssh"""
      -    return ""
      -
      -
      -
      -def enable(self, *args, **kwargs) -
      -
      -

      No enable mode on firepower ssh

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """No enable mode on firepower ssh"""
      -    return ""
      -
      -
      def send_config_set(self, *args, **kwargs)
      @@ -908,7 +837,7 @@

      Methods

      Canot change config on FTD via ssh

      Source code -
      def send_config_set(self, *args, **kwargs):
      +
      def send_config_set(self, *args: Any, **kwargs: Any) -> str:
           """Canot change config on FTD via ssh"""
           raise NotImplementedError
      @@ -920,9 +849,9 @@

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
      -    self._test_channel_read()
      +    self._test_channel_read(pattern=r"[>#]")
           self.set_base_prompt()
      @@ -934,10 +863,11 @@

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • +
    • config_mode
    • disable_paging
    • disconnect
    • +
    • enable
    • establish_connection
    • exit_config_mode
    • exit_enable_mode
    • @@ -945,9 +875,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -958,6 +888,7 @@

      Inherited members

    • send_command_expect
    • send_command_timing
    • send_config_from_file
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • @@ -973,7 +904,7 @@

      Inherited members

      class CiscoIosBase -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Common Methods for IOS (both SSH and telnet).

      @@ -981,151 +912,118 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoIosBase(CiscoBaseConnection):
         """Common Methods for IOS (both SSH and telnet)."""
     
    -    def __init__(self, *args, **kwargs):
    -        # Cisco-IOS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             cmd = "terminal width 511"
             self.set_terminal_width(command=cmd, pattern=cmd)
             self.disable_paging()
             self.set_base_prompt()
     
    -    def check_config_mode(self, check_string=")#", pattern="#"):
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = r"#") -> bool:
             """
             Checks if the device is in configuration mode or not.
     
    @@ -1133,7 +1031,9 @@ 

    Inherited members

    """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using Copy Run Start""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -1161,7 +1061,9 @@

    Methods

    Saves Config Using Copy Run Start

    Source code -
    def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Saves Config Using Copy Run Start"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -1175,7 +1077,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         cmd = "terminal width 511"
         self.set_terminal_width(command=cmd, pattern=cmd)
    @@ -1192,9 +1094,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1205,9 +1106,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1218,6 +1119,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -1280,7 +1182,7 @@

    Inherited members

    class CiscoIosSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco IOS SSH driver.

    @@ -1288,131 +1190,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1435,9 +1310,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1448,9 +1322,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1462,6 +1336,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1478,7 +1353,7 @@

    Inherited members

    class CiscoIosSerial -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco IOS Serial driver.

    @@ -1486,131 +1361,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1633,9 +1481,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1646,9 +1493,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1660,6 +1507,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1676,7 +1524,7 @@

    Inherited members

    class CiscoIosTelnet -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco IOS Telnet driver.

    @@ -1684,131 +1532,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1831,9 +1652,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1844,9 +1664,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1858,6 +1678,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1874,7 +1695,7 @@

    Inherited members

    class CiscoNxosFileTransfer -(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0, progress=None, progress4=None) +(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0, progress=None, progress4=None, hash_supported=True)

    Cisco NXOS SCP File Transfer driver.

    @@ -1885,20 +1706,24 @@

    Inherited members

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="bootflash:", - direction="put", - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: str = "bootflash:", + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for NX-OS") + if file_system: self.file_system = file_system else: @@ -1917,12 +1742,12 @@

    Inherited members

    self.progress = progress self.progress4 = progress4 - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"dir {self.file_system}{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: return False @@ -1932,19 +1757,25 @@

    Inherited members

    raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Invalid value for file transfer direction.") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Invalid value for file transfer direction.") if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if re.search("no such file or directory", remote_out, flags=re.I): raise IOError("Unable to find file on remote system") # Match line containing file name @@ -1959,23 +1790,27 @@

    Inherited members

    raise IOError("Unable to find file on remote system") @staticmethod - def process_md5(md5_output, pattern=r"= (.*)"): + def process_md5(md5_output: str, pattern: str = r"= (.*)") -> str: """Not needed on NX-OS.""" raise NotImplementedError - def remote_md5(self, base_cmd="show file", remote_file=None): + def remote_md5( + self, base_cmd: str = "show file", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}{remote_file} md5sum" - return self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500).strip() + output = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + output = output.strip() + return output - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -1993,7 +1828,7 @@

    Static methods

    Source code
    @staticmethod
    -def process_md5(md5_output, pattern=r"= (.*)"):
    +def process_md5(md5_output: str, pattern: str = r"= (.*)") -> str:
         """Not needed on NX-OS."""
         raise NotImplementedError
    @@ -2025,7 +1860,7 @@

    Inherited members

    class CiscoNxosSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -2033,142 +1868,109 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoNxosSSH(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        # Cisco NX-OS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
             # NX-OS has an issue where it echoes the command even though it hasn't returned the prompt
    @@ -2179,46 +1981,45 @@ 

    Inherited members

    self.disable_paging() self.set_base_prompt() - def normalize_linefeeds(self, a_string): + def normalize_linefeeds(self, a_string: str) -> str: """Convert '\r\n' or '\r\r\n' to '\n, and remove extra '\r's in the text.""" newline = re.compile(r"(\r\r\n\r|\r\r\n|\r\n)") # NX-OS fix for incorrect MD5 on 9K (due to strange <enter> patterns on NX-OS) return newline.sub(self.RESPONSE_RETURN, a_string).replace("\r", "\n") - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """Checks if the device is in configuration mode or not.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() + output = "" if confirm: - output = self.send_command_timing( + output += self._send_command_timing_str( command_string=cmd, strip_prompt=False, strip_command=False ) if confirm_response: - output += self.send_command_timing( + output += self._send_command_timing_str( confirm_response, strip_prompt=False, strip_command=False ) else: # Send enter by default - output += self.send_command_timing( + output += self._send_command_timing_str( self.RETURN, strip_prompt=False, strip_command=False ) else: # NX-OS is very slow on save_config ensure it waits long enough. - # FIX: this is a hack as delay_factor will be set to .1 via fast_cli=True in - # send_command so increase max_loops. - output = self.send_command( + output += self._send_command_str( command_string=cmd, strip_prompt=False, strip_command=False, - max_loops=5000, + read_timeout=100, ) return output
    @@ -2237,7 +2038,7 @@

    Methods

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string=")#", pattern="#"):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
         """Checks if the device is in configuration mode or not."""
         return super().check_config_mode(check_string=check_string, pattern=pattern)
    @@ -2253,7 +2054,7 @@

    Methods

    's in the text.

    Source code -
    def normalize_linefeeds(self, a_string):
    +
    def normalize_linefeeds(self, a_string: str) -> str:
         """Convert '\r\n' or '\r\r\n' to '\n, and remove extra '\r's in the text."""
         newline = re.compile(r"(\r\r\n\r|\r\r\n|\r\n)")
         # NX-OS fix for incorrect MD5 on 9K (due to strange <enter> patterns on NX-OS)
    @@ -2267,7 +2068,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
         # NX-OS has an issue where it echoes the command even though it hasn't returned the prompt
    @@ -2287,9 +2088,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -2299,9 +2099,9 @@

    Inherited members

  • find_prompt
  • is_alive
  • normalize_cmd
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -2313,6 +2113,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -2328,7 +2129,7 @@

    Inherited members

    class CiscoS300SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Support for Cisco SG300 series of devices.

    @@ -2339,472 +2140,557 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CiscoS300SSH(CiscoSSHConnection):
    -    """
    -    Support for Cisco SG300 series of devices.
    -
    -    Note, must configure the following to disable SG300 from prompting for username twice:
    -
    -    configure terminal
    -    ip ssh password-auth
    -    """
    -
    -    def session_preparation(self):
    -        """Prepare the session after the connection has been established."""
    -        self.ansi_escape_codes = True
    -        self._test_channel_read()
    -        self.set_base_prompt()
    -        self.set_terminal_width(command="terminal width 511", pattern="terminal")
    -        self.disable_paging(command="terminal datadump")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -
    -    def save_config(self, cmd="write memory", confirm=True, confirm_response="Y"):
    -        return super().save_config(
    -            cmd=cmd, confirm=confirm, confirm_response=confirm_response
    -        )
    +
    class CiscoS300SSH(CiscoS300Base):
    +    pass

    Ancestors

    -

    Methods

    -
    -
    -def session_preparation(self) -
    -
    -

    Prepare the session after the connection has been established.

    -
    -Source code -
    def session_preparation(self):
    -    """Prepare the session after the connection has been established."""
    -    self.ansi_escape_codes = True
    -    self._test_channel_read()
    -    self.set_base_prompt()
    -    self.set_terminal_width(command="terminal width 511", pattern="terminal")
    -    self.disable_paging(command="terminal datadump")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -
    -
    -

    Inherited members

    -
    -class CiscoTpTcCeSSH -(*args, **kwargs) +
    +class CiscoS300Telnet +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Support for Cisco SG300 series of devices, with telnet. +Note: can be used with Sx200 series, with telnet enabled.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class CiscoTpTcCeSSH(CiscoSSHConnection):
    -    def __init__(self, *args, **kwargs):
    -        default_enter = kwargs.get("default_enter")
    -        kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
    -        super().__init__(*args, **kwargs)
    -
    -    def disable_paging(self, *args, **kwargs):
    -        """Paging is disabled by default."""
    -        return ""
    -
    -    def session_preparation(self):
    -        """
    -        Prepare the session after the connection has been established
    -
    -        This method handles some of vagaries that occur between various devices
    -        early on in the session.
    -
    -        In general, it should include:
    -        self.set_base_prompt()
    -        self.disable_paging()
    -        self.set_terminal_width()
    -        """
    -        self._test_channel_read()
    -        self.set_base_prompt()
    -        self.set_terminal_width()
    -        self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def set_base_prompt(self, *args, **kwargs):
    -        """Use 'OK' as base_prompt."""
    -        self.base_prompt = "OK"
    -        return self.base_prompt
    -
    -    def find_prompt(self, *args, **kwargs):
    -        """Use 'OK' as standard prompt."""
    -        return "OK"
    -
    -    def strip_prompt(self, a_string):
    -        """Strip the trailing router prompt from the output."""
    -        expect_string = r"^(OK|ERROR|Command not recognized\.)$"
    -        response_list = a_string.split(self.RESPONSE_RETURN)
    -        last_line = response_list[-1]
    -        if re.search(expect_string, last_line):
    -            return self.RESPONSE_RETURN.join(response_list[:-1])
    -        else:
    -            return a_string
    -
    -    def send_command(self, *args, **kwargs):
    -        """
    -        Send command to network device retrieve output until router_prompt or expect_string
    -
    -        By default this method will keep waiting to receive data until the network device prompt is
    -        detected. The current network device prompt will be determined automatically.
    -        """
    -        if len(args) >= 2:
    -            expect_string = args[1]
    -        else:
    -            expect_string = kwargs.get("expect_string")
    -            if expect_string is None:
    -                expect_string = r"(OK|ERROR|Command not recognized\.)"
    -                expect_string = self.RETURN + expect_string + self.RETURN
    -                kwargs.setdefault("expect_string", expect_string)
    -
    -        output = super().send_command(*args, **kwargs)
    -        return output
    +
    class CiscoS300Telnet(CiscoS300Base):
    +    """
    +    Support for Cisco SG300 series of devices, with telnet.
    +    Note: can be used with Sx200 series, with telnet enabled.
    +    """
     
    -    def save_config(self, *args, **kwargs):
    -        """Not Implemented"""
    -        raise NotImplementedError
    + pass

    Ancestors

    -

    Methods

    -
    -
    -def disable_paging(self, *args, **kwargs) -
    -
    -

    Paging is disabled by default.

    -
    -Source code -
    def disable_paging(self, *args, **kwargs):
    -    """Paging is disabled by default."""
    -    return ""
    -
    +

    Inherited members

    +
    -
    -def find_prompt(self, *args, **kwargs) +
    +class CiscoTpTcCeSSH +(*args, **kwargs)
    -

    Use 'OK' as standard prompt.

    -
    -Source code -
    def find_prompt(self, *args, **kwargs):
    +

    Base Class for cisco-like behavior.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class CiscoTpTcCeSSH(CiscoSSHConnection):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
    +        default_enter = kwargs.get("default_enter")
    +        kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
    +        super().__init__(*args, **kwargs)
    +
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
    +        """Paging is disabled by default."""
    +        return ""
    +
    +    def session_preparation(self) -> None:
    +        """
    +        Prepare the session after the connection has been established
    +
    +        This method handles some of vagaries that occur between various devices
    +        early on in the session.
    +
    +        In general, it should include:
    +        self.set_base_prompt()
    +        self.disable_paging()
    +        self.set_terminal_width()
    +        """
    +        # Could not work out what the CLI looked like. It would be good to switch to
    +        # a pattern on the _test_channel_read() call.
    +        self._test_channel_read()
    +        self.set_base_prompt()
    +        self.set_terminal_width()
    +        self.disable_paging()
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
    +        """Use 'OK' as base_prompt."""
    +        self.base_prompt = "OK"
    +        return self.base_prompt
    +
    +    def find_prompt(self, *args: Any, **kwargs: Any) -> str:
    +        """Use 'OK' as standard prompt."""
    +        return "OK"
    +
    +    def strip_prompt(self, a_string: str) -> str:
    +        """Strip the trailing router prompt from the output."""
    +        expect_string = r"^(OK|ERROR|Command not recognized\.)$"
    +        response_list = a_string.split(self.RESPONSE_RETURN)
    +        last_line = response_list[-1]
    +        if re.search(expect_string, last_line):
    +            return self.RESPONSE_RETURN.join(response_list[:-1])
    +        else:
    +            return a_string
    +
    +    def send_command(
    +        self, *args: Any, **kwargs: Any
    +    ) -> Union[str, List[Any], Dict[str, Any]]:
    +        """
    +        Send command to network device retrieve output until router_prompt or expect_string
    +
    +        By default this method will keep waiting to receive data until the network device prompt is
    +        detected. The current network device prompt will be determined automatically.
    +        """
    +        if len(args) >= 2:
    +            expect_string = args[1]
    +        else:
    +            expect_string = kwargs.get("expect_string")
    +            if expect_string is None:
    +                expect_string = r"(OK|ERROR|Command not recognized\.)"
    +                expect_string = self.RETURN + expect_string + self.RETURN
    +                kwargs.setdefault("expect_string", expect_string)
    +
    +        output = super().send_command(*args, **kwargs)
    +        return output
    +
    +    def save_config(self, *args: Any, **kwargs: Any) -> str:
    +        """Not Implemented"""
    +        raise NotImplementedError
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def disable_paging(self, *args, **kwargs) +
    +
    +

    Paging is disabled by default.

    +
    +Source code +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
    +    """Paging is disabled by default."""
    +    return ""
    +
    +
    +
    +def find_prompt(self, *args, **kwargs) +
    +
    +

    Use 'OK' as standard prompt.

    +
    +Source code +
    def find_prompt(self, *args: Any, **kwargs: Any) -> str:
         """Use 'OK' as standard prompt."""
         return "OK"
    @@ -2816,7 +2702,7 @@

    Methods

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -2830,7 +2716,9 @@

    Methods

    detected. The current network device prompt will be determined automatically.

    Source code -
    def send_command(self, *args, **kwargs):
    +
    def send_command(
    +    self, *args: Any, **kwargs: Any
    +) -> Union[str, List[Any], Dict[str, Any]]:
         """
         Send command to network device retrieve output until router_prompt or expect_string
     
    @@ -2863,7 +2751,7 @@ 

    Methods

    self.set_terminal_width()

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established
     
    @@ -2875,6 +2763,8 @@ 

    Methods

    self.disable_paging() self.set_terminal_width() """ + # Could not work out what the CLI looked like. It would be good to switch to + # a pattern on the _test_channel_read() call. self._test_channel_read() self.set_base_prompt() self.set_terminal_width() @@ -2891,7 +2781,7 @@

    Methods

    Use 'OK' as base_prompt.

    Source code -
    def set_base_prompt(self, *args, **kwargs):
    +
    def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
         """Use 'OK' as base_prompt."""
         self.base_prompt = "OK"
         return self.base_prompt
    @@ -2904,7 +2794,7 @@

    Methods

    Strip the trailing router prompt from the output.

    Source code -
    def strip_prompt(self, a_string):
    +
    def strip_prompt(self, a_string: str) -> str:
         """Strip the trailing router prompt from the output."""
         expect_string = r"^(OK|ERROR|Command not recognized\.)$"
         response_list = a_string.split(self.RESPONSE_RETURN)
    @@ -2924,9 +2814,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disconnect
  • enable
  • establish_connection
  • @@ -2935,23 +2824,342 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • +
  • read_until_pattern
  • +
  • read_until_prompt
  • +
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • +
  • select_delay_factor
  • +
  • send_command_expect
  • +
  • send_command_timing
  • +
  • send_config_from_file
  • +
  • send_config_set
  • +
  • send_multiline
  • +
  • set_terminal_width
  • +
  • special_login_handler
  • +
  • strip_ansi_escape_codes
  • +
  • strip_backspaces
  • +
  • strip_command
  • +
  • telnet_login
  • +
  • write_channel
  • + + + +
    +
    +class CiscoViptelaSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Subclass specific to Cisco Viptela.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class CiscoViptelaSSH(CiscoSSHConnection):
    +    """Subclass specific to Cisco Viptela."""
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>#]")
    +        self.set_base_prompt()
    +        self.disable_paging(command="paginate false")
    +
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
    +        """Checks if the device is in configuration mode or not."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def commit(self, confirm: bool = False, confirm_response: str = "") -> str:
    +        cmd = "commit"
    +        return super().save_config(
    +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
    +        )
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "conf terminal",
    +        pattern: str = "",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = False,
    +        **kwargs: Any,
    +    ) -> str:
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#") -> str:
    +        """
    +        Exit from configuration mode.
    +
    +        Viptela might have the following in the output (if no 'commit()' occurred.
    +
    +        Uncommitted changes found, commit them? [yes/no/CANCEL]
    +        """
    +        output = ""
    +        if self.check_config_mode():
    +            self.write_channel(self.normalize_cmd(exit_config))
    +            # Make sure you read until you detect the command echo (avoid getting out of sync)
    +            if self.global_cmd_verify is not False:
    +                output += self.read_until_pattern(
    +                    pattern=re.escape(exit_config.strip())
    +                )
    +            if not re.search(pattern, output, flags=re.M):
    +                uncommit_pattern = r"Uncommitted changes found"
    +                new_pattern = f"({pattern}|{uncommit_pattern})"
    +                output += self.read_until_pattern(pattern=new_pattern)
    +                # Do not save 'uncommited changes'
    +                if uncommit_pattern in output:
    +                    self.write_channel(self.normalize_cmd("no"))
    +                    output += self.read_until_pattern(pattern=pattern)
    +
    +            if self.check_config_mode():
    +                raise ValueError("Failed to exit configuration mode")
    +        return output
    +
    +    def save_config(
    +        self, cmd: str = "commit", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
    +        """Saves Config"""
    +        raise NotImplementedError
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string=')#', pattern='#') +
    +
    +

    Checks if the device is in configuration mode or not.

    +
    +Source code +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
    +    """Checks if the device is in configuration mode or not."""
    +    return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def exit_config_mode(self, exit_config='end', pattern='#') +
    +
    +

    Exit from configuration mode.

    +

    Viptela might have the following in the output (if no 'commit()' occurred.

    +

    Uncommitted changes found, commit them? [yes/no/CANCEL]

    +
    +Source code +
    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#") -> str:
    +    """
    +    Exit from configuration mode.
    +
    +    Viptela might have the following in the output (if no 'commit()' occurred.
    +
    +    Uncommitted changes found, commit them? [yes/no/CANCEL]
    +    """
    +    output = ""
    +    if self.check_config_mode():
    +        self.write_channel(self.normalize_cmd(exit_config))
    +        # Make sure you read until you detect the command echo (avoid getting out of sync)
    +        if self.global_cmd_verify is not False:
    +            output += self.read_until_pattern(
    +                pattern=re.escape(exit_config.strip())
    +            )
    +        if not re.search(pattern, output, flags=re.M):
    +            uncommit_pattern = r"Uncommitted changes found"
    +            new_pattern = f"({pattern}|{uncommit_pattern})"
    +            output += self.read_until_pattern(pattern=new_pattern)
    +            # Do not save 'uncommited changes'
    +            if uncommit_pattern in output:
    +                self.write_channel(self.normalize_cmd("no"))
    +                output += self.read_until_pattern(pattern=pattern)
    +
    +        if self.check_config_mode():
    +            raise ValueError("Failed to exit configuration mode")
    +    return output
    +
    +
    +
    +def save_config(self, cmd='commit', confirm=False, confirm_response='') +
    +
    +

    Saves Config

    +
    +Source code +
    def save_config(
    +    self, cmd: str = "commit", confirm: bool = False, confirm_response: str = ""
    +) -> str:
    +    """Saves Config"""
    +    raise NotImplementedError
    +
    +
    +
    +def session_preparation(self) +
    +
    +

    Prepare the session after the connection has been established.

    +
    +Source code +
    def session_preparation(self) -> None:
    +    """Prepare the session after the connection has been established."""
    +    self._test_channel_read(pattern=r"[>#]")
    +    self.set_base_prompt()
    +    self.disable_paging(command="paginate false")
    +
    +
    +
    +

    Inherited members

    +
      +
    • CiscoSSHConnection: + @@ -2968,144 +3176,117 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoWlcSSH(BaseConnection):
         """Netmiko Cisco WLC support."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             # WLC/AireOS has an issue where you can get "No Existing Session" with
             # the default conn_timeout (so increase conn_timeout to 10-seconds).
             kwargs.setdefault("conn_timeout", 10)
             return super().__init__(*args, **kwargs)
     
    -    def special_login_handler(self, delay_factor=1):
    +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
             """WLC presents with the following on login (in certain OS versions)
     
             login as: user
    @@ -3124,17 +3305,19 @@ 

    Inherited members

    output = self.read_channel() if output: if "login as" in output or "User:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) else: - self.write_channel(self.RETURN) + # no output read, sleep and go for one more round of read channel time.sleep(delay_factor * 1.5) i += 1 - def send_command_w_enter(self, *args, **kwargs): + def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str: """ For 'show run-config' Cisco WLC adds a 'Press Enter to continue...' message Even though pagination is disabled @@ -3148,7 +3331,7 @@

    Inherited members

    # If no delay_factor use 1 for default value delay_factor = kwargs.get("delay_factor", 1) kwargs["delay_factor"] = self.select_delay_factor(delay_factor) - output = self.send_command_timing(*args, **kwargs) + output = self._send_command_timing_str(*args, **kwargs) if "Press any key" in output or "Press Enter to" in output: new_args = list(args) @@ -3160,7 +3343,7 @@

    Inherited members

    kwargs["max_loops"] = 150 # Send an 'enter' - output = self.send_command_timing(*new_args, **kwargs) + output += self._send_command_timing_str(*new_args, **kwargs) # WLC has excessive delay after this appears on screen if "802.11b Advanced Configuration" in output: @@ -3186,13 +3369,30 @@

    Inherited members

    output = self.strip_prompt(output) return output - def session_preparation(self): + def send_command_w_yes(self, *args: Any, **kwargs: Any) -> str: + """ + For 'show interface summary' Cisco WLC adds a + 'Would you like to display the next 15 entries?' message + Even though pagination is disabled + Arguments are the same as send_command_timing() method + """ + output = self._send_command_timing_str(*args, **kwargs) + if "(y/n)" in output: + output += self._send_command_timing_str("y") + strip_prompt = kwargs.get("strip_prompt", True) + if strip_prompt: + # Had to strip trailing prompt twice. + output = self.strip_prompt(output) + output = self.strip_prompt(output) + return output + + def session_preparation(self) -> None: """ Prepare the session after the connection has been established Cisco WLC uses "config paging disable" to disable paging """ - self._test_channel_read() + self._test_channel_read(pattern=r"[>#]") try: self.set_base_prompt() @@ -3201,11 +3401,8 @@

    Inherited members

    raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - def cleanup(self, command="logout"): + def cleanup(self, command: str = "logout") -> None: """Reset WLC back to normal paging and gracefully close session.""" self.send_command_timing("config paging enable") @@ -3241,31 +3438,33 @@

    Inherited members

    break count += 1 - def check_config_mode(self, check_string="config", pattern=""): + def check_config_mode( + self, check_string: str = "config", pattern: str = "" + ) -> bool: """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) return super().check_config_mode(check_string, pattern) - def config_mode(self, config_command="config", pattern=""): + def config_mode( + self, config_command: str = "config", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter into config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) - return super().config_mode(config_command, pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=""): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: """Exit config_mode.""" - if not pattern: - pattern = re.escape(self.base_prompt) return super().exit_config_mode(exit_config, pattern) def send_config_set( self, - config_commands=None, - exit_config_mode=False, - enter_config_mode=False, - **kwargs, - ): + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + enter_config_mode: bool = False, + **kwargs: Any, + ) -> str: return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, @@ -3273,19 +3472,24 @@

    Inherited members

    **kwargs, ) - def save_config(self, cmd="save config", confirm=True, confirm_response="y"): + def save_config( + self, + cmd: str = "save config", + confirm: bool = True, + confirm_response: str = "y", + ) -> str: """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self._send_command_timing_str(command_string=cmd) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self._send_command_timing_str(confirm_response) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self._send_command_timing_str(self.RETURN) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) return output

    Ancestors

    @@ -3301,7 +3505,9 @@

    Methods

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string="config", pattern=""):
    +
    def check_config_mode(
    +    self, check_string: str = "config", pattern: str = ""
    +) -> bool:
         """Checks if the device is in configuration mode or not."""
         if not pattern:
             pattern = re.escape(self.base_prompt)
    @@ -3315,7 +3521,7 @@ 

    Methods

    Reset WLC back to normal paging and gracefully close session.

    Source code -
    def cleanup(self, command="logout"):
    +
    def cleanup(self, command: str = "logout") -> None:
         """Reset WLC back to normal paging and gracefully close session."""
         self.send_command_timing("config paging enable")
     
    @@ -3353,17 +3559,19 @@ 

    Methods

    -def config_mode(self, config_command='config', pattern='') +def config_mode(self, config_command='config', pattern='', re_flags=0)

    Enter into config_mode.

    Source code -
    def config_mode(self, config_command="config", pattern=""):
    +
    def config_mode(
    +    self, config_command: str = "config", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter into config_mode."""
    -    if not pattern:
    -        pattern = re.escape(self.base_prompt)
    -    return super().config_mode(config_command, pattern)
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    @@ -3373,10 +3581,8 @@

    Methods

    Exit config_mode.

    Source code -
    def exit_config_mode(self, exit_config="exit", pattern=""):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
         """Exit config_mode."""
    -    if not pattern:
    -        pattern = re.escape(self.base_prompt)
         return super().exit_config_mode(exit_config, pattern)
    @@ -3387,19 +3593,24 @@

    Methods

    Saves Config.

    Source code -
    def save_config(self, cmd="save config", confirm=True, confirm_response="y"):
    +
    def save_config(
    +    self,
    +    cmd: str = "save config",
    +    confirm: bool = True,
    +    confirm_response: str = "y",
    +) -> str:
         """Saves Config."""
         self.enable()
         if confirm:
    -        output = self.send_command_timing(command_string=cmd)
    +        output = self._send_command_timing_str(command_string=cmd)
             if confirm_response:
    -            output += self.send_command_timing(confirm_response)
    +            output += self._send_command_timing_str(confirm_response)
             else:
                 # Send enter by default
    -            output += self.send_command_timing(self.RETURN)
    +            output += self._send_command_timing_str(self.RETURN)
         else:
             # Some devices are slow so match on trailing-prompt if you can
    -        output = self.send_command(command_string=cmd)
    +        output = self._send_command_str(command_string=cmd)
         return output
    @@ -3414,7 +3625,7 @@

    Methods

    Arguments are the same as send_command_timing() method

    Source code -
    def send_command_w_enter(self, *args, **kwargs):
    +
    def send_command_w_enter(self, *args: Any, **kwargs: Any) -> str:
         """
         For 'show run-config' Cisco WLC adds a 'Press Enter to continue...' message
         Even though pagination is disabled
    @@ -3428,7 +3639,7 @@ 

    Methods

    # If no delay_factor use 1 for default value delay_factor = kwargs.get("delay_factor", 1) kwargs["delay_factor"] = self.select_delay_factor(delay_factor) - output = self.send_command_timing(*args, **kwargs) + output = self._send_command_timing_str(*args, **kwargs) if "Press any key" in output or "Press Enter to" in output: new_args = list(args) @@ -3440,7 +3651,7 @@

    Methods

    kwargs["max_loops"] = 150 # Send an 'enter' - output = self.send_command_timing(*new_args, **kwargs) + output += self._send_command_timing_str(*new_args, **kwargs) # WLC has excessive delay after this appears on screen if "802.11b Advanced Configuration" in output: @@ -3467,6 +3678,34 @@

    Methods

    return output
    +
    +def send_command_w_yes(self, *args, **kwargs) +
    +
    +

    For 'show interface summary' Cisco WLC adds a +'Would you like to display the next 15 entries?' message +Even though pagination is disabled +Arguments are the same as send_command_timing() method

    +
    +Source code +
    def send_command_w_yes(self, *args: Any, **kwargs: Any) -> str:
    +    """
    +    For 'show interface summary' Cisco WLC adds a
    +    'Would you like to display the next 15 entries?' message
    +    Even though pagination is disabled
    +    Arguments are the same as send_command_timing() method
    +    """
    +    output = self._send_command_timing_str(*args, **kwargs)
    +    if "(y/n)" in output:
    +        output += self._send_command_timing_str("y")
    +    strip_prompt = kwargs.get("strip_prompt", True)
    +    if strip_prompt:
    +        # Had to strip trailing prompt twice.
    +        output = self.strip_prompt(output)
    +        output = self.strip_prompt(output)
    +    return output
    +
    +
    def session_preparation(self)
    @@ -3475,13 +3714,13 @@

    Methods

    Cisco WLC uses "config paging disable" to disable paging

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established
     
         Cisco WLC uses "config paging disable" to disable paging
         """
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
     
         try:
             self.set_base_prompt()
    @@ -3489,14 +3728,11 @@ 

    Methods

    msg = f"Authentication failed: {self.host}" raise NetmikoAuthenticationException(msg) - self.disable_paging(command="config paging disable") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer()
    + self.disable_paging(command="config paging disable")
    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    WLC presents with the following on login (in certain OS versions)

    @@ -3506,7 +3742,7 @@

    Methods

    Password:****

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """WLC presents with the following on login (in certain OS versions)
     
         login as: user
    @@ -3525,13 +3761,15 @@ 

    Methods

    output = self.read_channel() if output: if "login as" in output or "User:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) else: - self.write_channel(self.RETURN) + # no output read, sleep and go for one more round of read channel time.sleep(delay_factor * 1.5) i += 1
    @@ -3543,7 +3781,6 @@

    Inherited members

    Ancestors

    @@ -3632,10 +3873,10 @@

    Ancestors

  • CiscoFileTransfer
  • BaseFileTransfer
  • -

    Methods

    +

    Static methods

    -def process_md5(self, md5_output, pattern='^([a-fA-F0-9]+)$') +def process_md5(md5_output, pattern='^([a-fA-F0-9]+)$')

    IOS-XR defaults with timestamps enabled

    @@ -3645,7 +3886,8 @@

    show md5 file /bootflash:/boot/g c84843f0030efd44b01343fdb8c2e801

    Source code -
    def process_md5(self, md5_output, pattern=r"^([a-fA-F0-9]+)$"):
    +
    @staticmethod
    +def process_md5(md5_output: str, pattern: str = r"^([a-fA-F0-9]+)$") -> str:
         """
         IOS-XR defaults with timestamps enabled
     
    @@ -3660,6 +3902,9 @@ 

    show md5 file /bootflash:/boot/g raise ValueError(f"Invalid output from MD5 command: {md5_output}")

    +
    +

    Methods

    +
    def remote_md5(self, base_cmd='show md5 file', remote_file=None)
    @@ -3668,7 +3913,9 @@

    show md5 file /bootflash:/boot/g

    show md5 file /bootflash:/boot/grub/grub.cfg

    Source code -
    def remote_md5(self, base_cmd="show md5 file", remote_file=None):
    +
    def remote_md5(
    +    self, base_cmd: str = "show md5 file", remote_file: Optional[str] = None
    +) -> str:
         """
         IOS-XR for MD5 requires this extra leading /
     
    @@ -3681,7 +3928,7 @@ 

    show md5 file /bootflash:/boot/g remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here remote_md5_cmd = f"{base_cmd} /{self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5

    @@ -3712,7 +3959,7 @@

    Inherited members

    class CiscoXrSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco XR SSH driver.

    @@ -3720,131 +3967,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:

    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -3867,9 +4087,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -3880,9 +4099,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -3894,6 +4113,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -3910,7 +4130,7 @@

    Inherited members

    class CiscoXrTelnet -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Cisco XR Telnet driver.

    @@ -3918,131 +4138,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -4065,9 +4258,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -4078,9 +4270,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -4092,6 +4284,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -4108,7 +4301,7 @@

    Inherited members

    class InLineTransfer -(ssh_conn, source_file=None, dest_file=None, file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None) +(ssh_conn, source_file='', dest_file='', file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None, hash_supported=True)

    Use TCL on Cisco IOS to directly transfer file.

    @@ -4119,16 +4312,24 @@

    Inherited members

    def __init__( self, - ssh_conn, - source_file=None, - dest_file=None, - file_system=None, - direction="put", - source_config=None, - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str = "", + dest_file: str = "", + file_system: Optional[str] = None, + direction: str = "put", + source_config: Optional[str] = None, + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: + + if not dest_file: + raise ValueError( + "Destination file must be specified for InlineTransfer operations." + ) + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for InLineTransfer") if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -4145,13 +4346,12 @@

    Inherited members

    self.progress4 = progress4 self.ssh_ctl_chan = ssh_conn + self.source_file = source_file if source_file: - self.source_file = source_file self.source_config = None self.source_md5 = self.file_md5(source_file) self.file_size = os.stat(source_file).st_size elif source_config: - self.source_file = None self.source_config = source_config self.source_md5 = self.config_md5(source_config) self.file_size = len(source_config.encode("UTF-8")) @@ -4166,12 +4366,12 @@

    Inherited members

    self.socket_timeout = socket_timeout @staticmethod - def _read_file(file_name): + def _read_file(file_name: str) -> str: with io.open(file_name, "rt", encoding="utf-8") as f: return f.read() @staticmethod - def _tcl_newline_rationalize(tcl_string): + def _tcl_newline_rationalize(tcl_string: str) -> str: r""" When using put inside a TCL {} section the newline is considered a new TCL statement and causes a missing curly-brace message. Convert "\n" to "\r". TCL @@ -4186,17 +4386,22 @@

    Inherited members

    raise ValueError(msg) return tmp_string - def __enter__(self): + def __enter__(self) -> "InLineTransfer": self._enter_tcl_mode() return self - def __exit__(self, exc_type, exc_value, traceback): - _ = self._exit_tcl_mode() # noqa + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: + self._exit_tcl_mode() - def _enter_tcl_mode(self): + def _enter_tcl_mode(self) -> str: TCL_ENTER = "tclsh" cmd_failed = ['Translating "tclsh"', "% Unknown command", "% Bad IP address"] - output = self.ssh_ctl_chan.send_command( + output = self.ssh_ctl_chan._send_command_str( TCL_ENTER, expect_string=r"\(tcl\)#", strip_prompt=False, @@ -4207,7 +4412,7 @@

    Inherited members

    raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output - def _exit_tcl_mode(self): + def _exit_tcl_mode(self) -> str: TCL_EXIT = "tclquit" self.ssh_ctl_chan.write_channel("\r") time.sleep(1) @@ -4218,29 +4423,33 @@

    Inherited members

    output += self.ssh_ctl_chan.read_channel() return output - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: raise NotImplementedError - def close_scp_chan(self): + def close_scp_chan(self) -> None: raise NotImplementedError - def local_space_available(self): + def local_space_available(self) -> bool: raise NotImplementedError - def file_md5(self, file_name): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file.""" + if add_newline is True: + raise ValueError( + "add_newline argument is not supported for inline transfers." + ) file_contents = self._read_file(file_name) file_contents = file_contents + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def config_md5(self, source_config): + def config_md5(self, source_config: str) -> str: """Compute MD5 hash of text.""" file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def put_file(self): + def put_file(self) -> None: curlybrace = r"{" TCL_FILECMD_ENTER = 'puts [open "{}{}" w+] {}'.format( self.file_system, self.dest_file, curlybrace @@ -4262,21 +4471,21 @@

    Inherited members

    self.ssh_ctl_chan.write_channel(TCL_FILECMD_EXIT + "\r") # This operation can be slow (depends on the size of the file) - max_loops = 400 + read_timeout = 100 sleep_time = 4 if self.file_size >= 2500: - max_loops = 1500 + read_timeout = 300 sleep_time = 12 elif self.file_size >= 7500: - max_loops = 3000 + read_timeout = 600 sleep_time = 25 # Initial delay time.sleep(sleep_time) # File paste and TCL_FILECMD_exit should be indicated by "router(tcl)#" - output = self.ssh_ctl_chan._read_channel_expect( - pattern=r"\(tcl\)", max_loops=max_loops + output = self.ssh_ctl_chan.read_until_pattern( + pattern=r"\(tcl\).*$", re_flags=re.M, read_timeout=read_timeout ) # The file doesn't write until tclquit @@ -4285,16 +4494,20 @@

    Inherited members

    time.sleep(1) # Read all data remaining from the TCLSH session - output += self.ssh_ctl_chan._read_channel_expect(max_loops=max_loops) - return output + pattern = rf"tclquit.*{self.ssh_ctl_chan.base_prompt}.*$" + re_flags = re.DOTALL | re.M + output += self.ssh_ctl_chan.read_until_pattern( + pattern=pattern, re_flags=re_flags, read_timeout=read_timeout + ) + return None - def get_file(self): + def get_file(self) -> None: raise NotImplementedError - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -4312,26 +4525,30 @@

    Methods

    Compute MD5 hash of text.

    Source code -
    def config_md5(self, source_config):
    +
    def config_md5(self, source_config: str) -> str:
         """Compute MD5 hash of text."""
         file_contents = source_config + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    -def file_md5(self, file_name) +def file_md5(self, file_name, add_newline=False)

    Compute MD5 hash of file.

    Source code -
    def file_md5(self, file_name):
    +
    def file_md5(self, file_name: str, add_newline: bool = False) -> str:
         """Compute MD5 hash of file."""
    +    if add_newline is True:
    +        raise ValueError(
    +            "add_newline argument is not supported for inline transfers."
    +        )
         file_contents = self._read_file(file_name)
         file_contents = file_contents + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    @@ -4381,6 +4598,7 @@

    Index

  • netmiko.cisco.cisco_nxos_ssh
  • netmiko.cisco.cisco_s300
  • netmiko.cisco.cisco_tp_tcce
  • +
  • netmiko.cisco.cisco_viptela
  • netmiko.cisco.cisco_wlc_ssh
  • netmiko.cisco.cisco_xr
  • @@ -4397,7 +4615,6 @@

    normalize_linefeeds
  • save_config
  • send_command
  • -
  • send_command_expect
  • send_command_timing
  • session_preparation
  • set_base_prompt
  • @@ -4407,8 +4624,6 @@

    CiscoFtdSSH

    @@ -4448,9 +4663,9 @@

    CiscoS300SSH

    - + +
  • +

    CiscoS300Telnet

  • CiscoTpTcCeSSH

    @@ -4465,6 +4680,15 @@

    CiscoViptelaSSH

    + +
  • +
  • CiscoWlcSSH

    diff --git a/docs/netmiko/cisco_base_connection.html b/docs/netmiko/cisco_base_connection.html index f4734a5ef..c16efae55 100644 --- a/docs/netmiko/cisco_base_connection.html +++ b/docs/netmiko/cisco_base_connection.html @@ -24,37 +24,38 @@

    Module netmiko.cisco_base_connection

    Source code
    """CiscoBaseConnection is netmiko SSH class for Cisco and Cisco-like platforms."""
    -from netmiko.base_connection import BaseConnection
    -from netmiko.scp_handler import BaseFileTransfer
    -from netmiko.ssh_exception import NetmikoAuthenticationException
    +from typing import Optional
     import re
     import time
    +from netmiko.base_connection import BaseConnection
    +from netmiko.scp_handler import BaseFileTransfer
    +from netmiko.exceptions import NetmikoAuthenticationException
     
     
     class CiscoBaseConnection(BaseConnection):
         """Base Class for cisco-like behavior."""
     
    -    def check_enable_mode(self, check_string="#"):
    +    def check_enable_mode(self, check_string: str = "#") -> bool:
             """Check if in enable mode. Return boolean."""
             return super().check_enable_mode(check_string=check_string)
     
         def enable(
             self,
    -        cmd="enable",
    -        pattern="ssword",
    -        enable_pattern=None,
    -        re_flags=re.IGNORECASE,
    -    ):
    +        cmd: str = "enable",
    +        pattern: str = "ssword",
    +        enable_pattern: Optional[str] = None,
    +        re_flags: int = re.IGNORECASE,
    +    ) -> str:
             """Enter enable mode."""
             return super().enable(
                 cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
             )
     
    -    def exit_enable_mode(self, exit_command="disable"):
    +    def exit_enable_mode(self, exit_command: str = "disable") -> str:
             """Exits enable (privileged exec) mode."""
             return super().exit_enable_mode(exit_command=exit_command)
     
    -    def check_config_mode(self, check_string=")#", pattern=""):
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
             """
             Checks if the device is in configuration mode or not.
     
    @@ -62,31 +63,29 @@ 

    Module netmiko.cisco_base_connection

    """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure terminal", pattern="", re_flags=0): - """ - Enter into configuration mode on remote device. - - Cisco IOS devices abbreviate the prompt at 20 chars in config mode - """ - if not pattern: - pattern = re.escape(self.base_prompt[:16]) + def config_mode( + self, + config_command: str = "configure terminal", + pattern: str = "", + re_flags: int = 0, + ) -> str: return super().config_mode( config_command=config_command, pattern=pattern, re_flags=re_flags ) - def exit_config_mode(self, exit_config="end", pattern=r"\#"): + def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#.*") -> str: """Exit from configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, - pri_prompt_terminator=r"\#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"\#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: self.write_channel(self.TELNET_RETURN) output = self.read_channel() if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -105,17 +104,16 @@

    Module netmiko.cisco_base_connection

    def telnet_login( self, - pri_prompt_terminator=r"\#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login|user name)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"\#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login|user name)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """Telnet login. Can be username/password or just password.""" delay_factor = self.select_delay_factor(delay_factor) - # FIX: Cleanup in future versions of Netmiko if delay_factor < 1: if not self._legacy_mode and self.fast_cli: delay_factor = 1 @@ -144,6 +142,7 @@

    Module netmiko.cisco_base_connection

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -171,9 +170,12 @@

    Module netmiko.cisco_base_connection

    # Check for device with no password configured if re.search(r"assword required, but none set", output): + assert self.remote_conn is not None self.remote_conn.close() - msg = "Login failed - Password required, but none set: {}".format( - self.host + msg = ( + "Login failed - Password required, but none set: {}".format( + self.host + ) ) raise NetmikoAuthenticationException(msg) @@ -186,6 +188,7 @@

    Module netmiko.cisco_base_connection

    i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -205,11 +208,12 @@

    Module netmiko.cisco_base_connection

    ): return return_msg + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -218,20 +222,23 @@

    Module netmiko.cisco_base_connection

    except Exception: pass # Always try to send final 'exit' (command) - self._session_log_fin = True + if self.session_log: + self.session_log.fin = True self.write_channel(command + self.RETURN) - def _autodetect_fs(self, cmd="dir", pattern=r"Directory of (.*)/"): + def _autodetect_fs( + self, cmd: str = "dir", pattern: str = r"Directory of (.*)/" + ) -> str: """Autodetect the file system on the remote device. Used by SCP operations.""" if not self.check_enable_mode(): raise ValueError("Must be in enable mode to auto-detect the file-system.") - output = self.send_command_expect(cmd) + output = self._send_command_str(cmd) match = re.search(pattern, output) if match: file_system = match.group(1) # Test file_system cmd = f"dir {file_system}" - output = self.send_command_expect(cmd) + output = self._send_command_str(cmd) if "% Invalid" in output or "%Error:" in output: raise ValueError( "An error occurred in dynamically determining remote file " @@ -247,28 +254,28 @@

    Module netmiko.cisco_base_connection

    def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing( + output = self._send_command_timing_str( command_string=cmd, strip_prompt=False, strip_command=False ) if confirm_response: - output += self.send_command_timing( + output += self._send_command_timing_str( confirm_response, strip_prompt=False, strip_command=False ) else: # Send enter by default - output += self.send_command_timing( + output += self._send_command_timing_str( self.RETURN, strip_prompt=False, strip_command=False ) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command( + output = self._send_command_str( command_string=cmd, strip_prompt=False, strip_command=False ) return output @@ -293,7 +300,7 @@

    Classes

    class CiscoBaseConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -301,158 +308,131 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class CiscoBaseConnection(BaseConnection):
         """Base Class for cisco-like behavior."""
     
    -    def check_enable_mode(self, check_string="#"):
    +    def check_enable_mode(self, check_string: str = "#") -> bool:
             """Check if in enable mode. Return boolean."""
             return super().check_enable_mode(check_string=check_string)
     
         def enable(
             self,
    -        cmd="enable",
    -        pattern="ssword",
    -        enable_pattern=None,
    -        re_flags=re.IGNORECASE,
    -    ):
    +        cmd: str = "enable",
    +        pattern: str = "ssword",
    +        enable_pattern: Optional[str] = None,
    +        re_flags: int = re.IGNORECASE,
    +    ) -> str:
             """Enter enable mode."""
             return super().enable(
                 cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
             )
     
    -    def exit_enable_mode(self, exit_command="disable"):
    +    def exit_enable_mode(self, exit_command: str = "disable") -> str:
             """Exits enable (privileged exec) mode."""
             return super().exit_enable_mode(exit_command=exit_command)
     
    -    def check_config_mode(self, check_string=")#", pattern=""):
    +    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
             """
             Checks if the device is in configuration mode or not.
     
    @@ -460,31 +440,29 @@ 

    Classes

    """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure terminal", pattern="", re_flags=0): - """ - Enter into configuration mode on remote device. - - Cisco IOS devices abbreviate the prompt at 20 chars in config mode - """ - if not pattern: - pattern = re.escape(self.base_prompt[:16]) + def config_mode( + self, + config_command: str = "configure terminal", + pattern: str = "", + re_flags: int = 0, + ) -> str: return super().config_mode( config_command=config_command, pattern=pattern, re_flags=re_flags ) - def exit_config_mode(self, exit_config="end", pattern=r"\#"): + def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#.*") -> str: """Exit from configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, - pri_prompt_terminator=r"\#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"\#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: self.write_channel(self.TELNET_RETURN) output = self.read_channel() if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -503,17 +481,16 @@

    Classes

    def telnet_login( self, - pri_prompt_terminator=r"\#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(?:user:|username|login|user name)", - pwd_pattern=r"assword", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"\#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(?:user:|username|login|user name)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """Telnet login. Can be username/password or just password.""" delay_factor = self.select_delay_factor(delay_factor) - # FIX: Cleanup in future versions of Netmiko if delay_factor < 1: if not self._legacy_mode and self.fast_cli: delay_factor = 1 @@ -542,6 +519,7 @@

    Classes

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -569,9 +547,12 @@

    Classes

    # Check for device with no password configured if re.search(r"assword required, but none set", output): + assert self.remote_conn is not None self.remote_conn.close() - msg = "Login failed - Password required, but none set: {}".format( - self.host + msg = ( + "Login failed - Password required, but none set: {}".format( + self.host + ) ) raise NetmikoAuthenticationException(msg) @@ -584,6 +565,7 @@

    Classes

    i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -603,11 +585,12 @@

    Classes

    ): return return_msg + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -616,20 +599,23 @@

    Classes

    except Exception: pass # Always try to send final 'exit' (command) - self._session_log_fin = True + if self.session_log: + self.session_log.fin = True self.write_channel(command + self.RETURN) - def _autodetect_fs(self, cmd="dir", pattern=r"Directory of (.*)/"): + def _autodetect_fs( + self, cmd: str = "dir", pattern: str = r"Directory of (.*)/" + ) -> str: """Autodetect the file system on the remote device. Used by SCP operations.""" if not self.check_enable_mode(): raise ValueError("Must be in enable mode to auto-detect the file-system.") - output = self.send_command_expect(cmd) + output = self._send_command_str(cmd) match = re.search(pattern, output) if match: file_system = match.group(1) # Test file_system cmd = f"dir {file_system}" - output = self.send_command_expect(cmd) + output = self._send_command_str(cmd) if "% Invalid" in output or "%Error:" in output: raise ValueError( "An error occurred in dynamically determining remote file " @@ -645,28 +631,28 @@

    Classes

    def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing( + output = self._send_command_timing_str( command_string=cmd, strip_prompt=False, strip_command=False ) if confirm_response: - output += self.send_command_timing( + output += self._send_command_timing_str( confirm_response, strip_prompt=False, strip_command=False ) else: # Send enter by default - output += self.send_command_timing( + output += self._send_command_timing_str( self.RETURN, strip_prompt=False, strip_command=False ) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command( + output = self._send_command_str( command_string=cmd, strip_prompt=False, strip_command=False ) return output
    @@ -705,7 +691,7 @@

    Methods

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode

    Source code -
    def check_config_mode(self, check_string=")#", pattern=""):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
         """
         Checks if the device is in configuration mode or not.
     
    @@ -721,7 +707,7 @@ 

    Methods

    Check if in enable mode. Return boolean.

    Source code -
    def check_enable_mode(self, check_string="#"):
    +
    def check_enable_mode(self, check_string: str = "#") -> bool:
         """Check if in enable mode. Return boolean."""
         return super().check_enable_mode(check_string=check_string)
    @@ -733,7 +719,7 @@

    Methods

    Gracefully exit the SSH session.

    Source code -
    def cleanup(self, command="exit"):
    +
    def cleanup(self, command: str = "exit") -> None:
         """Gracefully exit the SSH session."""
         try:
             # The pattern="" forces use of send_command_timing
    @@ -742,31 +728,11 @@ 

    Methods

    except Exception: pass # Always try to send final 'exit' (command) - self._session_log_fin = True + if self.session_log: + self.session_log.fin = True self.write_channel(command + self.RETURN)
    -
    -def config_mode(self, config_command='configure terminal', pattern='', re_flags=0) -
    -
    -

    Enter into configuration mode on remote device.

    -

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode

    -
    -Source code -
    def config_mode(self, config_command="configure terminal", pattern="", re_flags=0):
    -    """
    -    Enter into configuration mode on remote device.
    -
    -    Cisco IOS devices abbreviate the prompt at 20 chars in config mode
    -    """
    -    if not pattern:
    -        pattern = re.escape(self.base_prompt[:16])
    -    return super().config_mode(
    -        config_command=config_command, pattern=pattern, re_flags=re_flags
    -    )
    -
    -
    def enable(self, cmd='enable', pattern='ssword', enable_pattern=None, re_flags=)
    @@ -776,11 +742,11 @@

    Methods

    Source code
    def enable(
         self,
    -    cmd="enable",
    -    pattern="ssword",
    -    enable_pattern=None,
    -    re_flags=re.IGNORECASE,
    -):
    +    cmd: str = "enable",
    +    pattern: str = "ssword",
    +    enable_pattern: Optional[str] = None,
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
         """Enter enable mode."""
         return super().enable(
             cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
    @@ -788,13 +754,13 @@ 

    Methods

    -def exit_config_mode(self, exit_config='end', pattern='\\#') +def exit_config_mode(self, exit_config='end', pattern='#.*')

    Exit from configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="end", pattern=r"\#"):
    +
    def exit_config_mode(self, exit_config: str = "end", pattern: str = r"#.*") -> str:
         """Exit from configuration mode."""
         return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
    @@ -806,7 +772,7 @@

    Methods

    Exits enable (privileged exec) mode.

    Source code -
    def exit_enable_mode(self, exit_command="disable"):
    +
    def exit_enable_mode(self, exit_command: str = "disable") -> str:
         """Exits enable (privileged exec) mode."""
         return super().exit_enable_mode(exit_command=exit_command)
    @@ -820,35 +786,35 @@

    Methods

    Source code
    def save_config(
         self,
    -    cmd="copy running-config startup-config",
    -    confirm=False,
    -    confirm_response="",
    -):
    +    cmd: str = "copy running-config startup-config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config."""
         self.enable()
         if confirm:
    -        output = self.send_command_timing(
    +        output = self._send_command_timing_str(
                 command_string=cmd, strip_prompt=False, strip_command=False
             )
             if confirm_response:
    -            output += self.send_command_timing(
    +            output += self._send_command_timing_str(
                     confirm_response, strip_prompt=False, strip_command=False
                 )
             else:
                 # Send enter by default
    -            output += self.send_command_timing(
    +            output += self._send_command_timing_str(
                     self.RETURN, strip_prompt=False, strip_command=False
                 )
         else:
             # Some devices are slow so match on trailing-prompt if you can
    -        output = self.send_command(
    +        output = self._send_command_str(
                 command_string=cmd, strip_prompt=False, strip_command=False
             )
         return output
    -def serial_login(self, pri_prompt_terminator='\\#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login)', pwd_pattern='assword', delay_factor=1, max_loops=20) +def serial_login(self, pri_prompt_terminator='\\#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)
    @@ -856,13 +822,13 @@

    Methods

    Source code
    def serial_login(
         self,
    -    pri_prompt_terminator=r"\#\s*$",
    -    alt_prompt_terminator=r">\s*$",
    -    username_pattern=r"(?:user:|username|login)",
    -    pwd_pattern=r"assword",
    -    delay_factor=1,
    -    max_loops=20,
    -):
    +    pri_prompt_terminator: str = r"\#\s*$",
    +    alt_prompt_terminator: str = r">\s*$",
    +    username_pattern: str = r"(?:user:|username|login)",
    +    pwd_pattern: str = r"assword",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 20,
    +) -> str:
         self.write_channel(self.TELNET_RETURN)
         output = self.read_channel()
         if re.search(pri_prompt_terminator, output, flags=re.M) or re.search(
    @@ -881,7 +847,7 @@ 

    Methods

    -def telnet_login(self, pri_prompt_terminator='\\#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login|user name)', pwd_pattern='assword', delay_factor=1, max_loops=20) +def telnet_login(self, pri_prompt_terminator='\\#\\s*$', alt_prompt_terminator='>\\s*$', username_pattern='(?:user:|username|login|user name)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)

    Telnet login. Can be username/password or just password.

    @@ -889,17 +855,16 @@

    Methods

    Source code
    def telnet_login(
         self,
    -    pri_prompt_terminator=r"\#\s*$",
    -    alt_prompt_terminator=r">\s*$",
    -    username_pattern=r"(?:user:|username|login|user name)",
    -    pwd_pattern=r"assword",
    -    delay_factor=1,
    -    max_loops=20,
    -):
    +    pri_prompt_terminator: str = r"\#\s*$",
    +    alt_prompt_terminator: str = r">\s*$",
    +    username_pattern: str = r"(?:user:|username|login|user name)",
    +    pwd_pattern: str = r"assword",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 20,
    +) -> str:
         """Telnet login. Can be username/password or just password."""
         delay_factor = self.select_delay_factor(delay_factor)
     
    -    # FIX: Cleanup in future versions of Netmiko
         if delay_factor < 1:
             if not self._legacy_mode and self.fast_cli:
                 delay_factor = 1
    @@ -928,6 +893,7 @@ 

    Methods

    # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): # Sometimes username/password must be terminated with "\r" and not "\r\n" + assert isinstance(self.password, str) self.write_channel(self.password + "\r") time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -955,9 +921,12 @@

    Methods

    # Check for device with no password configured if re.search(r"assword required, but none set", output): + assert self.remote_conn is not None self.remote_conn.close() - msg = "Login failed - Password required, but none set: {}".format( - self.host + msg = ( + "Login failed - Password required, but none set: {}".format( + self.host + ) ) raise NetmikoAuthenticationException(msg) @@ -970,6 +939,7 @@

    Methods

    i += 1 except EOFError: + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg) @@ -989,6 +959,7 @@

    Methods

    ): return return_msg + assert self.remote_conn is not None self.remote_conn.close() msg = f"Login failed: {self.host}" raise NetmikoAuthenticationException(msg)
    @@ -1000,8 +971,8 @@

    Inherited members

  • BaseConnection:
  • class CiscoSSHConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -1094,131 +1066,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
  • -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1244,12 +1189,14 @@

    Subclasses

  • CiscoAsaSSH
  • CiscoFtdSSH
  • CiscoNxosSSH
  • -
  • CiscoS300SSH
  • +
  • CiscoS300Base
  • CiscoTpTcCeSSH
  • +
  • CiscoViptelaSSH
  • CloudGenixIonSSH
  • CoriantSSH
  • DellForce10SSH
  • DellOS10SSH
  • +
  • DellSonicSSH
  • DlinkDSBase
  • EltexSSH
  • EltexEsrSSH
  • @@ -1260,6 +1207,7 @@

    Subclasses

  • ExtremeNetironBase
  • ExtremeNosSSH
  • ExtremeSlxSSH
  • +
  • ExtremeTierraSSH
  • ExtremeVspSSH
  • ExtremeWingSSH
  • LinuxSSH
  • @@ -1277,6 +1225,7 @@

    Subclasses

  • TPLinkJetStreamBase
  • UbiquitiEdgeSSH
  • VyOSSSH
  • +
  • ZyxelSSH
  • Inherited members

      @@ -1286,9 +1235,8 @@

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • -
    • config_mode
    • +
    • config_mode
    • disable_paging
    • disconnect
    • enable
    • @@ -1299,9 +1247,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -1313,6 +1261,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -1349,7 +1298,6 @@

      check_config_mode
    • check_enable_mode
    • cleanup
    • -
    • config_mode
    • enable
    • exit_config_mode
    • exit_enable_mode
    • diff --git a/docs/netmiko/citrix/index.html b/docs/netmiko/citrix/index.html index a0db84726..c2cbea3b2 100644 --- a/docs/netmiko/citrix/index.html +++ b/docs/netmiko/citrix/index.html @@ -45,191 +45,150 @@

      Classes

      class NetscalerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
      -

      Netscaler SSH class.

      +

      Netscaler SSH class.

          Initialize attributes for establishing connection to target device.
       
           :param ip: IP address of target device. Not required if `host` is
               provided.
      -    :type ip: str
       
           :param host: Hostname of target device. Not required if `ip` is
                   provided.
      -    :type host: str
       
           :param username: Username to authenticate against target device if
                   required.
      -    :type username: str
       
           :param password: Password to authenticate against target device if
                   required.
      -    :type password: str
       
           :param secret: The enable password if target device requires one.
      -    :type secret: str
       
           :param port: The destination port used to connect to the target
                   device.
      -    :type port: int or None
       
           :param device_type: Class selection based on device type.
      -    :type device_type: str
       
           :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
       
           :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
       
           :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
       
           :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
       
           :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
       
           :param passphrase: Passphrase to use for encrypted key; password will be used for key
                   decryption if not specified.
      -    :type passphrase: str
      +
      +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
      +            documentation for a description of the expected format.
       
           :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
       
           :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                   means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
       
           :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      +
           :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                   alt_key_file.
      -    :type alt_host_keys: bool
       
           :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
       
           :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
       
           :param timeout: Connection timeout.
      -    :type timeout: float
       
           :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
       
           :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
       
           :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
       
           :param 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).
      -    :type keepalive: int
       
           :param default_enter: Character(s) to send to correspond to enter key (default:
       
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code -
      class NetscalerSSH(BaseConnection):
      -    """ Netscaler SSH class. """
      +
      class NetscalerSSH(NoConfig, BaseConnection):
      +    """Netscaler SSH class."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
      -        # 0 will defer to the global delay factor
      -        delay_factor = self.select_delay_factor(delay_factor=0)
      -        self._test_channel_read()
      +        self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
               cmd = f"{self.RETURN}set cli mode -page OFF{self.RETURN}"
               self.disable_paging(command=cmd)
      -        time.sleep(1 * delay_factor)
               self.set_base_prompt()
      -        time.sleep(0.3 * delay_factor)
      -        self.clear_buffer()
       
           def set_base_prompt(
      -        self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1
      -    ):
      +        self,
      +        pri_prompt_terminator: str = ">",
      +        alt_prompt_terminator: str = "#",
      +        delay_factor: float = 1.0,
      +        pattern: Optional[str] = None,
      +    ) -> str:
               """Sets self.base_prompt.
       
      -        Netscaler has '>' for the prompt.
      +        Netscaler has only '>' for the prompt.
               """
      -        prompt = self.find_prompt(delay_factor=delay_factor)
      -        if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator):
      -            raise ValueError(f"Router prompt not found: {repr(prompt)}")
      -
      -        prompt = prompt.strip()
      -        if len(prompt) == 1:
      -            self.base_prompt = prompt
      -        else:
      -            # Strip off trailing terminator
      -            self.base_prompt = prompt[:-1]
      +        base_prompt = super().set_base_prompt(
      +            pri_prompt_terminator=pri_prompt_terminator,
      +            alt_prompt_terminator=alt_prompt_terminator,
      +            delay_factor=delay_factor,
      +            pattern=pattern,
      +        )
      +        # If null-string, set base_prompt to just ">"
      +        if not base_prompt:
      +            self.base_prompt = pri_prompt_terminator
               return self.base_prompt
       
      -    def check_config_mode(self):
      -        """Netscaler devices do not have a config mode."""
      -        return False
      -
      -    def config_mode(self):
      -        """Netscaler devices do not have a config mode."""
      -        return ""
      -
      -    def exit_config_mode(self):
      -        """Netscaler devices do not have a config mode."""
      -        return ""
      -
      -    def strip_prompt(self, a_string):
      -        """ Strip 'Done' from command output """
      +    def strip_prompt(self, a_string: str) -> str:
      +        """Strip 'Done' from command output"""
               output = super().strip_prompt(a_string)
               lines = output.split(self.RESPONSE_RETURN)
               if "Done" in lines[-1]:
      @@ -239,46 +198,11 @@ 

      Classes

      Ancestors

      Methods

      -
      -def check_config_mode(self) -
      -
      -

      Netscaler devices do not have a config mode.

      -
      -Source code -
      def check_config_mode(self):
      -    """Netscaler devices do not have a config mode."""
      -    return False
      -
      -
      -
      -def config_mode(self) -
      -
      -

      Netscaler devices do not have a config mode.

      -
      -Source code -
      def config_mode(self):
      -    """Netscaler devices do not have a config mode."""
      -    return ""
      -
      -
      -
      -def exit_config_mode(self) -
      -
      -

      Netscaler devices do not have a config mode.

      -
      -Source code -
      def exit_config_mode(self):
      -    """Netscaler devices do not have a config mode."""
      -    return ""
      -
      -
      def session_preparation(self)
      @@ -286,45 +210,43 @@

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
      -    # 0 will defer to the global delay factor
      -    delay_factor = self.select_delay_factor(delay_factor=0)
      -    self._test_channel_read()
      +    self._test_channel_read(pattern=r"[>#]")
           self.set_base_prompt()
           cmd = f"{self.RETURN}set cli mode -page OFF{self.RETURN}"
           self.disable_paging(command=cmd)
      -    time.sleep(1 * delay_factor)
      -    self.set_base_prompt()
      -    time.sleep(0.3 * delay_factor)
      -    self.clear_buffer()
      + self.set_base_prompt()
      -def set_base_prompt(self, pri_prompt_terminator='#', alt_prompt_terminator='>', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

      Sets self.base_prompt.

      -

      Netscaler has '>' for the prompt.

      +

      Netscaler has only '>' for the prompt.

      Source code
      def set_base_prompt(
      -    self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1
      -):
      +    self,
      +    pri_prompt_terminator: str = ">",
      +    alt_prompt_terminator: str = "#",
      +    delay_factor: float = 1.0,
      +    pattern: Optional[str] = None,
      +) -> str:
           """Sets self.base_prompt.
       
      -    Netscaler has '>' for the prompt.
      +    Netscaler has only '>' for the prompt.
           """
      -    prompt = self.find_prompt(delay_factor=delay_factor)
      -    if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator):
      -        raise ValueError(f"Router prompt not found: {repr(prompt)}")
      -
      -    prompt = prompt.strip()
      -    if len(prompt) == 1:
      -        self.base_prompt = prompt
      -    else:
      -        # Strip off trailing terminator
      -        self.base_prompt = prompt[:-1]
      +    base_prompt = super().set_base_prompt(
      +        pri_prompt_terminator=pri_prompt_terminator,
      +        alt_prompt_terminator=alt_prompt_terminator,
      +        delay_factor=delay_factor,
      +        pattern=pattern,
      +    )
      +    # If null-string, set base_prompt to just ">"
      +    if not base_prompt:
      +        self.base_prompt = pri_prompt_terminator
           return self.base_prompt
      @@ -335,8 +257,8 @@

      Methods

      Strip 'Done' from command output

      Source code -
      def strip_prompt(self, a_string):
      -    """ Strip 'Done' from command output """
      +
      def strip_prompt(self, a_string: str) -> str:
      +    """Strip 'Done' from command output"""
           output = super().strip_prompt(a_string)
           lines = output.split(self.RESPONSE_RETURN)
           if "Done" in lines[-1]:
      @@ -350,23 +272,25 @@ 

      Inherited members

      • BaseConnection:
          +
        • check_config_mode
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • commit
        • +
        • config_mode
        • disable_paging
        • disconnect
        • enable
        • establish_connection
        • +
        • exit_config_mode
        • exit_enable_mode
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -378,6 +302,7 @@

          Inherited members

        • send_command_timing
        • send_config_from_file
        • send_config_set
        • +
        • send_multiline
        • set_terminal_width
        • special_login_handler
        • strip_ansi_escape_codes
        • @@ -412,10 +337,7 @@

          Index

          • NetscalerSSH

            -
              -
            • check_config_mode
            • -
            • config_mode
            • -
            • exit_config_mode
            • +
              • session_preparation
              • set_base_prompt
              • strip_prompt
              • diff --git a/docs/netmiko/citrix/netscaler_ssh.html b/docs/netmiko/citrix/netscaler_ssh.html index 532d9100b..9560e20ee 100644 --- a/docs/netmiko/citrix/netscaler_ssh.html +++ b/docs/netmiko/citrix/netscaler_ssh.html @@ -22,60 +22,46 @@

                Module netmiko.citrix.netscaler_ssh

                Source code -
                import time
                -
                +
                from typing import Optional
                +from netmiko.no_config import NoConfig
                 from netmiko.base_connection import BaseConnection
                 
                 
                -class NetscalerSSH(BaseConnection):
                -    """ Netscaler SSH class. """
                +class NetscalerSSH(NoConfig, BaseConnection):
                +    """Netscaler SSH class."""
                 
                -    def session_preparation(self):
                +    def session_preparation(self) -> None:
                         """Prepare the session after the connection has been established."""
                -        # 0 will defer to the global delay factor
                -        delay_factor = self.select_delay_factor(delay_factor=0)
                -        self._test_channel_read()
                +        self._test_channel_read(pattern=r"[>#]")
                         self.set_base_prompt()
                         cmd = f"{self.RETURN}set cli mode -page OFF{self.RETURN}"
                         self.disable_paging(command=cmd)
                -        time.sleep(1 * delay_factor)
                         self.set_base_prompt()
                -        time.sleep(0.3 * delay_factor)
                -        self.clear_buffer()
                 
                     def set_base_prompt(
                -        self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1
                -    ):
                +        self,
                +        pri_prompt_terminator: str = ">",
                +        alt_prompt_terminator: str = "#",
                +        delay_factor: float = 1.0,
                +        pattern: Optional[str] = None,
                +    ) -> str:
                         """Sets self.base_prompt.
                 
                -        Netscaler has '>' for the prompt.
                +        Netscaler has only '>' for the prompt.
                         """
                -        prompt = self.find_prompt(delay_factor=delay_factor)
                -        if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator):
                -            raise ValueError(f"Router prompt not found: {repr(prompt)}")
                -
                -        prompt = prompt.strip()
                -        if len(prompt) == 1:
                -            self.base_prompt = prompt
                -        else:
                -            # Strip off trailing terminator
                -            self.base_prompt = prompt[:-1]
                +        base_prompt = super().set_base_prompt(
                +            pri_prompt_terminator=pri_prompt_terminator,
                +            alt_prompt_terminator=alt_prompt_terminator,
                +            delay_factor=delay_factor,
                +            pattern=pattern,
                +        )
                +        # If null-string, set base_prompt to just ">"
                +        if not base_prompt:
                +            self.base_prompt = pri_prompt_terminator
                         return self.base_prompt
                 
                -    def check_config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return False
                -
                -    def config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return ""
                -
                -    def exit_config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return ""
                -
                -    def strip_prompt(self, a_string):
                -        """ Strip 'Done' from command output """
                +    def strip_prompt(self, a_string: str) -> str:
                +        """Strip 'Done' from command output"""
                         output = super().strip_prompt(a_string)
                         lines = output.split(self.RESPONSE_RETURN)
                         if "Done" in lines[-1]:
                @@ -95,191 +81,150 @@ 

                Classes

                class NetscalerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
                -

                Netscaler SSH class.

                +

                Netscaler SSH class.

                    Initialize attributes for establishing connection to target device.
                 
                     :param ip: IP address of target device. Not required if `host` is
                         provided.
                -    :type ip: str
                 
                     :param host: Hostname of target device. Not required if `ip` is
                             provided.
                -    :type host: str
                 
                     :param username: Username to authenticate against target device if
                             required.
                -    :type username: str
                 
                     :param password: Password to authenticate against target device if
                             required.
                -    :type password: str
                 
                     :param secret: The enable password if target device requires one.
                -    :type secret: str
                 
                     :param port: The destination port used to connect to the target
                             device.
                -    :type port: int or None
                 
                     :param device_type: Class selection based on device type.
                -    :type device_type: str
                 
                     :param verbose: Enable additional messages to standard output.
                -    :type verbose: bool
                 
                     :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                -    :type global_delay_factor: int
                 
                     :param use_keys: Connect to target device using SSH keys.
                -    :type use_keys: bool
                 
                     :param key_file: Filename path of the SSH key file to use.
                -    :type key_file: str
                 
                     :param pkey: SSH key object to use.
                -    :type pkey: paramiko.PKey
                 
                     :param passphrase: Passphrase to use for encrypted key; password will be used for key
                             decryption if not specified.
                -    :type passphrase: str
                +
                +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
                +            documentation for a description of the expected format.
                 
                     :param allow_agent: Enable use of SSH key-agent.
                -    :type allow_agent: bool
                 
                     :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                             means unknown SSH host keys will be accepted).
                -    :type ssh_strict: bool
                 
                     :param system_host_keys: Load host keys from the users known_hosts file.
                -    :type system_host_keys: bool
                +
                     :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                             alt_key_file.
                -    :type alt_host_keys: bool
                 
                     :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                -    :type alt_key_file: str
                 
                     :param ssh_config_file: File name of OpenSSH configuration file.
                -    :type ssh_config_file: str
                 
                     :param timeout: Connection timeout.
                -    :type timeout: float
                 
                     :param session_timeout: Set a timeout for parallel requests.
                -    :type session_timeout: float
                 
                     :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                -    :type auth_timeout: float
                 
                     :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                -    :type banner_timeout: float
                 
                     :param 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).
                -    :type keepalive: int
                 
                     :param default_enter: Character(s) to send to correspond to enter key (default:
                 
                -

                ). -:type default_enter: str

                +

                ).

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

                ) -:type response_return: str

                +

                )

                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                             to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                +            (default: True)
                 
                     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                 
                     :param session_log_record_writes: The session log generally only records channel reads due
                             to eliminate command duplication due to command echo. You can enable this if you
                             want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                 
                     :param session_log_file_mode: "write" or "append" for session_log file mode
                             (default: "write")
                -    :type session_log_file_mode: str
                 
                     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                             (default: False)
                -    :type allow_auto_change: bool
                 
                     :param encoding: Encoding to be used when writing bytes to the output channel.
                             (default: ascii)
                -    :type encoding: str
                 
                     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                             communication to the target host (default: None).
                -    :type sock: socket
                 
                     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                             (default: None). Global attribute takes precedence over function `cmd_verify`
                             argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                 
                     :param auto_connect: Control whether Netmiko automatically establishes the connection as
                             part of the object creation (default: True).
                -    :type auto_connect: bool
                +
                +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                +            eliminated in Netmiko 5.x (default: False).
                 
                Source code -
                class NetscalerSSH(BaseConnection):
                -    """ Netscaler SSH class. """
                +
                class NetscalerSSH(NoConfig, BaseConnection):
                +    """Netscaler SSH class."""
                 
                -    def session_preparation(self):
                +    def session_preparation(self) -> None:
                         """Prepare the session after the connection has been established."""
                -        # 0 will defer to the global delay factor
                -        delay_factor = self.select_delay_factor(delay_factor=0)
                -        self._test_channel_read()
                +        self._test_channel_read(pattern=r"[>#]")
                         self.set_base_prompt()
                         cmd = f"{self.RETURN}set cli mode -page OFF{self.RETURN}"
                         self.disable_paging(command=cmd)
                -        time.sleep(1 * delay_factor)
                         self.set_base_prompt()
                -        time.sleep(0.3 * delay_factor)
                -        self.clear_buffer()
                 
                     def set_base_prompt(
                -        self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1
                -    ):
                +        self,
                +        pri_prompt_terminator: str = ">",
                +        alt_prompt_terminator: str = "#",
                +        delay_factor: float = 1.0,
                +        pattern: Optional[str] = None,
                +    ) -> str:
                         """Sets self.base_prompt.
                 
                -        Netscaler has '>' for the prompt.
                +        Netscaler has only '>' for the prompt.
                         """
                -        prompt = self.find_prompt(delay_factor=delay_factor)
                -        if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator):
                -            raise ValueError(f"Router prompt not found: {repr(prompt)}")
                -
                -        prompt = prompt.strip()
                -        if len(prompt) == 1:
                -            self.base_prompt = prompt
                -        else:
                -            # Strip off trailing terminator
                -            self.base_prompt = prompt[:-1]
                +        base_prompt = super().set_base_prompt(
                +            pri_prompt_terminator=pri_prompt_terminator,
                +            alt_prompt_terminator=alt_prompt_terminator,
                +            delay_factor=delay_factor,
                +            pattern=pattern,
                +        )
                +        # If null-string, set base_prompt to just ">"
                +        if not base_prompt:
                +            self.base_prompt = pri_prompt_terminator
                         return self.base_prompt
                 
                -    def check_config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return False
                -
                -    def config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return ""
                -
                -    def exit_config_mode(self):
                -        """Netscaler devices do not have a config mode."""
                -        return ""
                -
                -    def strip_prompt(self, a_string):
                -        """ Strip 'Done' from command output """
                +    def strip_prompt(self, a_string: str) -> str:
                +        """Strip 'Done' from command output"""
                         output = super().strip_prompt(a_string)
                         lines = output.split(self.RESPONSE_RETURN)
                         if "Done" in lines[-1]:
                @@ -289,46 +234,11 @@ 

                Classes

                Ancestors

                Methods

                -
                -def check_config_mode(self) -
                -
                -

                Netscaler devices do not have a config mode.

                -
                -Source code -
                def check_config_mode(self):
                -    """Netscaler devices do not have a config mode."""
                -    return False
                -
                -
                -
                -def config_mode(self) -
                -
                -

                Netscaler devices do not have a config mode.

                -
                -Source code -
                def config_mode(self):
                -    """Netscaler devices do not have a config mode."""
                -    return ""
                -
                -
                -
                -def exit_config_mode(self) -
                -
                -

                Netscaler devices do not have a config mode.

                -
                -Source code -
                def exit_config_mode(self):
                -    """Netscaler devices do not have a config mode."""
                -    return ""
                -
                -
                def session_preparation(self)
                @@ -336,45 +246,43 @@

                Methods

                Prepare the session after the connection has been established.

                Source code -
                def session_preparation(self):
                +
                def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                -    # 0 will defer to the global delay factor
                -    delay_factor = self.select_delay_factor(delay_factor=0)
                -    self._test_channel_read()
                +    self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
                     cmd = f"{self.RETURN}set cli mode -page OFF{self.RETURN}"
                     self.disable_paging(command=cmd)
                -    time.sleep(1 * delay_factor)
                -    self.set_base_prompt()
                -    time.sleep(0.3 * delay_factor)
                -    self.clear_buffer()
                + self.set_base_prompt()
                -def set_base_prompt(self, pri_prompt_terminator='#', alt_prompt_terminator='>', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

                Sets self.base_prompt.

                -

                Netscaler has '>' for the prompt.

                +

                Netscaler has only '>' for the prompt.

                Source code
                def set_base_prompt(
                -    self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1
                -):
                +    self,
                +    pri_prompt_terminator: str = ">",
                +    alt_prompt_terminator: str = "#",
                +    delay_factor: float = 1.0,
                +    pattern: Optional[str] = None,
                +) -> str:
                     """Sets self.base_prompt.
                 
                -    Netscaler has '>' for the prompt.
                +    Netscaler has only '>' for the prompt.
                     """
                -    prompt = self.find_prompt(delay_factor=delay_factor)
                -    if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator):
                -        raise ValueError(f"Router prompt not found: {repr(prompt)}")
                -
                -    prompt = prompt.strip()
                -    if len(prompt) == 1:
                -        self.base_prompt = prompt
                -    else:
                -        # Strip off trailing terminator
                -        self.base_prompt = prompt[:-1]
                +    base_prompt = super().set_base_prompt(
                +        pri_prompt_terminator=pri_prompt_terminator,
                +        alt_prompt_terminator=alt_prompt_terminator,
                +        delay_factor=delay_factor,
                +        pattern=pattern,
                +    )
                +    # If null-string, set base_prompt to just ">"
                +    if not base_prompt:
                +        self.base_prompt = pri_prompt_terminator
                     return self.base_prompt
                @@ -385,8 +293,8 @@

                Methods

                Strip 'Done' from command output

                Source code -
                def strip_prompt(self, a_string):
                -    """ Strip 'Done' from command output """
                +
                def strip_prompt(self, a_string: str) -> str:
                +    """Strip 'Done' from command output"""
                     output = super().strip_prompt(a_string)
                     lines = output.split(self.RESPONSE_RETURN)
                     if "Done" in lines[-1]:
                @@ -400,23 +308,25 @@ 

                Inherited members

                • BaseConnection:
                    +
                  • check_config_mode
                  • check_enable_mode
                  • cleanup
                  • clear_buffer
                  • -
                  • close_session_log
                  • commit
                  • +
                  • config_mode
                  • disable_paging
                  • disconnect
                  • enable
                  • establish_connection
                  • +
                  • exit_config_mode
                  • exit_enable_mode
                  • find_prompt
                  • is_alive
                  • normalize_cmd
                  • normalize_linefeeds
                  • -
                  • open_session_log
                  • paramiko_cleanup
                  • read_channel
                  • +
                  • read_channel_timing
                  • read_until_pattern
                  • read_until_prompt
                  • read_until_prompt_or_pattern
                  • @@ -428,6 +338,7 @@

                    Inherited members

                  • send_command_timing
                  • send_config_from_file
                  • send_config_set
                  • +
                  • send_multiline
                  • set_terminal_width
                  • special_login_handler
                  • strip_ansi_escape_codes
                  • @@ -457,10 +368,7 @@

                    Index

                    • NetscalerSSH

                      -
                        -
                      • check_config_mode
                      • -
                      • config_mode
                      • -
                      • exit_config_mode
                      • +
                        • session_preparation
                        • set_base_prompt
                        • strip_prompt
                        • diff --git a/docs/netmiko/cli_tools/index.html b/docs/netmiko/cli_tools/index.html new file mode 100644 index 000000000..94f2785c8 --- /dev/null +++ b/docs/netmiko/cli_tools/index.html @@ -0,0 +1,75 @@ + + + + + + +netmiko.cli_tools API documentation + + + + + + + + + +
                          + + +
                          + + + + + \ No newline at end of file diff --git a/docs/netmiko/cli_tools/netmiko_cfg.html b/docs/netmiko/cli_tools/netmiko_cfg.html new file mode 100644 index 000000000..b7ed0ee13 --- /dev/null +++ b/docs/netmiko/cli_tools/netmiko_cfg.html @@ -0,0 +1,521 @@ + + + + + + +netmiko.cli_tools.netmiko_cfg API documentation + + + + + + + + + +
                          +
                          +
                          +

                          Module netmiko.cli_tools.netmiko_cfg

                          +
                          +
                          +

                          Return output from single show cmd using Netmiko.

                          +
                          +Source code +
                          #!/usr/bin/env python
                          +"""Return output from single show cmd using Netmiko."""
                          +from __future__ import print_function
                          +from __future__ import unicode_literals
                          +
                          +import argparse
                          +import sys
                          +import os
                          +import subprocess
                          +import threading
                          +
                          +try:
                          +    from Queue import Queue
                          +except ImportError:
                          +    from queue import Queue
                          +from datetime import datetime
                          +from getpass import getpass
                          +
                          +from netmiko import ConnectHandler
                          +from netmiko.utilities import load_devices, display_inventory
                          +from netmiko.utilities import obtain_all_devices
                          +from netmiko.utilities import write_tmp_file, ensure_dir_exists
                          +from netmiko.utilities import find_netmiko_dir
                          +from netmiko.utilities import SHOW_RUN_MAPPER
                          +
                          +GREP = "/bin/grep"
                          +if not os.path.exists(GREP):
                          +    GREP = "/usr/bin/grep"
                          +NETMIKO_BASE_DIR = "~/.netmiko"
                          +ERROR_PATTERN = "%%%failed%%%"
                          +__version__ = "0.1.0"
                          +
                          +PY2 = sys.version_info.major == 2
                          +PY3 = sys.version_info.major == 3
                          +
                          +if sys.version_info.major == 3:
                          +    string_types = (str,)
                          +    text_type = str
                          +else:
                          +    string_types = (basestring,)  # noqa
                          +    text_type = unicode  # noqa
                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +def ssh_conn(device_name, a_device, cfg_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        if isinstance(cfg_command, string_types):
                          +            cfg_command = [cfg_command]
                          +        output = net_connect.send_config_set(cfg_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = "Execute single config cmd using Netmiko"
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--infile", help="Read commands from file", type=argparse.FileType("r")
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Config command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices:
                          +            parser.error("Devices not specified.")
                          +        if not cli_args.cmd and not cli_args.infile:
                          +            parser.error("No configuration commands provided.")
                          +    return cli_args
                          +
                          +
                          +def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-cfg v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +        if r"\n" in cli_command:
                          +            cli_command = cli_command.strip()
                          +            cli_command = cli_command.split(r"\n")
                          +    elif input:
                          +        cmd_arg = True
                          +        command_data = cli_args.infile.read()
                          +        command_data = command_data.strip()
                          +        cli_command = command_data.splitlines()
                          +    else:
                          +        raise ValueError("No configuration commands provided.")
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = r"."
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    for device_name, a_device in device_group.items():
                          +        if cli_username:
                          +            a_device["username"] = cli_username
                          +        if cli_password:
                          +            a_device["password"] = cli_password
                          +        if cli_secret:
                          +            a_device["secret"] = cli_secret
                          +        if not cmd_arg:
                          +            cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +        my_thread = threading.Thread(
                          +            target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +        )
                          +        my_thread.start()
                          +    # Make sure all threads have finished
                          +    main_thread = threading.currentThread()
                          +    for some_thread in threading.enumerate():
                          +        if some_thread != main_thread:
                          +            some_thread.join()
                          +    # Write files
                          +    while not output_q.empty():
                          +        my_dict = output_q.get()
                          +        netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +        ensure_dir_exists(netmiko_base_dir)
                          +        ensure_dir_exists(netmiko_full_dir)
                          +        for device_name, output in my_dict.items():
                          +            file_name = write_tmp_file(device_name, output)
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +if __name__ == "__main__":
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          +

                          Functions

                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True) +
                          +
                          +

                          Call system grep

                          +
                          +Source code +
                          def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +
                          +def main(args) +
                          +
                          +
                          +
                          +Source code +
                          def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-cfg v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +        if r"\n" in cli_command:
                          +            cli_command = cli_command.strip()
                          +            cli_command = cli_command.split(r"\n")
                          +    elif input:
                          +        cmd_arg = True
                          +        command_data = cli_args.infile.read()
                          +        command_data = command_data.strip()
                          +        cli_command = command_data.splitlines()
                          +    else:
                          +        raise ValueError("No configuration commands provided.")
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = r"."
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    for device_name, a_device in device_group.items():
                          +        if cli_username:
                          +            a_device["username"] = cli_username
                          +        if cli_password:
                          +            a_device["password"] = cli_password
                          +        if cli_secret:
                          +            a_device["secret"] = cli_secret
                          +        if not cmd_arg:
                          +            cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +        my_thread = threading.Thread(
                          +            target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +        )
                          +        my_thread.start()
                          +    # Make sure all threads have finished
                          +    main_thread = threading.currentThread()
                          +    for some_thread in threading.enumerate():
                          +        if some_thread != main_thread:
                          +            some_thread.join()
                          +    # Write files
                          +    while not output_q.empty():
                          +        my_dict = output_q.get()
                          +        netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +        ensure_dir_exists(netmiko_base_dir)
                          +        ensure_dir_exists(netmiko_full_dir)
                          +        for device_name, output in my_dict.items():
                          +            file_name = write_tmp_file(device_name, output)
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +
                          +def main_ep() +
                          +
                          +
                          +
                          +Source code +
                          def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +def parse_arguments(args) +
                          +
                          +

                          Parse command-line arguments.

                          +
                          +Source code +
                          def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = "Execute single config cmd using Netmiko"
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--infile", help="Read commands from file", type=argparse.FileType("r")
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Config command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices:
                          +            parser.error("Devices not specified.")
                          +        if not cli_args.cmd and not cli_args.infile:
                          +            parser.error("No configuration commands provided.")
                          +    return cli_args
                          +
                          +
                          +
                          +def ssh_conn(device_name, a_device, cfg_command, output_q) +
                          +
                          +
                          +
                          +Source code +
                          def ssh_conn(device_name, a_device, cfg_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        if isinstance(cfg_command, string_types):
                          +            cfg_command = [cfg_command]
                          +        output = net_connect.send_config_set(cfg_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          + +
                          + + + + + \ No newline at end of file diff --git a/docs/netmiko/cli_tools/netmiko_grep.html b/docs/netmiko/cli_tools/netmiko_grep.html new file mode 100644 index 000000000..b4124e155 --- /dev/null +++ b/docs/netmiko/cli_tools/netmiko_grep.html @@ -0,0 +1,513 @@ + + + + + + +netmiko.cli_tools.netmiko_grep API documentation + + + + + + + + + +
                          +
                          +
                          +

                          Module netmiko.cli_tools.netmiko_grep

                          +
                          +
                          +

                          Create grep like remote behavior on show run or command output.

                          +
                          +Source code +
                          #!/usr/bin/env python
                          +"""Create grep like remote behavior on show run or command output."""
                          +from __future__ import print_function
                          +from __future__ import unicode_literals
                          +
                          +import argparse
                          +import sys
                          +import os
                          +import subprocess
                          +import threading
                          +
                          +try:
                          +    from Queue import Queue
                          +except ImportError:
                          +    from queue import Queue
                          +from datetime import datetime
                          +from getpass import getpass
                          +
                          +from netmiko import ConnectHandler
                          +from netmiko.utilities import load_devices, display_inventory
                          +from netmiko.utilities import obtain_all_devices
                          +from netmiko.utilities import obtain_netmiko_filename, write_tmp_file, ensure_dir_exists
                          +from netmiko.utilities import find_netmiko_dir
                          +from netmiko.utilities import SHOW_RUN_MAPPER
                          +
                          +GREP = "/bin/grep"
                          +if not os.path.exists(GREP):
                          +    GREP = "/usr/bin/grep"
                          +NETMIKO_BASE_DIR = "~/.netmiko"
                          +ERROR_PATTERN = "%%%failed%%%"
                          +__version__ = "0.1.0"
                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +def ssh_conn(device_name, a_device, cli_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        output = net_connect.send_command_expect(cli_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = "Grep pattern search on Netmiko output (defaults to running-config)"
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "pattern", nargs="?", help="Pattern to search for", action="store", type=str
                          +    )
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Remote command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument("--use-cache", help="Use cached files", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices or not cli_args.pattern:
                          +            parser.error("Grep pattern or devices not specified.")
                          +    return cli_args
                          +
                          +
                          +def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-grep v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = cli_args.pattern
                          +    use_cached_files = cli_args.use_cache
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    if not use_cached_files:
                          +        for device_name, a_device in device_group.items():
                          +            if cli_username:
                          +                a_device["username"] = cli_username
                          +            if cli_password:
                          +                a_device["password"] = cli_password
                          +            if cli_secret:
                          +                a_device["secret"] = cli_secret
                          +            if not cmd_arg:
                          +                cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +            my_thread = threading.Thread(
                          +                target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +            )
                          +            my_thread.start()
                          +        # Make sure all threads have finished
                          +        main_thread = threading.currentThread()
                          +        for some_thread in threading.enumerate():
                          +            if some_thread != main_thread:
                          +                some_thread.join()
                          +        # Write files
                          +        while not output_q.empty():
                          +            my_dict = output_q.get()
                          +            netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +            ensure_dir_exists(netmiko_base_dir)
                          +            ensure_dir_exists(netmiko_full_dir)
                          +            for device_name, output in my_dict.items():
                          +                file_name = write_tmp_file(device_name, output)
                          +                if ERROR_PATTERN not in output:
                          +                    my_files.append(file_name)
                          +                else:
                          +                    failed_devices.append(device_name)
                          +    else:
                          +        for device_name in device_group:
                          +            file_name = obtain_netmiko_filename(device_name)
                          +            try:
                          +                with open(file_name) as f:
                          +                    output = f.read()
                          +            except IOError:
                          +                return "Some cache files are missing: unable to use --use-cache option."
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +if __name__ == "__main__":
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          +

                          Functions

                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True) +
                          +
                          +

                          Call system grep

                          +
                          +Source code +
                          def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +
                          +def main(args) +
                          +
                          +
                          +
                          +Source code +
                          def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-grep v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = cli_args.pattern
                          +    use_cached_files = cli_args.use_cache
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    if not use_cached_files:
                          +        for device_name, a_device in device_group.items():
                          +            if cli_username:
                          +                a_device["username"] = cli_username
                          +            if cli_password:
                          +                a_device["password"] = cli_password
                          +            if cli_secret:
                          +                a_device["secret"] = cli_secret
                          +            if not cmd_arg:
                          +                cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +            my_thread = threading.Thread(
                          +                target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +            )
                          +            my_thread.start()
                          +        # Make sure all threads have finished
                          +        main_thread = threading.currentThread()
                          +        for some_thread in threading.enumerate():
                          +            if some_thread != main_thread:
                          +                some_thread.join()
                          +        # Write files
                          +        while not output_q.empty():
                          +            my_dict = output_q.get()
                          +            netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +            ensure_dir_exists(netmiko_base_dir)
                          +            ensure_dir_exists(netmiko_full_dir)
                          +            for device_name, output in my_dict.items():
                          +                file_name = write_tmp_file(device_name, output)
                          +                if ERROR_PATTERN not in output:
                          +                    my_files.append(file_name)
                          +                else:
                          +                    failed_devices.append(device_name)
                          +    else:
                          +        for device_name in device_group:
                          +            file_name = obtain_netmiko_filename(device_name)
                          +            try:
                          +                with open(file_name) as f:
                          +                    output = f.read()
                          +            except IOError:
                          +                return "Some cache files are missing: unable to use --use-cache option."
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +
                          +def main_ep() +
                          +
                          +
                          +
                          +Source code +
                          def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +def parse_arguments(args) +
                          +
                          +

                          Parse command-line arguments.

                          +
                          +Source code +
                          def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = "Grep pattern search on Netmiko output (defaults to running-config)"
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "pattern", nargs="?", help="Pattern to search for", action="store", type=str
                          +    )
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Remote command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument("--use-cache", help="Use cached files", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices or not cli_args.pattern:
                          +            parser.error("Grep pattern or devices not specified.")
                          +    return cli_args
                          +
                          +
                          +
                          +def ssh_conn(device_name, a_device, cli_command, output_q) +
                          +
                          +
                          +
                          +Source code +
                          def ssh_conn(device_name, a_device, cli_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        output = net_connect.send_command_expect(cli_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          + +
                          + + + + + \ No newline at end of file diff --git a/docs/netmiko/cli_tools/netmiko_show.html b/docs/netmiko/cli_tools/netmiko_show.html new file mode 100644 index 000000000..ed1299e5a --- /dev/null +++ b/docs/netmiko/cli_tools/netmiko_show.html @@ -0,0 +1,511 @@ + + + + + + +netmiko.cli_tools.netmiko_show API documentation + + + + + + + + + +
                          +
                          +
                          +

                          Module netmiko.cli_tools.netmiko_show

                          +
                          +
                          +

                          Return output from single show cmd using Netmiko.

                          +
                          +Source code +
                          #!/usr/bin/env python
                          +"""Return output from single show cmd using Netmiko."""
                          +from __future__ import print_function
                          +from __future__ import unicode_literals
                          +
                          +import argparse
                          +import sys
                          +import os
                          +import subprocess
                          +import threading
                          +
                          +try:
                          +    from Queue import Queue
                          +except ImportError:
                          +    from queue import Queue
                          +from datetime import datetime
                          +from getpass import getpass
                          +
                          +from netmiko import ConnectHandler
                          +from netmiko.utilities import load_devices, display_inventory
                          +from netmiko.utilities import obtain_all_devices
                          +from netmiko.utilities import obtain_netmiko_filename, write_tmp_file, ensure_dir_exists
                          +from netmiko.utilities import find_netmiko_dir
                          +from netmiko.utilities import SHOW_RUN_MAPPER
                          +
                          +GREP = "/bin/grep"
                          +if not os.path.exists(GREP):
                          +    GREP = "/usr/bin/grep"
                          +NETMIKO_BASE_DIR = "~/.netmiko"
                          +ERROR_PATTERN = "%%%failed%%%"
                          +__version__ = "0.1.0"
                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +def ssh_conn(device_name, a_device, cli_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        output = net_connect.send_command_expect(cli_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = (
                          +        "Return output from single show cmd using Netmiko (defaults to running-config)"
                          +    )
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Remote command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument("--use-cache", help="Use cached files", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices:
                          +            parser.error("Devices not specified.")
                          +    return cli_args
                          +
                          +
                          +def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-show v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = r"."
                          +    use_cached_files = cli_args.use_cache
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    if not use_cached_files:
                          +        for device_name, a_device in device_group.items():
                          +            if cli_username:
                          +                a_device["username"] = cli_username
                          +            if cli_password:
                          +                a_device["password"] = cli_password
                          +            if cli_secret:
                          +                a_device["secret"] = cli_secret
                          +            if not cmd_arg:
                          +                cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +            my_thread = threading.Thread(
                          +                target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +            )
                          +            my_thread.start()
                          +        # Make sure all threads have finished
                          +        main_thread = threading.currentThread()
                          +        for some_thread in threading.enumerate():
                          +            if some_thread != main_thread:
                          +                some_thread.join()
                          +        # Write files
                          +        while not output_q.empty():
                          +            my_dict = output_q.get()
                          +            netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +            ensure_dir_exists(netmiko_base_dir)
                          +            ensure_dir_exists(netmiko_full_dir)
                          +            for device_name, output in my_dict.items():
                          +                file_name = write_tmp_file(device_name, output)
                          +                if ERROR_PATTERN not in output:
                          +                    my_files.append(file_name)
                          +                else:
                          +                    failed_devices.append(device_name)
                          +    else:
                          +        for device_name in device_group:
                          +            file_name = obtain_netmiko_filename(device_name)
                          +            try:
                          +                with open(file_name) as f:
                          +                    output = f.read()
                          +            except IOError:
                          +                return "Some cache files are missing: unable to use --use-cache option."
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +if __name__ == "__main__":
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          +

                          Functions

                          +
                          +
                          +def grepx(files, pattern, grep_options, use_colors=True) +
                          +
                          +

                          Call system grep

                          +
                          +Source code +
                          def grepx(files, pattern, grep_options, use_colors=True):
                          +    """Call system grep"""
                          +    if not isinstance(files, (list, tuple)):
                          +        files = [files]
                          +    if use_colors:
                          +        grep_options += ["--color=auto"]
                          +
                          +    # Make grep output look nicer by 'cd netmiko_full_dir'
                          +    _, netmiko_full_dir = find_netmiko_dir()
                          +    os.chdir(netmiko_full_dir)
                          +    # Convert files to strip off the directory
                          +    retrieve_file = lambda x: x.split("/")[-1]  # noqa
                          +    files = [retrieve_file(a_file) for a_file in files]
                          +    files.sort()
                          +    grep_list = [GREP] + grep_options + [pattern] + files
                          +    proc = subprocess.Popen(grep_list, shell=False)
                          +    proc.communicate()
                          +    return ""
                          +
                          +
                          +
                          +def main(args) +
                          +
                          +
                          +
                          +Source code +
                          def main(args):
                          +    start_time = datetime.now()
                          +    cli_args = parse_arguments(args)
                          +
                          +    cli_username = cli_args.username if cli_args.username else None
                          +    cli_password = getpass() if cli_args.password else None
                          +    cli_secret = getpass("Enable secret: ") if cli_args.secret else None
                          +
                          +    version = cli_args.version
                          +    if version:
                          +        print("netmiko-show v{}".format(__version__))
                          +        return 0
                          +    list_devices = cli_args.list_devices
                          +    if list_devices:
                          +        my_devices = load_devices()
                          +        display_inventory(my_devices)
                          +        return 0
                          +
                          +    cli_command = cli_args.cmd
                          +    cmd_arg = False
                          +    if cli_command:
                          +        cmd_arg = True
                          +    device_or_group = cli_args.devices.strip()
                          +    pattern = r"."
                          +    use_cached_files = cli_args.use_cache
                          +    hide_failed = cli_args.hide_failed
                          +
                          +    output_q = Queue()
                          +    my_devices = load_devices()
                          +    if device_or_group == "all":
                          +        device_group = obtain_all_devices(my_devices)
                          +    else:
                          +        try:
                          +            devicedict_or_group = my_devices[device_or_group]
                          +            device_group = {}
                          +            if isinstance(devicedict_or_group, list):
                          +                for tmp_device_name in devicedict_or_group:
                          +                    device_group[tmp_device_name] = my_devices[tmp_device_name]
                          +            else:
                          +                device_group[device_or_group] = devicedict_or_group
                          +        except KeyError:
                          +            return (
                          +                "Error reading from netmiko devices file."
                          +                " Device or group not found: {0}".format(device_or_group)
                          +            )
                          +
                          +    # Retrieve output from devices
                          +    my_files = []
                          +    failed_devices = []
                          +    if not use_cached_files:
                          +        for device_name, a_device in device_group.items():
                          +            if cli_username:
                          +                a_device["username"] = cli_username
                          +            if cli_password:
                          +                a_device["password"] = cli_password
                          +            if cli_secret:
                          +                a_device["secret"] = cli_secret
                          +            if not cmd_arg:
                          +                cli_command = SHOW_RUN_MAPPER.get(a_device["device_type"], "show run")
                          +            my_thread = threading.Thread(
                          +                target=ssh_conn, args=(device_name, a_device, cli_command, output_q)
                          +            )
                          +            my_thread.start()
                          +        # Make sure all threads have finished
                          +        main_thread = threading.currentThread()
                          +        for some_thread in threading.enumerate():
                          +            if some_thread != main_thread:
                          +                some_thread.join()
                          +        # Write files
                          +        while not output_q.empty():
                          +            my_dict = output_q.get()
                          +            netmiko_base_dir, netmiko_full_dir = find_netmiko_dir()
                          +            ensure_dir_exists(netmiko_base_dir)
                          +            ensure_dir_exists(netmiko_full_dir)
                          +            for device_name, output in my_dict.items():
                          +                file_name = write_tmp_file(device_name, output)
                          +                if ERROR_PATTERN not in output:
                          +                    my_files.append(file_name)
                          +                else:
                          +                    failed_devices.append(device_name)
                          +    else:
                          +        for device_name in device_group:
                          +            file_name = obtain_netmiko_filename(device_name)
                          +            try:
                          +                with open(file_name) as f:
                          +                    output = f.read()
                          +            except IOError:
                          +                return "Some cache files are missing: unable to use --use-cache option."
                          +            if ERROR_PATTERN not in output:
                          +                my_files.append(file_name)
                          +            else:
                          +                failed_devices.append(device_name)
                          +
                          +    grep_options = []
                          +    grepx(my_files, pattern, grep_options)
                          +    if cli_args.display_runtime:
                          +        print("Total time: {0}".format(datetime.now() - start_time))
                          +
                          +    if not hide_failed:
                          +        if failed_devices:
                          +            print("\n")
                          +            print("-" * 20)
                          +            print("Failed devices:")
                          +            failed_devices.sort()
                          +            for device_name in failed_devices:
                          +                print("  {}".format(device_name))
                          +            print()
                          +    return 0
                          +
                          +
                          +
                          +def main_ep() +
                          +
                          +
                          +
                          +Source code +
                          def main_ep():
                          +    sys.exit(main(sys.argv[1:]))
                          +
                          +
                          +
                          +def parse_arguments(args) +
                          +
                          +

                          Parse command-line arguments.

                          +
                          +Source code +
                          def parse_arguments(args):
                          +    """Parse command-line arguments."""
                          +    description = (
                          +        "Return output from single show cmd using Netmiko (defaults to running-config)"
                          +    )
                          +    parser = argparse.ArgumentParser(description=description)
                          +    parser.add_argument(
                          +        "devices",
                          +        nargs="?",
                          +        help="Device or group to connect to",
                          +        action="store",
                          +        type=str,
                          +    )
                          +    parser.add_argument(
                          +        "--cmd",
                          +        help="Remote command to execute",
                          +        action="store",
                          +        default=None,
                          +        type=str,
                          +    )
                          +    parser.add_argument("--username", help="Username", action="store", type=str)
                          +    parser.add_argument("--password", help="Password", action="store_true")
                          +    parser.add_argument("--secret", help="Enable Secret", action="store_true")
                          +    parser.add_argument("--use-cache", help="Use cached files", action="store_true")
                          +    parser.add_argument(
                          +        "--list-devices", help="List devices from inventory", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--display-runtime", help="Display program runtime", action="store_true"
                          +    )
                          +    parser.add_argument(
                          +        "--hide-failed", help="Hide failed devices", action="store_true"
                          +    )
                          +    parser.add_argument("--version", help="Display version", action="store_true")
                          +    cli_args = parser.parse_args(args)
                          +    if not cli_args.list_devices and not cli_args.version:
                          +        if not cli_args.devices:
                          +            parser.error("Devices not specified.")
                          +    return cli_args
                          +
                          +
                          +
                          +def ssh_conn(device_name, a_device, cli_command, output_q) +
                          +
                          +
                          +
                          +Source code +
                          def ssh_conn(device_name, a_device, cli_command, output_q):
                          +    try:
                          +        net_connect = ConnectHandler(**a_device)
                          +        net_connect.enable()
                          +        output = net_connect.send_command_expect(cli_command)
                          +        net_connect.disconnect()
                          +    except Exception:
                          +        output = ERROR_PATTERN
                          +    output_q.put({device_name: output})
                          +
                          +
                          +
                          +
                          +
                          +
                          +
                          + +
                          + + + + + \ No newline at end of file diff --git a/docs/netmiko/cloudgenix/cloudgenix_ion.html b/docs/netmiko/cloudgenix/cloudgenix_ion.html index d969c030f..681e7d7f3 100644 --- a/docs/netmiko/cloudgenix/cloudgenix_ion.html +++ b/docs/netmiko/cloudgenix/cloudgenix_ion.html @@ -22,52 +22,49 @@

                          Module netmiko.cloudgenix.cloudgenix_ion

                          Source code -
                          from netmiko.cisco_base_connection import CiscoSSHConnection
                          +
                          from typing import Any, Union, Sequence, TextIO, Optional
                          +from netmiko.no_config import NoConfig
                          +from netmiko.cisco_base_connection import CiscoSSHConnection
                           
                           
                          -class CloudGenixIonSSH(CiscoSSHConnection):
                          -    def establish_connection(self):
                          -        super().establish_connection(width=100, height=1000)
                          +class CloudGenixIonSSH(NoConfig, CiscoSSHConnection):
                          +    def establish_connection(self, width: int = 100, height: int = 1000) -> None:
                          +        super().establish_connection(width=width, height=height)
                           
                          -    def session_preparation(self, *args, **kwargs):
                          +    def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                                   """Prepare the session after the connection has been established."""
                                   self.ansi_escape_codes = True
                          -        self._test_channel_read()
                          +        self._test_channel_read(pattern=r"[>#]")
                                   self.write_channel(self.RETURN)
                                   self.set_base_prompt(delay_factor=5)
                           
                          -    def disable_paging(self, *args, **kwargs):
                          +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                                   """Cloud Genix ION sets terminal height in establish_connection"""
                                   return ""
                           
                          -    def find_prompt(self, delay_factor=1):
                          -        prompt = super().find_prompt(delay_factor=delay_factor)
                          +    def find_prompt(
                          +        self, delay_factor: float = 1.0, pattern: Optional[str] = None
                          +    ) -> str:
                          +        prompt = super().find_prompt(delay_factor=delay_factor, pattern=pattern)
                                   prompt = self.strip_backspaces(prompt).strip()
                                   return prompt
                           
                          -    def strip_command(self, command_string, output):
                          +    def strip_command(self, command_string: str, output: str) -> str:
                                   output = super().strip_command(command_string, output)
                                   # command_string gets repainted potentially multiple times (grab everything after last one)
                                   output = output.split(command_string)[-1]
                                   return output
                           
                          -    def check_config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return False
                          +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                          +        """Not Implemented"""
                          +        raise NotImplementedError
                           
                          -    def config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return ""
                          -
                          -    def exit_config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return ""
                          -
                          -    def save_config(self, *args, **kwargs):
                          -        """No save method on ION SSH"""
                          -        pass
                          -
                          -    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
                          +    def send_config_set(
                          +        self,
                          +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
                          +        exit_config_mode: bool = False,
                          +        **kwargs: Any
                          +    ) -> str:
                                   return super().send_config_set(
                                       config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
                                   )
                          @@ -84,221 +81,171 @@

                          Classes

                          class CloudGenixIonSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
                          -

                          Base Class for cisco-like behavior.

                          +

                          Class for platforms that have no config mode.

                          +

                          check_config_mode returns True as the expectation is that configuration commands +can be executed directly. So in your current state, you are in "config mode" i.e. +you can make configuration changes.

                          +

                          If you truly cannot make any configuration changes to device then you should probably +overwrite check_config_mode in the platform specific driver and return False.

                              Initialize attributes for establishing connection to target device.
                           
                               :param ip: IP address of target device. Not required if `host` is
                                   provided.
                          -    :type ip: str
                           
                               :param host: Hostname of target device. Not required if `ip` is
                                       provided.
                          -    :type host: str
                           
                               :param username: Username to authenticate against target device if
                                       required.
                          -    :type username: str
                           
                               :param password: Password to authenticate against target device if
                                       required.
                          -    :type password: str
                           
                               :param secret: The enable password if target device requires one.
                          -    :type secret: str
                           
                               :param port: The destination port used to connect to the target
                                       device.
                          -    :type port: int or None
                           
                               :param device_type: Class selection based on device type.
                          -    :type device_type: str
                           
                               :param verbose: Enable additional messages to standard output.
                          -    :type verbose: bool
                           
                               :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                          -    :type global_delay_factor: int
                           
                               :param use_keys: Connect to target device using SSH keys.
                          -    :type use_keys: bool
                           
                               :param key_file: Filename path of the SSH key file to use.
                          -    :type key_file: str
                           
                               :param pkey: SSH key object to use.
                          -    :type pkey: paramiko.PKey
                           
                               :param passphrase: Passphrase to use for encrypted key; password will be used for key
                                       decryption if not specified.
                          -    :type passphrase: str
                          +
                          +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
                          +            documentation for a description of the expected format.
                           
                               :param allow_agent: Enable use of SSH key-agent.
                          -    :type allow_agent: bool
                           
                               :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                                       means unknown SSH host keys will be accepted).
                          -    :type ssh_strict: bool
                           
                               :param system_host_keys: Load host keys from the users known_hosts file.
                          -    :type system_host_keys: bool
                          +
                               :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                                       alt_key_file.
                          -    :type alt_host_keys: bool
                           
                               :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                          -    :type alt_key_file: str
                           
                               :param ssh_config_file: File name of OpenSSH configuration file.
                          -    :type ssh_config_file: str
                           
                               :param timeout: Connection timeout.
                          -    :type timeout: float
                           
                               :param session_timeout: Set a timeout for parallel requests.
                          -    :type session_timeout: float
                           
                               :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                          -    :type auth_timeout: float
                           
                               :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                          -    :type banner_timeout: float
                           
                               :param 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).
                          -    :type keepalive: int
                           
                               :param default_enter: Character(s) to send to correspond to enter key (default:
                           
                          -

                          ). -:type default_enter: str

                          +

                          ).

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

                          ) -:type response_return: str

                          +

                          )

                              :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                       to select smallest of global and specific. Sets default global_delay_factor to .1
                          -            (default: False)
                          -    :type fast_cli: boolean
                          +            (default: True)
                           
                               :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                          -    :type session_log: str
                           
                               :param session_log_record_writes: The session log generally only records channel reads due
                                       to eliminate command duplication due to command echo. You can enable this if you
                                       want to record both channel reads and channel writes in the log (default: False).
                          -    :type session_log_record_writes: boolean
                           
                               :param session_log_file_mode: "write" or "append" for session_log file mode
                                       (default: "write")
                          -    :type session_log_file_mode: str
                           
                               :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                       (default: False)
                          -    :type allow_auto_change: bool
                           
                               :param encoding: Encoding to be used when writing bytes to the output channel.
                                       (default: ascii)
                          -    :type encoding: str
                           
                               :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                       communication to the target host (default: None).
                          -    :type sock: socket
                           
                               :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                       (default: None). Global attribute takes precedence over function `cmd_verify`
                                       argument. Value of `None` indicates to use function `cmd_verify` argument.
                          -    :type global_cmd_verify: bool|None
                           
                               :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                       part of the object creation (default: True).
                          -    :type auto_connect: bool
                          +
                          +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                          +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                          +            eliminated in Netmiko 5.x (default: False).
                           
                          Source code -
                          class CloudGenixIonSSH(CiscoSSHConnection):
                          -    def establish_connection(self):
                          -        super().establish_connection(width=100, height=1000)
                          +
                          class CloudGenixIonSSH(NoConfig, CiscoSSHConnection):
                          +    def establish_connection(self, width: int = 100, height: int = 1000) -> None:
                          +        super().establish_connection(width=width, height=height)
                           
                          -    def session_preparation(self, *args, **kwargs):
                          +    def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                                   """Prepare the session after the connection has been established."""
                                   self.ansi_escape_codes = True
                          -        self._test_channel_read()
                          +        self._test_channel_read(pattern=r"[>#]")
                                   self.write_channel(self.RETURN)
                                   self.set_base_prompt(delay_factor=5)
                           
                          -    def disable_paging(self, *args, **kwargs):
                          +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                                   """Cloud Genix ION sets terminal height in establish_connection"""
                                   return ""
                           
                          -    def find_prompt(self, delay_factor=1):
                          -        prompt = super().find_prompt(delay_factor=delay_factor)
                          +    def find_prompt(
                          +        self, delay_factor: float = 1.0, pattern: Optional[str] = None
                          +    ) -> str:
                          +        prompt = super().find_prompt(delay_factor=delay_factor, pattern=pattern)
                                   prompt = self.strip_backspaces(prompt).strip()
                                   return prompt
                           
                          -    def strip_command(self, command_string, output):
                          +    def strip_command(self, command_string: str, output: str) -> str:
                                   output = super().strip_command(command_string, output)
                                   # command_string gets repainted potentially multiple times (grab everything after last one)
                                   output = output.split(command_string)[-1]
                                   return output
                           
                          -    def check_config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return False
                          +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                          +        """Not Implemented"""
                          +        raise NotImplementedError
                           
                          -    def config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return ""
                          -
                          -    def exit_config_mode(self):
                          -        """Devices do not have a config mode."""
                          -        return ""
                          -
                          -    def save_config(self, *args, **kwargs):
                          -        """No save method on ION SSH"""
                          -        pass
                          -
                          -    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
                          +    def send_config_set(
                          +        self,
                          +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
                          +        exit_config_mode: bool = False,
                          +        **kwargs: Any
                          +    ) -> str:
                                   return super().send_config_set(
                                       config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
                                   )

                          Ancestors

                          Methods

                          -
                          -def check_config_mode(self) -
                          -
                          -

                          Devices do not have a config mode.

                          -
                          -Source code -
                          def check_config_mode(self):
                          -    """Devices do not have a config mode."""
                          -    return False
                          -
                          -
                          -
                          -def config_mode(self) -
                          -
                          -

                          Devices do not have a config mode.

                          -
                          -Source code -
                          def config_mode(self):
                          -    """Devices do not have a config mode."""
                          -    return ""
                          -
                          -
                          def disable_paging(self, *args, **kwargs)
                          @@ -306,33 +253,21 @@

                          Methods

                          Cloud Genix ION sets terminal height in establish_connection

                          Source code -
                          def disable_paging(self, *args, **kwargs):
                          +
                          def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                               """Cloud Genix ION sets terminal height in establish_connection"""
                               return ""
                          -
                          -def exit_config_mode(self) -
                          -
                          -

                          Devices do not have a config mode.

                          -
                          -Source code -
                          def exit_config_mode(self):
                          -    """Devices do not have a config mode."""
                          -    return ""
                          -
                          -
                          def save_config(self, *args, **kwargs)
                          -

                          No save method on ION SSH

                          +

                          Not Implemented

                          Source code -
                          def save_config(self, *args, **kwargs):
                          -    """No save method on ION SSH"""
                          -    pass
                          +
                          def save_config(self, *args: Any, **kwargs: Any) -> str:
                          +    """Not Implemented"""
                          +    raise NotImplementedError
                          @@ -342,10 +277,10 @@

                          Methods

                          Prepare the session after the connection has been established.

                          Source code -
                          def session_preparation(self, *args, **kwargs):
                          +
                          def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                               """Prepare the session after the connection has been established."""
                               self.ansi_escape_codes = True
                          -    self._test_channel_read()
                          +    self._test_channel_read(pattern=r"[>#]")
                               self.write_channel(self.RETURN)
                               self.set_base_prompt(delay_factor=5)
                          @@ -355,22 +290,24 @@

                          Inherited members

                          • CiscoSSHConnection:
                              +
                            • check_config_mode
                            • check_enable_mode
                            • cleanup
                            • clear_buffer
                            • -
                            • close_session_log
                            • commit
                            • +
                            • config_mode
                            • disconnect
                            • enable
                            • establish_connection
                            • +
                            • exit_config_mode
                            • exit_enable_mode
                            • find_prompt
                            • is_alive
                            • normalize_cmd
                            • normalize_linefeeds
                            • -
                            • open_session_log
                            • paramiko_cleanup
                            • read_channel
                            • +
                            • read_channel_timing
                            • read_until_pattern
                            • read_until_prompt
                            • read_until_prompt_or_pattern
                            • @@ -381,6 +318,7 @@

                              Inherited members

                            • send_command_timing
                            • send_config_from_file
                            • send_config_set
                            • +
                            • send_multiline
                            • set_base_prompt
                            • set_terminal_width
                            • special_login_handler
                            • @@ -412,11 +350,8 @@

                              Index

                              • CloudGenixIonSSH

                                -
                                  -
                                • check_config_mode
                                • -
                                • config_mode
                                • + diff --git a/docs/netmiko/cloudgenix/index.html b/docs/netmiko/cloudgenix/index.html index c5ec0399a..1147f698c 100644 --- a/docs/netmiko/cloudgenix/index.html +++ b/docs/netmiko/cloudgenix/index.html @@ -45,221 +45,171 @@

                                  Classes

                                  class CloudGenixIonSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
                                  -

                                  Base Class for cisco-like behavior.

                                  +

                                  Class for platforms that have no config mode.

                                  +

                                  check_config_mode returns True as the expectation is that configuration commands +can be executed directly. So in your current state, you are in "config mode" i.e. +you can make configuration changes.

                                  +

                                  If you truly cannot make any configuration changes to device then you should probably +overwrite check_config_mode in the platform specific driver and return False.

                                      Initialize attributes for establishing connection to target device.
                                   
                                       :param ip: IP address of target device. Not required if `host` is
                                           provided.
                                  -    :type ip: str
                                   
                                       :param host: Hostname of target device. Not required if `ip` is
                                               provided.
                                  -    :type host: str
                                   
                                       :param username: Username to authenticate against target device if
                                               required.
                                  -    :type username: str
                                   
                                       :param password: Password to authenticate against target device if
                                               required.
                                  -    :type password: str
                                   
                                       :param secret: The enable password if target device requires one.
                                  -    :type secret: str
                                   
                                       :param port: The destination port used to connect to the target
                                               device.
                                  -    :type port: int or None
                                   
                                       :param device_type: Class selection based on device type.
                                  -    :type device_type: str
                                   
                                       :param verbose: Enable additional messages to standard output.
                                  -    :type verbose: bool
                                   
                                       :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                                  -    :type global_delay_factor: int
                                   
                                       :param use_keys: Connect to target device using SSH keys.
                                  -    :type use_keys: bool
                                   
                                       :param key_file: Filename path of the SSH key file to use.
                                  -    :type key_file: str
                                   
                                       :param pkey: SSH key object to use.
                                  -    :type pkey: paramiko.PKey
                                   
                                       :param passphrase: Passphrase to use for encrypted key; password will be used for key
                                               decryption if not specified.
                                  -    :type passphrase: str
                                  +
                                  +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
                                  +            documentation for a description of the expected format.
                                   
                                       :param allow_agent: Enable use of SSH key-agent.
                                  -    :type allow_agent: bool
                                   
                                       :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                                               means unknown SSH host keys will be accepted).
                                  -    :type ssh_strict: bool
                                   
                                       :param system_host_keys: Load host keys from the users known_hosts file.
                                  -    :type system_host_keys: bool
                                  +
                                       :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                                               alt_key_file.
                                  -    :type alt_host_keys: bool
                                   
                                       :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                                  -    :type alt_key_file: str
                                   
                                       :param ssh_config_file: File name of OpenSSH configuration file.
                                  -    :type ssh_config_file: str
                                   
                                       :param timeout: Connection timeout.
                                  -    :type timeout: float
                                   
                                       :param session_timeout: Set a timeout for parallel requests.
                                  -    :type session_timeout: float
                                   
                                       :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                                  -    :type auth_timeout: float
                                   
                                       :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                                  -    :type banner_timeout: float
                                   
                                       :param 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).
                                  -    :type keepalive: int
                                   
                                       :param default_enter: Character(s) to send to correspond to enter key (default:
                                   
                                  -

                                  ). -:type default_enter: str

                                  +

                                  ).

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

                                  ) -:type response_return: str

                                  +

                                  )

                                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                               to select smallest of global and specific. Sets default global_delay_factor to .1
                                  -            (default: False)
                                  -    :type fast_cli: boolean
                                  +            (default: True)
                                   
                                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                                  -    :type session_log: str
                                   
                                       :param session_log_record_writes: The session log generally only records channel reads due
                                               to eliminate command duplication due to command echo. You can enable this if you
                                               want to record both channel reads and channel writes in the log (default: False).
                                  -    :type session_log_record_writes: boolean
                                   
                                       :param session_log_file_mode: "write" or "append" for session_log file mode
                                               (default: "write")
                                  -    :type session_log_file_mode: str
                                   
                                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                               (default: False)
                                  -    :type allow_auto_change: bool
                                   
                                       :param encoding: Encoding to be used when writing bytes to the output channel.
                                               (default: ascii)
                                  -    :type encoding: str
                                   
                                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                               communication to the target host (default: None).
                                  -    :type sock: socket
                                   
                                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                               (default: None). Global attribute takes precedence over function `cmd_verify`
                                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                                  -    :type global_cmd_verify: bool|None
                                   
                                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                               part of the object creation (default: True).
                                  -    :type auto_connect: bool
                                  +
                                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                                  +            eliminated in Netmiko 5.x (default: False).
                                   
                                  Source code -
                                  class CloudGenixIonSSH(CiscoSSHConnection):
                                  -    def establish_connection(self):
                                  -        super().establish_connection(width=100, height=1000)
                                  +
                                  class CloudGenixIonSSH(NoConfig, CiscoSSHConnection):
                                  +    def establish_connection(self, width: int = 100, height: int = 1000) -> None:
                                  +        super().establish_connection(width=width, height=height)
                                   
                                  -    def session_preparation(self, *args, **kwargs):
                                  +    def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                                           """Prepare the session after the connection has been established."""
                                           self.ansi_escape_codes = True
                                  -        self._test_channel_read()
                                  +        self._test_channel_read(pattern=r"[>#]")
                                           self.write_channel(self.RETURN)
                                           self.set_base_prompt(delay_factor=5)
                                   
                                  -    def disable_paging(self, *args, **kwargs):
                                  +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                                           """Cloud Genix ION sets terminal height in establish_connection"""
                                           return ""
                                   
                                  -    def find_prompt(self, delay_factor=1):
                                  -        prompt = super().find_prompt(delay_factor=delay_factor)
                                  +    def find_prompt(
                                  +        self, delay_factor: float = 1.0, pattern: Optional[str] = None
                                  +    ) -> str:
                                  +        prompt = super().find_prompt(delay_factor=delay_factor, pattern=pattern)
                                           prompt = self.strip_backspaces(prompt).strip()
                                           return prompt
                                   
                                  -    def strip_command(self, command_string, output):
                                  +    def strip_command(self, command_string: str, output: str) -> str:
                                           output = super().strip_command(command_string, output)
                                           # command_string gets repainted potentially multiple times (grab everything after last one)
                                           output = output.split(command_string)[-1]
                                           return output
                                   
                                  -    def check_config_mode(self):
                                  -        """Devices do not have a config mode."""
                                  -        return False
                                  -
                                  -    def config_mode(self):
                                  -        """Devices do not have a config mode."""
                                  -        return ""
                                  -
                                  -    def exit_config_mode(self):
                                  -        """Devices do not have a config mode."""
                                  -        return ""
                                  +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                                  +        """Not Implemented"""
                                  +        raise NotImplementedError
                                   
                                  -    def save_config(self, *args, **kwargs):
                                  -        """No save method on ION SSH"""
                                  -        pass
                                  -
                                  -    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
                                  +    def send_config_set(
                                  +        self,
                                  +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
                                  +        exit_config_mode: bool = False,
                                  +        **kwargs: Any
                                  +    ) -> str:
                                           return super().send_config_set(
                                               config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
                                           )

                                  Ancestors

                                  Methods

                                  -
                                  -def check_config_mode(self) -
                                  -
                                  -

                                  Devices do not have a config mode.

                                  -
                                  -Source code -
                                  def check_config_mode(self):
                                  -    """Devices do not have a config mode."""
                                  -    return False
                                  -
                                  -
                                  -
                                  -def config_mode(self) -
                                  -
                                  -

                                  Devices do not have a config mode.

                                  -
                                  -Source code -
                                  def config_mode(self):
                                  -    """Devices do not have a config mode."""
                                  -    return ""
                                  -
                                  -
                                  def disable_paging(self, *args, **kwargs)
                                  @@ -267,33 +217,21 @@

                                  Methods

                                  Cloud Genix ION sets terminal height in establish_connection

                                  Source code -
                                  def disable_paging(self, *args, **kwargs):
                                  +
                                  def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                                       """Cloud Genix ION sets terminal height in establish_connection"""
                                       return ""
                                  -
                                  -def exit_config_mode(self) -
                                  -
                                  -

                                  Devices do not have a config mode.

                                  -
                                  -Source code -
                                  def exit_config_mode(self):
                                  -    """Devices do not have a config mode."""
                                  -    return ""
                                  -
                                  -
                                  def save_config(self, *args, **kwargs)
                                  -

                                  No save method on ION SSH

                                  +

                                  Not Implemented

                                  Source code -
                                  def save_config(self, *args, **kwargs):
                                  -    """No save method on ION SSH"""
                                  -    pass
                                  +
                                  def save_config(self, *args: Any, **kwargs: Any) -> str:
                                  +    """Not Implemented"""
                                  +    raise NotImplementedError
                                  @@ -303,10 +241,10 @@

                                  Methods

                                  Prepare the session after the connection has been established.

                                  Source code -
                                  def session_preparation(self, *args, **kwargs):
                                  +
                                  def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                                       """Prepare the session after the connection has been established."""
                                       self.ansi_escape_codes = True
                                  -    self._test_channel_read()
                                  +    self._test_channel_read(pattern=r"[>#]")
                                       self.write_channel(self.RETURN)
                                       self.set_base_prompt(delay_factor=5)
                                  @@ -316,22 +254,24 @@

                                  Inherited members

                                  • CiscoSSHConnection:
                                      +
                                    • check_config_mode
                                    • check_enable_mode
                                    • cleanup
                                    • clear_buffer
                                    • -
                                    • close_session_log
                                    • commit
                                    • +
                                    • config_mode
                                    • disconnect
                                    • enable
                                    • establish_connection
                                    • +
                                    • exit_config_mode
                                    • exit_enable_mode
                                    • find_prompt
                                    • is_alive
                                    • normalize_cmd
                                    • normalize_linefeeds
                                    • -
                                    • open_session_log
                                    • paramiko_cleanup
                                    • read_channel
                                    • +
                                    • read_channel_timing
                                    • read_until_pattern
                                    • read_until_prompt
                                    • read_until_prompt_or_pattern
                                    • @@ -342,6 +282,7 @@

                                      Inherited members

                                    • send_command_timing
                                    • send_config_from_file
                                    • send_config_set
                                    • +
                                    • send_multiline
                                    • set_base_prompt
                                    • set_terminal_width
                                    • special_login_handler
                                    • @@ -378,11 +319,8 @@

                                      Index

                                      • CloudGenixIonSSH

                                        -
                                          -
                                        • check_config_mode
                                        • -
                                        • config_mode
                                        • + diff --git a/docs/netmiko/coriant/coriant_ssh.html b/docs/netmiko/coriant/coriant_ssh.html index 9c2d0c950..40dc18d23 100644 --- a/docs/netmiko/coriant/coriant_ssh.html +++ b/docs/netmiko/coriant/coriant_ssh.html @@ -22,47 +22,34 @@

                                          Module netmiko.coriant.coriant_ssh

                                          Source code -
                                          from netmiko.cisco_base_connection import CiscoSSHConnection
                                          +
                                          from typing import Any, Optional
                                          +from netmiko.no_enable import NoEnable
                                          +from netmiko.no_config import NoConfig
                                          +from netmiko.cisco_base_connection import CiscoSSHConnection
                                           
                                           
                                          -class CoriantSSH(CiscoSSHConnection):
                                          -    def session_preparation(self):
                                          -        self._test_channel_read()
                                          +class CoriantSSH(NoEnable, NoConfig, CiscoSSHConnection):
                                          +    def session_preparation(self) -> None:
                                          +        self._test_channel_read(pattern=r"[>:]")
                                                   self.set_base_prompt()
                                           
                                          -    def check_enable_mode(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def enable(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def exit_enable_mode(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def check_config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return False
                                          -
                                          -    def config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return ""
                                          -
                                          -    def exit_config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return ""
                                          -
                                               def set_base_prompt(
                                          -        self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2
                                          -    ):
                                          +        self,
                                          +        pri_prompt_terminator: str = ":",
                                          +        alt_prompt_terminator: str = ">",
                                          +        delay_factor: float = 2.0,
                                          +        pattern: Optional[str] = None,
                                          +    ) -> str:
                                                   """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                                                   super().set_base_prompt(
                                                       pri_prompt_terminator=pri_prompt_terminator,
                                                       alt_prompt_terminator=alt_prompt_terminator,
                                                       delay_factor=delay_factor,
                                          +            pattern=pattern,
                                                   )
                                                   return self.base_prompt
                                           
                                          -    def save_config(self, *args, **kwargs):
                                          +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                                                   """Not Implemented"""
                                                   raise NotImplementedError
                                          @@ -78,227 +65,157 @@

                                          Classes

                                          class CoriantSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
                                          -

                                          Base Class for cisco-like behavior.

                                          +

                                          Class for platforms that have no enable mode.

                                          +

                                          Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

                                          +

                                          The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

                                          +

                                          Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

                                              Initialize attributes for establishing connection to target device.
                                           
                                               :param ip: IP address of target device. Not required if `host` is
                                                   provided.
                                          -    :type ip: str
                                           
                                               :param host: Hostname of target device. Not required if `ip` is
                                                       provided.
                                          -    :type host: str
                                           
                                               :param username: Username to authenticate against target device if
                                                       required.
                                          -    :type username: str
                                           
                                               :param password: Password to authenticate against target device if
                                                       required.
                                          -    :type password: str
                                           
                                               :param secret: The enable password if target device requires one.
                                          -    :type secret: str
                                           
                                               :param port: The destination port used to connect to the target
                                                       device.
                                          -    :type port: int or None
                                           
                                               :param device_type: Class selection based on device type.
                                          -    :type device_type: str
                                           
                                               :param verbose: Enable additional messages to standard output.
                                          -    :type verbose: bool
                                           
                                               :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                                          -    :type global_delay_factor: int
                                           
                                               :param use_keys: Connect to target device using SSH keys.
                                          -    :type use_keys: bool
                                           
                                               :param key_file: Filename path of the SSH key file to use.
                                          -    :type key_file: str
                                           
                                               :param pkey: SSH key object to use.
                                          -    :type pkey: paramiko.PKey
                                           
                                               :param passphrase: Passphrase to use for encrypted key; password will be used for key
                                                       decryption if not specified.
                                          -    :type passphrase: str
                                          +
                                          +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
                                          +            documentation for a description of the expected format.
                                           
                                               :param allow_agent: Enable use of SSH key-agent.
                                          -    :type allow_agent: bool
                                           
                                               :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                                                       means unknown SSH host keys will be accepted).
                                          -    :type ssh_strict: bool
                                           
                                               :param system_host_keys: Load host keys from the users known_hosts file.
                                          -    :type system_host_keys: bool
                                          +
                                               :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                                                       alt_key_file.
                                          -    :type alt_host_keys: bool
                                           
                                               :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                                          -    :type alt_key_file: str
                                           
                                               :param ssh_config_file: File name of OpenSSH configuration file.
                                          -    :type ssh_config_file: str
                                           
                                               :param timeout: Connection timeout.
                                          -    :type timeout: float
                                           
                                               :param session_timeout: Set a timeout for parallel requests.
                                          -    :type session_timeout: float
                                           
                                               :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                                          -    :type auth_timeout: float
                                           
                                               :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                                          -    :type banner_timeout: float
                                           
                                               :param 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).
                                          -    :type keepalive: int
                                           
                                               :param default_enter: Character(s) to send to correspond to enter key (default:
                                           
                                          -

                                          ). -:type default_enter: str

                                          +

                                          ).

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

                                          ) -:type response_return: str

                                          +

                                          )

                                              :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                                       to select smallest of global and specific. Sets default global_delay_factor to .1
                                          -            (default: False)
                                          -    :type fast_cli: boolean
                                          +            (default: True)
                                           
                                               :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                                          -    :type session_log: str
                                           
                                               :param session_log_record_writes: The session log generally only records channel reads due
                                                       to eliminate command duplication due to command echo. You can enable this if you
                                                       want to record both channel reads and channel writes in the log (default: False).
                                          -    :type session_log_record_writes: boolean
                                           
                                               :param session_log_file_mode: "write" or "append" for session_log file mode
                                                       (default: "write")
                                          -    :type session_log_file_mode: str
                                           
                                               :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                                       (default: False)
                                          -    :type allow_auto_change: bool
                                           
                                               :param encoding: Encoding to be used when writing bytes to the output channel.
                                                       (default: ascii)
                                          -    :type encoding: str
                                           
                                               :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                                       communication to the target host (default: None).
                                          -    :type sock: socket
                                           
                                               :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                                       (default: None). Global attribute takes precedence over function `cmd_verify`
                                                       argument. Value of `None` indicates to use function `cmd_verify` argument.
                                          -    :type global_cmd_verify: bool|None
                                           
                                               :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                                       part of the object creation (default: True).
                                          -    :type auto_connect: bool
                                          +
                                          +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                                          +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                                          +            eliminated in Netmiko 5.x (default: False).
                                           
                                          Source code -
                                          class CoriantSSH(CiscoSSHConnection):
                                          -    def session_preparation(self):
                                          -        self._test_channel_read()
                                          +
                                          class CoriantSSH(NoEnable, NoConfig, CiscoSSHConnection):
                                          +    def session_preparation(self) -> None:
                                          +        self._test_channel_read(pattern=r"[>:]")
                                                   self.set_base_prompt()
                                           
                                          -    def check_enable_mode(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def enable(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def exit_enable_mode(self, *args, **kwargs):
                                          -        raise AttributeError("Coriant devices do not support enable mode!")
                                          -
                                          -    def check_config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return False
                                          -
                                          -    def config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return ""
                                          -
                                          -    def exit_config_mode(self):
                                          -        """Coriant devices do not have a config mode."""
                                          -        return ""
                                          -
                                               def set_base_prompt(
                                          -        self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2
                                          -    ):
                                          +        self,
                                          +        pri_prompt_terminator: str = ":",
                                          +        alt_prompt_terminator: str = ">",
                                          +        delay_factor: float = 2.0,
                                          +        pattern: Optional[str] = None,
                                          +    ) -> str:
                                                   """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                                                   super().set_base_prompt(
                                                       pri_prompt_terminator=pri_prompt_terminator,
                                                       alt_prompt_terminator=alt_prompt_terminator,
                                                       delay_factor=delay_factor,
                                          +            pattern=pattern,
                                                   )
                                                   return self.base_prompt
                                           
                                          -    def save_config(self, *args, **kwargs):
                                          +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                                                   """Not Implemented"""
                                                   raise NotImplementedError

                                          Ancestors

                                          Methods

                                          -
                                          -def check_config_mode(self) -
                                          -
                                          -

                                          Coriant devices do not have a config mode.

                                          -
                                          -Source code -
                                          def check_config_mode(self):
                                          -    """Coriant devices do not have a config mode."""
                                          -    return False
                                          -
                                          -
                                          -
                                          -def config_mode(self) -
                                          -
                                          -

                                          Coriant devices do not have a config mode.

                                          -
                                          -Source code -
                                          def config_mode(self):
                                          -    """Coriant devices do not have a config mode."""
                                          -    return ""
                                          -
                                          -
                                          -
                                          -def exit_config_mode(self) -
                                          -
                                          -

                                          Coriant devices do not have a config mode.

                                          -
                                          -Source code -
                                          def exit_config_mode(self):
                                          -    """Coriant devices do not have a config mode."""
                                          -    return ""
                                          -
                                          -
                                          def save_config(self, *args, **kwargs)
                                          @@ -306,26 +223,31 @@

                                          Methods

                                          Not Implemented

                                          Source code -
                                          def save_config(self, *args, **kwargs):
                                          +
                                          def save_config(self, *args: Any, **kwargs: Any) -> str:
                                               """Not Implemented"""
                                               raise NotImplementedError
                                          -def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='>', delay_factor=2) +def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='>', delay_factor=2.0, pattern=None)

                                          Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

                                          Source code
                                          def set_base_prompt(
                                          -    self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2
                                          -):
                                          +    self,
                                          +    pri_prompt_terminator: str = ":",
                                          +    alt_prompt_terminator: str = ">",
                                          +    delay_factor: float = 2.0,
                                          +    pattern: Optional[str] = None,
                                          +) -> str:
                                               """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                                               super().set_base_prompt(
                                                   pri_prompt_terminator=pri_prompt_terminator,
                                                   alt_prompt_terminator=alt_prompt_terminator,
                                                   delay_factor=delay_factor,
                                          +        pattern=pattern,
                                               )
                                               return self.base_prompt
                                          @@ -335,23 +257,25 @@

                                          Inherited members

                                          • CiscoSSHConnection:
                                              +
                                            • check_config_mode
                                            • check_enable_mode
                                            • cleanup
                                            • clear_buffer
                                            • -
                                            • close_session_log
                                            • commit
                                            • +
                                            • config_mode
                                            • disable_paging
                                            • disconnect
                                            • enable
                                            • establish_connection
                                            • +
                                            • exit_config_mode
                                            • exit_enable_mode
                                            • find_prompt
                                            • is_alive
                                            • normalize_cmd
                                            • normalize_linefeeds
                                            • -
                                            • open_session_log
                                            • paramiko_cleanup
                                            • read_channel
                                            • +
                                            • read_channel_timing
                                            • read_until_pattern
                                            • read_until_prompt
                                            • read_until_prompt_or_pattern
                                            • @@ -362,6 +286,7 @@

                                              Inherited members

                                            • send_command_timing
                                            • send_config_from_file
                                            • send_config_set
                                            • +
                                            • send_multiline
                                            • session_preparation
                                            • set_terminal_width
                                            • special_login_handler
                                            • @@ -394,9 +319,6 @@

                                              Index

                                            • CoriantSSH

                                              diff --git a/docs/netmiko/coriant/index.html b/docs/netmiko/coriant/index.html index cf3590288..ab7dbcf15 100644 --- a/docs/netmiko/coriant/index.html +++ b/docs/netmiko/coriant/index.html @@ -45,227 +45,157 @@

                                              Classes

                                              class CoriantSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
                                              -

                                              Base Class for cisco-like behavior.

                                              +

                                              Class for platforms that have no enable mode.

                                              +

                                              Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

                                              +

                                              The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

                                              +

                                              Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

                                                  Initialize attributes for establishing connection to target device.
                                               
                                                   :param ip: IP address of target device. Not required if `host` is
                                                       provided.
                                              -    :type ip: str
                                               
                                                   :param host: Hostname of target device. Not required if `ip` is
                                                           provided.
                                              -    :type host: str
                                               
                                                   :param username: Username to authenticate against target device if
                                                           required.
                                              -    :type username: str
                                               
                                                   :param password: Password to authenticate against target device if
                                                           required.
                                              -    :type password: str
                                               
                                                   :param secret: The enable password if target device requires one.
                                              -    :type secret: str
                                               
                                                   :param port: The destination port used to connect to the target
                                                           device.
                                              -    :type port: int or None
                                               
                                                   :param device_type: Class selection based on device type.
                                              -    :type device_type: str
                                               
                                                   :param verbose: Enable additional messages to standard output.
                                              -    :type verbose: bool
                                               
                                                   :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                                              -    :type global_delay_factor: int
                                               
                                                   :param use_keys: Connect to target device using SSH keys.
                                              -    :type use_keys: bool
                                               
                                                   :param key_file: Filename path of the SSH key file to use.
                                              -    :type key_file: str
                                               
                                                   :param pkey: SSH key object to use.
                                              -    :type pkey: paramiko.PKey
                                               
                                                   :param passphrase: Passphrase to use for encrypted key; password will be used for key
                                                           decryption if not specified.
                                              -    :type passphrase: str
                                              +
                                              +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
                                              +            documentation for a description of the expected format.
                                               
                                                   :param allow_agent: Enable use of SSH key-agent.
                                              -    :type allow_agent: bool
                                               
                                                   :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                                                           means unknown SSH host keys will be accepted).
                                              -    :type ssh_strict: bool
                                               
                                                   :param system_host_keys: Load host keys from the users known_hosts file.
                                              -    :type system_host_keys: bool
                                              +
                                                   :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                                                           alt_key_file.
                                              -    :type alt_host_keys: bool
                                               
                                                   :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                                              -    :type alt_key_file: str
                                               
                                                   :param ssh_config_file: File name of OpenSSH configuration file.
                                              -    :type ssh_config_file: str
                                               
                                                   :param timeout: Connection timeout.
                                              -    :type timeout: float
                                               
                                                   :param session_timeout: Set a timeout for parallel requests.
                                              -    :type session_timeout: float
                                               
                                                   :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                                              -    :type auth_timeout: float
                                               
                                                   :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                                              -    :type banner_timeout: float
                                               
                                                   :param 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).
                                              -    :type keepalive: int
                                               
                                                   :param default_enter: Character(s) to send to correspond to enter key (default:
                                               
                                              -

                                              ). -:type default_enter: str

                                              +

                                              ).

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

                                              ) -:type response_return: str

                                              +

                                              )

                                                  :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                                           to select smallest of global and specific. Sets default global_delay_factor to .1
                                              -            (default: False)
                                              -    :type fast_cli: boolean
                                              +            (default: True)
                                               
                                                   :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                                              -    :type session_log: str
                                               
                                                   :param session_log_record_writes: The session log generally only records channel reads due
                                                           to eliminate command duplication due to command echo. You can enable this if you
                                                           want to record both channel reads and channel writes in the log (default: False).
                                              -    :type session_log_record_writes: boolean
                                               
                                                   :param session_log_file_mode: "write" or "append" for session_log file mode
                                                           (default: "write")
                                              -    :type session_log_file_mode: str
                                               
                                                   :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                                           (default: False)
                                              -    :type allow_auto_change: bool
                                               
                                                   :param encoding: Encoding to be used when writing bytes to the output channel.
                                                           (default: ascii)
                                              -    :type encoding: str
                                               
                                                   :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                                           communication to the target host (default: None).
                                              -    :type sock: socket
                                               
                                                   :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                                           (default: None). Global attribute takes precedence over function `cmd_verify`
                                                           argument. Value of `None` indicates to use function `cmd_verify` argument.
                                              -    :type global_cmd_verify: bool|None
                                               
                                                   :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                                           part of the object creation (default: True).
                                              -    :type auto_connect: bool
                                              +
                                              +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                                              +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                                              +            eliminated in Netmiko 5.x (default: False).
                                               
                                              Source code -
                                              class CoriantSSH(CiscoSSHConnection):
                                              -    def session_preparation(self):
                                              -        self._test_channel_read()
                                              +
                                              class CoriantSSH(NoEnable, NoConfig, CiscoSSHConnection):
                                              +    def session_preparation(self) -> None:
                                              +        self._test_channel_read(pattern=r"[>:]")
                                                       self.set_base_prompt()
                                               
                                              -    def check_enable_mode(self, *args, **kwargs):
                                              -        raise AttributeError("Coriant devices do not support enable mode!")
                                              -
                                              -    def enable(self, *args, **kwargs):
                                              -        raise AttributeError("Coriant devices do not support enable mode!")
                                              -
                                              -    def exit_enable_mode(self, *args, **kwargs):
                                              -        raise AttributeError("Coriant devices do not support enable mode!")
                                              -
                                              -    def check_config_mode(self):
                                              -        """Coriant devices do not have a config mode."""
                                              -        return False
                                              -
                                              -    def config_mode(self):
                                              -        """Coriant devices do not have a config mode."""
                                              -        return ""
                                              -
                                              -    def exit_config_mode(self):
                                              -        """Coriant devices do not have a config mode."""
                                              -        return ""
                                              -
                                                   def set_base_prompt(
                                              -        self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2
                                              -    ):
                                              +        self,
                                              +        pri_prompt_terminator: str = ":",
                                              +        alt_prompt_terminator: str = ">",
                                              +        delay_factor: float = 2.0,
                                              +        pattern: Optional[str] = None,
                                              +    ) -> str:
                                                       """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                                                       super().set_base_prompt(
                                                           pri_prompt_terminator=pri_prompt_terminator,
                                                           alt_prompt_terminator=alt_prompt_terminator,
                                                           delay_factor=delay_factor,
                                              +            pattern=pattern,
                                                       )
                                                       return self.base_prompt
                                               
                                              -    def save_config(self, *args, **kwargs):
                                              +    def save_config(self, *args: Any, **kwargs: Any) -> str:
                                                       """Not Implemented"""
                                                       raise NotImplementedError

                                              Ancestors

                                              Methods

                                              -
                                              -def check_config_mode(self) -
                                              -
                                              -

                                              Coriant devices do not have a config mode.

                                              -
                                              -Source code -
                                              def check_config_mode(self):
                                              -    """Coriant devices do not have a config mode."""
                                              -    return False
                                              -
                                              -
                                              -
                                              -def config_mode(self) -
                                              -
                                              -

                                              Coriant devices do not have a config mode.

                                              -
                                              -Source code -
                                              def config_mode(self):
                                              -    """Coriant devices do not have a config mode."""
                                              -    return ""
                                              -
                                              -
                                              -
                                              -def exit_config_mode(self) -
                                              -
                                              -

                                              Coriant devices do not have a config mode.

                                              -
                                              -Source code -
                                              def exit_config_mode(self):
                                              -    """Coriant devices do not have a config mode."""
                                              -    return ""
                                              -
                                              -
                                              def save_config(self, *args, **kwargs)
                                              @@ -273,26 +203,31 @@

                                              Methods

                                              Not Implemented

                                              Source code -
                                              def save_config(self, *args, **kwargs):
                                              +
                                              def save_config(self, *args: Any, **kwargs: Any) -> str:
                                                   """Not Implemented"""
                                                   raise NotImplementedError
                                              -def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='>', delay_factor=2) +def set_base_prompt(self, pri_prompt_terminator=':', alt_prompt_terminator='>', delay_factor=2.0, pattern=None)

                                              Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

                                              Source code
                                              def set_base_prompt(
                                              -    self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2
                                              -):
                                              +    self,
                                              +    pri_prompt_terminator: str = ":",
                                              +    alt_prompt_terminator: str = ">",
                                              +    delay_factor: float = 2.0,
                                              +    pattern: Optional[str] = None,
                                              +) -> str:
                                                   """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
                                                   super().set_base_prompt(
                                                       pri_prompt_terminator=pri_prompt_terminator,
                                                       alt_prompt_terminator=alt_prompt_terminator,
                                                       delay_factor=delay_factor,
                                              +        pattern=pattern,
                                                   )
                                                   return self.base_prompt
                                              @@ -302,23 +237,25 @@

                                              Inherited members

                                              • CiscoSSHConnection:
                                                  +
                                                • check_config_mode
                                                • check_enable_mode
                                                • cleanup
                                                • clear_buffer
                                                • -
                                                • close_session_log
                                                • commit
                                                • +
                                                • config_mode
                                                • disable_paging
                                                • disconnect
                                                • enable
                                                • establish_connection
                                                • +
                                                • exit_config_mode
                                                • exit_enable_mode
                                                • find_prompt
                                                • is_alive
                                                • normalize_cmd
                                                • normalize_linefeeds
                                                • -
                                                • open_session_log
                                                • paramiko_cleanup
                                                • read_channel
                                                • +
                                                • read_channel_timing
                                                • read_until_pattern
                                                • read_until_prompt
                                                • read_until_prompt_or_pattern
                                                • @@ -329,6 +266,7 @@

                                                  Inherited members

                                                • send_command_timing
                                                • send_config_from_file
                                                • send_config_set
                                                • +
                                                • send_multiline
                                                • session_preparation
                                                • set_terminal_width
                                                • special_login_handler
                                                • @@ -366,9 +304,6 @@

                                                  Index

                                                • CoriantSSH

                                                  diff --git a/docs/netmiko/dell/dell_dnos6.html b/docs/netmiko/dell/dell_dnos6.html index 306b5d77e..d1e575038 100644 --- a/docs/netmiko/dell/dell_dnos6.html +++ b/docs/netmiko/dell/dell_dnos6.html @@ -25,28 +25,24 @@

                                                  Module netmiko.dell.dell_dnos6

                                                  Source code
                                                  """Dell N2/3/4000 base driver- supports DNOS6."""
                                                   from netmiko.dell.dell_powerconnect import DellPowerConnectBase
                                                  -import time
                                                   
                                                   
                                                   class DellDNOS6Base(DellPowerConnectBase):
                                                  -    def session_preparation(self):
                                                  +    def session_preparation(self) -> None:
                                                           """Prepare the session after the connection has been established."""
                                                           self.ansi_escape_codes = True
                                                  -        self._test_channel_read()
                                                  +        self._test_channel_read(pattern=r"[>#]")
                                                           self.set_base_prompt()
                                                           self.enable()
                                                           self.set_terminal_width()
                                                           self.disable_paging(command="terminal length 0")
                                                  -        # Clear the read buffer
                                                  -        time.sleep(0.3 * self.global_delay_factor)
                                                  -        self.clear_buffer()
                                                   
                                                       def save_config(
                                                           self,
                                                  -        cmd="copy running-configuration startup-configuration",
                                                  -        confirm=False,
                                                  -        confirm_response="",
                                                  -    ):
                                                  +        cmd: str = "copy running-configuration startup-configuration",
                                                  +        confirm: bool = False,
                                                  +        confirm_response: str = "",
                                                  +    ) -> str:
                                                           """Saves Config"""
                                                           return super().save_config(
                                                               cmd=cmd, confirm=confirm, confirm_response=confirm_response
                                                  @@ -72,7 +68,7 @@ 

                                                  Classes

                                                  class DellDNOS6Base -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                                                  Dell PowerConnect Driver.

                                                  @@ -80,153 +76,123 @@

                                                  Classes

                                                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                                                  -

                                                  ). -:type default_enter: str

                                                  +

                                                  ).

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

                                                  ) -:type response_return: str

                                                  +

                                                  )

                                                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                                               to select smallest of global and specific. Sets default global_delay_factor to .1
                                                  -            (default: False)
                                                  -    :type fast_cli: boolean
                                                  +            (default: True)
                                                   
                                                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                                                  -    :type session_log: str
                                                   
                                                       :param session_log_record_writes: The session log generally only records channel reads due
                                                               to eliminate command duplication due to command echo. You can enable this if you
                                                               want to record both channel reads and channel writes in the log (default: False).
                                                  -    :type session_log_record_writes: boolean
                                                   
                                                       :param session_log_file_mode: "write" or "append" for session_log file mode
                                                               (default: "write")
                                                  -    :type session_log_file_mode: str
                                                   
                                                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                                               (default: False)
                                                  -    :type allow_auto_change: bool
                                                   
                                                       :param encoding: Encoding to be used when writing bytes to the output channel.
                                                               (default: ascii)
                                                  -    :type encoding: str
                                                   
                                                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                                               communication to the target host (default: None).
                                                  -    :type sock: socket
                                                   
                                                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                                               (default: None). Global attribute takes precedence over function `cmd_verify`
                                                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                                                  -    :type global_cmd_verify: bool|None
                                                   
                                                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                                               part of the object creation (default: True).
                                                  -    :type auto_connect: bool
                                                  +
                                                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                                                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                                                  +            eliminated in Netmiko 5.x (default: False).
                                                   
                                          Source code
                                          class DellDNOS6Base(DellPowerConnectBase):
                                          -    def session_preparation(self):
                                          +    def session_preparation(self) -> None:
                                                   """Prepare the session after the connection has been established."""
                                                   self.ansi_escape_codes = True
                                          -        self._test_channel_read()
                                          +        self._test_channel_read(pattern=r"[>#]")
                                                   self.set_base_prompt()
                                                   self.enable()
                                                   self.set_terminal_width()
                                                   self.disable_paging(command="terminal length 0")
                                          -        # Clear the read buffer
                                          -        time.sleep(0.3 * self.global_delay_factor)
                                          -        self.clear_buffer()
                                           
                                               def save_config(
                                                   self,
                                          -        cmd="copy running-configuration startup-configuration",
                                          -        confirm=False,
                                          -        confirm_response="",
                                          -    ):
                                          +        cmd: str = "copy running-configuration startup-configuration",
                                          +        confirm: bool = False,
                                          +        confirm_response: str = "",
                                          +    ) -> str:
                                                   """Saves Config"""
                                                   return super().save_config(
                                                       cmd=cmd, confirm=confirm, confirm_response=confirm_response
                                          @@ -254,10 +220,10 @@ 

                                          Methods

                                          Source code
                                          def save_config(
                                               self,
                                          -    cmd="copy running-configuration startup-configuration",
                                          -    confirm=False,
                                          -    confirm_response="",
                                          -):
                                          +    cmd: str = "copy running-configuration startup-configuration",
                                          +    confirm: bool = False,
                                          +    confirm_response: str = "",
                                          +) -> str:
                                               """Saves Config"""
                                               return super().save_config(
                                                   cmd=cmd, confirm=confirm, confirm_response=confirm_response
                                          @@ -273,9 +239,8 @@ 

                                          Inherited members

                                        • check_enable_mode
                                        • cleanup
                                        • clear_buffer
                                        • -
                                        • close_session_log
                                        • commit
                                        • -
                                        • config_mode
                                        • +
                                        • config_mode
                                        • disable_paging
                                        • disconnect
                                        • enable
                                        • @@ -286,9 +251,9 @@

                                          Inherited members

                                        • is_alive
                                        • normalize_cmd
                                        • normalize_linefeeds
                                        • -
                                        • open_session_log
                                        • paramiko_cleanup
                                        • read_channel
                                        • +
                                        • read_channel_timing
                                        • read_until_pattern
                                        • read_until_prompt
                                        • read_until_prompt_or_pattern
                                        • @@ -299,6 +264,7 @@

                                          Inherited members

                                        • send_command_timing
                                        • send_config_from_file
                                        • send_config_set
                                        • +
                                        • send_multiline
                                        • session_preparation
                                        • set_base_prompt
                                        • set_terminal_width
                                        • @@ -315,7 +281,7 @@

                                          Inherited members

                                          class DellDNOS6SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                                          Dell PowerConnect Driver.

                                          @@ -323,131 +289,104 @@

                                          Inherited members

                                          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                                          -

                                          ). -:type default_enter: str

                                          +

                                          ).

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

                                          ) -:type response_return: str

                                          +

                                          )

                                              :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                                       to select smallest of global and specific. Sets default global_delay_factor to .1
                                          -            (default: False)
                                          -    :type fast_cli: boolean
                                          +            (default: True)
                                           
                                               :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                                          -    :type session_log: str
                                           
                                               :param session_log_record_writes: The session log generally only records channel reads due
                                                       to eliminate command duplication due to command echo. You can enable this if you
                                                       want to record both channel reads and channel writes in the log (default: False).
                                          -    :type session_log_record_writes: boolean
                                           
                                               :param session_log_file_mode: "write" or "append" for session_log file mode
                                                       (default: "write")
                                          -    :type session_log_file_mode: str
                                           
                                               :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                                       (default: False)
                                          -    :type allow_auto_change: bool
                                           
                                               :param encoding: Encoding to be used when writing bytes to the output channel.
                                                       (default: ascii)
                                          -    :type encoding: str
                                           
                                               :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                                       communication to the target host (default: None).
                                          -    :type sock: socket
                                           
                                               :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                                       (default: None). Global attribute takes precedence over function `cmd_verify`
                                                       argument. Value of `None` indicates to use function `cmd_verify` argument.
                                          -    :type global_cmd_verify: bool|None
                                           
                                               :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                                       part of the object creation (default: True).
                                          -    :type auto_connect: bool
                                          +
                                          +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                                          +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                                          +            eliminated in Netmiko 5.x (default: False).
                                           
                          Source code @@ -469,9 +408,8 @@

                          Inherited members

                        • check_enable_mode
                        • cleanup
                        • clear_buffer
                        • -
                        • close_session_log
                        • commit
                        • -
                        • config_mode
                        • +
                        • config_mode
                        • disable_paging
                        • disconnect
                        • enable
                        • @@ -482,9 +420,9 @@

                          Inherited members

                        • is_alive
                        • normalize_cmd
                        • normalize_linefeeds
                        • -
                        • open_session_log
                        • paramiko_cleanup
                        • read_channel
                        • +
                        • read_channel_timing
                        • read_until_pattern
                        • read_until_prompt
                        • read_until_prompt_or_pattern
                        • @@ -496,6 +434,7 @@

                          Inherited members

                        • send_command_timing
                        • send_config_from_file
                        • send_config_set
                        • +
                        • send_multiline
                        • session_preparation
                        • set_base_prompt
                        • set_terminal_width
                        • @@ -512,7 +451,7 @@

                          Inherited members

                          class DellDNOS6Telnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                          Dell PowerConnect Driver.

                          @@ -520,131 +459,104 @@

                          Inherited members

                          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                -

                ). -:type default_enter: str

                +

                ).

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

                ) -:type response_return: str

                +

                )

                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                             to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                +            (default: True)
                 
                     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                 
                     :param session_log_record_writes: The session log generally only records channel reads due
                             to eliminate command duplication due to command echo. You can enable this if you
                             want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                 
                     :param session_log_file_mode: "write" or "append" for session_log file mode
                             (default: "write")
                -    :type session_log_file_mode: str
                 
                     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                             (default: False)
                -    :type allow_auto_change: bool
                 
                     :param encoding: Encoding to be used when writing bytes to the output channel.
                             (default: ascii)
                -    :type encoding: str
                 
                     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                             communication to the target host (default: None).
                -    :type sock: socket
                 
                     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                             (default: None). Global attribute takes precedence over function `cmd_verify`
                             argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                 
                     :param auto_connect: Control whether Netmiko automatically establishes the connection as
                             part of the object creation (default: True).
                -    :type auto_connect: bool
                +
                +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                +            eliminated in Netmiko 5.x (default: False).
                 
                Source code @@ -666,9 +578,8 @@

                Inherited members

              • check_enable_mode
              • cleanup
              • clear_buffer
              • -
              • close_session_log
              • commit
              • -
              • config_mode
              • +
              • config_mode
              • disable_paging
              • disconnect
              • enable
              • @@ -679,9 +590,9 @@

                Inherited members

              • is_alive
              • normalize_cmd
              • normalize_linefeeds
              • -
              • open_session_log
              • paramiko_cleanup
              • read_channel
              • +
              • read_channel_timing
              • read_until_pattern
              • read_until_prompt
              • read_until_prompt_or_pattern
              • @@ -693,6 +604,7 @@

                Inherited members

              • send_command_timing
              • send_config_from_file
              • send_config_set
              • +
              • send_multiline
              • session_preparation
              • set_base_prompt
              • set_terminal_width
              • diff --git a/docs/netmiko/dell/dell_force10_ssh.html b/docs/netmiko/dell/dell_force10_ssh.html index 8d7d9d94f..b78262ad4 100644 --- a/docs/netmiko/dell/dell_force10_ssh.html +++ b/docs/netmiko/dell/dell_force10_ssh.html @@ -32,10 +32,10 @@

                Module netmiko.dell.dell_force10_ssh

                def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -53,7 +53,7 @@

                Classes

                class DellForce10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                Dell Force10 Driver - supports DNOS9.

                @@ -61,131 +61,104 @@

                Classes

                :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                -

                ). -:type default_enter: str

                +

                ).

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

                ) -:type response_return: str

                +

                )

                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                             to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                +            (default: True)
                 
                     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                 
                     :param session_log_record_writes: The session log generally only records channel reads due
                             to eliminate command duplication due to command echo. You can enable this if you
                             want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                 
                     :param session_log_file_mode: "write" or "append" for session_log file mode
                             (default: "write")
                -    :type session_log_file_mode: str
                 
                     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                             (default: False)
                -    :type allow_auto_change: bool
                 
                     :param encoding: Encoding to be used when writing bytes to the output channel.
                             (default: ascii)
                -    :type encoding: str
                 
                     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                             communication to the target host (default: None).
                -    :type sock: socket
                 
                     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                             (default: None). Global attribute takes precedence over function `cmd_verify`
                             argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                 
                     :param auto_connect: Control whether Netmiko automatically establishes the connection as
                             part of the object creation (default: True).
                -    :type auto_connect: bool
                +
                +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                +            eliminated in Netmiko 5.x (default: False).
                 
                Source code @@ -194,10 +167,10 @@

                Classes

                def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -220,10 +193,10 @@

                Methods

                Source code
                def save_config(
                     self,
                -    cmd="copy running-configuration startup-configuration",
                -    confirm=False,
                -    confirm_response="",
                -):
                +    cmd: str = "copy running-configuration startup-configuration",
                +    confirm: bool = False,
                +    confirm_response: str = "",
                +) -> str:
                     """Saves Config"""
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
                @@ -239,9 +212,8 @@ 

                Inherited members

              • check_enable_mode
              • cleanup
              • clear_buffer
              • -
              • close_session_log
              • commit
              • -
              • config_mode
              • +
              • config_mode
              • disable_paging
              • disconnect
              • enable
              • @@ -252,9 +224,9 @@

                Inherited members

              • is_alive
              • normalize_cmd
              • normalize_linefeeds
              • -
              • open_session_log
              • paramiko_cleanup
              • read_channel
              • +
              • read_channel_timing
              • read_until_pattern
              • read_until_prompt
              • read_until_prompt_or_pattern
              • @@ -265,6 +237,7 @@

                Inherited members

              • send_command_timing
              • send_config_from_file
              • send_config_set
              • +
              • send_multiline
              • session_preparation
              • set_base_prompt
              • set_terminal_width
              • diff --git a/docs/netmiko/dell/dell_isilon_ssh.html b/docs/netmiko/dell/dell_isilon_ssh.html index 8aaf4ef7a..97f892aa0 100644 --- a/docs/netmiko/dell/dell_isilon_ssh.html +++ b/docs/netmiko/dell/dell_isilon_ssh.html @@ -22,92 +22,108 @@

                Module netmiko.dell.dell_isilon_ssh

                Source code -
                import time
                +
                from typing import Any, Optional
                +import time
                 import re
                 
                 from netmiko.base_connection import BaseConnection
                 
                 
                 class DellIsilonSSH(BaseConnection):
                +    def session_preparation(self) -> None:
                +        """Prepare the session after the connection has been established."""
                +        self.ansi_escape_codes = True
                +        self._test_channel_read(pattern=r"[#\$]")
                +        self._zsh_mode()
                +        self.find_prompt()
                +        self.set_base_prompt()
                +
                     def set_base_prompt(
                -        self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
                -    ):
                +        self,
                +        pri_prompt_terminator: str = "$",
                +        alt_prompt_terminator: str = "#",
                +        delay_factor: float = 1.0,
                +        pattern: Optional[str] = None,
                +    ) -> str:
                         """Determine base prompt."""
                         return super().set_base_prompt(
                             pri_prompt_terminator=pri_prompt_terminator,
                             alt_prompt_terminator=alt_prompt_terminator,
                             delay_factor=delay_factor,
                +            pattern=pattern,
                         )
                 
                -    def strip_ansi_escape_codes(self, string_buffer):
                +    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
                         """Remove Null code"""
                         output = re.sub(r"\x00", "", string_buffer)
                         return super().strip_ansi_escape_codes(output)
                 
                -    def session_preparation(self):
                -        """Prepare the session after the connection has been established."""
                -        self.ansi_escape_codes = True
                -        self.zsh_mode()
                -        self.find_prompt(delay_factor=1)
                -        self.set_base_prompt()
                -        # Clear the read buffer
                -        time.sleep(0.3 * self.global_delay_factor)
                -        self.clear_buffer()
                -
                -    def zsh_mode(self, delay_factor=1, prompt_terminator="$"):
                +    def _zsh_mode(self, prompt_terminator: str = "$") -> None:
                         """Run zsh command to unify the environment"""
                -        delay_factor = self.select_delay_factor(delay_factor)
                -        self.clear_buffer()
                +        if self.global_delay_factor < 1:
                +            delay_factor = 1.0
                +        else:
                +            delay_factor = self.global_delay_factor
                         command = self.RETURN + "zsh" + self.RETURN
                         self.write_channel(command)
                -        time.sleep(1 * delay_factor)
                -        self.set_prompt()
                +        time.sleep(0.25 * delay_factor)
                +        self._set_prompt(prompt_terminator)
                +        time.sleep(0.25 * delay_factor)
                         self.clear_buffer()
                 
                -    def set_prompt(self, prompt_terminator="$"):
                +    def _set_prompt(self, prompt_terminator: str = "$") -> None:
                         prompt = f"PROMPT='%m{prompt_terminator}'"
                         command = self.RETURN + prompt + self.RETURN
                         self.write_channel(command)
                 
                -    def disable_paging(self, *args, **kwargs):
                +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                         """Isilon doesn't have paging by default."""
                -        pass
                -
                -    def check_enable_mode(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def enable(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def exit_enable_mode(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def check_config_mode(self, check_string="#"):
                -        return super().check_config_mode(check_string=check_string)
                -
                -    def config_mode(self, config_command="sudo su"):
                -        """Attempt to become root."""
                +        return ""
                +
                +    def check_enable_mode(self, check_string: str = "#") -> bool:
                +        return super().check_enable_mode(check_string=check_string)
                +
                +    def enable(
                +        self,
                +        cmd: str = "sudo su",
                +        pattern: str = "ssword",
                +        enable_pattern: Optional[str] = None,
                +        re_flags: int = re.IGNORECASE,
                +    ) -> str:
                         delay_factor = self.select_delay_factor(delay_factor=1)
                         output = ""
                -        if not self.check_config_mode():
                -            output += self.send_command_timing(
                -                config_command, strip_prompt=False, strip_command=False
                +        if not self.check_enable_mode():
                +            output += self._send_command_timing_str(
                +                cmd, strip_prompt=False, strip_command=False
                             )
                -            if "Password:" in output:
                -                output = self.write_channel(self.normalize_cmd(self.secret))
                -            self.set_prompt(prompt_terminator="#")
                +            if re.search(pattern, output, flags=re_flags):
                +                self.write_channel(self.normalize_cmd(self.secret))
                +            output += self.read_until_pattern(pattern=r"#.*$")
                             time.sleep(1 * delay_factor)
                -            self.set_base_prompt()
                -            if not self.check_config_mode():
                -                raise ValueError("Failed to configuration mode")
                +            self._set_prompt(prompt_terminator="#")
                +            if not self.check_enable_mode():
                +                raise ValueError("Failed to enter enable mode")
                         return output
                 
                -    def exit_config_mode(self, exit_config="exit"):
                -        """Exit enable mode."""
                -        return super().exit_config_mode(exit_config=exit_config)
                + def exit_enable_mode(self, exit_command: str = "exit") -> str: + return super().exit_enable_mode(exit_command=exit_command) + + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: + """Use equivalent enable method.""" + return self.check_enable_mode(check_string=check_string) + + def config_mode( + self, + config_command: str = "sudo su", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: + """Use equivalent enable method.""" + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: + """Use equivalent enable method.""" + return self.exit_enable_mode(exit_command=exit_config)
                @@ -121,7 +137,7 @@

                Classes

                class DellIsilonSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                Defines vendor independent methods.

                @@ -130,214 +146,202 @@

                Classes

                :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                -

                ). -:type default_enter: str

                +

                ).

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

                ) -:type response_return: str

                +

                )

                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                             to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                +            (default: True)
                 
                     :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                 
                     :param session_log_record_writes: The session log generally only records channel reads due
                             to eliminate command duplication due to command echo. You can enable this if you
                             want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                 
                     :param session_log_file_mode: "write" or "append" for session_log file mode
                             (default: "write")
                -    :type session_log_file_mode: str
                 
                     :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                             (default: False)
                -    :type allow_auto_change: bool
                 
                     :param encoding: Encoding to be used when writing bytes to the output channel.
                             (default: ascii)
                -    :type encoding: str
                 
                     :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                             communication to the target host (default: None).
                -    :type sock: socket
                 
                     :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                             (default: None). Global attribute takes precedence over function `cmd_verify`
                             argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                 
                     :param auto_connect: Control whether Netmiko automatically establishes the connection as
                             part of the object creation (default: True).
                -    :type auto_connect: bool
                +
                +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                +            eliminated in Netmiko 5.x (default: False).
                 
                Source code
                class DellIsilonSSH(BaseConnection):
                +    def session_preparation(self) -> None:
                +        """Prepare the session after the connection has been established."""
                +        self.ansi_escape_codes = True
                +        self._test_channel_read(pattern=r"[#\$]")
                +        self._zsh_mode()
                +        self.find_prompt()
                +        self.set_base_prompt()
                +
                     def set_base_prompt(
                -        self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
                -    ):
                +        self,
                +        pri_prompt_terminator: str = "$",
                +        alt_prompt_terminator: str = "#",
                +        delay_factor: float = 1.0,
                +        pattern: Optional[str] = None,
                +    ) -> str:
                         """Determine base prompt."""
                         return super().set_base_prompt(
                             pri_prompt_terminator=pri_prompt_terminator,
                             alt_prompt_terminator=alt_prompt_terminator,
                             delay_factor=delay_factor,
                +            pattern=pattern,
                         )
                 
                -    def strip_ansi_escape_codes(self, string_buffer):
                +    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
                         """Remove Null code"""
                         output = re.sub(r"\x00", "", string_buffer)
                         return super().strip_ansi_escape_codes(output)
                 
                -    def session_preparation(self):
                -        """Prepare the session after the connection has been established."""
                -        self.ansi_escape_codes = True
                -        self.zsh_mode()
                -        self.find_prompt(delay_factor=1)
                -        self.set_base_prompt()
                -        # Clear the read buffer
                -        time.sleep(0.3 * self.global_delay_factor)
                -        self.clear_buffer()
                -
                -    def zsh_mode(self, delay_factor=1, prompt_terminator="$"):
                +    def _zsh_mode(self, prompt_terminator: str = "$") -> None:
                         """Run zsh command to unify the environment"""
                -        delay_factor = self.select_delay_factor(delay_factor)
                -        self.clear_buffer()
                +        if self.global_delay_factor < 1:
                +            delay_factor = 1.0
                +        else:
                +            delay_factor = self.global_delay_factor
                         command = self.RETURN + "zsh" + self.RETURN
                         self.write_channel(command)
                -        time.sleep(1 * delay_factor)
                -        self.set_prompt()
                +        time.sleep(0.25 * delay_factor)
                +        self._set_prompt(prompt_terminator)
                +        time.sleep(0.25 * delay_factor)
                         self.clear_buffer()
                 
                -    def set_prompt(self, prompt_terminator="$"):
                +    def _set_prompt(self, prompt_terminator: str = "$") -> None:
                         prompt = f"PROMPT='%m{prompt_terminator}'"
                         command = self.RETURN + prompt + self.RETURN
                         self.write_channel(command)
                 
                -    def disable_paging(self, *args, **kwargs):
                +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                         """Isilon doesn't have paging by default."""
                -        pass
                -
                -    def check_enable_mode(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def enable(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def exit_enable_mode(self, *args, **kwargs):
                -        """No enable mode on Isilon."""
                -        pass
                -
                -    def check_config_mode(self, check_string="#"):
                -        return super().check_config_mode(check_string=check_string)
                -
                -    def config_mode(self, config_command="sudo su"):
                -        """Attempt to become root."""
                +        return ""
                +
                +    def check_enable_mode(self, check_string: str = "#") -> bool:
                +        return super().check_enable_mode(check_string=check_string)
                +
                +    def enable(
                +        self,
                +        cmd: str = "sudo su",
                +        pattern: str = "ssword",
                +        enable_pattern: Optional[str] = None,
                +        re_flags: int = re.IGNORECASE,
                +    ) -> str:
                         delay_factor = self.select_delay_factor(delay_factor=1)
                         output = ""
                -        if not self.check_config_mode():
                -            output += self.send_command_timing(
                -                config_command, strip_prompt=False, strip_command=False
                +        if not self.check_enable_mode():
                +            output += self._send_command_timing_str(
                +                cmd, strip_prompt=False, strip_command=False
                             )
                -            if "Password:" in output:
                -                output = self.write_channel(self.normalize_cmd(self.secret))
                -            self.set_prompt(prompt_terminator="#")
                +            if re.search(pattern, output, flags=re_flags):
                +                self.write_channel(self.normalize_cmd(self.secret))
                +            output += self.read_until_pattern(pattern=r"#.*$")
                             time.sleep(1 * delay_factor)
                -            self.set_base_prompt()
                -            if not self.check_config_mode():
                -                raise ValueError("Failed to configuration mode")
                +            self._set_prompt(prompt_terminator="#")
                +            if not self.check_enable_mode():
                +                raise ValueError("Failed to enter enable mode")
                         return output
                 
                -    def exit_config_mode(self, exit_config="exit"):
                -        """Exit enable mode."""
                -        return super().exit_config_mode(exit_config=exit_config)
                + def exit_enable_mode(self, exit_command: str = "exit") -> str: + return super().exit_enable_mode(exit_command=exit_command) + + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: + """Use equivalent enable method.""" + return self.check_enable_mode(check_string=check_string) + + def config_mode( + self, + config_command: str = "sudo su", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: + """Use equivalent enable method.""" + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: + """Use equivalent enable method.""" + return self.exit_enable_mode(exit_command=exit_config)

      Ancestors

        @@ -345,41 +349,33 @@

        Ancestors

      Methods

      -
      -def check_enable_mode(self, *args, **kwargs) +
      +def check_config_mode(self, check_string='#', pattern='')
      -

      No enable mode on Isilon.

      +

      Use equivalent enable method.

      Source code -
      def check_enable_mode(self, *args, **kwargs):
      -    """No enable mode on Isilon."""
      -    pass
      +
      def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
      +    """Use equivalent enable method."""
      +    return self.check_enable_mode(check_string=check_string)
      -def config_mode(self, config_command='sudo su') +def config_mode(self, config_command='sudo su', pattern='ssword', re_flags=)
      -

      Attempt to become root.

      +

      Use equivalent enable method.

      Source code -
      def config_mode(self, config_command="sudo su"):
      -    """Attempt to become root."""
      -    delay_factor = self.select_delay_factor(delay_factor=1)
      -    output = ""
      -    if not self.check_config_mode():
      -        output += self.send_command_timing(
      -            config_command, strip_prompt=False, strip_command=False
      -        )
      -        if "Password:" in output:
      -            output = self.write_channel(self.normalize_cmd(self.secret))
      -        self.set_prompt(prompt_terminator="#")
      -        time.sleep(1 * delay_factor)
      -        self.set_base_prompt()
      -        if not self.check_config_mode():
      -            raise ValueError("Failed to configuration mode")
      -    return output
      +
      def config_mode(
      +    self,
      +    config_command: str = "sudo su",
      +    pattern: str = "ssword",
      +    re_flags: int = re.IGNORECASE,
      +) -> str:
      +    """Use equivalent enable method."""
      +    return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags)
      @@ -389,45 +385,21 @@

      Methods

      Isilon doesn't have paging by default.

      Source code -
      def disable_paging(self, *args, **kwargs):
      +
      def disable_paging(self, *args: Any, **kwargs: Any) -> str:
           """Isilon doesn't have paging by default."""
      -    pass
      -
      - -
      -def enable(self, *args, **kwargs) -
      -
      -

      No enable mode on Isilon.

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """No enable mode on Isilon."""
      -    pass
      + return ""
    -def exit_config_mode(self, exit_config='exit') -
    -
    -

    Exit enable mode.

    -
    -Source code -
    def exit_config_mode(self, exit_config="exit"):
    -    """Exit enable mode."""
    -    return super().exit_config_mode(exit_config=exit_config)
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) +def exit_config_mode(self, exit_config='exit', pattern='')
    -

    No enable mode on Isilon.

    +

    Use equivalent enable method.

    Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Isilon."""
    -    pass
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
    +    """Use equivalent enable method."""
    +    return self.exit_enable_mode(exit_command=exit_config)
    @@ -437,48 +409,38 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    self.zsh_mode()
    -    self.find_prompt(delay_factor=1)
    -    self.set_base_prompt()
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self._test_channel_read(pattern=r"[#\$]") + self._zsh_mode() + self.find_prompt() + self.set_base_prompt()
    -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

    Determine base prompt.

    Source code
    def set_base_prompt(
    -    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
    -):
    +    self,
    +    pri_prompt_terminator: str = "$",
    +    alt_prompt_terminator: str = "#",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Determine base prompt."""
         return super().set_base_prompt(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             delay_factor=delay_factor,
    +        pattern=pattern,
         )
    -
    -def set_prompt(self, prompt_terminator='$') -
    -
    -
    -
    -Source code -
    def set_prompt(self, prompt_terminator="$"):
    -    prompt = f"PROMPT='%m{prompt_terminator}'"
    -    command = self.RETURN + prompt + self.RETURN
    -    self.write_channel(command)
    -
    -
    def strip_ansi_escape_codes(self, string_buffer)
    @@ -486,49 +448,32 @@

    Methods

    Remove Null code

    Source code -
    def strip_ansi_escape_codes(self, string_buffer):
    +
    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
         """Remove Null code"""
         output = re.sub(r"\x00", "", string_buffer)
         return super().strip_ansi_escape_codes(output)
    -
    -def zsh_mode(self, delay_factor=1, prompt_terminator='$') -
    -
    -

    Run zsh command to unify the environment

    -
    -Source code -
    def zsh_mode(self, delay_factor=1, prompt_terminator="$"):
    -    """Run zsh command to unify the environment"""
    -    delay_factor = self.select_delay_factor(delay_factor)
    -    self.clear_buffer()
    -    command = self.RETURN + "zsh" + self.RETURN
    -    self.write_channel(command)
    -    time.sleep(1 * delay_factor)
    -    self.set_prompt()
    -    self.clear_buffer()
    -
    -

    Inherited members

    • BaseConnection: diff --git a/docs/netmiko/dell/dell_os10_ssh.html b/docs/netmiko/dell/dell_os10_ssh.html index 154e9466a..d0c3732ab 100644 --- a/docs/netmiko/dell/dell_os10_ssh.html +++ b/docs/netmiko/dell/dell_os10_ssh.html @@ -24,7 +24,8 @@

      Module netmiko.dell.dell_os10_ssh

      Source code
      """Dell EMC Networking OS10 Driver - supports dellos10."""
      -
      +from typing import Any, Optional
      +from netmiko.base_connection import BaseConnection
       from netmiko.cisco_base_connection import CiscoSSHConnection
       from netmiko.scp_handler import BaseFileTransfer
       import os
      @@ -36,10 +37,10 @@ 

      Module netmiko.dell.dell_os10_ssh

      def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -51,13 +52,13 @@

      Module netmiko.dell.dell_os10_ssh

      def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/home/admin", - direction="put", - **kwargs, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = "/home/admin", + direction: str = "put", + **kwargs: Any, + ) -> None: super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -68,15 +69,19 @@

      Module netmiko.dell.dell_os10_ssh

      ) self.folder_name = "/config" - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: file_size = line.split()[4] @@ -86,10 +91,10 @@

      Module netmiko.dell.dell_os10_ssh

      else: return int(file_size) - def remote_space_available(self, search_pattern=r"(\d+) bytes free"): + def remote_space_available(self, search_pattern: str = r"(\d+) bytes free") -> int: """Return space available on remote device.""" remote_cmd = f'system "df {self.folder_name}"' - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: space_available = line.split()[-3] @@ -97,40 +102,46 @@

      Module netmiko.dell.dell_os10_ssh

      return int(space_available) @staticmethod - def process_md5(md5_output, pattern=r"(.*) (.*)"): + def process_md5(md5_output: str, pattern: str = r"(.*) (.*)") -> str: return super(DellOS10FileTransfer, DellOS10FileTransfer).process_md5( - md5_output, pattern=r"(.*) (.*)" + md5_output, pattern=pattern ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): - """Calculate remote MD5 and returns the hash. """ + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: + """Calculate remote MD5 and returns the hash.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_md5_cmd = f'system "md5sum {self.file_system}/{remote_file}"' - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5.strip() - def check_file_exists(self, remote_cmd="dir home"): + def check_file_exists(self, remote_cmd: str = "dir home") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"Directory contents .*{}".format(self.dest_file) return bool(re.search(search_string, remote_out, flags=re.DOTALL)) elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("self.direction is set to an invalid value") - def put_file(self): + def put_file(self) -> None: """SCP copy the file from the local system to the remote device.""" destination = f"{self.dest_file}" self.scp_conn.scp_transfer_file(self.source_file, destination) # Must close the SCP connection to get the file written (flush) self.scp_conn.close() - def get_file(self): + def get_file(self) -> None: """SCP copy the file from the remote device to local system.""" source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) @@ -159,13 +170,13 @@

      Classes

      def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/home/admin", - direction="put", - **kwargs, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = "/home/admin", + direction: str = "put", + **kwargs: Any, + ) -> None: super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -176,15 +187,19 @@

      Classes

      ) self.folder_name = "/config" - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: file_size = line.split()[4] @@ -194,10 +209,10 @@

      Classes

      else: return int(file_size) - def remote_space_available(self, search_pattern=r"(\d+) bytes free"): + def remote_space_available(self, search_pattern: str = r"(\d+) bytes free") -> int: """Return space available on remote device.""" remote_cmd = f'system "df {self.folder_name}"' - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: space_available = line.split()[-3] @@ -205,40 +220,46 @@

      Classes

      return int(space_available) @staticmethod - def process_md5(md5_output, pattern=r"(.*) (.*)"): + def process_md5(md5_output: str, pattern: str = r"(.*) (.*)") -> str: return super(DellOS10FileTransfer, DellOS10FileTransfer).process_md5( - md5_output, pattern=r"(.*) (.*)" + md5_output, pattern=pattern ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): - """Calculate remote MD5 and returns the hash. """ + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: + """Calculate remote MD5 and returns the hash.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_md5_cmd = f'system "md5sum {self.file_system}/{remote_file}"' - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5.strip() - def check_file_exists(self, remote_cmd="dir home"): + def check_file_exists(self, remote_cmd: str = "dir home") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"Directory contents .*{}".format(self.dest_file) return bool(re.search(search_string, remote_out, flags=re.DOTALL)) elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("self.direction is set to an invalid value") - def put_file(self): + def put_file(self) -> None: """SCP copy the file from the local system to the remote device.""" destination = f"{self.dest_file}" self.scp_conn.scp_transfer_file(self.source_file, destination) # Must close the SCP connection to get the file written (flush) self.scp_conn.close() - def get_file(self): + def get_file(self) -> None: """SCP copy the file from the remote device to local system.""" source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) @@ -257,15 +278,19 @@

      Methods

      Calculate remote MD5 and returns the hash.

      Source code -
      def remote_md5(self, base_cmd="verify /md5", remote_file=None):
      -    """Calculate remote MD5 and returns the hash. """
      +
      def remote_md5(
      +    self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None
      +) -> str:
      +    """Calculate remote MD5 and returns the hash."""
           if remote_file is None:
               if self.direction == "put":
                   remote_file = self.dest_file
               elif self.direction == "get":
                   remote_file = self.source_file
      +        else:
      +            raise ValueError("self.direction is set to an invalid value")
           remote_md5_cmd = f'system "md5sum {self.file_system}/{remote_file}"'
      -    dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500)
      +    dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300)
           dest_md5 = self.process_md5(dest_md5)
           return dest_md5.strip()
      @@ -297,7 +322,7 @@

      Inherited members

      class DellOS10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Dell EMC Networking OS10 Driver - supports dellos10.

      @@ -305,131 +330,104 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -438,10 +436,10 @@

      Inherited members

      def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -464,10 +462,10 @@

      Methods

      Source code
      def save_config(
           self,
      -    cmd="copy running-configuration startup-configuration",
      -    confirm=False,
      -    confirm_response="",
      -):
      +    cmd: str = "copy running-configuration startup-configuration",
      +    confirm: bool = False,
      +    confirm_response: str = "",
      +) -> str:
           """Saves Config"""
           return super().save_config(
               cmd=cmd, confirm=confirm, confirm_response=confirm_response
      @@ -483,9 +481,8 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • -
    • config_mode
    • +
    • config_mode
    • disable_paging
    • disconnect
    • enable
    • @@ -496,9 +493,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -509,6 +506,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • diff --git a/docs/netmiko/dell/dell_powerconnect.html b/docs/netmiko/dell/dell_powerconnect.html index a04d1d874..2080d71e4 100644 --- a/docs/netmiko/dell/dell_powerconnect.html +++ b/docs/netmiko/dell/dell_powerconnect.html @@ -24,52 +24,55 @@

      Module netmiko.dell.dell_powerconnect

      Source code
      """Dell PowerConnect Driver."""
      +from typing import Optional
       from paramiko import SSHClient
       import time
       from os import path
      +from netmiko.ssh_auth import SSHClient_noauth
       from netmiko.cisco_base_connection import CiscoBaseConnection
       
       
      -class SSHClient_noauth(SSHClient):
      -    def _auth(self, username, *args):
      -        self._transport.auth_none(username)
      -        return
      -
      -
       class DellPowerConnectBase(CiscoBaseConnection):
           """Dell PowerConnect Driver."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self.ansi_escape_codes = True
      -        self._test_channel_read()
      +        self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
               self.enable()
               self.disable_paging(command="terminal datadump")
      -        # Clear the read buffer
      -        time.sleep(0.3 * self.global_delay_factor)
      -        self.clear_buffer()
       
           def set_base_prompt(
      -        self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
      -    ):
      +        self,
      +        pri_prompt_terminator: str = ">",
      +        alt_prompt_terminator: str = "#",
      +        delay_factor: float = 1.0,
      +        pattern: Optional[str] = None,
      +    ) -> str:
               """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
               prompt = super().set_base_prompt(
                   pri_prompt_terminator=pri_prompt_terminator,
                   alt_prompt_terminator=alt_prompt_terminator,
                   delay_factor=delay_factor,
      +            pattern=pattern,
               )
               prompt = prompt.strip()
               self.base_prompt = prompt
               return self.base_prompt
       
      -    def check_config_mode(self, check_string="(config)#"):
      +    def check_config_mode(
      +        self, check_string: str = "(config)#", pattern: str = ""
      +    ) -> bool:
               """Checks if the device is in configuration mode"""
      -        return super().check_config_mode(check_string=check_string)
      +        return super().check_config_mode(check_string=check_string, pattern=pattern)
       
      -    def config_mode(self, config_command="config"):
      -        """Enter configuration mode."""
      -        return super().config_mode(config_command=config_command)
      +    def config_mode(
      +        self, config_command: str = "config", pattern: str = "", re_flags: int = 0
      +    ) -> str:
      +        return super().config_mode(
      +            config_command=config_command, pattern=pattern, re_flags=re_flags
      +        )
       
       
       class DellPowerConnectSSH(DellPowerConnectBase):
      @@ -79,13 +82,14 @@ 

      Module netmiko.dell.dell_powerconnect

      If we use login/password, the ssh server use the (none) auth mechanism. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection. See base_connection.py file for any updates. """ # Create instance of SSHClient object # If user does not provide SSH key, we use noauth + remote_conn_pre: SSHClient if not self.use_keys: remote_conn_pre = SSHClient_noauth() else: @@ -101,7 +105,7 @@

      Module netmiko.dell.dell_powerconnect

      remote_conn_pre.set_missing_host_key_policy(self.key_policy) return remote_conn_pre - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """ Powerconnect presents with the following on login @@ -117,8 +121,10 @@

      Module netmiko.dell.dell_powerconnect

      output = self.read_channel() if output: if "User Name:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -145,7 +151,7 @@

      Classes

      class DellPowerConnectBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Dell PowerConnect Driver.

      @@ -153,168 +159,148 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class DellPowerConnectBase(CiscoBaseConnection):
           """Dell PowerConnect Driver."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self.ansi_escape_codes = True
      -        self._test_channel_read()
      +        self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
               self.enable()
               self.disable_paging(command="terminal datadump")
      -        # Clear the read buffer
      -        time.sleep(0.3 * self.global_delay_factor)
      -        self.clear_buffer()
       
           def set_base_prompt(
      -        self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
      -    ):
      +        self,
      +        pri_prompt_terminator: str = ">",
      +        alt_prompt_terminator: str = "#",
      +        delay_factor: float = 1.0,
      +        pattern: Optional[str] = None,
      +    ) -> str:
               """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
               prompt = super().set_base_prompt(
                   pri_prompt_terminator=pri_prompt_terminator,
                   alt_prompt_terminator=alt_prompt_terminator,
                   delay_factor=delay_factor,
      +            pattern=pattern,
               )
               prompt = prompt.strip()
               self.base_prompt = prompt
               return self.base_prompt
       
      -    def check_config_mode(self, check_string="(config)#"):
      +    def check_config_mode(
      +        self, check_string: str = "(config)#", pattern: str = ""
      +    ) -> bool:
               """Checks if the device is in configuration mode"""
      -        return super().check_config_mode(check_string=check_string)
      -
      -    def config_mode(self, config_command="config"):
      -        """Enter configuration mode."""
      -        return super().config_mode(config_command=config_command)
      + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, config_command: str = "config", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )

      Ancestors

        @@ -330,27 +316,17 @@

        Subclasses

        Methods

        -def check_config_mode(self, check_string='(config)#') +def check_config_mode(self, check_string='(config)#', pattern='')

        Checks if the device is in configuration mode

        Source code -
        def check_config_mode(self, check_string="(config)#"):
        +
        def check_config_mode(
        +    self, check_string: str = "(config)#", pattern: str = ""
        +) -> bool:
             """Checks if the device is in configuration mode"""
        -    return super().check_config_mode(check_string=check_string)
        -
        -
        -
        -def config_mode(self, config_command='config') -
        -
        -

        Enter configuration mode.

        -
        -Source code -
        def config_mode(self, config_command="config"):
        -    """Enter configuration mode."""
        -    return super().config_mode(config_command=config_command)
        + return super().check_config_mode(check_string=check_string, pattern=pattern)
    @@ -360,33 +336,35 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    self._test_channel_read()
    +    self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
         self.enable()
    -    self.disable_paging(command="terminal datadump")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="terminal datadump")
    -def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

    Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

    Source code
    def set_base_prompt(
    -    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
    -):
    +    self,
    +    pri_prompt_terminator: str = ">",
    +    alt_prompt_terminator: str = "#",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
         prompt = super().set_base_prompt(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             delay_factor=delay_factor,
    +        pattern=pattern,
         )
         prompt = prompt.strip()
         self.base_prompt = prompt
    @@ -401,8 +379,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -413,9 +391,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -427,6 +405,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_terminal_width
  • special_login_handler
  • strip_ansi_escape_codes
  • @@ -441,7 +420,7 @@

    Inherited members

    class DellPowerConnectSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Driver.

    @@ -451,131 +430,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -586,13 +538,14 @@

    Inherited members

    If we use login/password, the ssh server use the (none) auth mechanism. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection. See base_connection.py file for any updates. """ # Create instance of SSHClient object # If user does not provide SSH key, we use noauth + remote_conn_pre: SSHClient if not self.use_keys: remote_conn_pre = SSHClient_noauth() else: @@ -608,7 +561,7 @@

    Inherited members

    remote_conn_pre.set_missing_host_key_policy(self.key_policy) return remote_conn_pre - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """ Powerconnect presents with the following on login @@ -624,8 +577,10 @@

    Inherited members

    output = self.read_channel() if output: if "User Name:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -643,7 +598,7 @@

    Ancestors

    Methods

    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Powerconnect presents with the following on login

    @@ -651,7 +606,7 @@

    Methods

    Password: ****

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """
         Powerconnect presents with the following on login
     
    @@ -667,8 +622,10 @@ 

    Methods

    output = self.read_channel() if output: if "User Name:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -687,9 +644,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -700,9 +656,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -714,6 +670,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -729,7 +686,7 @@

    Inherited members

    class DellPowerConnectTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Telnet Driver.

    @@ -737,131 +694,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -884,9 +814,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -897,9 +826,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -911,6 +840,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -925,42 +855,6 @@

    Inherited members

    -
    -class SSHClient_noauth -
    -
    -

    A high-level representation of a session with an SSH server. -This class -wraps .Transport, .Channel, and .SFTPClient to take care of most -aspects of authenticating and opening channels. -A typical use case is::

    -
    client = SSHClient()
    -client.load_system_host_keys()
    -client.connect('ssh.example.com')
    -stdin, stdout, stderr = client.exec_command('ls -l')
    -
    -

    You may pass in explicit overrides for authentication and server host key -checking. -The default mechanism is to try to use local key files or an -SSH agent (if one is running).

    -

    Instances of this class may be used as context managers.

    -
    -

    Added in version: 1.6

    -
    -

    Create a new SSHClient.

    -
    -Source code -
    class SSHClient_noauth(SSHClient):
    -    def _auth(self, username, *args):
    -        self._transport.auth_none(username)
    -        return
    -
    -

    Ancestors

    -
      -
    • paramiko.client.SSHClient
    • -
    • paramiko.util.ClosingContextManager
    • -
    -
    @@ -981,7 +875,6 @@

    Index

    DellPowerConnectBase

    @@ -995,9 +888,6 @@

    DellPowerConnectTelnet

    -
  • -

    SSHClient_noauth

    -
  • diff --git a/docs/netmiko/dell/dell_sonic_ssh.html b/docs/netmiko/dell/dell_sonic_ssh.html new file mode 100644 index 000000000..1e4a7b507 --- /dev/null +++ b/docs/netmiko/dell/dell_sonic_ssh.html @@ -0,0 +1,329 @@ + + + + + + +netmiko.dell.dell_sonic_ssh API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.dell.dell_sonic_ssh

    +
    +
    +

    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution by Dell Technologies Driver +- supports dellenterprisesonic.

    +
    +Source code +
    """
    +Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution by Dell Technologies Driver
    +- supports dellenterprisesonic.
    +"""
    +from netmiko.no_enable import NoEnable
    +from netmiko.cisco_base_connection import CiscoSSHConnection
    +from netmiko import log
    +
    +
    +class DellSonicSSH(NoEnable, CiscoSSHConnection):
    +    """
    +    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution
    +    by Dell Technologies Driver - supports dellenterprisesonic.
    +    """
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>$#]")
    +        self._enter_shell()
    +        self.disable_paging()
    +        self.set_base_prompt(alt_prompt_terminator="$")
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "configure terminal",
    +        pattern: str = r"\#",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def _enter_shell(self) -> str:
    +        """Enter the sonic-cli Shell."""
    +        log.debug("Enter sonic-cli Shell.")
    +        return self._send_command_str("sonic-cli", expect_string=r"\#")
    +
    +    def _return_cli(self) -> str:
    +        """Return to the CLI."""
    +        return self._send_command_str("exit", expect_string=r"\$")
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class DellSonicSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution +by Dell Technologies Driver - supports dellenterprisesonic.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class DellSonicSSH(NoEnable, CiscoSSHConnection):
    +    """
    +    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution
    +    by Dell Technologies Driver - supports dellenterprisesonic.
    +    """
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>$#]")
    +        self._enter_shell()
    +        self.disable_paging()
    +        self.set_base_prompt(alt_prompt_terminator="$")
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "configure terminal",
    +        pattern: str = r"\#",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def _enter_shell(self) -> str:
    +        """Enter the sonic-cli Shell."""
    +        log.debug("Enter sonic-cli Shell.")
    +        return self._send_command_str("sonic-cli", expect_string=r"\#")
    +
    +    def _return_cli(self) -> str:
    +        """Return to the CLI."""
    +        return self._send_command_str("exit", expect_string=r"\$")
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def session_preparation(self) +
    +
    +

    Prepare the session after the connection has been established.

    +
    +Source code +
    def session_preparation(self) -> None:
    +    """Prepare the session after the connection has been established."""
    +    self._test_channel_read(pattern=r"[>$#]")
    +    self._enter_shell()
    +    self.disable_paging()
    +    self.set_base_prompt(alt_prompt_terminator="$")
    +
    +
    +
    +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/dell/index.html b/docs/netmiko/dell/index.html index 86aabe5e6..fb4385e7d 100644 --- a/docs/netmiko/dell/index.html +++ b/docs/netmiko/dell/index.html @@ -26,6 +26,7 @@

    Module netmiko.dell

    from netmiko.dell.dell_dnos6 import DellDNOS6Telnet from netmiko.dell.dell_force10_ssh import DellForce10SSH from netmiko.dell.dell_os10_ssh import DellOS10SSH, DellOS10FileTransfer +from netmiko.dell.dell_sonic_ssh import DellSonicSSH from netmiko.dell.dell_powerconnect import DellPowerConnectSSH from netmiko.dell.dell_powerconnect import DellPowerConnectTelnet from netmiko.dell.dell_isilon_ssh import DellIsilonSSH @@ -35,6 +36,7 @@

    Module netmiko.dell

    "DellPowerConnectSSH", "DellPowerConnectTelnet", "DellOS10SSH", + "DellSonicSSH", "DellOS10FileTransfer", "DellIsilonSSH", "DellDNOS6SSH", @@ -65,6 +67,11 @@

    Sub-modules

    Dell PowerConnect Driver.

    +
    netmiko.dell.dell_sonic_ssh
    +
    +

    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution by Dell Technologies Driver +- supports dellenterprisesonic.

    +
    @@ -76,7 +83,7 @@

    Classes

    class DellDNOS6SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Driver.

    @@ -84,131 +91,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -230,9 +210,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -243,9 +222,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -257,6 +236,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -273,7 +253,7 @@

    Inherited members

    class DellDNOS6Telnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Driver.

    @@ -281,131 +261,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -427,9 +380,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -440,9 +392,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -454,6 +406,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -470,7 +423,7 @@

    Inherited members

    class DellForce10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell Force10 Driver - supports DNOS9.

    @@ -478,131 +431,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -611,10 +537,10 @@

    Inherited members

    def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -637,10 +563,10 @@

    Methods

    Source code
    def save_config(
         self,
    -    cmd="copy running-configuration startup-configuration",
    -    confirm=False,
    -    confirm_response="",
    -):
    +    cmd: str = "copy running-configuration startup-configuration",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -656,9 +582,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -669,9 +594,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -682,6 +607,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -698,7 +624,7 @@

    Inherited members

    class DellIsilonSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Defines vendor independent methods.

    @@ -707,214 +633,202 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class DellIsilonSSH(BaseConnection):
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self.ansi_escape_codes = True
    +        self._test_channel_read(pattern=r"[#\$]")
    +        self._zsh_mode()
    +        self.find_prompt()
    +        self.set_base_prompt()
    +
         def set_base_prompt(
    -        self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
    -    ):
    +        self,
    +        pri_prompt_terminator: str = "$",
    +        alt_prompt_terminator: str = "#",
    +        delay_factor: float = 1.0,
    +        pattern: Optional[str] = None,
    +    ) -> str:
             """Determine base prompt."""
             return super().set_base_prompt(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 delay_factor=delay_factor,
    +            pattern=pattern,
             )
     
    -    def strip_ansi_escape_codes(self, string_buffer):
    +    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
             """Remove Null code"""
             output = re.sub(r"\x00", "", string_buffer)
             return super().strip_ansi_escape_codes(output)
     
    -    def session_preparation(self):
    -        """Prepare the session after the connection has been established."""
    -        self.ansi_escape_codes = True
    -        self.zsh_mode()
    -        self.find_prompt(delay_factor=1)
    -        self.set_base_prompt()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def zsh_mode(self, delay_factor=1, prompt_terminator="$"):
    +    def _zsh_mode(self, prompt_terminator: str = "$") -> None:
             """Run zsh command to unify the environment"""
    -        delay_factor = self.select_delay_factor(delay_factor)
    -        self.clear_buffer()
    +        if self.global_delay_factor < 1:
    +            delay_factor = 1.0
    +        else:
    +            delay_factor = self.global_delay_factor
             command = self.RETURN + "zsh" + self.RETURN
             self.write_channel(command)
    -        time.sleep(1 * delay_factor)
    -        self.set_prompt()
    +        time.sleep(0.25 * delay_factor)
    +        self._set_prompt(prompt_terminator)
    +        time.sleep(0.25 * delay_factor)
             self.clear_buffer()
     
    -    def set_prompt(self, prompt_terminator="$"):
    +    def _set_prompt(self, prompt_terminator: str = "$") -> None:
             prompt = f"PROMPT='%m{prompt_terminator}'"
             command = self.RETURN + prompt + self.RETURN
             self.write_channel(command)
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Isilon doesn't have paging by default."""
    -        pass
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Isilon."""
    -        pass
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on Isilon."""
    -        pass
    +        return ""
     
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Isilon."""
    -        pass
    +    def check_enable_mode(self, check_string: str = "#") -> bool:
    +        return super().check_enable_mode(check_string=check_string)
     
    -    def check_config_mode(self, check_string="#"):
    -        return super().check_config_mode(check_string=check_string)
    -
    -    def config_mode(self, config_command="sudo su"):
    -        """Attempt to become root."""
    +    def enable(
    +        self,
    +        cmd: str = "sudo su",
    +        pattern: str = "ssword",
    +        enable_pattern: Optional[str] = None,
    +        re_flags: int = re.IGNORECASE,
    +    ) -> str:
             delay_factor = self.select_delay_factor(delay_factor=1)
             output = ""
    -        if not self.check_config_mode():
    -            output += self.send_command_timing(
    -                config_command, strip_prompt=False, strip_command=False
    +        if not self.check_enable_mode():
    +            output += self._send_command_timing_str(
    +                cmd, strip_prompt=False, strip_command=False
                 )
    -            if "Password:" in output:
    -                output = self.write_channel(self.normalize_cmd(self.secret))
    -            self.set_prompt(prompt_terminator="#")
    +            if re.search(pattern, output, flags=re_flags):
    +                self.write_channel(self.normalize_cmd(self.secret))
    +            output += self.read_until_pattern(pattern=r"#.*$")
                 time.sleep(1 * delay_factor)
    -            self.set_base_prompt()
    -            if not self.check_config_mode():
    -                raise ValueError("Failed to configuration mode")
    +            self._set_prompt(prompt_terminator="#")
    +            if not self.check_enable_mode():
    +                raise ValueError("Failed to enter enable mode")
             return output
     
    -    def exit_config_mode(self, exit_config="exit"):
    -        """Exit enable mode."""
    -        return super().exit_config_mode(exit_config=exit_config)
    + def exit_enable_mode(self, exit_command: str = "exit") -> str: + return super().exit_enable_mode(exit_command=exit_command) + + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: + """Use equivalent enable method.""" + return self.check_enable_mode(check_string=check_string) + + def config_mode( + self, + config_command: str = "sudo su", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: + """Use equivalent enable method.""" + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: + """Use equivalent enable method.""" + return self.exit_enable_mode(exit_command=exit_config)

    Ancestors

      @@ -922,41 +836,33 @@

      Ancestors

    Methods

    -
    -def check_enable_mode(self, *args, **kwargs) +
    +def check_config_mode(self, check_string='#', pattern='')
    -

    No enable mode on Isilon.

    +

    Use equivalent enable method.

    Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Isilon."""
    -    pass
    +
    def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
    +    """Use equivalent enable method."""
    +    return self.check_enable_mode(check_string=check_string)
    -def config_mode(self, config_command='sudo su') +def config_mode(self, config_command='sudo su', pattern='ssword', re_flags=)
    -

    Attempt to become root.

    +

    Use equivalent enable method.

    Source code -
    def config_mode(self, config_command="sudo su"):
    -    """Attempt to become root."""
    -    delay_factor = self.select_delay_factor(delay_factor=1)
    -    output = ""
    -    if not self.check_config_mode():
    -        output += self.send_command_timing(
    -            config_command, strip_prompt=False, strip_command=False
    -        )
    -        if "Password:" in output:
    -            output = self.write_channel(self.normalize_cmd(self.secret))
    -        self.set_prompt(prompt_terminator="#")
    -        time.sleep(1 * delay_factor)
    -        self.set_base_prompt()
    -        if not self.check_config_mode():
    -            raise ValueError("Failed to configuration mode")
    -    return output
    +
    def config_mode(
    +    self,
    +    config_command: str = "sudo su",
    +    pattern: str = "ssword",
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
    +    """Use equivalent enable method."""
    +    return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags)
    @@ -966,45 +872,21 @@

    Methods

    Isilon doesn't have paging by default.

    Source code -
    def disable_paging(self, *args, **kwargs):
    +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
         """Isilon doesn't have paging by default."""
    -    pass
    -
    - -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on Isilon.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on Isilon."""
    -    pass
    + return ""
    -def exit_config_mode(self, exit_config='exit') -
    -
    -

    Exit enable mode.

    -
    -Source code -
    def exit_config_mode(self, exit_config="exit"):
    -    """Exit enable mode."""
    -    return super().exit_config_mode(exit_config=exit_config)
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) +def exit_config_mode(self, exit_config='exit', pattern='')
    -

    No enable mode on Isilon.

    +

    Use equivalent enable method.

    Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Isilon."""
    -    pass
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str:
    +    """Use equivalent enable method."""
    +    return self.exit_enable_mode(exit_command=exit_config)
    @@ -1014,48 +896,38 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    self.zsh_mode()
    -    self.find_prompt(delay_factor=1)
    -    self.set_base_prompt()
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self._test_channel_read(pattern=r"[#\$]") + self._zsh_mode() + self.find_prompt() + self.set_base_prompt()
    -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

    Determine base prompt.

    Source code
    def set_base_prompt(
    -    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
    -):
    +    self,
    +    pri_prompt_terminator: str = "$",
    +    alt_prompt_terminator: str = "#",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Determine base prompt."""
         return super().set_base_prompt(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             delay_factor=delay_factor,
    +        pattern=pattern,
         )
    -
    -def set_prompt(self, prompt_terminator='$') -
    -
    -
    -
    -Source code -
    def set_prompt(self, prompt_terminator="$"):
    -    prompt = f"PROMPT='%m{prompt_terminator}'"
    -    command = self.RETURN + prompt + self.RETURN
    -    self.write_channel(command)
    -
    -
    def strip_ansi_escape_codes(self, string_buffer)
    @@ -1063,49 +935,32 @@

    Methods

    Remove Null code

    Source code -
    def strip_ansi_escape_codes(self, string_buffer):
    +
    def strip_ansi_escape_codes(self, string_buffer: str) -> str:
         """Remove Null code"""
         output = re.sub(r"\x00", "", string_buffer)
         return super().strip_ansi_escape_codes(output)
    -
    -def zsh_mode(self, delay_factor=1, prompt_terminator='$') -
    -
    -

    Run zsh command to unify the environment

    -
    -Source code -
    def zsh_mode(self, delay_factor=1, prompt_terminator="$"):
    -    """Run zsh command to unify the environment"""
    -    delay_factor = self.select_delay_factor(delay_factor)
    -    self.clear_buffer()
    -    command = self.RETURN + "zsh" + self.RETURN
    -    self.write_channel(command)
    -    time.sleep(1 * delay_factor)
    -    self.set_prompt()
    -    self.clear_buffer()
    -
    -

    Inherited members

    • BaseConnection:
        -
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1117,6 +972,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_terminal_width
      • special_login_handler
      • strip_backspaces
      • @@ -1141,13 +997,13 @@

        Inherited members

        def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/home/admin", - direction="put", - **kwargs, - ): + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = "/home/admin", + direction: str = "put", + **kwargs: Any, + ) -> None: super().__init__( ssh_conn=ssh_conn, source_file=source_file, @@ -1158,15 +1014,19 @@

        Inherited members

        ) self.folder_name = "/config" - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: file_size = line.split()[4] @@ -1176,10 +1036,10 @@

        Inherited members

        else: return int(file_size) - def remote_space_available(self, search_pattern=r"(\d+) bytes free"): + def remote_space_available(self, search_pattern: str = r"(\d+) bytes free") -> int: """Return space available on remote device.""" remote_cmd = f'system "df {self.folder_name}"' - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: space_available = line.split()[-3] @@ -1187,40 +1047,46 @@

        Inherited members

        return int(space_available) @staticmethod - def process_md5(md5_output, pattern=r"(.*) (.*)"): + def process_md5(md5_output: str, pattern: str = r"(.*) (.*)") -> str: return super(DellOS10FileTransfer, DellOS10FileTransfer).process_md5( - md5_output, pattern=r"(.*) (.*)" + md5_output, pattern=pattern ) - def remote_md5(self, base_cmd="verify /md5", remote_file=None): - """Calculate remote MD5 and returns the hash. """ + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: + """Calculate remote MD5 and returns the hash.""" if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("self.direction is set to an invalid value") remote_md5_cmd = f'system "md5sum {self.file_system}/{remote_file}"' - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5.strip() - def check_file_exists(self, remote_cmd="dir home"): + def check_file_exists(self, remote_cmd: str = "dir home") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"Directory contents .*{}".format(self.dest_file) return bool(re.search(search_string, remote_out, flags=re.DOTALL)) elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("self.direction is set to an invalid value") - def put_file(self): + def put_file(self) -> None: """SCP copy the file from the local system to the remote device.""" destination = f"{self.dest_file}" self.scp_conn.scp_transfer_file(self.source_file, destination) # Must close the SCP connection to get the file written (flush) self.scp_conn.close() - def get_file(self): + def get_file(self) -> None: """SCP copy the file from the remote device to local system.""" source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) @@ -1239,15 +1105,19 @@

        Methods

        Calculate remote MD5 and returns the hash.

        Source code -
        def remote_md5(self, base_cmd="verify /md5", remote_file=None):
        -    """Calculate remote MD5 and returns the hash. """
        +
        def remote_md5(
        +    self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None
        +) -> str:
        +    """Calculate remote MD5 and returns the hash."""
             if remote_file is None:
                 if self.direction == "put":
                     remote_file = self.dest_file
                 elif self.direction == "get":
                     remote_file = self.source_file
        +        else:
        +            raise ValueError("self.direction is set to an invalid value")
             remote_md5_cmd = f'system "md5sum {self.file_system}/{remote_file}"'
        -    dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500)
        +    dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300)
             dest_md5 = self.process_md5(dest_md5)
             return dest_md5.strip()
        @@ -1279,7 +1149,7 @@

        Inherited members

        class DellOS10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Dell EMC Networking OS10 Driver - supports dellos10.

        @@ -1287,131 +1157,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1420,10 +1263,10 @@

    Inherited members

    def save_config( self, - cmd="copy running-configuration startup-configuration", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-configuration startup-configuration", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -1446,10 +1289,10 @@

    Methods

    Source code
    def save_config(
         self,
    -    cmd="copy running-configuration startup-configuration",
    -    confirm=False,
    -    confirm_response="",
    -):
    +    cmd: str = "copy running-configuration startup-configuration",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -1465,9 +1308,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1478,9 +1320,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1491,6 +1333,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1507,7 +1350,7 @@

    Inherited members

    class DellPowerConnectSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Driver.

    @@ -1517,131 +1360,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1652,13 +1468,14 @@

    Inherited members

    If we use login/password, the ssh server use the (none) auth mechanism. """ - def _build_ssh_client(self): + def _build_ssh_client(self) -> SSHClient: """Prepare for Paramiko SSH connection. See base_connection.py file for any updates. """ # Create instance of SSHClient object # If user does not provide SSH key, we use noauth + remote_conn_pre: SSHClient if not self.use_keys: remote_conn_pre = SSHClient_noauth() else: @@ -1674,7 +1491,7 @@

    Inherited members

    remote_conn_pre.set_missing_host_key_policy(self.key_policy) return remote_conn_pre - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """ Powerconnect presents with the following on login @@ -1690,8 +1507,10 @@

    Inherited members

    output = self.read_channel() if output: if "User Name:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -1709,7 +1528,7 @@

    Ancestors

    Methods

    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Powerconnect presents with the following on login

    @@ -1717,7 +1536,7 @@

    Methods

    Password: ****

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """
         Powerconnect presents with the following on login
     
    @@ -1733,8 +1552,10 @@ 

    Methods

    output = self.read_channel() if output: if "User Name:" in output: + assert isinstance(self.username, str) self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert isinstance(self.password, str) self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -1753,9 +1574,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1766,9 +1586,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1780,6 +1600,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1795,7 +1616,7 @@

    Inherited members

    class DellPowerConnectTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Dell PowerConnect Telnet Driver.

    @@ -1803,131 +1624,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1950,9 +1744,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1963,9 +1756,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1977,6 +1770,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1991,6 +1785,223 @@

    Inherited members

    +
    +class DellSonicSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
    +
    +

    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution +by Dell Technologies Driver - supports dellenterprisesonic.

    +
        Initialize attributes for establishing connection to target device.
    +
    +    :param ip: IP address of target device. Not required if `host` is
    +        provided.
    +
    +    :param host: Hostname of target device. Not required if `ip` is
    +            provided.
    +
    +    :param username: Username to authenticate against target device if
    +            required.
    +
    +    :param password: Password to authenticate against target device if
    +            required.
    +
    +    :param secret: The enable password if target device requires one.
    +
    +    :param port: The destination port used to connect to the target
    +            device.
    +
    +    :param device_type: Class selection based on device type.
    +
    +    :param verbose: Enable additional messages to standard output.
    +
    +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    +
    +    :param use_keys: Connect to target device using SSH keys.
    +
    +    :param key_file: Filename path of the SSH key file to use.
    +
    +    :param pkey: SSH key object to use.
    +
    +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    +            decryption if not specified.
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
    +
    +    :param allow_agent: Enable use of SSH key-agent.
    +
    +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    +            means unknown SSH host keys will be accepted).
    +
    +    :param system_host_keys: Load host keys from the users known_hosts file.
    +
    +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    +            alt_key_file.
    +
    +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    +
    +    :param ssh_config_file: File name of OpenSSH configuration file.
    +
    +    :param timeout: Connection timeout.
    +
    +    :param session_timeout: Set a timeout for parallel requests.
    +
    +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    +
    +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    +
    +    :param 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).
    +
    +    :param default_enter: Character(s) to send to correspond to enter key (default:
    +
    +

    ).

    +
        :param response_return: Character(s) to use in normalized return data to represent
    +            enter key (default:
    +
    +

    )

    +
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    +            to select smallest of global and specific. Sets default global_delay_factor to .1
    +            (default: True)
    +
    +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    +
    +    :param session_log_record_writes: The session log generally only records channel reads due
    +            to eliminate command duplication due to command echo. You can enable this if you
    +            want to record both channel reads and channel writes in the log (default: False).
    +
    +    :param session_log_file_mode: "write" or "append" for session_log file mode
    +            (default: "write")
    +
    +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    +            (default: False)
    +
    +    :param encoding: Encoding to be used when writing bytes to the output channel.
    +            (default: ascii)
    +
    +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    +            communication to the target host (default: None).
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
    +
    +
    +Source code +
    class DellSonicSSH(NoEnable, CiscoSSHConnection):
    +    """
    +    Dell EMC PowerSwitch platforms running Enterprise SONiC Distribution
    +    by Dell Technologies Driver - supports dellenterprisesonic.
    +    """
    +
    +    def session_preparation(self) -> None:
    +        """Prepare the session after the connection has been established."""
    +        self._test_channel_read(pattern=r"[>$#]")
    +        self._enter_shell()
    +        self.disable_paging()
    +        self.set_base_prompt(alt_prompt_terminator="$")
    +
    +    def config_mode(
    +        self,
    +        config_command: str = "configure terminal",
    +        pattern: str = r"\#",
    +        re_flags: int = 0,
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
    +
    +    def _enter_shell(self) -> str:
    +        """Enter the sonic-cli Shell."""
    +        log.debug("Enter sonic-cli Shell.")
    +        return self._send_command_str("sonic-cli", expect_string=r"\#")
    +
    +    def _return_cli(self) -> str:
    +        """Return to the CLI."""
    +        return self._send_command_str("exit", expect_string=r"\$")
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def session_preparation(self) +
    +
    +

    Prepare the session after the connection has been established.

    +
    +Source code +
    def session_preparation(self) -> None:
    +    """Prepare the session after the connection has been established."""
    +    self._test_channel_read(pattern=r"[>$#]")
    +    self._enter_shell()
    +    self.disable_paging()
    +    self.set_base_prompt(alt_prompt_terminator="$")
    +
    +
    +
    +

    Inherited members

    + +
    @@ -2012,6 +2023,7 @@

    Index

  • netmiko.dell.dell_isilon_ssh
  • netmiko.dell.dell_os10_ssh
  • netmiko.dell.dell_powerconnect
  • +
  • netmiko.dell.dell_sonic_ssh
  • Classes

    @@ -2031,17 +2043,13 @@

    DellIsilonSSH

  • @@ -2065,6 +2073,12 @@

    DellPowerConnectTelnet

  • +
  • +

    DellSonicSSH

    + +
  • diff --git a/docs/netmiko/dlink/dlink_ds.html b/docs/netmiko/dlink/dlink_ds.html index 3bceabf2c..8d2ae473b 100644 --- a/docs/netmiko/dlink/dlink_ds.html +++ b/docs/netmiko/dlink/dlink_ds.html @@ -22,60 +22,34 @@

    Module netmiko.dlink.dlink_ds

    Source code -
    from netmiko.cisco_base_connection import CiscoSSHConnection
    -import time
    +
    from typing import Any
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
    +from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    -class DlinkDSBase(CiscoSSHConnection):
    +class DlinkDSBase(NoEnable, NoConfig, CiscoSSHConnection):
         """Supports D-Link DGS/DES device series (there are some DGS/DES devices that are web-only)"""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"#")
             self.set_base_prompt()
    -        self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    +        self.disable_paging(command="disable clipaging")
     
    -    def disable_paging(self, command="disable clipaging", delay_factor=1):
    -        return super().disable_paging(command=command, delay_factor=delay_factor)
    -
    -    def enable(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return ""
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return True
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return ""
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return False
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return ""
    -
    -    def save_config(self, cmd="save", confirm=False, confirm_response=""):
    +    def save_config(
    +        self, cmd: str = "save", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             """Saves configuration."""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
             )
     
    -    def cleanup(self):
    +    def cleanup(self, command: str = "logout") -> None:
             """Return paging before disconnect"""
             self.send_command_timing("enable clipaging")
    -        return super().cleanup()
    +        return super().cleanup(command=command)
     
     
     class DlinkDSSSH(DlinkDSBase):
    @@ -83,7 +57,7 @@ 

    Module netmiko.dlink.dlink_ds

    class DlinkDSTelnet(DlinkDSBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs)
    @@ -100,7 +74,7 @@

    Classes

    Supports D-Link DGS/DES device series (there are some DGS/DES devices that are web-only)

    @@ -108,187 +82,134 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class DlinkDSBase(CiscoSSHConnection):
    +
    class DlinkDSBase(NoEnable, NoConfig, CiscoSSHConnection):
         """Supports D-Link DGS/DES device series (there are some DGS/DES devices that are web-only)"""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
    -        self._test_channel_read()
    +        self._test_channel_read(pattern=r"#")
             self.set_base_prompt()
    -        self.disable_paging()
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def disable_paging(self, command="disable clipaging", delay_factor=1):
    -        return super().disable_paging(command=command, delay_factor=delay_factor)
    -
    -    def enable(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return ""
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return True
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No implemented enable mode on D-Link yet"""
    -        return ""
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return False
    +        self.disable_paging(command="disable clipaging")
     
    -    def config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No config mode on D-Link"""
    -        return ""
    -
    -    def save_config(self, cmd="save", confirm=False, confirm_response=""):
    +    def save_config(
    +        self, cmd: str = "save", confirm: bool = False, confirm_response: str = ""
    +    ) -> str:
             """Saves configuration."""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
             )
     
    -    def cleanup(self):
    +    def cleanup(self, command: str = "logout") -> None:
             """Return paging before disconnect"""
             self.send_command_timing("enable clipaging")
    -        return super().cleanup()
    + return super().cleanup(command=command)

    Ancestors

    Methods

    - -
    -

    No config mode on D-Link

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No config mode on D-Link"""
    -    return False
    -
    -
    - -
    -

    No implemented enable mode on D-Link yet

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No implemented enable mode on D-Link yet"""
    -    return True
    -
    -

    Return paging before disconnect

    Source code -
    def cleanup(self):
    +
    def cleanup(self, command: str = "logout") -> None:
         """Return paging before disconnect"""
         self.send_command_timing("enable clipaging")
    -    return super().cleanup()
    -
    -
    - -
    -

    No config mode on D-Link

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No config mode on D-Link"""
    -    return ""
    -
    -
    - -
    -

    No implemented enable mode on D-Link yet

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No implemented enable mode on D-Link yet"""
    -    return ""
    -
    -
    - -
    -

    No config mode on D-Link

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No config mode on D-Link"""
    -    return ""
    -
    -
    - -
    -

    No implemented enable mode on D-Link yet

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No implemented enable mode on D-Link yet"""
    -    return ""
    + return super().cleanup(command=command)
    -

    Generic handler that will write to both SSH and telnet channel.

    +

    Generic method that will write data out the channel.

    :param out_data: data to be written to the channel -:type out_data: str (can be either unicode/byte string)

    +:type out_data: str

    Source code -
    def write_channel(self, out_data):
    -    """Generic handler that will write to both SSH and telnet channel.
    +
    @lock_channel
    +@log_writes
    +def write_channel(self, out_data: str) -> None:
    +    """Generic method that will write data out the channel.
     
         :param out_data: data to be written to the channel
    -    :type out_data: str (can be either unicode/byte string)
    +    :type out_data: str
         """
    -    self._lock_netmiko_session()
    -    try:
    -        self._write_channel(out_data)
    -    finally:
    -        # Always unlock the SSH channel, even on exception.
    -        self._unlock_netmiko_session()
    + self.channel.write_channel(out_data)
    @@ -4790,20 +5372,41 @@

    Methods

    Exception raised for invalid configuration error.

    Source code -
    class ConfigInvalidException(Exception):
    +
    class ConfigInvalidException(NetmikoBaseException):
         """Exception raised for invalid configuration error."""
     
         pass

    Ancestors

    + +
    +class ConnectionException +(*args, **kwargs) +
    +
    +

    Generic exception indicating the connection failed.

    +
    +Source code +
    class ConnectionException(NetmikoBaseException):
    +    """Generic exception indicating the connection failed."""
    +
    +    pass
    +
    +

    Ancestors

    +
    class InLineTransfer -(ssh_conn, source_file=None, dest_file=None, file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None) +(ssh_conn, source_file='', dest_file='', file_system=None, direction='put', source_config=None, socket_timeout=10.0, progress=None, progress4=None, hash_supported=True)

    Use TCL on Cisco IOS to directly transfer file.

    @@ -4814,16 +5417,24 @@

    Ancestors

    def __init__( self, - ssh_conn, - source_file=None, - dest_file=None, - file_system=None, - direction="put", - source_config=None, - socket_timeout=10.0, - progress=None, - progress4=None, - ): + ssh_conn: BaseConnection, + source_file: str = "", + dest_file: str = "", + file_system: Optional[str] = None, + direction: str = "put", + source_config: Optional[str] = None, + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: + + if not dest_file: + raise ValueError( + "Destination file must be specified for InlineTransfer operations." + ) + if hash_supported is False: + raise ValueError("hash_supported=False is not supported for InLineTransfer") if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -4840,13 +5451,12 @@

    Ancestors

    self.progress4 = progress4 self.ssh_ctl_chan = ssh_conn + self.source_file = source_file if source_file: - self.source_file = source_file self.source_config = None self.source_md5 = self.file_md5(source_file) self.file_size = os.stat(source_file).st_size elif source_config: - self.source_file = None self.source_config = source_config self.source_md5 = self.config_md5(source_config) self.file_size = len(source_config.encode("UTF-8")) @@ -4861,12 +5471,12 @@

    Ancestors

    self.socket_timeout = socket_timeout @staticmethod - def _read_file(file_name): + def _read_file(file_name: str) -> str: with io.open(file_name, "rt", encoding="utf-8") as f: return f.read() @staticmethod - def _tcl_newline_rationalize(tcl_string): + def _tcl_newline_rationalize(tcl_string: str) -> str: r""" When using put inside a TCL {} section the newline is considered a new TCL statement and causes a missing curly-brace message. Convert "\n" to "\r". TCL @@ -4881,17 +5491,22 @@

    Ancestors

    raise ValueError(msg) return tmp_string - def __enter__(self): + def __enter__(self) -> "InLineTransfer": self._enter_tcl_mode() return self - def __exit__(self, exc_type, exc_value, traceback): - _ = self._exit_tcl_mode() # noqa + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: + self._exit_tcl_mode() - def _enter_tcl_mode(self): + def _enter_tcl_mode(self) -> str: TCL_ENTER = "tclsh" cmd_failed = ['Translating "tclsh"', "% Unknown command", "% Bad IP address"] - output = self.ssh_ctl_chan.send_command( + output = self.ssh_ctl_chan._send_command_str( TCL_ENTER, expect_string=r"\(tcl\)#", strip_prompt=False, @@ -4902,7 +5517,7 @@

    Ancestors

    raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output - def _exit_tcl_mode(self): + def _exit_tcl_mode(self) -> str: TCL_EXIT = "tclquit" self.ssh_ctl_chan.write_channel("\r") time.sleep(1) @@ -4913,29 +5528,33 @@

    Ancestors

    output += self.ssh_ctl_chan.read_channel() return output - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: raise NotImplementedError - def close_scp_chan(self): + def close_scp_chan(self) -> None: raise NotImplementedError - def local_space_available(self): + def local_space_available(self) -> bool: raise NotImplementedError - def file_md5(self, file_name): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file.""" + if add_newline is True: + raise ValueError( + "add_newline argument is not supported for inline transfers." + ) file_contents = self._read_file(file_name) file_contents = file_contents + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def config_md5(self, source_config): + def config_md5(self, source_config: str) -> str: """Compute MD5 hash of text.""" file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest() - def put_file(self): + def put_file(self) -> None: curlybrace = r"{" TCL_FILECMD_ENTER = 'puts [open "{}{}" w+] {}'.format( self.file_system, self.dest_file, curlybrace @@ -4957,21 +5576,21 @@

    Ancestors

    self.ssh_ctl_chan.write_channel(TCL_FILECMD_EXIT + "\r") # This operation can be slow (depends on the size of the file) - max_loops = 400 + read_timeout = 100 sleep_time = 4 if self.file_size >= 2500: - max_loops = 1500 + read_timeout = 300 sleep_time = 12 elif self.file_size >= 7500: - max_loops = 3000 + read_timeout = 600 sleep_time = 25 # Initial delay time.sleep(sleep_time) # File paste and TCL_FILECMD_exit should be indicated by "router(tcl)#" - output = self.ssh_ctl_chan._read_channel_expect( - pattern=r"\(tcl\)", max_loops=max_loops + output = self.ssh_ctl_chan.read_until_pattern( + pattern=r"\(tcl\).*$", re_flags=re.M, read_timeout=read_timeout ) # The file doesn't write until tclquit @@ -4980,16 +5599,20 @@

    Ancestors

    time.sleep(1) # Read all data remaining from the TCLSH session - output += self.ssh_ctl_chan._read_channel_expect(max_loops=max_loops) - return output + pattern = rf"tclquit.*{self.ssh_ctl_chan.base_prompt}.*$" + re_flags = re.DOTALL | re.M + output += self.ssh_ctl_chan.read_until_pattern( + pattern=pattern, re_flags=re_flags, read_timeout=read_timeout + ) + return None - def get_file(self): + def get_file(self) -> None: raise NotImplementedError - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -5007,26 +5630,30 @@

    Methods

    Compute MD5 hash of text.

    Source code -
    def config_md5(self, source_config):
    +
    def config_md5(self, source_config: str) -> str:
         """Compute MD5 hash of text."""
         file_contents = source_config + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    -def file_md5(self, file_name) +def file_md5(self, file_name, add_newline=False)

    Compute MD5 hash of file.

    Source code -
    def file_md5(self, file_name):
    +
    def file_md5(self, file_name: str, add_newline: bool = False) -> str:
         """Compute MD5 hash of file."""
    +    if add_newline is True:
    +        raise ValueError(
    +            "add_newline argument is not supported for inline transfers."
    +        )
         file_contents = self._read_file(file_name)
         file_contents = file_contents + "\n"  # Cisco IOS automatically adds this
    -    file_contents = file_contents.encode("UTF-8")
    -    return hashlib.md5(file_contents).hexdigest()
    + file_contents_bytes = file_contents.encode("UTF-8") + return hashlib.md5(file_contents_bytes).hexdigest()
    @@ -5116,6 +5743,32 @@

    Ancestors

  • builtins.BaseException
  • +
    +class NetmikoBaseException +(*args, **kwargs) +
    +
    +

    General base exception except for exceptions that inherit from Paramiko.

    +
    +Source code +
    class NetmikoBaseException(Exception):
    +    """General base exception except for exceptions that inherit from Paramiko."""
    +
    +    pass
    +
    +

    Ancestors

    +
      +
    • builtins.Exception
    • +
    • builtins.BaseException
    • +
    +

    Subclasses

    + +
    class NetmikoTimeoutException (*args, **kwargs) @@ -5136,6 +5789,51 @@

    Ancestors

  • builtins.BaseException
  • +
    +class ReadException +(*args, **kwargs) +
    +
    +

    General exception indicating an error occurred during a Netmiko read operation.

    +
    +Source code +
    class ReadException(NetmikoBaseException):
    +    """General exception indicating an error occurred during a Netmiko read operation."""
    +
    +    pass
    +
    +

    Ancestors

    + +

    Subclasses

    + +
    +
    +class ReadTimeout +(*args, **kwargs) +
    +
    +

    General exception indicating an error occurred during a Netmiko read operation.

    +
    +Source code +
    class ReadTimeout(ReadException):
    +    """General exception indicating an error occurred during a Netmiko read operation."""
    +
    +    pass
    +
    +

    Ancestors

    + +
    class SCPConn (ssh_conn, socket_timeout=10.0, progress=None, progress4=None) @@ -5152,14 +5850,20 @@

    Ancestors

    Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn, socket_timeout=10.0, progress=None, progress4=None): + def __init__( + self, + ssh_conn: "BaseConnection", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + ) -> None: self.ssh_ctl_chan = ssh_conn self.socket_timeout = socket_timeout self.progress = progress self.progress4 = progress4 self.establish_scp_conn() - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: """Establish the secure copy connection.""" ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() @@ -5171,26 +5875,19 @@

    Ancestors

    progress4=self.progress4, ) - def scp_transfer_file(self, source_file, dest_file): + def scp_transfer_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP (for backwards compatibility).""" self.scp_client.put(source_file, dest_file) - def scp_get_file(self, source_file, dest_file): + def scp_get_file(self, source_file: str, dest_file: str) -> None: """Get file using SCP.""" - platform = self.ssh_ctl_chan.device_type - if "cisco_ios" in platform or "cisco_xe" in platform: - try: - self.scp_client.get(source_file, dest_file) - except EOFError: - pass - else: - self.scp_client.get(source_file, dest_file) + self.scp_client.get(source_file, dest_file) - def scp_put_file(self, source_file, dest_file): + def scp_put_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP.""" self.scp_client.put(source_file, dest_file) - def close(self): + def close(self) -> None: """Close the SCP connection.""" self.scp_conn.close()
    @@ -5203,7 +5900,7 @@

    Methods

    Close the SCP connection.

    Source code -
    def close(self):
    +
    def close(self) -> None:
         """Close the SCP connection."""
         self.scp_conn.close()
    @@ -5215,7 +5912,7 @@

    Methods

    Establish the secure copy connection.

    Source code -
    def establish_scp_conn(self):
    +
    def establish_scp_conn(self) -> None:
         """Establish the secure copy connection."""
         ssh_connect_params = self.ssh_ctl_chan._connect_params_dict()
         self.scp_conn = self.ssh_ctl_chan._build_ssh_client()
    @@ -5235,16 +5932,9 @@ 

    Methods

    Get file using SCP.

    Source code -
    def scp_get_file(self, source_file, dest_file):
    +
    def scp_get_file(self, source_file: str, dest_file: str) -> None:
         """Get file using SCP."""
    -    platform = self.ssh_ctl_chan.device_type
    -    if "cisco_ios" in platform or "cisco_xe" in platform:
    -        try:
    -            self.scp_client.get(source_file, dest_file)
    -        except EOFError:
    -            pass
    -    else:
    -        self.scp_client.get(source_file, dest_file)
    + self.scp_client.get(source_file, dest_file)
    @@ -5254,7 +5944,7 @@

    Methods

    Put file using SCP.

    Source code -
    def scp_put_file(self, source_file, dest_file):
    +
    def scp_put_file(self, source_file: str, dest_file: str) -> None:
         """Put file using SCP."""
         self.scp_client.put(source_file, dest_file)
    @@ -5266,7 +5956,7 @@

    Methods

    Put file using SCP (for backwards compatibility).

    Source code -
    def scp_transfer_file(self, source_file, dest_file):
    +
    def scp_transfer_file(self, source_file: str, dest_file: str) -> None:
         """Put file using SCP (for backwards compatibility)."""
         self.scp_client.put(source_file, dest_file)
    @@ -5329,7 +6019,7 @@

    Methods

    Try to determine the device type. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: """ Constructor of the SSHDetect class """ @@ -5341,10 +6031,10 @@

    Methods

    # Call the _test_channel_read() in base to clear initial data output = BaseConnection._test_channel_read(self.connection) self.initial_buffer = output - self.potential_matches = {} - self._results_cache = {} + self.potential_matches: Dict[str, int] = {} + self._results_cache: Dict[str, str] = {} - def autodetect(self): + def autodetect(self) -> Union[str, None]: """ Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE @@ -5356,6 +6046,7 @@

    Methods

    for device_type, autodetect_dict in SSH_MAPPER_BASE: tmp_dict = autodetect_dict.copy() call_method = tmp_dict.pop("dispatch") + assert isinstance(call_method, str) autodetect_method = getattr(self, call_method) accuracy = autodetect_method(**tmp_dict) if accuracy: @@ -5364,6 +6055,10 @@

    Methods

    best_match = sorted( self.potential_matches.items(), key=lambda t: t[1], reverse=True ) + # WLC needs two different auto-dectect solutions + if "cisco_wlc_85" in best_match[0]: + best_match[0] = ("cisco_wlc", 99) + self.connection.disconnect() return best_match[0][0] @@ -5377,7 +6072,7 @@

    Methods

    self.connection.disconnect() return best_match[0][0] - def _send_command(self, cmd=""): + def _send_command(self, cmd: str = "") -> str: """ Handle reading/writing channel directly. It is also sanitizing the output received. @@ -5393,11 +6088,11 @@

    Methods

    """ self.connection.write_channel(cmd + "\n") time.sleep(1) - output = self.connection._read_channel_timing() + output = self.connection.read_channel_timing() output = self.connection.strip_backspaces(output) return output - def _send_command_wrapper(self, cmd): + def _send_command_wrapper(self, cmd: str) -> str: """ Send command to the remote device with a caching feature to avoid sending the same command twice based on the SSH_MAPPER_BASE dict cmd key. @@ -5421,8 +6116,12 @@

    Methods

    return cached_results def _autodetect_remote_version( - self, search_patterns=None, re_flags=re.IGNORECASE, priority=99, **kwargs - ): + self, + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + **kwargs: Any + ) -> int: """ Method to try auto-detect the device type, by matching a regular expression on the reported remote version of the SSH server. @@ -5443,7 +6142,10 @@

    Methods

    return 0 try: - remote_version = self.connection.remote_conn.transport.remote_version + remote_conn = self.connection.remote_conn + assert isinstance(remote_conn, paramiko.Channel) + assert remote_conn.transport is not None + remote_version = remote_conn.transport.remote_version for pattern in invalid_responses: match = re.search(pattern, remote_version, flags=re.I) if match: @@ -5457,8 +6159,12 @@

    Methods

    return 0 def _autodetect_std( - self, cmd="", search_patterns=None, re_flags=re.IGNORECASE, priority=99 - ): + self, + cmd: str = "", + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + ) -> int: """ Standard method to try to auto-detect the device type. This method will be called for each device_type present in SSH_MAPPER_BASE dict ('dispatch' key). It will attempt to send a @@ -5483,6 +6189,7 @@

    Methods

    r"%Error", r"command not found", r"Syntax Error: unexpected argument", + r"% Unrecognized command found at", ] if not cmd or not search_patterns: return 0 @@ -5516,7 +6223,7 @@

    Returns

    Source code -
    def autodetect(self):
    +
    def autodetect(self) -> Union[str, None]:
         """
         Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE
     
    @@ -5528,6 +6235,7 @@ 

    Returns

    for device_type, autodetect_dict in SSH_MAPPER_BASE: tmp_dict = autodetect_dict.copy() call_method = tmp_dict.pop("dispatch") + assert isinstance(call_method, str) autodetect_method = getattr(self, call_method) accuracy = autodetect_method(**tmp_dict) if accuracy: @@ -5536,6 +6244,10 @@

    Returns

    best_match = sorted( self.potential_matches.items(), key=lambda t: t[1], reverse=True ) + # WLC needs two different auto-dectect solutions + if "cisco_wlc_85" in best_match[0]: + best_match[0] = ("cisco_wlc", 99) + self.connection.disconnect() return best_match[0][0] @@ -5577,11 +6289,13 @@

    Index

  • netmiko.calix
  • netmiko.cdot
  • netmiko.centec
  • +
  • netmiko.channel
  • netmiko.checkpoint
  • netmiko.ciena
  • netmiko.cisco
  • netmiko.cisco_base_connection
  • netmiko.citrix
  • +
  • netmiko.cli_tools
  • netmiko.cloudgenix
  • netmiko.coriant
  • netmiko.dell
  • @@ -5590,6 +6304,7 @@

    Index

  • netmiko.endace
  • netmiko.enterasys
  • netmiko.ericsson
  • +
  • netmiko.exceptions
  • netmiko.extreme
  • netmiko.f5
  • netmiko.flexvnf
  • @@ -5606,6 +6321,8 @@

    Index

  • netmiko.netapp
  • netmiko.netgear
  • netmiko.netmiko_globals
  • +
  • netmiko.no_config
  • +
  • netmiko.no_enable
  • netmiko.nokia
  • netmiko.oneaccess
  • netmiko.ovs
  • @@ -5618,11 +6335,12 @@

    Index

  • netmiko.ruijie
  • netmiko.scp_functions
  • netmiko.scp_handler
  • +
  • netmiko.session_log
  • netmiko.sixwind
  • netmiko.snmp_autodetect
  • netmiko.sophos
  • +
  • netmiko.ssh_auth
  • netmiko.ssh_autodetect
  • -
  • netmiko.ssh_exception
  • netmiko.supermicro
  • netmiko.terminal_server
  • netmiko.tplink
  • @@ -5632,10 +6350,13 @@

    Index

  • netmiko.watchguard
  • netmiko.yamaha
  • netmiko.zte
  • +
  • netmiko.zyxel
  • Functions

      +
    • ConnLogOnly
    • +
    • ConnUnify
    • ConnectHandler
    • FileTransfer
    • Netmiko
    • @@ -5654,7 +6375,7 @@

      BaseC
    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • +
    • command_echo_read
    • commit
    • config_mode
    • disable_paging
    • @@ -5667,9 +6388,9 @@

      BaseC
    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -5681,6 +6402,8 @@

      BaseC
    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • +
    • send_multiline_timing
    • serial_login
    • session_preparation
    • set_base_prompt
    • @@ -5698,6 +6421,9 @@

      BaseC

      ConfigInvalidException

    • +

      ConnectionException

      +
    • +
    • InLineTransfer

      • config_md5
      • @@ -5714,9 +6440,18 @@

        NetmikoAuthenticationException

      • +

        NetmikoBaseException

        +
      • +
      • NetmikoTimeoutException

      • +

        ReadException

        +
      • +
      • +

        ReadTimeout

        +
      • +
      • SCPConn

        • close
        • diff --git a/docs/netmiko/ipinfusion/index.html b/docs/netmiko/ipinfusion/index.html index 54044ced7..c8ee4b2e3 100644 --- a/docs/netmiko/ipinfusion/index.html +++ b/docs/netmiko/ipinfusion/index.html @@ -56,131 +56,104 @@

          Classes

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
  • -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -203,9 +176,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -216,9 +188,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -230,6 +202,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -255,138 +228,111 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class IpInfusionOcNOSTelnet(IpInfusionOcNOSBase):
         """IP Infusion OcNOS  Telnet driver."""
     
    -    def _process_option(self, tsocket, command, option):
    +    def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None:
             """
             For all telnet options, re-implement the default telnetlib behaviour
             and refuse to handle any options. If the server expresses interest in
    @@ -402,14 +348,16 @@ 

    Inherited members

    def telnet_login( self, - pri_prompt_terminator="#", - alt_prompt_terminator=">", - username_pattern=r"(?:user:|sername|login|user name)", - pwd_pattern=r"assword:", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + username_pattern: str = r"(?:user:|sername|login|user name)", + pwd_pattern: str = r"assword:", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert self.remote_conn is not None + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, @@ -434,9 +382,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -447,9 +394,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -461,6 +408,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/ipinfusion/ipinfusion_ocnos.html b/docs/netmiko/ipinfusion/ipinfusion_ocnos.html index e9099ef3f..119f40c20 100644 --- a/docs/netmiko/ipinfusion/ipinfusion_ocnos.html +++ b/docs/netmiko/ipinfusion/ipinfusion_ocnos.html @@ -23,19 +23,22 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    Source code
    import time
    -from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, TTYPE
    +from typing import Any
    +from socket import socket
    +
    +from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, TTYPE, Telnet
     from netmiko.cisco_base_connection import CiscoBaseConnection
     
     
     class IpInfusionOcNOSBase(CiscoBaseConnection):
         """Common Methods for IP Infusion OcNOS support."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
    -        return super().__init__(**kwargs)
    +        super().__init__(**kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             self._test_channel_read()
             self.set_base_prompt()
             self.disable_paging(command="terminal length 0")
    @@ -44,7 +47,9 @@ 

    Module netmiko.ipinfusion.ipinfusion_ocnos

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using write command""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -60,7 +65,7 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    class IpInfusionOcNOSTelnet(IpInfusionOcNOSBase): """IP Infusion OcNOS Telnet driver.""" - def _process_option(self, tsocket, command, option): + def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None: """ For all telnet options, re-implement the default telnetlib behaviour and refuse to handle any options. If the server expresses interest in @@ -76,14 +81,16 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    def telnet_login( self, - pri_prompt_terminator="#", - alt_prompt_terminator=">", - username_pattern=r"(?:user:|sername|login|user name)", - pwd_pattern=r"assword:", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + username_pattern: str = r"(?:user:|sername|login|user name)", + pwd_pattern: str = r"assword:", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert self.remote_conn is not None + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, @@ -114,143 +121,116 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class IpInfusionOcNOSBase(CiscoBaseConnection):
         """Common Methods for IP Infusion OcNOS support."""
     
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             if kwargs.get("default_enter") is None:
                 kwargs["default_enter"] = "\r"
    -        return super().__init__(**kwargs)
    +        super().__init__(**kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             self._test_channel_read()
             self.set_base_prompt()
             self.disable_paging(command="terminal length 0")
    @@ -259,7 +239,9 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using write command""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -284,7 +266,9 @@

    Methods

    Saves Config Using write command

    Source code -
    def save_config(self, cmd="write", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
    +) -> str:
         """Saves Config Using write command"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -300,9 +284,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -313,9 +296,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -326,6 +309,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -350,131 +334,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -497,9 +454,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -510,9 +466,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -524,6 +480,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -549,138 +506,111 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class IpInfusionOcNOSTelnet(IpInfusionOcNOSBase):
         """IP Infusion OcNOS  Telnet driver."""
     
    -    def _process_option(self, tsocket, command, option):
    +    def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None:
             """
             For all telnet options, re-implement the default telnetlib behaviour
             and refuse to handle any options. If the server expresses interest in
    @@ -696,14 +626,16 @@ 

    Inherited members

    def telnet_login( self, - pri_prompt_terminator="#", - alt_prompt_terminator=">", - username_pattern=r"(?:user:|sername|login|user name)", - pwd_pattern=r"assword:", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + username_pattern: str = r"(?:user:|sername|login|user name)", + pwd_pattern: str = r"assword:", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert self.remote_conn is not None + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, @@ -728,9 +660,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -741,9 +672,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -755,6 +686,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/juniper/index.html b/docs/netmiko/juniper/index.html index 7610b586f..a30c96b48 100644 --- a/docs/netmiko/juniper/index.html +++ b/docs/netmiko/juniper/index.html @@ -61,14 +61,14 @@

    Classes

    def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -77,27 +77,31 @@

    Classes

    **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="file checksum md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "file checksum md5", remote_file: Optional[str] = None + ) -> str: return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -131,142 +135,114 @@

    Inherited members

    class JuniperSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Juniper Networks devices.

    -

    Disables enable() and check_enable_mode() -methods. +

    methods. Overrides several methods for Juniper-specific compatibility.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -276,6 +252,7 @@

    Inherited members

    Ancestors

    Inherited members

    @@ -283,26 +260,25 @@

    Inherited members

  • JuniperBase:
  • class JuniperScreenOsSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Juniper ScreenOS devices.

    @@ -339,259 +316,143 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class JuniperScreenOsSSH(BaseConnection):
    +
    class JuniperScreenOsSSH(NoEnable, NoConfig, BaseConnection):
         """
         Implement methods for interacting with Juniper ScreenOS devices.
         """
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
    -        Prepare the session after the connection has been established.
    -
    -        Disable paging (the '--more--' prompts).
    -        Set the base prompt for interaction ('>').
    +        ScreenOS can be configured to require: Accept this agreement y/[n]
             """
    -        self._test_channel_read()
    +        terminator = r"\->"
    +        pattern = rf"(Accept this|{terminator})"
    +        data = self._test_channel_read(pattern=pattern)
    +        if "Accept this" in data:
    +            self.write_channel("y")
    +            data += self._test_channel_read(pattern=terminator)
    +
             self.set_base_prompt()
             self.disable_paging(command="set console page 0")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return True
    -
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return False
     
    -    def config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
    +    def save_config(
    +        self,
    +        cmd: str = "save config",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Save Config."""
    -        return self.send_command(command_string=cmd)
    + return self._send_command_str(command_string=cmd)

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return True
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    def save_config(self, cmd='save config', confirm=False, confirm_response='')
    @@ -599,33 +460,36 @@

    Methods

    Save Config.

    Source code -
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "save config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Save Config."""
    -    return self.send_command(command_string=cmd)
    + return self._send_command_str(command_string=cmd)
    def session_preparation(self)
    -

    Prepare the session after the connection has been established.

    -

    Disable paging (the '–more–' prompts). -Set the base prompt for interaction ('>').

    +

    ScreenOS can be configured to require: Accept this agreement y/[n]

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
    -    Prepare the session after the connection has been established.
    -
    -    Disable paging (the '--more--' prompts).
    -    Set the base prompt for interaction ('>').
    +    ScreenOS can be configured to require: Accept this agreement y/[n]
         """
    -    self._test_channel_read()
    +    terminator = r"\->"
    +    pattern = rf"(Accept this|{terminator})"
    +    data = self._test_channel_read(pattern=pattern)
    +    if "Accept this" in data:
    +        self.write_channel("y")
    +        data += self._test_channel_read(pattern=terminator)
    +
         self.set_base_prompt()
    -    self.disable_paging(command="set console page 0")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="set console page 0")
    @@ -633,20 +497,25 @@

    Inherited members

    Implement methods for interacting with Juniper Networks devices.

    -

    Disables enable() and check_enable_mode() -methods. +

    methods. Overrides several methods for Juniper-specific compatibility.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class JuniperTelnet(JuniperBase):
    -    def __init__(self, *args, **kwargs):
    +    def __init__(self, *args: Any, **kwargs: Any) -> None:
             default_enter = kwargs.get("default_enter")
             kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
             super().__init__(*args, **kwargs)
    @@ -820,6 +662,7 @@

    Inherited members

    Ancestors

    Inherited members

    @@ -827,26 +670,25 @@

    Inherited members

  • JuniperBase:
    • check_config_mode
    • -
    • check_enable_mode
    • +
    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • disconnect
    • -
    • enable
    • +
    • enable
    • enter_cli_mode
    • establish_connection
    • exit_config_mode
    • -
    • exit_enable_mode
    • +
    • exit_enable_mode
    • find_prompt
    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -858,6 +700,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -903,13 +746,7 @@

      JuniperScreenOsSSH

      -
        -
      • check_config_mode
      • -
      • check_enable_mode
      • -
      • config_mode
      • -
      • enable
      • -
      • exit_config_mode
      • -
      • exit_enable_mode
      • + diff --git a/docs/netmiko/juniper/juniper.html b/docs/netmiko/juniper/juniper.html index a45222e76..16a6cb49c 100644 --- a/docs/netmiko/juniper/juniper.html +++ b/docs/netmiko/juniper/juniper.html @@ -24,26 +24,22 @@

        Module netmiko.juniper.juniper

        Source code
        import re
         import time
        +import warnings
        +from typing import Optional, Any
         
        -from netmiko.base_connection import BaseConnection
        +from netmiko.no_enable import NoEnable
        +from netmiko.base_connection import BaseConnection, DELAY_FACTOR_DEPR_SIMPLE_MSG
         from netmiko.scp_handler import BaseFileTransfer
         
         
        -class JuniperBase(BaseConnection):
        +class JuniperBase(NoEnable, BaseConnection):
             """
             Implement methods for interacting with Juniper Networks devices.
         
        -    Disables `enable()` and `check_enable_mode()`
             methods.  Overrides several methods for Juniper-specific compatibility.
             """
         
        -    def __init__(self, *args, **kwargs):
        -        # Cisco-IOS defaults to fast_cli=True and legacy_mode=False
        -        kwargs.setdefault("fast_cli", True)
        -        kwargs.setdefault("_legacy_mode", False)
        -        return super().__init__(*args, **kwargs)
        -
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.enter_cli_mode()
                 cmd = "set cli screen-width 511"
        @@ -58,15 +54,15 @@ 

        Module netmiko.juniper.juniper

        ) self.set_base_prompt() - def _enter_shell(self): + def _enter_shell(self) -> str: """Enter the Bourne Shell.""" - return self.send_command("start shell sh", expect_string=r"[\$#]") + return self._send_command_str("start shell sh", expect_string=r"[\$#]") - def _return_cli(self): + def _return_cli(self) -> str: """Return to the Juniper CLI.""" - return self.send_command("exit", expect_string=r"[#>]") + return self._send_command_str("exit", expect_string=r"[#>]") - def enter_cli_mode(self): + def enter_cli_mode(self) -> None: """Check if at shell prompt root@ and go into CLI.""" delay_factor = self.select_delay_factor(delay_factor=0) count = 0 @@ -84,42 +80,32 @@

        Module netmiko.juniper.juniper

        break count += 1 - def check_enable_mode(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def check_config_mode(self, check_string="]"): + def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" return super().check_config_mode(check_string=check_string) def config_mode( self, - config_command="configure", - pattern=r"Entering configuration mode", - **kwargs, - ): + config_command: str = "configure", + pattern: str = r"Entering configuration mode", + re_flags: int = 0, + ) -> str: """Enter configuration mode.""" return super().config_mode( - config_command=config_command, pattern=pattern, **kwargs + config_command=config_command, pattern=pattern, re_flags=re_flags ) - def exit_config_mode(self, exit_config="exit configuration-mode"): + def exit_config_mode( + self, exit_config: str = "exit configuration-mode", pattern: str = "" + ) -> str: """Exit configuration mode.""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output = self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Exit with uncommitted changes?" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "yes", strip_prompt=False, strip_command=False ) if self.check_config_mode(): @@ -128,13 +114,14 @@

        Module netmiko.juniper.juniper

        def commit( self, - confirm=False, - confirm_delay=None, - check=False, - comment="", - and_quit=False, - delay_factor=1, - ): + confirm: bool = False, + confirm_delay: Optional[int] = None, + check: bool = False, + comment: str = "", + and_quit: bool = False, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -156,18 +143,14 @@

        Module netmiko.juniper.juniper

        check: command_string = commit check - """ - delay_factor = self.select_delay_factor(delay_factor) + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - # Commit is very slow so this is needed. - # FIX: Cleanup in future versions of Netmiko - if delay_factor < 1: - if not self._legacy_mode and self.fast_cli: - delay_factor = 1 + """ + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if check and (confirm or confirm_delay or comment): raise ValueError("Invalid arguments supplied with commit check") - if confirm_delay and not confirm: raise ValueError( "Invalid arguments supplied to commit method both confirm and check" @@ -200,35 +183,27 @@

        Module netmiko.juniper.juniper

        output = self.config_mode() # and_quit will get out of config mode on commit - if and_quit: - expect_string = re.escape(self.base_prompt) - else: - expect_string = None + expect_string = re.escape(self.base_prompt) if and_quit else None - try: - fast_cli_state = self.fast_cli - self.fast_cli = False - output += self.send_command( - command_string, - expect_string=expect_string, - strip_prompt=False, - strip_command=False, - delay_factor=delay_factor, - ) - finally: - self.fast_cli = fast_cli_state + output += self._send_command_str( + command_string, + expect_string=expect_string, + strip_prompt=False, + strip_command=False, + read_timeout=read_timeout, + ) if commit_marker not in output: raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def strip_prompt(self, *args, **kwargs): + def strip_prompt(self, *args: Any, **kwargs: Any) -> str: """Strip the trailing router prompt from the output.""" a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) - def strip_context_items(self, a_string): + def strip_context_items(self, a_string: str) -> str: """Strip Juniper-specific output. Juniper will also put a configuration context: @@ -256,7 +231,7 @@

        Module netmiko.juniper.juniper

        return self.RESPONSE_RETURN.join(response_list[:-1]) return a_string - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -274,7 +249,7 @@

        Module netmiko.juniper.juniper

        class JuniperTelnet(JuniperBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs) @@ -285,14 +260,14 @@

        Module netmiko.juniper.juniper

        def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -301,27 +276,31 @@

        Module netmiko.juniper.juniper

        **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="file checksum md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "file checksum md5", remote_file: Optional[str] = None + ) -> str: return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError
  • @@ -336,160 +315,125 @@

    Classes

    class JuniperBase -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Juniper Networks devices.

    -

    Disables enable() and check_enable_mode() -methods. +

    methods. Overrides several methods for Juniper-specific compatibility.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class JuniperBase(BaseConnection):
    +
    class JuniperBase(NoEnable, BaseConnection):
         """
         Implement methods for interacting with Juniper Networks devices.
     
    -    Disables `enable()` and `check_enable_mode()`
         methods.  Overrides several methods for Juniper-specific compatibility.
         """
     
    -    def __init__(self, *args, **kwargs):
    -        # Cisco-IOS defaults to fast_cli=True and legacy_mode=False
    -        kwargs.setdefault("fast_cli", True)
    -        kwargs.setdefault("_legacy_mode", False)
    -        return super().__init__(*args, **kwargs)
    -
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.enter_cli_mode()
             cmd = "set cli screen-width 511"
    @@ -504,15 +448,15 @@ 

    Classes

    ) self.set_base_prompt() - def _enter_shell(self): + def _enter_shell(self) -> str: """Enter the Bourne Shell.""" - return self.send_command("start shell sh", expect_string=r"[\$#]") + return self._send_command_str("start shell sh", expect_string=r"[\$#]") - def _return_cli(self): + def _return_cli(self) -> str: """Return to the Juniper CLI.""" - return self.send_command("exit", expect_string=r"[#>]") + return self._send_command_str("exit", expect_string=r"[#>]") - def enter_cli_mode(self): + def enter_cli_mode(self) -> None: """Check if at shell prompt root@ and go into CLI.""" delay_factor = self.select_delay_factor(delay_factor=0) count = 0 @@ -530,42 +474,32 @@

    Classes

    break count += 1 - def check_enable_mode(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on Juniper.""" - pass - - def check_config_mode(self, check_string="]"): + def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" return super().check_config_mode(check_string=check_string) def config_mode( self, - config_command="configure", - pattern=r"Entering configuration mode", - **kwargs, - ): + config_command: str = "configure", + pattern: str = r"Entering configuration mode", + re_flags: int = 0, + ) -> str: """Enter configuration mode.""" return super().config_mode( - config_command=config_command, pattern=pattern, **kwargs + config_command=config_command, pattern=pattern, re_flags=re_flags ) - def exit_config_mode(self, exit_config="exit configuration-mode"): + def exit_config_mode( + self, exit_config: str = "exit configuration-mode", pattern: str = "" + ) -> str: """Exit configuration mode.""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output = self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Exit with uncommitted changes?" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "yes", strip_prompt=False, strip_command=False ) if self.check_config_mode(): @@ -574,13 +508,14 @@

    Classes

    def commit( self, - confirm=False, - confirm_delay=None, - check=False, - comment="", - and_quit=False, - delay_factor=1, - ): + confirm: bool = False, + confirm_delay: Optional[int] = None, + check: bool = False, + comment: str = "", + and_quit: bool = False, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -602,18 +537,14 @@

    Classes

    check: command_string = commit check - """ - delay_factor = self.select_delay_factor(delay_factor) + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - # Commit is very slow so this is needed. - # FIX: Cleanup in future versions of Netmiko - if delay_factor < 1: - if not self._legacy_mode and self.fast_cli: - delay_factor = 1 + """ + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if check and (confirm or confirm_delay or comment): raise ValueError("Invalid arguments supplied with commit check") - if confirm_delay and not confirm: raise ValueError( "Invalid arguments supplied to commit method both confirm and check" @@ -646,35 +577,27 @@

    Classes

    output = self.config_mode() # and_quit will get out of config mode on commit - if and_quit: - expect_string = re.escape(self.base_prompt) - else: - expect_string = None + expect_string = re.escape(self.base_prompt) if and_quit else None - try: - fast_cli_state = self.fast_cli - self.fast_cli = False - output += self.send_command( - command_string, - expect_string=expect_string, - strip_prompt=False, - strip_command=False, - delay_factor=delay_factor, - ) - finally: - self.fast_cli = fast_cli_state + output += self._send_command_str( + command_string, + expect_string=expect_string, + strip_prompt=False, + strip_command=False, + read_timeout=read_timeout, + ) if commit_marker not in output: raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def strip_prompt(self, *args, **kwargs): + def strip_prompt(self, *args: Any, **kwargs: Any) -> str: """Strip the trailing router prompt from the output.""" a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) - def strip_context_items(self, a_string): + def strip_context_items(self, a_string: str) -> str: """Strip Juniper-specific output. Juniper will also put a configuration context: @@ -702,7 +625,7 @@

    Classes

    return self.RESPONSE_RETURN.join(response_list[:-1]) return a_string - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -716,6 +639,7 @@

    Classes

    Ancestors

    Subclasses

    @@ -726,29 +650,17 @@

    Subclasses

    Methods

    -def check_config_mode(self, check_string=']') +def check_config_mode(self, check_string=']', pattern='')

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string="]"):
    +
    def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode or not."""
         return super().check_config_mode(check_string=check_string)
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper."""
    -    pass
    -
    -
    def cleanup(self, command='exit')
    @@ -756,7 +668,7 @@

    Methods

    Gracefully exit the SSH session.

    Source code -
    def cleanup(self, command="exit"):
    +
    def cleanup(self, command: str = "exit") -> None:
         """Gracefully exit the SSH session."""
         try:
             # The pattern="" forces use of send_command_timing
    @@ -770,7 +682,7 @@ 

    Methods

    -def commit(self, confirm=False, confirm_delay=None, check=False, comment='', and_quit=False, delay_factor=1) +def commit(self, confirm=False, confirm_delay=None, check=False, comment='', and_quit=False, read_timeout=120.0, delay_factor=None)

    Commit the candidate configuration.

    @@ -788,18 +700,20 @@

    Methods

    comment option command_string = commit confirmed or commit confirmed check: -command_string = commit check

    +command_string = commit check

    +

    delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

    Source code
    def commit(
         self,
    -    confirm=False,
    -    confirm_delay=None,
    -    check=False,
    -    comment="",
    -    and_quit=False,
    -    delay_factor=1,
    -):
    +    confirm: bool = False,
    +    confirm_delay: Optional[int] = None,
    +    check: bool = False,
    +    comment: str = "",
    +    and_quit: bool = False,
    +    read_timeout: float = 120.0,
    +    delay_factor: Optional[float] = None,
    +) -> str:
         """
         Commit the candidate configuration.
     
    @@ -821,18 +735,14 @@ 

    Methods

    check: command_string = commit check - """ - delay_factor = self.select_delay_factor(delay_factor) + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. - # Commit is very slow so this is needed. - # FIX: Cleanup in future versions of Netmiko - if delay_factor < 1: - if not self._legacy_mode and self.fast_cli: - delay_factor = 1 + """ + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if check and (confirm or confirm_delay or comment): raise ValueError("Invalid arguments supplied with commit check") - if confirm_delay and not confirm: raise ValueError( "Invalid arguments supplied to commit method both confirm and check" @@ -865,23 +775,15 @@

    Methods

    output = self.config_mode() # and_quit will get out of config mode on commit - if and_quit: - expect_string = re.escape(self.base_prompt) - else: - expect_string = None + expect_string = re.escape(self.base_prompt) if and_quit else None - try: - fast_cli_state = self.fast_cli - self.fast_cli = False - output += self.send_command( - command_string, - expect_string=expect_string, - strip_prompt=False, - strip_command=False, - delay_factor=delay_factor, - ) - finally: - self.fast_cli = fast_cli_state + output += self._send_command_str( + command_string, + expect_string=expect_string, + strip_prompt=False, + strip_command=False, + read_timeout=read_timeout, + ) if commit_marker not in output: raise ValueError(f"Commit failed with the following errors:\n\n{output}") @@ -890,7 +792,7 @@

    Methods

    -def config_mode(self, config_command='configure', pattern='Entering configuration mode', **kwargs) +def config_mode(self, config_command='configure', pattern='Entering configuration mode', re_flags=0)

    Enter configuration mode.

    @@ -898,28 +800,16 @@

    Methods

    Source code
    def config_mode(
         self,
    -    config_command="configure",
    -    pattern=r"Entering configuration mode",
    -    **kwargs,
    -):
    +    config_command: str = "configure",
    +    pattern: str = r"Entering configuration mode",
    +    re_flags: int = 0,
    +) -> str:
         """Enter configuration mode."""
         return super().config_mode(
    -        config_command=config_command, pattern=pattern, **kwargs
    +        config_command=config_command, pattern=pattern, re_flags=re_flags
         )
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on Juniper."""
    -    pass
    -
    -
    def enter_cli_mode(self)
    @@ -927,7 +817,7 @@

    Methods

    Check if at shell prompt root@ and go into CLI.

    Source code -
    def enter_cli_mode(self):
    +
    def enter_cli_mode(self) -> None:
         """Check if at shell prompt root@ and go into CLI."""
         delay_factor = self.select_delay_factor(delay_factor=0)
         count = 0
    @@ -947,21 +837,23 @@ 

    Methods

    -def exit_config_mode(self, exit_config='exit configuration-mode') +def exit_config_mode(self, exit_config='exit configuration-mode', pattern='')

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="exit configuration-mode"):
    +
    def exit_config_mode(
    +    self, exit_config: str = "exit configuration-mode", pattern: str = ""
    +) -> str:
         """Exit configuration mode."""
         output = ""
         if self.check_config_mode():
    -        output = self.send_command_timing(
    +        output = self._send_command_timing_str(
                 exit_config, strip_prompt=False, strip_command=False
             )
             if "Exit with uncommitted changes?" in output:
    -            output += self.send_command_timing(
    +            output += self._send_command_timing_str(
                     "yes", strip_prompt=False, strip_command=False
                 )
             if self.check_config_mode():
    @@ -969,18 +861,6 @@ 

    Methods

    return output
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper."""
    -    pass
    -
    -
    def session_preparation(self)
    @@ -988,7 +868,7 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.enter_cli_mode()
         cmd = "set cli screen-width 511"
    @@ -1016,7 +896,7 @@ 

    Methods

    This method removes those lines.

    Source code -
    def strip_context_items(self, a_string):
    +
    def strip_context_items(self, a_string: str) -> str:
         """Strip Juniper-specific output.
     
         Juniper will also put a configuration context:
    @@ -1052,7 +932,7 @@ 

    Methods

    Strip the trailing router prompt from the output.

    Source code -
    def strip_prompt(self, *args, **kwargs):
    +
    def strip_prompt(self, *args: Any, **kwargs: Any) -> str:
         """Strip the trailing router prompt from the output."""
         a_string = super().strip_prompt(*args, **kwargs)
         return self.strip_context_items(a_string)
    @@ -1063,18 +943,20 @@

    Inherited members

    • BaseConnection:
        +
      • check_enable_mode
      • clear_buffer
      • -
      • close_session_log
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1086,6 +968,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -1111,14 +994,14 @@

        Inherited members

        def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -1127,27 +1010,31 @@

        Inherited members

        **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="file checksum md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "file checksum md5", remote_file: Optional[str] = None + ) -> str: return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -1181,142 +1068,114 @@

    Inherited members

    class JuniperSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with Juniper Networks devices.

    -

    Disables enable() and check_enable_mode() -methods. +

    methods. Overrides several methods for Juniper-specific compatibility.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -1326,6 +1185,7 @@

    Inherited members

    Ancestors

    Inherited members

    @@ -1333,26 +1193,25 @@

    Inherited members

  • JuniperBase:
    • check_config_mode
    • -
    • check_enable_mode
    • +
    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • disconnect
    • -
    • enable
    • +
    • enable
    • enter_cli_mode
    • establish_connection
    • exit_config_mode
    • -
    • exit_enable_mode
    • +
    • exit_enable_mode
    • find_prompt
    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -1364,6 +1223,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -1385,143 +1245,115 @@

      Inherited members

      Implement methods for interacting with Juniper Networks devices.

      -

      Disables enable() and check_enable_mode() -methods. +

      methods. Overrides several methods for Juniper-specific compatibility.

          Initialize attributes for establishing connection to target device.
       
           :param ip: IP address of target device. Not required if `host` is
               provided.
      -    :type ip: str
       
           :param host: Hostname of target device. Not required if `ip` is
                   provided.
      -    :type host: str
       
           :param username: Username to authenticate against target device if
                   required.
      -    :type username: str
       
           :param password: Password to authenticate against target device if
                   required.
      -    :type password: str
       
           :param secret: The enable password if target device requires one.
      -    :type secret: str
       
           :param port: The destination port used to connect to the target
                   device.
      -    :type port: int or None
       
           :param device_type: Class selection based on device type.
      -    :type device_type: str
       
           :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
       
           :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
       
           :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
       
           :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
       
           :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
       
           :param passphrase: Passphrase to use for encrypted key; password will be used for key
                   decryption if not specified.
      -    :type passphrase: str
      +
      +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
      +            documentation for a description of the expected format.
       
           :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
       
           :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                   means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
       
           :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      +
           :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                   alt_key_file.
      -    :type alt_host_keys: bool
       
           :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
       
           :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
       
           :param timeout: Connection timeout.
      -    :type timeout: float
       
           :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
       
           :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
       
           :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
       
           :param 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).
      -    :type keepalive: int
       
           :param default_enter: Character(s) to send to correspond to enter key (default:
       
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class JuniperTelnet(JuniperBase):
      -    def __init__(self, *args, **kwargs):
      +    def __init__(self, *args: Any, **kwargs: Any) -> None:
               default_enter = kwargs.get("default_enter")
               kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
               super().__init__(*args, **kwargs)
      @@ -1529,6 +1361,7 @@

      Inherited members

      Ancestors

      Inherited members

      @@ -1536,26 +1369,25 @@

      Inherited members

    • JuniperBase:
      • check_config_mode
      • -
      • check_enable_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • disconnect
      • -
      • enable
      • +
      • enable
      • enter_cli_mode
      • establish_connection
      • exit_config_mode
      • -
      • exit_enable_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1567,6 +1399,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -1602,14 +1435,11 @@

        Index

        JuniperBase

        • check_config_mode
        • -
        • check_enable_mode
        • cleanup
        • commit
        • config_mode
        • -
        • enable
        • enter_cli_mode
        • exit_config_mode
        • -
        • exit_enable_mode
        • session_preparation
        • strip_context_items
        • strip_prompt
        • diff --git a/docs/netmiko/juniper/juniper_screenos.html b/docs/netmiko/juniper/juniper_screenos.html index 2f73e67ce..d5f174581 100644 --- a/docs/netmiko/juniper/juniper_screenos.html +++ b/docs/netmiko/juniper/juniper_screenos.html @@ -22,56 +22,38 @@

          Module netmiko.juniper.juniper_screenos

          Source code -
          import time
          +
          from netmiko.no_enable import NoEnable
          +from netmiko.no_config import NoConfig
           from netmiko.base_connection import BaseConnection
           
           
          -class JuniperScreenOsSSH(BaseConnection):
          +class JuniperScreenOsSSH(NoEnable, NoConfig, BaseConnection):
               """
               Implement methods for interacting with Juniper ScreenOS devices.
               """
           
          -    def session_preparation(self):
          +    def session_preparation(self) -> None:
                   """
          -        Prepare the session after the connection has been established.
          -
          -        Disable paging (the '--more--' prompts).
          -        Set the base prompt for interaction ('>').
          +        ScreenOS can be configured to require: Accept this agreement y/[n]
                   """
          -        self._test_channel_read()
          +        terminator = r"\->"
          +        pattern = rf"(Accept this|{terminator})"
          +        data = self._test_channel_read(pattern=pattern)
          +        if "Accept this" in data:
          +            self.write_channel("y")
          +            data += self._test_channel_read(pattern=terminator)
          +
                   self.set_base_prompt()
                   self.disable_paging(command="set console page 0")
          -        # Clear the read buffer
          -        time.sleep(0.3 * self.global_delay_factor)
          -        self.clear_buffer()
          -
          -    def check_enable_mode(self, *args, **kwargs):
          -        """No enable mode on Juniper ScreenOS."""
          -        return True
          -
          -    def enable(self, *args, **kwargs):
          -        """No enable mode on Juniper ScreenOS."""
          -        return ""
          -
          -    def exit_enable_mode(self, *args, **kwargs):
          -        """No enable mode on Juniper ScreenOS."""
          -        return ""
          -
          -    def check_config_mode(self, *args, **kwargs):
          -        """No configuration mode on Juniper ScreenOS."""
          -        return False
          -
          -    def config_mode(self, *args, **kwargs):
          -        """No configuration mode on Juniper ScreenOS."""
          -        return ""
          -
          -    def exit_config_mode(self, *args, **kwargs):
          -        """No configuration mode on Juniper ScreenOS."""
          -        return ""
           
          -    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
          +    def save_config(
          +        self,
          +        cmd: str = "save config",
          +        confirm: bool = False,
          +        confirm_response: str = "",
          +    ) -> str:
                   """Save Config."""
          -        return self.send_command(command_string=cmd)
          + return self._send_command_str(command_string=cmd)
          @@ -85,7 +67,7 @@

          Classes

          class JuniperScreenOsSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

          Implement methods for interacting with Juniper ScreenOS devices.

          @@ -93,259 +75,143 @@

          Classes

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
  • -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class JuniperScreenOsSSH(BaseConnection):
    +
    class JuniperScreenOsSSH(NoEnable, NoConfig, BaseConnection):
         """
         Implement methods for interacting with Juniper ScreenOS devices.
         """
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """
    -        Prepare the session after the connection has been established.
    -
    -        Disable paging (the '--more--' prompts).
    -        Set the base prompt for interaction ('>').
    +        ScreenOS can be configured to require: Accept this agreement y/[n]
             """
    -        self._test_channel_read()
    +        terminator = r"\->"
    +        pattern = rf"(Accept this|{terminator})"
    +        data = self._test_channel_read(pattern=pattern)
    +        if "Accept this" in data:
    +            self.write_channel("y")
    +            data += self._test_channel_read(pattern=terminator)
    +
             self.set_base_prompt()
             self.disable_paging(command="set console page 0")
    -        # Clear the read buffer
    -        time.sleep(0.3 * self.global_delay_factor)
    -        self.clear_buffer()
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return True
     
    -    def enable(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """No enable mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def check_config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return False
    -
    -    def config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """No configuration mode on Juniper ScreenOS."""
    -        return ""
    -
    -    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
    +    def save_config(
    +        self,
    +        cmd: str = "save config",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Save Config."""
    -        return self.send_command(command_string=cmd)
    + return self._send_command_str(command_string=cmd)

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return True
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No configuration mode on Juniper ScreenOS.

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No configuration mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on Juniper ScreenOS.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on Juniper ScreenOS."""
    -    return ""
    -
    -
    def save_config(self, cmd='save config', confirm=False, confirm_response='')
    @@ -353,33 +219,36 @@

    Methods

    Save Config.

    Source code -
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "save config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Save Config."""
    -    return self.send_command(command_string=cmd)
    + return self._send_command_str(command_string=cmd)
    def session_preparation(self)
    -

    Prepare the session after the connection has been established.

    -

    Disable paging (the '–more–' prompts). -Set the base prompt for interaction ('>').

    +

    ScreenOS can be configured to require: Accept this agreement y/[n]

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
    -    Prepare the session after the connection has been established.
    -
    -    Disable paging (the '--more--' prompts).
    -    Set the base prompt for interaction ('>').
    +    ScreenOS can be configured to require: Accept this agreement y/[n]
         """
    -    self._test_channel_read()
    +    terminator = r"\->"
    +    pattern = rf"(Accept this|{terminator})"
    +    data = self._test_channel_read(pattern=pattern)
    +    if "Accept this" in data:
    +        self.write_channel("y")
    +        data += self._test_channel_read(pattern=terminator)
    +
         self.set_base_prompt()
    -    self.disable_paging(command="set console page 0")
    -    # Clear the read buffer
    -    time.sleep(0.3 * self.global_delay_factor)
    -    self.clear_buffer()
    + self.disable_paging(command="set console page 0")
    @@ -387,20 +256,25 @@

    Inherited members

    • BaseConnection:
        +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -411,6 +285,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -442,13 +317,7 @@

        Index

        • JuniperScreenOsSSH

          -
            -
          • check_config_mode
          • -
          • check_enable_mode
          • -
          • config_mode
          • -
          • enable
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • + diff --git a/docs/netmiko/keymile/index.html b/docs/netmiko/keymile/index.html index 25d6e5392..528bda949 100644 --- a/docs/netmiko/keymile/index.html +++ b/docs/netmiko/keymile/index.html @@ -50,7 +50,7 @@

            Classes

            class KeymileNOSSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Common Methods for IOS (both SSH and telnet).

            @@ -58,143 +58,116 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class KeymileNOSSSH(CiscoIosBase):
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.set_base_prompt()
             self.disable_paging()
             time.sleep(0.3 * self.global_delay_factor)
             self.clear_buffer()
     
    -    def _test_channel_read(self, count=40, pattern=""):
    +    def _test_channel_read(self, count: int = 40, pattern: str = "") -> str:
             """Since Keymile NOS always returns True on paramiko.connect() we
             check the output for substring Login incorrect after connecting."""
             output = super()._test_channel_read(count=count, pattern=pattern)
    @@ -208,7 +181,7 @@ 

    Classes

    else: return output - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" self._test_channel_read(pattern=r"(>|Login incorrect)")
    @@ -222,14 +195,14 @@

    Ancestors

    Methods

    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """Since Keymile NOS always returns True on paramiko.connect() we
         check the output for substring Login incorrect after connecting."""
         self._test_channel_read(pattern=r"(>|Login incorrect)")
    @@ -244,9 +217,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -257,9 +229,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -271,6 +243,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -289,233 +262,62 @@

    Inherited members

    (**kwargs)
    -

    Common Methods for IOS (both SSH and telnet).

    -
        Initialize attributes for establishing connection to target device.
    -
    -    :param ip: IP address of target device. Not required if `host` is
    -        provided.
    -    :type ip: str
    -
    -    :param host: Hostname of target device. Not required if `ip` is
    -            provided.
    -    :type host: str
    -
    -    :param username: Username to authenticate against target device if
    -            required.
    -    :type username: str
    -
    -    :param password: Password to authenticate against target device if
    -            required.
    -    :type password: str
    -
    -    :param secret: The enable password if target device requires one.
    -    :type secret: str
    -
    -    :param port: The destination port used to connect to the target
    -            device.
    -    :type port: int or None
    -
    -    :param device_type: Class selection based on device type.
    -    :type device_type: str
    -
    -    :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
    -
    -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
    -
    -    :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
    -
    -    :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
    -
    -    :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
    -
    -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    -            decryption if not specified.
    -    :type passphrase: str
    -
    -    :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
    -
    -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    -            means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
    -
    -    :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    -            alt_key_file.
    -    :type alt_host_keys: bool
    -
    -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
    -
    -    :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
    -
    -    :param timeout: Connection timeout.
    -    :type timeout: float
    -
    -    :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
    -
    -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
    -
    -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
    -
    -    :param 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).
    -    :type keepalive: int
    -
    -    :param default_enter: Character(s) to send to correspond to enter key (default:
    -
    -

    ). -:type default_enter: str

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

    ) -:type response_return: str

    -
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    -            to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    -
    -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
    -
    -    :param session_log_record_writes: The session log generally only records channel reads due
    -            to eliminate command duplication due to command echo. You can enable this if you
    -            want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
    -
    -    :param session_log_file_mode: "write" or "append" for session_log file mode
    -            (default: "write")
    -    :type session_log_file_mode: str
    -
    -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    -            (default: False)
    -    :type allow_auto_change: bool
    -
    -    :param encoding: Encoding to be used when writing bytes to the output channel.
    -            (default: ascii)
    -    :type encoding: str
    -
    -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    -            communication to the target host (default: None).
    -    :type sock: socket
    -
    -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    -            (default: None). Global attribute takes precedence over function `cmd_verify`
    -            argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
    -
    -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    -            part of the object creation (default: True).
    -    :type auto_connect: bool
    -
    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

    Source code -
    class KeymileSSH(CiscoIosBase):
    -    def __init__(self, **kwargs):
    +
    class KeymileSSH(NoEnable, NoConfig, CiscoIosBase):
    +    def __init__(self, **kwargs: Any) -> None:
             kwargs.setdefault("default_enter", "\r\n")
    -        return super().__init__(**kwargs)
    +        super().__init__(**kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r">")
             self.set_base_prompt()
             time.sleep(0.3 * self.global_delay_factor)
             self.clear_buffer()
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Keymile does not use paging."""
             return ""
     
    -    def check_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return False
    -
    -    def config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return False
    -
    -    def enable(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def strip_prompt(self, a_string):
    +    def strip_prompt(self, a_string: str) -> str:
             """Remove appending empty line and prompt from output"""
    -        self._write_session_log(a_string)
             a_string = a_string[:-1]
             return super().strip_prompt(a_string=a_string)
     
    -    def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
    -        """ set prompt termination  to >"""
    -        return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    + def set_base_prompt( + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: + """set prompt termination to >""" + return super().set_base_prompt( + pri_prompt_terminator=pri_prompt_terminator, + alt_prompt_terminator=alt_prompt_terminator, + delay_factor=delay_factor, + pattern=pattern, + )

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return False
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return ""
    -
    -
    def disable_paging(self, *args, **kwargs)
    @@ -523,58 +325,32 @@

    Methods

    Keymile does not use paging.

    Source code -
    def disable_paging(self, *args, **kwargs):
    +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
         """Keymile does not use paging."""
         return ""
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return ""
    -
    -
    -def set_base_prompt(self, pri_prompt_terminator='>', **kwargs) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='>', delay_factor=1.0, pattern=None)
    -

    set prompt termination -to >

    +

    set prompt termination to >

    Source code -
    def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
    -    """ set prompt termination  to >"""
    -    return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    +
    def set_base_prompt(
    +    self,
    +    pri_prompt_terminator: str = ">",
    +    alt_prompt_terminator: str = ">",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
    +    """set prompt termination to >"""
    +    return super().set_base_prompt(
    +        pri_prompt_terminator=pri_prompt_terminator,
    +        alt_prompt_terminator=alt_prompt_terminator,
    +        delay_factor=delay_factor,
    +        pattern=pattern,
    +    )
    @@ -584,9 +360,8 @@

    Methods

    Remove appending empty line and prompt from output

    Source code -
    def strip_prompt(self, a_string):
    +
    def strip_prompt(self, a_string: str) -> str:
         """Remove appending empty line and prompt from output"""
    -    self._write_session_log(a_string)
         a_string = a_string[:-1]
         return super().strip_prompt(a_string=a_string)
    @@ -596,19 +371,24 @@

    Inherited members

    @@ -69,7 +69,7 @@

    Classes

    class KeymileNOSSSH -(*args, **kwargs) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Common Methods for IOS (both SSH and telnet).

    @@ -77,143 +77,116 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class KeymileNOSSSH(CiscoIosBase):
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.set_base_prompt()
             self.disable_paging()
             time.sleep(0.3 * self.global_delay_factor)
             self.clear_buffer()
     
    -    def _test_channel_read(self, count=40, pattern=""):
    +    def _test_channel_read(self, count: int = 40, pattern: str = "") -> str:
             """Since Keymile NOS always returns True on paramiko.connect() we
             check the output for substring Login incorrect after connecting."""
             output = super()._test_channel_read(count=count, pattern=pattern)
    @@ -227,7 +200,7 @@ 

    Classes

    else: return output - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" self._test_channel_read(pattern=r"(>|Login incorrect)")
    @@ -241,14 +214,14 @@

    Ancestors

    Methods

    -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

    Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.

    Source code -
    def special_login_handler(self, delay_factor=1):
    +
    def special_login_handler(self, delay_factor: float = 1.0) -> None:
         """Since Keymile NOS always returns True on paramiko.connect() we
         check the output for substring Login incorrect after connecting."""
         self._test_channel_read(pattern=r"(>|Login incorrect)")
    @@ -263,9 +236,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -276,9 +248,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -290,6 +262,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/keymile/keymile_ssh.html b/docs/netmiko/keymile/keymile_ssh.html index cbb77167a..e95cc85ed 100644 --- a/docs/netmiko/keymile/keymile_ssh.html +++ b/docs/netmiko/keymile/keymile_ssh.html @@ -22,60 +22,49 @@

    Module netmiko.keymile.keymile_ssh

    Source code -
    import time
    +
    from typing import Any, Optional
    +import time
     
    +from netmiko.no_enable import NoEnable
    +from netmiko.no_config import NoConfig
     from netmiko.cisco.cisco_ios import CiscoIosBase
     
     
    -class KeymileSSH(CiscoIosBase):
    -    def __init__(self, **kwargs):
    +class KeymileSSH(NoEnable, NoConfig, CiscoIosBase):
    +    def __init__(self, **kwargs: Any) -> None:
             kwargs.setdefault("default_enter", "\r\n")
    -        return super().__init__(**kwargs)
    +        super().__init__(**kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r">")
             self.set_base_prompt()
             time.sleep(0.3 * self.global_delay_factor)
             self.clear_buffer()
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Keymile does not use paging."""
             return ""
     
    -    def check_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return False
    -
    -    def config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return False
    -
    -    def enable(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def strip_prompt(self, a_string):
    +    def strip_prompt(self, a_string: str) -> str:
             """Remove appending empty line and prompt from output"""
    -        self._write_session_log(a_string)
             a_string = a_string[:-1]
             return super().strip_prompt(a_string=a_string)
     
    -    def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
    -        """ set prompt termination  to >"""
    -        return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    + def set_base_prompt( + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: + """set prompt termination to >""" + return super().set_base_prompt( + pri_prompt_terminator=pri_prompt_terminator, + alt_prompt_terminator=alt_prompt_terminator, + delay_factor=delay_factor, + pattern=pattern, + )
    @@ -92,233 +81,62 @@

    Classes

    (**kwargs)
    -

    Common Methods for IOS (both SSH and telnet).

    -
        Initialize attributes for establishing connection to target device.
    -
    -    :param ip: IP address of target device. Not required if `host` is
    -        provided.
    -    :type ip: str
    -
    -    :param host: Hostname of target device. Not required if `ip` is
    -            provided.
    -    :type host: str
    -
    -    :param username: Username to authenticate against target device if
    -            required.
    -    :type username: str
    -
    -    :param password: Password to authenticate against target device if
    -            required.
    -    :type password: str
    -
    -    :param secret: The enable password if target device requires one.
    -    :type secret: str
    -
    -    :param port: The destination port used to connect to the target
    -            device.
    -    :type port: int or None
    -
    -    :param device_type: Class selection based on device type.
    -    :type device_type: str
    -
    -    :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
    -
    -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
    -
    -    :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
    -
    -    :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
    -
    -    :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
    -
    -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
    -            decryption if not specified.
    -    :type passphrase: str
    -
    -    :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
    -
    -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
    -            means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
    -
    -    :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
    -            alt_key_file.
    -    :type alt_host_keys: bool
    -
    -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
    -
    -    :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
    -
    -    :param timeout: Connection timeout.
    -    :type timeout: float
    -
    -    :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
    -
    -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
    -
    -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
    -
    -    :param 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).
    -    :type keepalive: int
    -
    -    :param default_enter: Character(s) to send to correspond to enter key (default:
    -
    -

    ). -:type default_enter: str

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

    ) -:type response_return: str

    -
        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
    -            to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    -
    -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
    -
    -    :param session_log_record_writes: The session log generally only records channel reads due
    -            to eliminate command duplication due to command echo. You can enable this if you
    -            want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
    -
    -    :param session_log_file_mode: "write" or "append" for session_log file mode
    -            (default: "write")
    -    :type session_log_file_mode: str
    -
    -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
    -            (default: False)
    -    :type allow_auto_change: bool
    -
    -    :param encoding: Encoding to be used when writing bytes to the output channel.
    -            (default: ascii)
    -    :type encoding: str
    -
    -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
    -            communication to the target host (default: None).
    -    :type sock: socket
    -
    -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    -            (default: None). Global attribute takes precedence over function `cmd_verify`
    -            argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
    -
    -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    -            part of the object creation (default: True).
    -    :type auto_connect: bool
    -
    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

    Source code -
    class KeymileSSH(CiscoIosBase):
    -    def __init__(self, **kwargs):
    +
    class KeymileSSH(NoEnable, NoConfig, CiscoIosBase):
    +    def __init__(self, **kwargs: Any) -> None:
             kwargs.setdefault("default_enter", "\r\n")
    -        return super().__init__(**kwargs)
    +        super().__init__(**kwargs)
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r">")
             self.set_base_prompt()
             time.sleep(0.3 * self.global_delay_factor)
             self.clear_buffer()
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Keymile does not use paging."""
             return ""
     
    -    def check_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return False
    -
    -    def config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def exit_config_mode(self, *args, **kwargs):
    -        """Keymile does not use config mode."""
    -        return ""
    -
    -    def check_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return False
    -
    -    def enable(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def exit_enable_mode(self, *args, **kwargs):
    -        """Keymile does not use enable mode."""
    -        return ""
    -
    -    def strip_prompt(self, a_string):
    +    def strip_prompt(self, a_string: str) -> str:
             """Remove appending empty line and prompt from output"""
    -        self._write_session_log(a_string)
             a_string = a_string[:-1]
             return super().strip_prompt(a_string=a_string)
     
    -    def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
    -        """ set prompt termination  to >"""
    -        return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    + def set_base_prompt( + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: + """set prompt termination to >""" + return super().set_base_prompt( + pri_prompt_terminator=pri_prompt_terminator, + alt_prompt_terminator=alt_prompt_terminator, + delay_factor=delay_factor, + pattern=pattern, + )

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return False
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return ""
    -
    -
    def disable_paging(self, *args, **kwargs)
    @@ -326,58 +144,32 @@

    Methods

    Keymile does not use paging.

    Source code -
    def disable_paging(self, *args, **kwargs):
    +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
         """Keymile does not use paging."""
         return ""
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use config mode.

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """Keymile does not use config mode."""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    Keymile does not use enable mode.

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """Keymile does not use enable mode."""
    -    return ""
    -
    -
    -def set_base_prompt(self, pri_prompt_terminator='>', **kwargs) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='>', delay_factor=1.0, pattern=None)
    -

    set prompt termination -to >

    +

    set prompt termination to >

    Source code -
    def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
    -    """ set prompt termination  to >"""
    -    return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    +
    def set_base_prompt(
    +    self,
    +    pri_prompt_terminator: str = ">",
    +    alt_prompt_terminator: str = ">",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
    +    """set prompt termination to >"""
    +    return super().set_base_prompt(
    +        pri_prompt_terminator=pri_prompt_terminator,
    +        alt_prompt_terminator=alt_prompt_terminator,
    +        delay_factor=delay_factor,
    +        pattern=pattern,
    +    )
    @@ -387,9 +179,8 @@

    Methods

    Remove appending empty line and prompt from output

    Source code -
    def strip_prompt(self, a_string):
    +
    def strip_prompt(self, a_string: str) -> str:
         """Remove appending empty line and prompt from output"""
    -    self._write_session_log(a_string)
         a_string = a_string[:-1]
         return super().strip_prompt(a_string=a_string)
    @@ -399,19 +190,24 @@

    Inherited members

    • CiscoIosBase:
        +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -423,6 +219,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_terminal_width
      • special_login_handler
      • @@ -453,14 +250,8 @@

        Index

        • KeymileSSH

          -
            -
          • check_config_mode
          • -
          • check_enable_mode
          • -
          • config_mode
          • + diff --git a/docs/netmiko/linux/index.html b/docs/netmiko/linux/index.html index 25045535c..4a2afa66d 100644 --- a/docs/netmiko/linux/index.html +++ b/docs/netmiko/linux/index.html @@ -61,14 +61,14 @@

            Classes

            def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -77,43 +77,45 @@

            Classes

            **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="md5sum", remote_file=None): + def remote_md5( + self, base_cmd: str = "md5sum", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=2 - ) - dest_md5 = self.process_md5(dest_md5) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + dest_md5 = self.process_md5(dest_md5).strip() return dest_md5 @staticmethod - def process_md5(md5_output, pattern=r"^(\S+)\s+"): + def process_md5(md5_output: str, pattern: str = r"^(\S+)\s+") -> str: return super(LinuxFileTransfer, LinuxFileTransfer).process_md5( md5_output, pattern=pattern ) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

    Ancestors

    @@ -148,7 +150,7 @@

    Inherited members

    class LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -156,166 +158,146 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class LinuxSSH(CiscoSSHConnection):
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.ansi_escape_codes = True
             return super().session_preparation()
     
    -    def _enter_shell(self):
    +    def _enter_shell(self) -> str:
             """Already in shell."""
             return ""
     
    -    def _return_cli(self):
    +    def _return_cli(self) -> str:
             """The shell is the CLI."""
             return ""
     
    -    def disable_paging(self, *args, **kwargs):
    +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
             """Linux doesn't have paging by default."""
             return ""
     
         def set_base_prompt(
             self,
    -        pri_prompt_terminator=LINUX_PROMPT_PRI,
    -        alt_prompt_terminator=LINUX_PROMPT_ALT,
    -        delay_factor=1,
    -    ):
    +        pri_prompt_terminator: str = LINUX_PROMPT_PRI,
    +        alt_prompt_terminator: str = LINUX_PROMPT_ALT,
    +        delay_factor: float = 1.0,
    +        pattern: Optional[str] = None,
    +    ) -> str:
             """Determine base prompt."""
             return super().set_base_prompt(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 delay_factor=delay_factor,
    +            pattern=pattern,
             )
     
    -    def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs):
    +    def send_config_set(
    +        self,
    +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +        exit_config_mode: bool = True,
    +        **kwargs: Any,
    +    ) -> str:
             """Can't exit from root (if root)"""
             if self.username == "root":
                 exit_config_mode = False
    @@ -323,24 +305,34 @@ 

    Inherited members

    config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def check_config_mode(self, check_string=LINUX_PROMPT_ROOT, pattern=""): + def check_config_mode( + self, check_string: str = LINUX_PROMPT_ROOT, pattern: str = "" + ) -> bool: """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo -s"): + def config_mode( + self, + config_command: str = "sudo -s", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" - return self.enable(cmd=config_command) + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: return self.exit_enable_mode(exit_command=exit_config) - def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): + def check_enable_mode(self, check_string: str = LINUX_PROMPT_ROOT) -> bool: """Verify root""" return super().check_enable_mode(check_string=check_string) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" delay_factor = self.select_delay_factor(delay_factor=0) + # You can run into a timing issue here if the time.sleep is too small + if delay_factor < 1: + delay_factor = 1 output = "" if self.check_enable_mode(): self.write_channel(self.normalize_cmd(exit_command)) @@ -350,7 +342,13 @@

    Inherited members

    raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "sudo -s", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -374,11 +372,11 @@

    Inherited members

    raise ValueError(msg) return output - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Try to Gracefully exit the SSH session.""" return super().cleanup(command=command) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError
    @@ -402,7 +400,9 @@

    Methods

    Verify root

    Source code -
    def check_config_mode(self, check_string=LINUX_PROMPT_ROOT, pattern=""):
    +
    def check_config_mode(
    +    self, check_string: str = LINUX_PROMPT_ROOT, pattern: str = ""
    +) -> bool:
         """Verify root"""
         return self.check_enable_mode(check_string=check_string)
    @@ -414,7 +414,7 @@

    Methods

    Verify root

    Source code -
    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT):
    +
    def check_enable_mode(self, check_string: str = LINUX_PROMPT_ROOT) -> bool:
         """Verify root"""
         return super().check_enable_mode(check_string=check_string)
    @@ -426,21 +426,26 @@

    Methods

    Try to Gracefully exit the SSH session.

    Source code -
    def cleanup(self, command="exit"):
    +
    def cleanup(self, command: str = "exit") -> None:
         """Try to Gracefully exit the SSH session."""
         return super().cleanup(command=command)
    -def config_mode(self, config_command='sudo -s') +def config_mode(self, config_command='sudo -s', pattern='ssword', re_flags=)

    Attempt to become root.

    Source code -
    def config_mode(self, config_command="sudo -s"):
    +
    def config_mode(
    +    self,
    +    config_command: str = "sudo -s",
    +    pattern: str = "ssword",
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
         """Attempt to become root."""
    -    return self.enable(cmd=config_command)
    + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags)
    @@ -450,19 +455,25 @@

    Methods

    Linux doesn't have paging by default.

    Source code -
    def disable_paging(self, *args, **kwargs):
    +
    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
         """Linux doesn't have paging by default."""
         return ""
    -def enable(self, cmd='sudo -s', pattern='ssword', re_flags=) +def enable(self, cmd='sudo -s', pattern='ssword', enable_pattern=None, re_flags=)

    Attempt to become root.

    Source code -
    def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE):
    +
    def enable(
    +    self,
    +    cmd: str = "sudo -s",
    +    pattern: str = "ssword",
    +    enable_pattern: Optional[str] = None,
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
         """Attempt to become root."""
         delay_factor = self.select_delay_factor(delay_factor=0)
         output = ""
    @@ -494,9 +505,12 @@ 

    Methods

    Exit enable mode.

    Source code -
    def exit_enable_mode(self, exit_command="exit"):
    +
    def exit_enable_mode(self, exit_command: str = "exit") -> str:
         """Exit enable mode."""
         delay_factor = self.select_delay_factor(delay_factor=0)
    +    # You can run into a timing issue here if the time.sleep is too small
    +    if delay_factor < 1:
    +        delay_factor = 1
         output = ""
         if self.check_enable_mode():
             self.write_channel(self.normalize_cmd(exit_command))
    @@ -514,7 +528,7 @@ 

    Methods

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -526,7 +540,12 @@

    Methods

    Can't exit from root (if root)

    Source code -
    def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs):
    +
    def send_config_set(
    +    self,
    +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
    +    exit_config_mode: bool = True,
    +    **kwargs: Any,
    +) -> str:
         """Can't exit from root (if root)"""
         if self.username == "root":
             exit_config_mode = False
    @@ -542,14 +561,14 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
         return super().session_preparation()
    -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

    Determine base prompt.

    @@ -557,15 +576,17 @@

    Methods

    Source code
    def set_base_prompt(
         self,
    -    pri_prompt_terminator=LINUX_PROMPT_PRI,
    -    alt_prompt_terminator=LINUX_PROMPT_ALT,
    -    delay_factor=1,
    -):
    +    pri_prompt_terminator: str = LINUX_PROMPT_PRI,
    +    alt_prompt_terminator: str = LINUX_PROMPT_ALT,
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """Determine base prompt."""
         return super().set_base_prompt(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             delay_factor=delay_factor,
    +        pattern=pattern,
         )
    @@ -575,7 +596,6 @@

    Inherited members

  • CiscoSSHConnection:
    • clear_buffer
    • -
    • close_session_log
    • commit
    • disconnect
    • establish_connection
    • @@ -584,9 +604,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -596,6 +616,7 @@

      Inherited members

    • send_command_expect
    • send_command_timing
    • send_config_from_file
    • +
    • send_multiline
    • set_terminal_width
    • special_login_handler
    • strip_ansi_escape_codes
    • diff --git a/docs/netmiko/linux/linux_ssh.html b/docs/netmiko/linux/linux_ssh.html index 99d923144..6f2fdc570 100644 --- a/docs/netmiko/linux/linux_ssh.html +++ b/docs/netmiko/linux/linux_ssh.html @@ -22,14 +22,18 @@

      Module netmiko.linux.linux_ssh

      Source code -
      import os
      +
      from typing import Any, Optional, TYPE_CHECKING, Union, Sequence, TextIO
      +import os
       import re
       import socket
       import time
       
      +if TYPE_CHECKING:
      +    from netmiko.base_connection import BaseConnection
      +
       from netmiko.cisco_base_connection import CiscoSSHConnection
       from netmiko.cisco_base_connection import CiscoFileTransfer
      -from netmiko.ssh_exception import NetmikoTimeoutException
      +from netmiko.exceptions import NetmikoTimeoutException
       
       LINUX_PROMPT_PRI = os.getenv("NETMIKO_LINUX_PROMPT_PRI", "$")
       LINUX_PROMPT_ALT = os.getenv("NETMIKO_LINUX_PROMPT_ALT", "#")
      @@ -37,37 +41,44 @@ 

      Module netmiko.linux.linux_ssh

      class LinuxSSH(CiscoSSHConnection): - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True return super().session_preparation() - def _enter_shell(self): + def _enter_shell(self) -> str: """Already in shell.""" return "" - def _return_cli(self): + def _return_cli(self) -> str: """The shell is the CLI.""" return "" - def disable_paging(self, *args, **kwargs): + def disable_paging(self, *args: Any, **kwargs: Any) -> str: """Linux doesn't have paging by default.""" return "" def set_base_prompt( self, - pri_prompt_terminator=LINUX_PROMPT_PRI, - alt_prompt_terminator=LINUX_PROMPT_ALT, - delay_factor=1, - ): + pri_prompt_terminator: str = LINUX_PROMPT_PRI, + alt_prompt_terminator: str = LINUX_PROMPT_ALT, + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Determine base prompt.""" return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) - def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = True, + **kwargs: Any, + ) -> str: """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False @@ -75,24 +86,34 @@

      Module netmiko.linux.linux_ssh

      config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def check_config_mode(self, check_string=LINUX_PROMPT_ROOT, pattern=""): + def check_config_mode( + self, check_string: str = LINUX_PROMPT_ROOT, pattern: str = "" + ) -> bool: """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo -s"): + def config_mode( + self, + config_command: str = "sudo -s", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" - return self.enable(cmd=config_command) + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: return self.exit_enable_mode(exit_command=exit_config) - def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): + def check_enable_mode(self, check_string: str = LINUX_PROMPT_ROOT) -> bool: """Verify root""" return super().check_enable_mode(check_string=check_string) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" delay_factor = self.select_delay_factor(delay_factor=0) + # You can run into a timing issue here if the time.sleep is too small + if delay_factor < 1: + delay_factor = 1 output = "" if self.check_enable_mode(): self.write_channel(self.normalize_cmd(exit_command)) @@ -102,7 +123,13 @@

      Module netmiko.linux.linux_ssh

      raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "sudo -s", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -126,11 +153,11 @@

      Module netmiko.linux.linux_ssh

      raise ValueError(msg) return output - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Try to Gracefully exit the SSH session.""" return super().cleanup(command=command) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError @@ -144,14 +171,14 @@

      Module netmiko.linux.linux_ssh

      def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -160,43 +187,45 @@

      Module netmiko.linux.linux_ssh

      **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="md5sum", remote_file=None): + def remote_md5( + self, base_cmd: str = "md5sum", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=2 - ) - dest_md5 = self.process_md5(dest_md5) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + dest_md5 = self.process_md5(dest_md5).strip() return dest_md5 @staticmethod - def process_md5(md5_output, pattern=r"^(\S+)\s+"): + def process_md5(md5_output: str, pattern: str = r"^(\S+)\s+") -> str: return super(LinuxFileTransfer, LinuxFileTransfer).process_md5( md5_output, pattern=pattern ) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError
      @@ -227,14 +256,14 @@

      Classes

      def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system="/var/tmp", - direction="put", - **kwargs, - ): - return super().__init__( + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = "/var/tmp", + direction: str = "put", + **kwargs: Any, + ) -> None: + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, @@ -243,43 +272,45 @@

      Classes

      **kwargs, ) - def remote_space_available(self, search_pattern=""): + def remote_space_available(self, search_pattern: str = "") -> int: """Return space available on remote device.""" return self._remote_space_available_unix(search_pattern=search_pattern) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" return self._check_file_exists_unix(remote_cmd=remote_cmd) - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" return self._remote_file_size_unix( remote_cmd=remote_cmd, remote_file=remote_file ) - def remote_md5(self, base_cmd="md5sum", remote_file=None): + def remote_md5( + self, base_cmd: str = "md5sum", remote_file: Optional[str] = None + ) -> str: if remote_file is None: if self.direction == "put": remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command( - remote_md5_cmd, max_loops=750, delay_factor=2 - ) - dest_md5 = self.process_md5(dest_md5) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) + dest_md5 = self.process_md5(dest_md5).strip() return dest_md5 @staticmethod - def process_md5(md5_output, pattern=r"^(\S+)\s+"): + def process_md5(md5_output: str, pattern: str = r"^(\S+)\s+") -> str: return super(LinuxFileTransfer, LinuxFileTransfer).process_md5( md5_output, pattern=pattern ) - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "") -> None: raise NotImplementedError - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "") -> None: raise NotImplementedError

      Ancestors

      @@ -314,7 +345,7 @@

      Inherited members

      class LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Base Class for cisco-like behavior.

      @@ -322,166 +353,146 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class LinuxSSH(CiscoSSHConnection):
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self.ansi_escape_codes = True
               return super().session_preparation()
       
      -    def _enter_shell(self):
      +    def _enter_shell(self) -> str:
               """Already in shell."""
               return ""
       
      -    def _return_cli(self):
      +    def _return_cli(self) -> str:
               """The shell is the CLI."""
               return ""
       
      -    def disable_paging(self, *args, **kwargs):
      +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
               """Linux doesn't have paging by default."""
               return ""
       
           def set_base_prompt(
               self,
      -        pri_prompt_terminator=LINUX_PROMPT_PRI,
      -        alt_prompt_terminator=LINUX_PROMPT_ALT,
      -        delay_factor=1,
      -    ):
      +        pri_prompt_terminator: str = LINUX_PROMPT_PRI,
      +        alt_prompt_terminator: str = LINUX_PROMPT_ALT,
      +        delay_factor: float = 1.0,
      +        pattern: Optional[str] = None,
      +    ) -> str:
               """Determine base prompt."""
               return super().set_base_prompt(
                   pri_prompt_terminator=pri_prompt_terminator,
                   alt_prompt_terminator=alt_prompt_terminator,
                   delay_factor=delay_factor,
      +            pattern=pattern,
               )
       
      -    def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs):
      +    def send_config_set(
      +        self,
      +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
      +        exit_config_mode: bool = True,
      +        **kwargs: Any,
      +    ) -> str:
               """Can't exit from root (if root)"""
               if self.username == "root":
                   exit_config_mode = False
      @@ -489,24 +500,34 @@ 

      Inherited members

      config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def check_config_mode(self, check_string=LINUX_PROMPT_ROOT, pattern=""): + def check_config_mode( + self, check_string: str = LINUX_PROMPT_ROOT, pattern: str = "" + ) -> bool: """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo -s"): + def config_mode( + self, + config_command: str = "sudo -s", + pattern: str = "ssword", + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" - return self.enable(cmd=config_command) + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "") -> str: return self.exit_enable_mode(exit_command=exit_config) - def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): + def check_enable_mode(self, check_string: str = LINUX_PROMPT_ROOT) -> bool: """Verify root""" return super().check_enable_mode(check_string=check_string) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" delay_factor = self.select_delay_factor(delay_factor=0) + # You can run into a timing issue here if the time.sleep is too small + if delay_factor < 1: + delay_factor = 1 output = "" if self.check_enable_mode(): self.write_channel(self.normalize_cmd(exit_command)) @@ -516,7 +537,13 @@

      Inherited members

      raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "sudo -s", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -540,11 +567,11 @@

      Inherited members

      raise ValueError(msg) return output - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Try to Gracefully exit the SSH session.""" return super().cleanup(command=command) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError
      @@ -568,7 +595,9 @@

      Methods

      Verify root

      Source code -
      def check_config_mode(self, check_string=LINUX_PROMPT_ROOT, pattern=""):
      +
      def check_config_mode(
      +    self, check_string: str = LINUX_PROMPT_ROOT, pattern: str = ""
      +) -> bool:
           """Verify root"""
           return self.check_enable_mode(check_string=check_string)
      @@ -580,7 +609,7 @@

      Methods

      Verify root

      Source code -
      def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT):
      +
      def check_enable_mode(self, check_string: str = LINUX_PROMPT_ROOT) -> bool:
           """Verify root"""
           return super().check_enable_mode(check_string=check_string)
      @@ -592,21 +621,26 @@

      Methods

      Try to Gracefully exit the SSH session.

      Source code -
      def cleanup(self, command="exit"):
      +
      def cleanup(self, command: str = "exit") -> None:
           """Try to Gracefully exit the SSH session."""
           return super().cleanup(command=command)
      -def config_mode(self, config_command='sudo -s') +def config_mode(self, config_command='sudo -s', pattern='ssword', re_flags=)

      Attempt to become root.

      Source code -
      def config_mode(self, config_command="sudo -s"):
      +
      def config_mode(
      +    self,
      +    config_command: str = "sudo -s",
      +    pattern: str = "ssword",
      +    re_flags: int = re.IGNORECASE,
      +) -> str:
           """Attempt to become root."""
      -    return self.enable(cmd=config_command)
      + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags)
      @@ -616,19 +650,25 @@

      Methods

      Linux doesn't have paging by default.

      Source code -
      def disable_paging(self, *args, **kwargs):
      +
      def disable_paging(self, *args: Any, **kwargs: Any) -> str:
           """Linux doesn't have paging by default."""
           return ""
      -def enable(self, cmd='sudo -s', pattern='ssword', re_flags=) +def enable(self, cmd='sudo -s', pattern='ssword', enable_pattern=None, re_flags=)

      Attempt to become root.

      Source code -
      def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE):
      +
      def enable(
      +    self,
      +    cmd: str = "sudo -s",
      +    pattern: str = "ssword",
      +    enable_pattern: Optional[str] = None,
      +    re_flags: int = re.IGNORECASE,
      +) -> str:
           """Attempt to become root."""
           delay_factor = self.select_delay_factor(delay_factor=0)
           output = ""
      @@ -660,9 +700,12 @@ 

      Methods

      Exit enable mode.

      Source code -
      def exit_enable_mode(self, exit_command="exit"):
      +
      def exit_enable_mode(self, exit_command: str = "exit") -> str:
           """Exit enable mode."""
           delay_factor = self.select_delay_factor(delay_factor=0)
      +    # You can run into a timing issue here if the time.sleep is too small
      +    if delay_factor < 1:
      +        delay_factor = 1
           output = ""
           if self.check_enable_mode():
               self.write_channel(self.normalize_cmd(exit_command))
      @@ -680,7 +723,7 @@ 

      Methods

      Not Implemented

      Source code -
      def save_config(self, *args, **kwargs):
      +
      def save_config(self, *args: Any, **kwargs: Any) -> str:
           """Not Implemented"""
           raise NotImplementedError
      @@ -692,7 +735,12 @@

      Methods

      Can't exit from root (if root)

      Source code -
      def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs):
      +
      def send_config_set(
      +    self,
      +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
      +    exit_config_mode: bool = True,
      +    **kwargs: Any,
      +) -> str:
           """Can't exit from root (if root)"""
           if self.username == "root":
               exit_config_mode = False
      @@ -708,14 +756,14 @@ 

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           self.ansi_escape_codes = True
           return super().session_preparation()
      -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

      Determine base prompt.

      @@ -723,15 +771,17 @@

      Methods

      Source code
      def set_base_prompt(
           self,
      -    pri_prompt_terminator=LINUX_PROMPT_PRI,
      -    alt_prompt_terminator=LINUX_PROMPT_ALT,
      -    delay_factor=1,
      -):
      +    pri_prompt_terminator: str = LINUX_PROMPT_PRI,
      +    alt_prompt_terminator: str = LINUX_PROMPT_ALT,
      +    delay_factor: float = 1.0,
      +    pattern: Optional[str] = None,
      +) -> str:
           """Determine base prompt."""
           return super().set_base_prompt(
               pri_prompt_terminator=pri_prompt_terminator,
               alt_prompt_terminator=alt_prompt_terminator,
               delay_factor=delay_factor,
      +        pattern=pattern,
           )
      @@ -741,7 +791,6 @@

      Inherited members

    • CiscoSSHConnection:
      • clear_buffer
      • -
      • close_session_log
      • commit
      • disconnect
      • establish_connection
      • @@ -750,9 +799,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -762,6 +811,7 @@

        Inherited members

      • send_command_expect
      • send_command_timing
      • send_config_from_file
      • +
      • send_multiline
      • set_terminal_width
      • special_login_handler
      • strip_ansi_escape_codes
      • diff --git a/docs/netmiko/mellanox/index.html b/docs/netmiko/mellanox/index.html index 21b312b0f..1576f6efe 100644 --- a/docs/netmiko/mellanox/index.html +++ b/docs/netmiko/mellanox/index.html @@ -45,7 +45,7 @@

        Classes

        class MellanoxMlnxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Mellanox MLNX-OS Switch support.

        @@ -53,159 +53,158 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class MellanoxMlnxosSSH(CiscoSSHConnection):
             """Mellanox MLNX-OS Switch support."""
         
        -    def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE):
        +    def enable(
        +        self,
        +        cmd: str = "enable",
        +        pattern: str = "#",
        +        enable_pattern: Optional[str] = None,
        +        re_flags: int = re.IGNORECASE,
        +    ) -> str:
                 """Enter into enable mode."""
                 output = ""
                 if not self.check_enable_mode():
                     self.write_channel(self.normalize_cmd(cmd))
                     output += self.read_until_prompt_or_pattern(
        -                pattern=pattern, re_flags=re_flags
        +                pattern=pattern, re_flags=re_flags, read_entire_line=True
                     )
                     if not self.check_enable_mode():
                         raise ValueError("Failed to enter enable mode.")
                 return output
         
        -    def config_mode(self, config_command="config term", pattern="#"):
        -        return super().config_mode(config_command=config_command, pattern=pattern)
        +    def config_mode(
        +        self,
        +        config_command: str = "config term",
        +        pattern: str = r"\#",
        +        re_flags: int = 0,
        +    ) -> str:
        +        return super().config_mode(
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
        +        )
         
        -    def check_config_mode(self, check_string="(config", pattern=r"#"):
        +    def check_config_mode(
        +        self, check_string: str = "(config", pattern: str = r"#"
        +    ) -> bool:
                 return super().check_config_mode(check_string=check_string, pattern=pattern)
         
        -    def disable_paging(self, command="no cli session paging enable", delay_factor=1):
        -        return super().disable_paging(command=command, delay_factor=delay_factor)
        +    def disable_paging(
        +        self,
        +        command: str = "no cli session paging enable",
        +        delay_factor: Optional[float] = None,
        +        cmd_verify: bool = True,
        +        pattern: Optional[str] = None,
        +    ) -> str:
        +        return super().disable_paging(
        +            command=command,
        +            delay_factor=delay_factor,
        +            cmd_verify=cmd_verify,
        +            pattern=pattern,
        +        )
         
        -    def exit_config_mode(self, exit_config="exit", pattern="#"):
        +    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str:
                 """Mellanox does not support a single command to completely exit configuration mode.
         
                 Consequently, need to keep checking and sending "exit".
        @@ -228,12 +227,15 @@ 

        Classes

        return output def save_config( - self, cmd="configuration write", confirm=False, confirm_response="" - ): + self, + cmd: str = "configuration write", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Save Config on Mellanox devices Enters and Leaves Config Mode""" output = self.enable() output += self.config_mode() - output += self.send_command(cmd) + output += self._send_command_str(cmd) output += self.exit_config_mode() return output
        @@ -246,19 +248,25 @@

        Ancestors

        Methods

        -def enable(self, cmd='enable', pattern='#', re_flags=) +def enable(self, cmd='enable', pattern='#', enable_pattern=None, re_flags=)

        Enter into enable mode.

        Source code -
        def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE):
        +
        def enable(
        +    self,
        +    cmd: str = "enable",
        +    pattern: str = "#",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
             """Enter into enable mode."""
             output = ""
             if not self.check_enable_mode():
                 self.write_channel(self.normalize_cmd(cmd))
                 output += self.read_until_prompt_or_pattern(
        -            pattern=pattern, re_flags=re_flags
        +            pattern=pattern, re_flags=re_flags, read_entire_line=True
                 )
                 if not self.check_enable_mode():
                     raise ValueError("Failed to enter enable mode.")
        @@ -273,7 +281,7 @@ 

        Methods

        Consequently, need to keep checking and sending "exit".

        Source code -
        def exit_config_mode(self, exit_config="exit", pattern="#"):
        +
        def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str:
             """Mellanox does not support a single command to completely exit configuration mode.
         
             Consequently, need to keep checking and sending "exit".
        @@ -304,12 +312,15 @@ 

        Methods

        Source code
        def save_config(
        -    self, cmd="configuration write", confirm=False, confirm_response=""
        -):
        +    self,
        +    cmd: str = "configuration write",
        +    confirm: bool = False,
        +    confirm_response: str = "",
        +) -> str:
             """Save Config on Mellanox devices Enters and Leaves Config Mode"""
             output = self.enable()
             output += self.config_mode()
        -    output += self.send_command(cmd)
        +    output += self._send_command_str(cmd)
             output += self.exit_config_mode()
             return output
        @@ -323,9 +334,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • establish_connection
      • @@ -334,9 +344,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -347,6 +357,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html b/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html index 554e16b88..5add9c30e 100644 --- a/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html +++ b/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html @@ -25,6 +25,8 @@

        Module netmiko.mellanox.mellanox_mlnxos_ssh

        Source code
        """Mellanox MLNX-OS Switch support."""
         import re
        +from typing import Optional
        +
         from netmiko.cisco_base_connection import CiscoSSHConnection
         from netmiko import log
         
        @@ -32,28 +34,54 @@ 

        Module netmiko.mellanox.mellanox_mlnxos_ssh

        class MellanoxMlnxosSSH(CiscoSSHConnection): """Mellanox MLNX-OS Switch support.""" - def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "#", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter into enable mode.""" output = "" if not self.check_enable_mode(): self.write_channel(self.normalize_cmd(cmd)) output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) if not self.check_enable_mode(): raise ValueError("Failed to enter enable mode.") return output - def config_mode(self, config_command="config term", pattern="#"): - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, + config_command: str = "config term", + pattern: str = r"\#", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def check_config_mode(self, check_string="(config", pattern=r"#"): + def check_config_mode( + self, check_string: str = "(config", pattern: str = r"#" + ) -> bool: return super().check_config_mode(check_string=check_string, pattern=pattern) - def disable_paging(self, command="no cli session paging enable", delay_factor=1): - return super().disable_paging(command=command, delay_factor=delay_factor) + def disable_paging( + self, + command: str = "no cli session paging enable", + delay_factor: Optional[float] = None, + cmd_verify: bool = True, + pattern: Optional[str] = None, + ) -> str: + return super().disable_paging( + command=command, + delay_factor=delay_factor, + cmd_verify=cmd_verify, + pattern=pattern, + ) - def exit_config_mode(self, exit_config="exit", pattern="#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str: """Mellanox does not support a single command to completely exit configuration mode. Consequently, need to keep checking and sending "exit". @@ -76,12 +104,15 @@

        Module netmiko.mellanox.mellanox_mlnxos_ssh

        return output def save_config( - self, cmd="configuration write", confirm=False, confirm_response="" - ): + self, + cmd: str = "configuration write", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Save Config on Mellanox devices Enters and Leaves Config Mode""" output = self.enable() output += self.config_mode() - output += self.send_command(cmd) + output += self._send_command_str(cmd) output += self.exit_config_mode() return output
        @@ -97,7 +128,7 @@

        Classes

        class MellanoxMlnxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Mellanox MLNX-OS Switch support.

        @@ -105,159 +136,158 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class MellanoxMlnxosSSH(CiscoSSHConnection):
             """Mellanox MLNX-OS Switch support."""
         
        -    def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE):
        +    def enable(
        +        self,
        +        cmd: str = "enable",
        +        pattern: str = "#",
        +        enable_pattern: Optional[str] = None,
        +        re_flags: int = re.IGNORECASE,
        +    ) -> str:
                 """Enter into enable mode."""
                 output = ""
                 if not self.check_enable_mode():
                     self.write_channel(self.normalize_cmd(cmd))
                     output += self.read_until_prompt_or_pattern(
        -                pattern=pattern, re_flags=re_flags
        +                pattern=pattern, re_flags=re_flags, read_entire_line=True
                     )
                     if not self.check_enable_mode():
                         raise ValueError("Failed to enter enable mode.")
                 return output
         
        -    def config_mode(self, config_command="config term", pattern="#"):
        -        return super().config_mode(config_command=config_command, pattern=pattern)
        +    def config_mode(
        +        self,
        +        config_command: str = "config term",
        +        pattern: str = r"\#",
        +        re_flags: int = 0,
        +    ) -> str:
        +        return super().config_mode(
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
        +        )
         
        -    def check_config_mode(self, check_string="(config", pattern=r"#"):
        +    def check_config_mode(
        +        self, check_string: str = "(config", pattern: str = r"#"
        +    ) -> bool:
                 return super().check_config_mode(check_string=check_string, pattern=pattern)
         
        -    def disable_paging(self, command="no cli session paging enable", delay_factor=1):
        -        return super().disable_paging(command=command, delay_factor=delay_factor)
        +    def disable_paging(
        +        self,
        +        command: str = "no cli session paging enable",
        +        delay_factor: Optional[float] = None,
        +        cmd_verify: bool = True,
        +        pattern: Optional[str] = None,
        +    ) -> str:
        +        return super().disable_paging(
        +            command=command,
        +            delay_factor=delay_factor,
        +            cmd_verify=cmd_verify,
        +            pattern=pattern,
        +        )
         
        -    def exit_config_mode(self, exit_config="exit", pattern="#"):
        +    def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str:
                 """Mellanox does not support a single command to completely exit configuration mode.
         
                 Consequently, need to keep checking and sending "exit".
        @@ -280,12 +310,15 @@ 

        Classes

        return output def save_config( - self, cmd="configuration write", confirm=False, confirm_response="" - ): + self, + cmd: str = "configuration write", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Save Config on Mellanox devices Enters and Leaves Config Mode""" output = self.enable() output += self.config_mode() - output += self.send_command(cmd) + output += self._send_command_str(cmd) output += self.exit_config_mode() return output
        @@ -298,19 +331,25 @@

        Ancestors

        Methods

        -def enable(self, cmd='enable', pattern='#', re_flags=) +def enable(self, cmd='enable', pattern='#', enable_pattern=None, re_flags=)

        Enter into enable mode.

        Source code -
        def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE):
        +
        def enable(
        +    self,
        +    cmd: str = "enable",
        +    pattern: str = "#",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
             """Enter into enable mode."""
             output = ""
             if not self.check_enable_mode():
                 self.write_channel(self.normalize_cmd(cmd))
                 output += self.read_until_prompt_or_pattern(
        -            pattern=pattern, re_flags=re_flags
        +            pattern=pattern, re_flags=re_flags, read_entire_line=True
                 )
                 if not self.check_enable_mode():
                     raise ValueError("Failed to enter enable mode.")
        @@ -325,7 +364,7 @@ 

        Methods

        Consequently, need to keep checking and sending "exit".

        Source code -
        def exit_config_mode(self, exit_config="exit", pattern="#"):
        +
        def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str:
             """Mellanox does not support a single command to completely exit configuration mode.
         
             Consequently, need to keep checking and sending "exit".
        @@ -356,12 +395,15 @@ 

        Methods

        Source code
        def save_config(
        -    self, cmd="configuration write", confirm=False, confirm_response=""
        -):
        +    self,
        +    cmd: str = "configuration write",
        +    confirm: bool = False,
        +    confirm_response: str = "",
        +) -> str:
             """Save Config on Mellanox devices Enters and Leaves Config Mode"""
             output = self.enable()
             output += self.config_mode()
        -    output += self.send_command(cmd)
        +    output += self._send_command_str(cmd)
             output += self.exit_config_mode()
             return output
        @@ -375,9 +417,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • establish_connection
      • @@ -386,9 +427,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -399,6 +440,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/mikrotik/index.html b/docs/netmiko/mikrotik/index.html index 95c790b04..6a52e5401 100644 --- a/docs/netmiko/mikrotik/index.html +++ b/docs/netmiko/mikrotik/index.html @@ -49,137 +49,7 @@

        Classes

        (**kwargs)
        -

        Mikrotik RouterOS SSH driver.

        -
            Initialize attributes for establishing connection to target device.
        -
        -    :param ip: IP address of target device. Not required if `host` is
        -        provided.
        -    :type ip: str
        -
        -    :param host: Hostname of target device. Not required if `ip` is
        -            provided.
        -    :type host: str
        -
        -    :param username: Username to authenticate against target device if
        -            required.
        -    :type username: str
        -
        -    :param password: Password to authenticate against target device if
        -            required.
        -    :type password: str
        -
        -    :param secret: The enable password if target device requires one.
        -    :type secret: str
        -
        -    :param port: The destination port used to connect to the target
        -            device.
        -    :type port: int or None
        -
        -    :param device_type: Class selection based on device type.
        -    :type device_type: str
        -
        -    :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
        -
        -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
        -
        -    :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
        -
        -    :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
        -
        -    :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
        -
        -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
        -            decryption if not specified.
        -    :type passphrase: str
        -
        -    :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
        -
        -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
        -            means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
        -
        -    :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
        -            alt_key_file.
        -    :type alt_host_keys: bool
        -
        -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
        -
        -    :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
        -
        -    :param timeout: Connection timeout.
        -    :type timeout: float
        -
        -    :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
        -
        -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
        -
        -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
        -
        -    :param 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).
        -    :type keepalive: int
        -
        -    :param default_enter: Character(s) to send to correspond to enter key (default:
        -
        -

        ). -:type default_enter: str

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

        ) -:type response_return: str

        -
            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
        -            to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        -
        -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
        -
        -    :param session_log_record_writes: The session log generally only records channel reads due
        -            to eliminate command duplication due to command echo. You can enable this if you
        -            want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
        -
        -    :param session_log_file_mode: "write" or "append" for session_log file mode
        -            (default: "write")
        -    :type session_log_file_mode: str
        -
        -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
        -            (default: False)
        -    :type allow_auto_change: bool
        -
        -    :param encoding: Encoding to be used when writing bytes to the output channel.
        -            (default: ascii)
        -    :type encoding: str
        -
        -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
        -            communication to the target host (default: None).
        -    :type sock: socket
        -
        -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
        -            (default: None). Global attribute takes precedence over function `cmd_verify`
        -            argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
        -
        -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
        -            part of the object creation (default: True).
        -    :type auto_connect: bool
        -
        +

        Mikrotik RouterOS SSH driver.

        Source code
        class MikrotikRouterOsSSH(MikrotikBase):
        @@ -190,6 +60,7 @@ 

        Classes

        Ancestors

        • MikrotikBase
        • +
        • NoEnable
        • CiscoSSHConnection
        • CiscoBaseConnection
        • BaseConnection
        • @@ -199,25 +70,24 @@

          Inherited members

        • MikrotikBase:
          • check_config_mode
          • -
          • check_enable_mode
          • +
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • config_mode
          • disable_paging
          • disconnect
          • -
          • enable
          • +
          • enable
          • establish_connection
          • exit_config_mode
          • -
          • exit_enable_mode
          • +
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -226,16 +96,17 @@

            Inherited members

          • select_delay_factor
          • send_command
          • send_command_expect
          • -
          • send_command_timing
          • +
          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • -
          • set_base_prompt
          • +
          • set_base_prompt
          • set_terminal_width
          • special_login_handler
          • strip_ansi_escape_codes
          • strip_backspaces
          • -
          • strip_command
          • +
          • strip_command
          • strip_prompt
          • telnet_login
          • write_channel
          • @@ -248,137 +119,7 @@

            Inherited members

            (**kwargs)
            -

            Mikrotik SwitchOS SSH driver.

            -
                Initialize attributes for establishing connection to target device.
            -
            -    :param ip: IP address of target device. Not required if `host` is
            -        provided.
            -    :type ip: str
            -
            -    :param host: Hostname of target device. Not required if `ip` is
            -            provided.
            -    :type host: str
            -
            -    :param username: Username to authenticate against target device if
            -            required.
            -    :type username: str
            -
            -    :param password: Password to authenticate against target device if
            -            required.
            -    :type password: str
            -
            -    :param secret: The enable password if target device requires one.
            -    :type secret: str
            -
            -    :param port: The destination port used to connect to the target
            -            device.
            -    :type port: int or None
            -
            -    :param device_type: Class selection based on device type.
            -    :type device_type: str
            -
            -    :param verbose: Enable additional messages to standard output.
            -    :type verbose: bool
            -
            -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
            -    :type global_delay_factor: int
            -
            -    :param use_keys: Connect to target device using SSH keys.
            -    :type use_keys: bool
            -
            -    :param key_file: Filename path of the SSH key file to use.
            -    :type key_file: str
            -
            -    :param pkey: SSH key object to use.
            -    :type pkey: paramiko.PKey
            -
            -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
            -            decryption if not specified.
            -    :type passphrase: str
            -
            -    :param allow_agent: Enable use of SSH key-agent.
            -    :type allow_agent: bool
            -
            -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
            -            means unknown SSH host keys will be accepted).
            -    :type ssh_strict: bool
            -
            -    :param system_host_keys: Load host keys from the users known_hosts file.
            -    :type system_host_keys: bool
            -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
            -            alt_key_file.
            -    :type alt_host_keys: bool
            -
            -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
            -    :type alt_key_file: str
            -
            -    :param ssh_config_file: File name of OpenSSH configuration file.
            -    :type ssh_config_file: str
            -
            -    :param timeout: Connection timeout.
            -    :type timeout: float
            -
            -    :param session_timeout: Set a timeout for parallel requests.
            -    :type session_timeout: float
            -
            -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
            -    :type auth_timeout: float
            -
            -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
            -    :type banner_timeout: float
            -
            -    :param 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).
            -    :type keepalive: int
            -
            -    :param default_enter: Character(s) to send to correspond to enter key (default:
            -
            -

            ). -:type default_enter: str

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

            ) -:type response_return: str

            -
                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
            -            to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            -
            -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
            -
            -    :param session_log_record_writes: The session log generally only records channel reads due
            -            to eliminate command duplication due to command echo. You can enable this if you
            -            want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
            -
            -    :param session_log_file_mode: "write" or "append" for session_log file mode
            -            (default: "write")
            -    :type session_log_file_mode: str
            -
            -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
            -            (default: False)
            -    :type allow_auto_change: bool
            -
            -    :param encoding: Encoding to be used when writing bytes to the output channel.
            -            (default: ascii)
            -    :type encoding: str
            -
            -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
            -            communication to the target host (default: None).
            -    :type sock: socket
            -
            -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
            -            (default: None). Global attribute takes precedence over function `cmd_verify`
            -            argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
            -
            -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
            -            part of the object creation (default: True).
            -    :type auto_connect: bool
            -
            +

            Mikrotik SwitchOS SSH driver.

            Source code
            class MikrotikSwitchOsSSH(MikrotikBase):
            @@ -389,6 +130,7 @@ 

            Inherited members

            Ancestors

            • MikrotikBase
            • +
            • NoEnable
            • CiscoSSHConnection
            • CiscoBaseConnection
            • BaseConnection
            • @@ -398,25 +140,24 @@

              Inherited members

            • MikrotikBase:
              • check_config_mode
              • -
              • check_enable_mode
              • +
              • check_enable_mode
              • cleanup
              • clear_buffer
              • -
              • close_session_log
              • commit
              • config_mode
              • disable_paging
              • disconnect
              • -
              • enable
              • +
              • enable
              • establish_connection
              • exit_config_mode
              • -
              • exit_enable_mode
              • +
              • exit_enable_mode
              • find_prompt
              • is_alive
              • normalize_cmd
              • normalize_linefeeds
              • -
              • open_session_log
              • paramiko_cleanup
              • read_channel
              • +
              • read_channel_timing
              • read_until_pattern
              • read_until_prompt
              • read_until_prompt_or_pattern
              • @@ -425,16 +166,17 @@

                Inherited members

              • select_delay_factor
              • send_command
              • send_command_expect
              • -
              • send_command_timing
              • +
              • send_command_timing
              • send_config_from_file
              • send_config_set
              • +
              • send_multiline
              • session_preparation
              • -
              • set_base_prompt
              • +
              • set_base_prompt
              • set_terminal_width
              • special_login_handler
              • strip_ansi_escape_codes
              • strip_backspaces
              • -
              • strip_command
              • +
              • strip_command
              • strip_prompt
              • telnet_login
              • write_channel
              • diff --git a/docs/netmiko/mikrotik/mikrotik_ssh.html b/docs/netmiko/mikrotik/mikrotik_ssh.html index b39ae6448..8349fb62e 100644 --- a/docs/netmiko/mikrotik/mikrotik_ssh.html +++ b/docs/netmiko/mikrotik/mikrotik_ssh.html @@ -22,13 +22,15 @@

                Module netmiko.mikrotik.mikrotik_ssh

                Source code -
                from netmiko.cisco_base_connection import CiscoSSHConnection
                +
                from typing import Any, Union, List, Dict, Optional
                +from netmiko.no_enable import NoEnable
                +from netmiko.cisco_base_connection import CiscoSSHConnection
                 
                 
                -class MikrotikBase(CiscoSSHConnection):
                +class MikrotikBase(NoEnable, CiscoSSHConnection):
                     """Common Methods for Mikrotik RouterOS and SwitchOS"""
                 
                -    def __init__(self, **kwargs):
                +    def __init__(self, **kwargs: Any) -> None:
                         if kwargs.get("default_enter") is None:
                             kwargs["default_enter"] = "\r\n"
                 
                @@ -36,15 +38,13 @@ 

                Module netmiko.mikrotik.mikrotik_ssh

                return super().__init__(**kwargs) - def session_preparation(self, *args, **kwargs): + def session_preparation(self, *args: Any, **kwargs: Any) -> None: """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - # Clear the read buffer - self.write_channel(self.RETURN) + self._test_channel_read(pattern=r"\].*>") self.set_base_prompt() - self.clear_buffer() - def _modify_connection_params(self): + def _modify_connection_params(self) -> None: """Append login options to username c: disable console colors e: enable dumb terminal mode @@ -52,72 +52,83 @@

                Module netmiko.mikrotik.mikrotik_ssh

                w511: set term width h4098: set term height """ - self.username += "+cetw511h4098" + self.username += "+ctw511h4098" - def disable_paging(self, *args, **kwargs): - """Microtik does not have paging by default.""" + def disable_paging(self, *args: Any, **kwargs: Any) -> str: + """Mikrotik does not have paging by default.""" return "" - def check_enable_mode(self, *args, **kwargs): - """No enable mode on RouterOS""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on RouterOS.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on RouterOS.""" - return "" - - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """No save command, all configuration is atomic""" - pass + return "" - def config_mode(self): - """No configuration mode on Microtik""" + def config_mode( + self, config_command: str = "", pattern: str = "", re_flags: int = 0 + ) -> str: + """No configuration mode on Mikrotik""" self._in_config_mode = True return "" - def check_config_mode(self, check_string=""): + def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool: """Checks whether in configuration mode. Returns a boolean.""" return self._in_config_mode - def exit_config_mode(self, exit_config=">"): - """No configuration mode on Microtik""" + def exit_config_mode(self, exit_config: str = ">", pattern: str = "") -> str: + """No configuration mode on Mikrotik""" self._in_config_mode = False return "" - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output. - MT adds some garbage trailing newlines, so - trim the last two lines from the output. - :param a_string: Returned string from device - :type a_string: str + Mikrotik just does a lot of formatting/has ansi escape codes in output so + we need a special handler here. + + There can be two trailing instances of the prompt probably due to + repainting. """ response_list = a_string.split(self.RESPONSE_RETURN) - last_line = response_list[-2] + last_line = response_list[-1] + + # Drop the first trailing prompt if self.base_prompt in last_line: - return self.RESPONSE_RETURN.join(response_list[:-2]) + a_string = self.RESPONSE_RETURN.join(response_list[:-1]) + a_string = a_string.rstrip() + # Now it should be just normal: call the parent method + a_string = super().strip_prompt(a_string) + return a_string.strip() else: + # Unexpected just return the original string return a_string - def strip_command(self, command_string, output): - """ - Strip command_string from output string - - MT returns, the Command\nRouterpromptCommand\n\n - start the defaut return at len(self.get_prompt())+2*len(command)+1 - - :param command_string: The command string sent to the device - :type command_string: str - - :param output: The returned output as a result of the command string sen - :type output: str - """ - command_length = len(self.find_prompt()) + 2 * (len(command_string)) + 2 - return output[command_length:] + def set_base_prompt( + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: + """Strip the trailing space off.""" + prompt = super().set_base_prompt( + pri_prompt_terminator=pri_prompt_terminator, + alt_prompt_terminator=alt_prompt_terminator, + delay_factor=delay_factor, + pattern=pattern, + ) + prompt = prompt.strip() + self.base_prompt = prompt + return self.base_prompt + + def send_command_timing( # type: ignore + self, + command_string: str, + cmd_verify: bool = True, + **kwargs: Any, + ) -> Union[str, List[Any], Dict[str, Any]]: + """Force cmd_verify to be True due to all of the line repainting""" + return super()._send_command_timing_str( + command_string=command_string, cmd_verify=cmd_verify, **kwargs + ) class MikrotikRouterOsSSH(MikrotikBase): @@ -146,143 +157,13 @@

                Classes

                (**kwargs)
                -

                Common Methods for Mikrotik RouterOS and SwitchOS

                -
                    Initialize attributes for establishing connection to target device.
                -
                -    :param ip: IP address of target device. Not required if `host` is
                -        provided.
                -    :type ip: str
                -
                -    :param host: Hostname of target device. Not required if `ip` is
                -            provided.
                -    :type host: str
                -
                -    :param username: Username to authenticate against target device if
                -            required.
                -    :type username: str
                -
                -    :param password: Password to authenticate against target device if
                -            required.
                -    :type password: str
                -
                -    :param secret: The enable password if target device requires one.
                -    :type secret: str
                -
                -    :param port: The destination port used to connect to the target
                -            device.
                -    :type port: int or None
                -
                -    :param device_type: Class selection based on device type.
                -    :type device_type: str
                -
                -    :param verbose: Enable additional messages to standard output.
                -    :type verbose: bool
                -
                -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                -    :type global_delay_factor: int
                -
                -    :param use_keys: Connect to target device using SSH keys.
                -    :type use_keys: bool
                -
                -    :param key_file: Filename path of the SSH key file to use.
                -    :type key_file: str
                -
                -    :param pkey: SSH key object to use.
                -    :type pkey: paramiko.PKey
                -
                -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
                -            decryption if not specified.
                -    :type passphrase: str
                -
                -    :param allow_agent: Enable use of SSH key-agent.
                -    :type allow_agent: bool
                -
                -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                -            means unknown SSH host keys will be accepted).
                -    :type ssh_strict: bool
                -
                -    :param system_host_keys: Load host keys from the users known_hosts file.
                -    :type system_host_keys: bool
                -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                -            alt_key_file.
                -    :type alt_host_keys: bool
                -
                -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                -    :type alt_key_file: str
                -
                -    :param ssh_config_file: File name of OpenSSH configuration file.
                -    :type ssh_config_file: str
                -
                -    :param timeout: Connection timeout.
                -    :type timeout: float
                -
                -    :param session_timeout: Set a timeout for parallel requests.
                -    :type session_timeout: float
                -
                -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                -    :type auth_timeout: float
                -
                -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                -    :type banner_timeout: float
                -
                -    :param 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).
                -    :type keepalive: int
                -
                -    :param default_enter: Character(s) to send to correspond to enter key (default:
                -
                -

                ). -:type default_enter: str

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

                ) -:type response_return: str

                -
                    :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                -            to select smallest of global and specific. Sets default global_delay_factor to .1
                -            (default: False)
                -    :type fast_cli: boolean
                -
                -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                -    :type session_log: str
                -
                -    :param session_log_record_writes: The session log generally only records channel reads due
                -            to eliminate command duplication due to command echo. You can enable this if you
                -            want to record both channel reads and channel writes in the log (default: False).
                -    :type session_log_record_writes: boolean
                -
                -    :param session_log_file_mode: "write" or "append" for session_log file mode
                -            (default: "write")
                -    :type session_log_file_mode: str
                -
                -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                -            (default: False)
                -    :type allow_auto_change: bool
                -
                -    :param encoding: Encoding to be used when writing bytes to the output channel.
                -            (default: ascii)
                -    :type encoding: str
                -
                -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                -            communication to the target host (default: None).
                -    :type sock: socket
                -
                -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                -            (default: None). Global attribute takes precedence over function `cmd_verify`
                -            argument. Value of `None` indicates to use function `cmd_verify` argument.
                -    :type global_cmd_verify: bool|None
                -
                -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
                -            part of the object creation (default: True).
                -    :type auto_connect: bool
                -
                +

                Common Methods for Mikrotik RouterOS and SwitchOS

                Source code -
                class MikrotikBase(CiscoSSHConnection):
                +
                class MikrotikBase(NoEnable, CiscoSSHConnection):
                     """Common Methods for Mikrotik RouterOS and SwitchOS"""
                 
                -    def __init__(self, **kwargs):
                +    def __init__(self, **kwargs: Any) -> None:
                         if kwargs.get("default_enter") is None:
                             kwargs["default_enter"] = "\r\n"
                 
                @@ -290,15 +171,13 @@ 

                Classes

                return super().__init__(**kwargs) - def session_preparation(self, *args, **kwargs): + def session_preparation(self, *args: Any, **kwargs: Any) -> None: """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - # Clear the read buffer - self.write_channel(self.RETURN) + self._test_channel_read(pattern=r"\].*>") self.set_base_prompt() - self.clear_buffer() - def _modify_connection_params(self): + def _modify_connection_params(self) -> None: """Append login options to username c: disable console colors e: enable dumb terminal mode @@ -306,75 +185,87 @@

                Classes

                w511: set term width h4098: set term height """ - self.username += "+cetw511h4098" - - def disable_paging(self, *args, **kwargs): - """Microtik does not have paging by default.""" - return "" - - def check_enable_mode(self, *args, **kwargs): - """No enable mode on RouterOS""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on RouterOS.""" - pass + self.username += "+ctw511h4098" - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on RouterOS.""" + def disable_paging(self, *args: Any, **kwargs: Any) -> str: + """Mikrotik does not have paging by default.""" return "" - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """No save command, all configuration is atomic""" - pass + return "" - def config_mode(self): - """No configuration mode on Microtik""" + def config_mode( + self, config_command: str = "", pattern: str = "", re_flags: int = 0 + ) -> str: + """No configuration mode on Mikrotik""" self._in_config_mode = True return "" - def check_config_mode(self, check_string=""): + def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool: """Checks whether in configuration mode. Returns a boolean.""" return self._in_config_mode - def exit_config_mode(self, exit_config=">"): - """No configuration mode on Microtik""" + def exit_config_mode(self, exit_config: str = ">", pattern: str = "") -> str: + """No configuration mode on Mikrotik""" self._in_config_mode = False return "" - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output. - MT adds some garbage trailing newlines, so - trim the last two lines from the output. - :param a_string: Returned string from device - :type a_string: str + Mikrotik just does a lot of formatting/has ansi escape codes in output so + we need a special handler here. + + There can be two trailing instances of the prompt probably due to + repainting. """ response_list = a_string.split(self.RESPONSE_RETURN) - last_line = response_list[-2] + last_line = response_list[-1] + + # Drop the first trailing prompt if self.base_prompt in last_line: - return self.RESPONSE_RETURN.join(response_list[:-2]) + a_string = self.RESPONSE_RETURN.join(response_list[:-1]) + a_string = a_string.rstrip() + # Now it should be just normal: call the parent method + a_string = super().strip_prompt(a_string) + return a_string.strip() else: + # Unexpected just return the original string return a_string - def strip_command(self, command_string, output): - """ - Strip command_string from output string - - MT returns, the Command\nRouterpromptCommand\n\n - start the defaut return at len(self.get_prompt())+2*len(command)+1 - - :param command_string: The command string sent to the device - :type command_string: str - - :param output: The returned output as a result of the command string sen - :type output: str - """ - command_length = len(self.find_prompt()) + 2 * (len(command_string)) + 2 - return output[command_length:]
                + def set_base_prompt( + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = ">", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: + """Strip the trailing space off.""" + prompt = super().set_base_prompt( + pri_prompt_terminator=pri_prompt_terminator, + alt_prompt_terminator=alt_prompt_terminator, + delay_factor=delay_factor, + pattern=pattern, + ) + prompt = prompt.strip() + self.base_prompt = prompt + return self.base_prompt + + def send_command_timing( # type: ignore + self, + command_string: str, + cmd_verify: bool = True, + **kwargs: Any, + ) -> Union[str, List[Any], Dict[str, Any]]: + """Force cmd_verify to be True due to all of the line repainting""" + return super()._send_command_timing_str( + command_string=command_string, cmd_verify=cmd_verify, **kwargs + )

                Ancestors

                  +
                • NoEnable
                • CiscoSSHConnection
                • CiscoBaseConnection
                • BaseConnection
                • @@ -387,38 +278,28 @@

                  Subclasses

                  Methods

                  -def check_config_mode(self, check_string='') +def check_config_mode(self, check_string='', pattern='')

                  Checks whether in configuration mode. Returns a boolean.

                  Source code -
                  def check_config_mode(self, check_string=""):
                  +
                  def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
                       """Checks whether in configuration mode. Returns a boolean."""
                       return self._in_config_mode
                  -
                  -def check_enable_mode(self, *args, **kwargs) -
                  -
                  -

                  No enable mode on RouterOS

                  -
                  -Source code -
                  def check_enable_mode(self, *args, **kwargs):
                  -    """No enable mode on RouterOS"""
                  -    pass
                  -
                  -
                  -def config_mode(self) +def config_mode(self, config_command='', pattern='', re_flags=0)
                  -

                  No configuration mode on Microtik

                  +

                  No configuration mode on Mikrotik

                  Source code -
                  def config_mode(self):
                  -    """No configuration mode on Microtik"""
                  +
                  def config_mode(
                  +    self, config_command: str = "", pattern: str = "", re_flags: int = 0
                  +) -> str:
                  +    """No configuration mode on Mikrotik"""
                       self._in_config_mode = True
                       return ""
                  @@ -427,61 +308,56 @@

                  Methods

                  def disable_paging(self, *args, **kwargs)
                  -

                  Microtik does not have paging by default.

                  +

                  Mikrotik does not have paging by default.

                  Source code -
                  def disable_paging(self, *args, **kwargs):
                  -    """Microtik does not have paging by default."""
                  +
                  def disable_paging(self, *args: Any, **kwargs: Any) -> str:
                  +    """Mikrotik does not have paging by default."""
                       return ""
                  -
                  -def enable(self, *args, **kwargs) -
                  -
                  -

                  No enable mode on RouterOS.

                  -
                  -Source code -
                  def enable(self, *args, **kwargs):
                  -    """No enable mode on RouterOS."""
                  -    pass
                  -
                  -
                  -def exit_config_mode(self, exit_config='>') +def exit_config_mode(self, exit_config='>', pattern='')
                  -

                  No configuration mode on Microtik

                  +

                  No configuration mode on Mikrotik

                  Source code -
                  def exit_config_mode(self, exit_config=">"):
                  -    """No configuration mode on Microtik"""
                  +
                  def exit_config_mode(self, exit_config: str = ">", pattern: str = "") -> str:
                  +    """No configuration mode on Mikrotik"""
                       self._in_config_mode = False
                       return ""
                  -
                  -def exit_enable_mode(self, *args, **kwargs) +
                  +def save_config(self, *args, **kwargs)
                  -

                  No enable mode on RouterOS.

                  +

                  No save command, all configuration is atomic

                  Source code -
                  def exit_enable_mode(self, *args, **kwargs):
                  -    """No enable mode on RouterOS."""
                  +
                  def save_config(self, *args: Any, **kwargs: Any) -> str:
                  +    """No save command, all configuration is atomic"""
                       return ""
                  -
                  -def save_config(self, *args, **kwargs) +
                  +def send_command_timing(self, command_string, cmd_verify=True, **kwargs)
                  -

                  No save command, all configuration is atomic

                  +

                  Force cmd_verify to be True due to all of the line repainting

                  Source code -
                  def save_config(self, *args, **kwargs):
                  -    """No save command, all configuration is atomic"""
                  -    pass
                  +
                  def send_command_timing(  # type: ignore
                  +    self,
                  +    command_string: str,
                  +    cmd_verify: bool = True,
                  +    **kwargs: Any,
                  +) -> Union[str, List[Any], Dict[str, Any]]:
                  +    """Force cmd_verify to be True due to all of the line repainting"""
                  +    return super()._send_command_timing_str(
                  +        command_string=command_string, cmd_verify=cmd_verify, **kwargs
                  +    )
                  @@ -491,74 +367,71 @@

                  Methods

                  Prepare the session after the connection has been established.

                  Source code -
                  def session_preparation(self, *args, **kwargs):
                  +
                  def session_preparation(self, *args: Any, **kwargs: Any) -> None:
                       """Prepare the session after the connection has been established."""
                       self.ansi_escape_codes = True
                  -    # Clear the read buffer
                  -    self.write_channel(self.RETURN)
                  -    self.set_base_prompt()
                  -    self.clear_buffer()
                  + self._test_channel_read(pattern=r"\].*>") + self.set_base_prompt()
                -
                -def strip_command(self, command_string, output) +
                +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='>', delay_factor=1.0, pattern=None)
                -

                Strip command_string from output string

                -
                    MT returns, the Command
                -
                -

                RouterpromptCommand

                -
                    start the defaut return at len(self.get_prompt())+2*len(command)+1
                -
                -    :param command_string: The command string sent to the device
                -    :type command_string: str
                -
                -    :param output: The returned output as a result of the command string sen
                -    :type output: str
                -
                +

                Strip the trailing space off.

                Source code -
                def strip_command(self, command_string, output):
                -    """
                -    Strip command_string from output string
                -
                -    MT returns, the Command\nRouterpromptCommand\n\n
                -    start the defaut return at len(self.get_prompt())+2*len(command)+1
                -
                -    :param command_string: The command string sent to the device
                -    :type command_string: str
                -
                -    :param output: The returned output as a result of the command string sen
                -    :type output: str
                -    """
                -    command_length = len(self.find_prompt()) + 2 * (len(command_string)) + 2
                -    return output[command_length:]
                +
                def set_base_prompt(
                +    self,
                +    pri_prompt_terminator: str = ">",
                +    alt_prompt_terminator: str = ">",
                +    delay_factor: float = 1.0,
                +    pattern: Optional[str] = None,
                +) -> str:
                +    """Strip the trailing space off."""
                +    prompt = super().set_base_prompt(
                +        pri_prompt_terminator=pri_prompt_terminator,
                +        alt_prompt_terminator=alt_prompt_terminator,
                +        delay_factor=delay_factor,
                +        pattern=pattern,
                +    )
                +    prompt = prompt.strip()
                +    self.base_prompt = prompt
                +    return self.base_prompt
                def strip_prompt(self, a_string)
                -

                Strip the trailing router prompt from the output. -MT adds some garbage trailing newlines, so -trim the last two lines from the output.

                -

                :param a_string: Returned string from device -:type a_string: str

                +

                Strip the trailing router prompt from the output.

                +

                Mikrotik just does a lot of formatting/has ansi escape codes in output so +we need a special handler here.

                +

                There can be two trailing instances of the prompt probably due to +repainting.

                Source code -
                def strip_prompt(self, a_string):
                +
                def strip_prompt(self, a_string: str) -> str:
                     """Strip the trailing router prompt from the output.
                -    MT adds some garbage trailing newlines, so
                -    trim the last two lines from the output.
                 
                -    :param a_string: Returned string from device
                -    :type a_string: str
                +    Mikrotik just does a lot of formatting/has ansi escape codes in output so
                +    we need a special handler here.
                +
                +    There can be two trailing instances of the prompt probably due to
                +    repainting.
                     """
                     response_list = a_string.split(self.RESPONSE_RETURN)
                -    last_line = response_list[-2]
                +    last_line = response_list[-1]
                +
                +    # Drop the first trailing prompt
                     if self.base_prompt in last_line:
                -        return self.RESPONSE_RETURN.join(response_list[:-2])
                +        a_string = self.RESPONSE_RETURN.join(response_list[:-1])
                +        a_string = a_string.rstrip()
                +        # Now it should be just normal: call the parent method
                +        a_string = super().strip_prompt(a_string)
                +        return a_string.strip()
                     else:
                +        # Unexpected just return the original string
                         return a_string
                @@ -567,19 +440,21 @@

                Inherited members

                • CiscoSSHConnection: @@ -606,137 +481,7 @@

                  Inherited members

                  (**kwargs)
                  -

                  Mikrotik RouterOS SSH driver.

                  -
                      Initialize attributes for establishing connection to target device.
                  -
                  -    :param ip: IP address of target device. Not required if `host` is
                  -        provided.
                  -    :type ip: str
                  -
                  -    :param host: Hostname of target device. Not required if `ip` is
                  -            provided.
                  -    :type host: str
                  -
                  -    :param username: Username to authenticate against target device if
                  -            required.
                  -    :type username: str
                  -
                  -    :param password: Password to authenticate against target device if
                  -            required.
                  -    :type password: str
                  -
                  -    :param secret: The enable password if target device requires one.
                  -    :type secret: str
                  -
                  -    :param port: The destination port used to connect to the target
                  -            device.
                  -    :type port: int or None
                  -
                  -    :param device_type: Class selection based on device type.
                  -    :type device_type: str
                  -
                  -    :param verbose: Enable additional messages to standard output.
                  -    :type verbose: bool
                  -
                  -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                  -    :type global_delay_factor: int
                  -
                  -    :param use_keys: Connect to target device using SSH keys.
                  -    :type use_keys: bool
                  -
                  -    :param key_file: Filename path of the SSH key file to use.
                  -    :type key_file: str
                  -
                  -    :param pkey: SSH key object to use.
                  -    :type pkey: paramiko.PKey
                  -
                  -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
                  -            decryption if not specified.
                  -    :type passphrase: str
                  -
                  -    :param allow_agent: Enable use of SSH key-agent.
                  -    :type allow_agent: bool
                  -
                  -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                  -            means unknown SSH host keys will be accepted).
                  -    :type ssh_strict: bool
                  -
                  -    :param system_host_keys: Load host keys from the users known_hosts file.
                  -    :type system_host_keys: bool
                  -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                  -            alt_key_file.
                  -    :type alt_host_keys: bool
                  -
                  -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                  -    :type alt_key_file: str
                  -
                  -    :param ssh_config_file: File name of OpenSSH configuration file.
                  -    :type ssh_config_file: str
                  -
                  -    :param timeout: Connection timeout.
                  -    :type timeout: float
                  -
                  -    :param session_timeout: Set a timeout for parallel requests.
                  -    :type session_timeout: float
                  -
                  -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                  -    :type auth_timeout: float
                  -
                  -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                  -    :type banner_timeout: float
                  -
                  -    :param 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).
                  -    :type keepalive: int
                  -
                  -    :param default_enter: Character(s) to send to correspond to enter key (default:
                  -
                  -

                  ). -:type default_enter: str

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

                  ) -:type response_return: str

                  -
                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                  -            to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  -
                  -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                  -
                  -    :param session_log_record_writes: The session log generally only records channel reads due
                  -            to eliminate command duplication due to command echo. You can enable this if you
                  -            want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                  -
                  -    :param session_log_file_mode: "write" or "append" for session_log file mode
                  -            (default: "write")
                  -    :type session_log_file_mode: str
                  -
                  -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                  -            (default: False)
                  -    :type allow_auto_change: bool
                  -
                  -    :param encoding: Encoding to be used when writing bytes to the output channel.
                  -            (default: ascii)
                  -    :type encoding: str
                  -
                  -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                  -            communication to the target host (default: None).
                  -    :type sock: socket
                  -
                  -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                  -            (default: None). Global attribute takes precedence over function `cmd_verify`
                  -            argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                  -
                  -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
                  -            part of the object creation (default: True).
                  -    :type auto_connect: bool
                  -
                  +

                  Mikrotik RouterOS SSH driver.

                  Source code
                  class MikrotikRouterOsSSH(MikrotikBase):
                  @@ -747,6 +492,7 @@ 

                  Inherited members

                  Ancestors

                  • MikrotikBase
                  • +
                  • NoEnable
                  • CiscoSSHConnection
                  • CiscoBaseConnection
                  • BaseConnection
                  • @@ -756,25 +502,24 @@

                    Inherited members

                  • MikrotikBase:
                    • check_config_mode
                    • -
                    • check_enable_mode
                    • +
                    • check_enable_mode
                    • cleanup
                    • clear_buffer
                    • -
                    • close_session_log
                    • commit
                    • config_mode
                    • disable_paging
                    • disconnect
                    • -
                    • enable
                    • +
                    • enable
                    • establish_connection
                    • exit_config_mode
                    • -
                    • exit_enable_mode
                    • +
                    • exit_enable_mode
                    • find_prompt
                    • is_alive
                    • normalize_cmd
                    • normalize_linefeeds
                    • -
                    • open_session_log
                    • paramiko_cleanup
                    • read_channel
                    • +
                    • read_channel_timing
                    • read_until_pattern
                    • read_until_prompt
                    • read_until_prompt_or_pattern
                    • @@ -783,16 +528,17 @@

                      Inherited members

                    • select_delay_factor
                    • send_command
                    • send_command_expect
                    • -
                    • send_command_timing
                    • +
                    • send_command_timing
                    • send_config_from_file
                    • send_config_set
                    • +
                    • send_multiline
                    • session_preparation
                    • -
                    • set_base_prompt
                    • +
                    • set_base_prompt
                    • set_terminal_width
                    • special_login_handler
                    • strip_ansi_escape_codes
                    • strip_backspaces
                    • -
                    • strip_command
                    • +
                    • strip_command
                    • strip_prompt
                    • telnet_login
                    • write_channel
                    • @@ -805,137 +551,7 @@

                      Inherited members

                      (**kwargs)
                      -

                      Mikrotik SwitchOS SSH driver.

                      -
                          Initialize attributes for establishing connection to target device.
                      -
                      -    :param ip: IP address of target device. Not required if `host` is
                      -        provided.
                      -    :type ip: str
                      -
                      -    :param host: Hostname of target device. Not required if `ip` is
                      -            provided.
                      -    :type host: str
                      -
                      -    :param username: Username to authenticate against target device if
                      -            required.
                      -    :type username: str
                      -
                      -    :param password: Password to authenticate against target device if
                      -            required.
                      -    :type password: str
                      -
                      -    :param secret: The enable password if target device requires one.
                      -    :type secret: str
                      -
                      -    :param port: The destination port used to connect to the target
                      -            device.
                      -    :type port: int or None
                      -
                      -    :param device_type: Class selection based on device type.
                      -    :type device_type: str
                      -
                      -    :param verbose: Enable additional messages to standard output.
                      -    :type verbose: bool
                      -
                      -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
                      -    :type global_delay_factor: int
                      -
                      -    :param use_keys: Connect to target device using SSH keys.
                      -    :type use_keys: bool
                      -
                      -    :param key_file: Filename path of the SSH key file to use.
                      -    :type key_file: str
                      -
                      -    :param pkey: SSH key object to use.
                      -    :type pkey: paramiko.PKey
                      -
                      -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
                      -            decryption if not specified.
                      -    :type passphrase: str
                      -
                      -    :param allow_agent: Enable use of SSH key-agent.
                      -    :type allow_agent: bool
                      -
                      -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                      -            means unknown SSH host keys will be accepted).
                      -    :type ssh_strict: bool
                      -
                      -    :param system_host_keys: Load host keys from the users known_hosts file.
                      -    :type system_host_keys: bool
                      -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                      -            alt_key_file.
                      -    :type alt_host_keys: bool
                      -
                      -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
                      -    :type alt_key_file: str
                      -
                      -    :param ssh_config_file: File name of OpenSSH configuration file.
                      -    :type ssh_config_file: str
                      -
                      -    :param timeout: Connection timeout.
                      -    :type timeout: float
                      -
                      -    :param session_timeout: Set a timeout for parallel requests.
                      -    :type session_timeout: float
                      -
                      -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
                      -    :type auth_timeout: float
                      -
                      -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
                      -    :type banner_timeout: float
                      -
                      -    :param 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).
                      -    :type keepalive: int
                      -
                      -    :param default_enter: Character(s) to send to correspond to enter key (default:
                      -
                      -

                      ). -:type default_enter: str

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

                      ) -:type response_return: str

                      -
                          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                      -            to select smallest of global and specific. Sets default global_delay_factor to .1
                      -            (default: False)
                      -    :type fast_cli: boolean
                      -
                      -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                      -    :type session_log: str
                      -
                      -    :param session_log_record_writes: The session log generally only records channel reads due
                      -            to eliminate command duplication due to command echo. You can enable this if you
                      -            want to record both channel reads and channel writes in the log (default: False).
                      -    :type session_log_record_writes: boolean
                      -
                      -    :param session_log_file_mode: "write" or "append" for session_log file mode
                      -            (default: "write")
                      -    :type session_log_file_mode: str
                      -
                      -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                      -            (default: False)
                      -    :type allow_auto_change: bool
                      -
                      -    :param encoding: Encoding to be used when writing bytes to the output channel.
                      -            (default: ascii)
                      -    :type encoding: str
                      -
                      -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                      -            communication to the target host (default: None).
                      -    :type sock: socket
                      -
                      -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                      -            (default: None). Global attribute takes precedence over function `cmd_verify`
                      -            argument. Value of `None` indicates to use function `cmd_verify` argument.
                      -    :type global_cmd_verify: bool|None
                      -
                      -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
                      -            part of the object creation (default: True).
                      -    :type auto_connect: bool
                      -
                      +

                      Mikrotik SwitchOS SSH driver.

                      Source code
                      class MikrotikSwitchOsSSH(MikrotikBase):
                      @@ -946,6 +562,7 @@ 

                      Inherited members

                      Ancestors

                      • MikrotikBase
                      • +
                      • NoEnable
                      • CiscoSSHConnection
                      • CiscoBaseConnection
                      • BaseConnection
                      • @@ -955,25 +572,24 @@

                        Inherited members

                      • MikrotikBase:
                        • check_config_mode
                        • -
                        • check_enable_mode
                        • +
                        • check_enable_mode
                        • cleanup
                        • clear_buffer
                        • -
                        • close_session_log
                        • commit
                        • config_mode
                        • disable_paging
                        • disconnect
                        • -
                        • enable
                        • +
                        • enable
                        • establish_connection
                        • exit_config_mode
                        • -
                        • exit_enable_mode
                        • +
                        • exit_enable_mode
                        • find_prompt
                        • is_alive
                        • normalize_cmd
                        • normalize_linefeeds
                        • -
                        • open_session_log
                        • paramiko_cleanup
                        • read_channel
                        • +
                        • read_channel_timing
                        • read_until_pattern
                        • read_until_prompt
                        • read_until_prompt_or_pattern
                        • @@ -982,16 +598,17 @@

                          Inherited members

                        • select_delay_factor
                        • send_command
                        • send_command_expect
                        • -
                        • send_command_timing
                        • +
                        • send_command_timing
                        • send_config_from_file
                        • send_config_set
                        • +
                        • send_multiline
                        • session_preparation
                        • -
                        • set_base_prompt
                        • +
                        • set_base_prompt
                        • set_terminal_width
                        • special_login_handler
                        • strip_ansi_escape_codes
                        • strip_backspaces
                        • -
                        • strip_command
                        • +
                        • strip_command
                        • strip_prompt
                        • telnet_login
                        • write_channel
                        • @@ -1019,15 +636,13 @@

                          Index

                          MikrotikBase

                          diff --git a/docs/netmiko/mrv/index.html b/docs/netmiko/mrv/index.html index 1b71ea3fe..2d7a8c246 100644 --- a/docs/netmiko/mrv/index.html +++ b/docs/netmiko/mrv/index.html @@ -50,7 +50,7 @@

                          Classes

                          class MrvLxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                          MRV Communications Driver (LX).

                          @@ -58,138 +58,111 @@

                          Classes

                          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                      -

                      ). -:type default_enter: str

                      +

                      ).

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

                      ) -:type response_return: str

                      +

                      )

                          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                                   to select smallest of global and specific. Sets default global_delay_factor to .1
                      -            (default: False)
                      -    :type fast_cli: boolean
                      +            (default: True)
                       
                           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                      -    :type session_log: str
                       
                           :param session_log_record_writes: The session log generally only records channel reads due
                                   to eliminate command duplication due to command echo. You can enable this if you
                                   want to record both channel reads and channel writes in the log (default: False).
                      -    :type session_log_record_writes: boolean
                       
                           :param session_log_file_mode: "write" or "append" for session_log file mode
                                   (default: "write")
                      -    :type session_log_file_mode: str
                       
                           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                                   (default: False)
                      -    :type allow_auto_change: bool
                       
                           :param encoding: Encoding to be used when writing bytes to the output channel.
                                   (default: ascii)
                      -    :type encoding: str
                       
                           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                                   communication to the target host (default: None).
                      -    :type sock: socket
                       
                           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                                   (default: None). Global attribute takes precedence over function `cmd_verify`
                                   argument. Value of `None` indicates to use function `cmd_verify` argument.
                      -    :type global_cmd_verify: bool|None
                       
                           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                                   part of the object creation (default: True).
                      -    :type auto_connect: bool
                      +
                      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                      +            eliminated in Netmiko 5.x (default: False).
                       
                Source code
                class MrvLxSSH(CiscoSSHConnection):
                     """MRV Communications Driver (LX)."""
                 
                -    def session_preparation(self):
                +    def session_preparation(self) -> None:
                         """Prepare the session after the connection has been established."""
                         self._test_channel_read(pattern=r"[>|>>]")
                         self.set_base_prompt()
                @@ -199,15 +172,26 @@ 

                Classes

                time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string=">>"): + def check_enable_mode(self, check_string: str = ">>") -> bool: """MRV has a >> for enable mode instead of # like Cisco""" return super().check_enable_mode(check_string=check_string) - def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "assword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode.""" return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -228,7 +212,7 @@

                Methods

                MRV has a >> for enable mode instead of # like Cisco

                Source code -
                def check_enable_mode(self, check_string=">>"):
                +
                def check_enable_mode(self, check_string: str = ">>") -> bool:
                     """MRV has a >> for enable mode instead of # like Cisco"""
                     return super().check_enable_mode(check_string=check_string)
                @@ -240,7 +224,12 @@

                Methods

                Saves configuration.

                Source code -
                def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
                +
                def save_config(
                +    self,
                +    cmd: str = "save config flash",
                +    confirm: bool = False,
                +    confirm_response: str = "",
                +) -> str:
                     """Saves configuration."""
                     return super().save_config(
                         cmd=cmd, confirm=confirm, confirm_response=confirm_response
                @@ -254,7 +243,7 @@ 

                Methods

                Prepare the session after the connection has been established.

                Source code -
                def session_preparation(self):
                +
                def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read(pattern=r"[>|>>]")
                     self.set_base_prompt()
                @@ -273,9 +262,8 @@ 

                Inherited members

              • check_config_mode
              • cleanup
              • clear_buffer
              • -
              • close_session_log
              • commit
              • -
              • config_mode
              • +
              • config_mode
              • disable_paging
              • disconnect
              • enable
              • @@ -286,9 +274,9 @@

                Inherited members

              • is_alive
              • normalize_cmd
              • normalize_linefeeds
              • -
              • open_session_log
              • paramiko_cleanup
              • read_channel
              • +
              • read_channel_timing
              • read_until_pattern
              • read_until_prompt
              • read_until_prompt_or_pattern
              • @@ -299,6 +287,7 @@

                Inherited members

              • send_command_timing
              • send_config_from_file
              • send_config_set
              • +
              • send_multiline
              • set_base_prompt
              • set_terminal_width
              • special_login_handler
              • @@ -314,7 +303,7 @@

                Inherited members

            class MrvOptiswitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            MRV Communications Driver (OptiSwitch).

            @@ -322,138 +311,111 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class MrvOptiswitchSSH(CiscoSSHConnection):
             """MRV Communications Driver (OptiSwitch)."""
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
        @@ -464,13 +426,19 @@ 

        Inherited members

        self.set_base_prompt() self.clear_buffer() - def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = r"#", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enable mode on MRV uses no password.""" output = "" if not self.check_enable_mode(): self.write_channel(self.normalize_cmd(cmd)) output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) if not self.check_enable_mode(): msg = ( @@ -480,7 +448,12 @@

        Inherited members

        raise ValueError(msg) return output - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -495,19 +468,25 @@

        Ancestors

        Methods

        -def enable(self, cmd='enable', pattern='#', re_flags=) +def enable(self, cmd='enable', pattern='#', enable_pattern=None, re_flags=)

        Enable mode on MRV uses no password.

        Source code -
        def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE):
        +
        def enable(
        +    self,
        +    cmd: str = "enable",
        +    pattern: str = r"#",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
             """Enable mode on MRV uses no password."""
             output = ""
             if not self.check_enable_mode():
                 self.write_channel(self.normalize_cmd(cmd))
                 output += self.read_until_prompt_or_pattern(
        -            pattern=pattern, re_flags=re_flags
        +            pattern=pattern, re_flags=re_flags, read_entire_line=True
                 )
                 if not self.check_enable_mode():
                     msg = (
        @@ -525,7 +504,12 @@ 

        Methods

        Saves configuration.

        Source code -
        def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self,
        +    cmd: str = "save config flash",
        +    confirm: bool = False,
        +    confirm_response: str = "",
        +) -> str:
             """Saves configuration."""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -539,7 +523,7 @@ 

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
        @@ -560,9 +544,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • establish_connection
      • @@ -572,9 +555,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -585,6 +568,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • diff --git a/docs/netmiko/mrv/mrv_lx.html b/docs/netmiko/mrv/mrv_lx.html index b540fcc3e..376040575 100644 --- a/docs/netmiko/mrv/mrv_lx.html +++ b/docs/netmiko/mrv/mrv_lx.html @@ -26,6 +26,7 @@

        Module netmiko.mrv.mrv_lx

        """MRV Communications Driver (LX)."""
         import time
         import re
        +from typing import Optional
         
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
        @@ -33,7 +34,7 @@ 

        Module netmiko.mrv.mrv_lx

        class MrvLxSSH(CiscoSSHConnection): """MRV Communications Driver (LX).""" - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self._test_channel_read(pattern=r"[>|>>]") self.set_base_prompt() @@ -43,15 +44,26 @@

        Module netmiko.mrv.mrv_lx

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string=">>"): + def check_enable_mode(self, check_string: str = ">>") -> bool: """MRV has a >> for enable mode instead of # like Cisco""" return super().check_enable_mode(check_string=check_string) - def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "assword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode.""" return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -69,7 +81,7 @@

        Classes

        class MrvLxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        MRV Communications Driver (LX).

        @@ -77,138 +89,111 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class MrvLxSSH(CiscoSSHConnection):
             """MRV Communications Driver (LX)."""
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>|>>]")
                 self.set_base_prompt()
        @@ -218,15 +203,26 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string=">>"): + def check_enable_mode(self, check_string: str = ">>") -> bool: """MRV has a >> for enable mode instead of # like Cisco""" return super().check_enable_mode(check_string=check_string) - def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "assword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode.""" return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -247,7 +243,7 @@

        Methods

        MRV has a >> for enable mode instead of # like Cisco

        Source code -
        def check_enable_mode(self, check_string=">>"):
        +
        def check_enable_mode(self, check_string: str = ">>") -> bool:
             """MRV has a >> for enable mode instead of # like Cisco"""
             return super().check_enable_mode(check_string=check_string)
        @@ -259,7 +255,12 @@

        Methods

        Saves configuration.

        Source code -
        def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self,
        +    cmd: str = "save config flash",
        +    confirm: bool = False,
        +    confirm_response: str = "",
        +) -> str:
             """Saves configuration."""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -273,7 +274,7 @@ 

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>|>>]")
             self.set_base_prompt()
        @@ -292,9 +293,8 @@ 

        Inherited members

      • check_config_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -305,9 +305,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -318,6 +318,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • diff --git a/docs/netmiko/mrv/mrv_ssh.html b/docs/netmiko/mrv/mrv_ssh.html index f6c383147..ad9682e6d 100644 --- a/docs/netmiko/mrv/mrv_ssh.html +++ b/docs/netmiko/mrv/mrv_ssh.html @@ -26,6 +26,7 @@

        Module netmiko.mrv.mrv_ssh

        """MRV Communications Driver (OptiSwitch)."""
         import time
         import re
        +from typing import Optional
         
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
        @@ -33,7 +34,7 @@ 

        Module netmiko.mrv.mrv_ssh

        class MrvOptiswitchSSH(CiscoSSHConnection): """MRV Communications Driver (OptiSwitch).""" - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() @@ -44,13 +45,19 @@

        Module netmiko.mrv.mrv_ssh

        self.set_base_prompt() self.clear_buffer() - def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = r"#", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enable mode on MRV uses no password.""" output = "" if not self.check_enable_mode(): self.write_channel(self.normalize_cmd(cmd)) output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) if not self.check_enable_mode(): msg = ( @@ -60,7 +67,12 @@

        Module netmiko.mrv.mrv_ssh

        raise ValueError(msg) return output - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -78,7 +90,7 @@

        Classes

        class MrvOptiswitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        MRV Communications Driver (OptiSwitch).

        @@ -86,138 +98,111 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class MrvOptiswitchSSH(CiscoSSHConnection):
             """MRV Communications Driver (OptiSwitch)."""
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
        @@ -228,13 +213,19 @@ 

        Classes

        self.set_base_prompt() self.clear_buffer() - def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = r"#", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enable mode on MRV uses no password.""" output = "" if not self.check_enable_mode(): self.write_channel(self.normalize_cmd(cmd)) output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) if not self.check_enable_mode(): msg = ( @@ -244,7 +235,12 @@

        Classes

        raise ValueError(msg) return output - def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "save config flash", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -259,19 +255,25 @@

        Ancestors

        Methods

        -def enable(self, cmd='enable', pattern='#', re_flags=) +def enable(self, cmd='enable', pattern='#', enable_pattern=None, re_flags=)

        Enable mode on MRV uses no password.

        Source code -
        def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE):
        +
        def enable(
        +    self,
        +    cmd: str = "enable",
        +    pattern: str = r"#",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
             """Enable mode on MRV uses no password."""
             output = ""
             if not self.check_enable_mode():
                 self.write_channel(self.normalize_cmd(cmd))
                 output += self.read_until_prompt_or_pattern(
        -            pattern=pattern, re_flags=re_flags
        +            pattern=pattern, re_flags=re_flags, read_entire_line=True
                 )
                 if not self.check_enable_mode():
                     msg = (
        @@ -289,7 +291,12 @@ 

        Methods

        Saves configuration.

        Source code -
        def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self,
        +    cmd: str = "save config flash",
        +    confirm: bool = False,
        +    confirm_response: str = "",
        +) -> str:
             """Saves configuration."""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -303,7 +310,7 @@ 

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
        @@ -324,9 +331,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • establish_connection
      • @@ -336,9 +342,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -349,6 +355,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • diff --git a/docs/netmiko/netapp/index.html b/docs/netmiko/netapp/index.html index 92f1f1183..c447ef15f 100644 --- a/docs/netmiko/netapp/index.html +++ b/docs/netmiko/netapp/index.html @@ -45,197 +45,164 @@

        Classes

        class NetAppcDotSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
        -

        Defines vendor independent methods.

        -

        Otherwise method left as a stub method.

        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code -
        class NetAppcDotSSH(BaseConnection):
        -    def session_preparation(self):
        +
        class NetAppcDotSSH(NoEnable, BaseConnection):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.set_base_prompt()
                 cmd = self.RETURN + "rows 0" + self.RETURN
                 self.disable_paging(command=cmd)
         
        -    def send_command_with_y(self, *args, **kwargs):
        -        output = self.send_command_timing(*args, **kwargs)
        +    def send_command_with_y(self, *args: Any, **kwargs: Any) -> str:
        +        output = self._send_command_timing_str(*args, **kwargs)
                 if "{y|n}" in output:
        -            output += self.send_command_timing(
        +            output += self._send_command_timing_str(
                         "y", strip_prompt=False, strip_command=False
                     )
                 return output
         
        -    def check_config_mode(self, check_string="*>"):
        -        return super().check_config_mode(check_string=check_string)
        +    def check_config_mode(self, check_string: str = "*>", pattern: str = "") -> bool:
        +        return super().check_config_mode(check_string=check_string, pattern=pattern)
         
             def config_mode(
        -        self, config_command="set -privilege diagnostic -confirmations off"
        -    ):
        -        return super().config_mode(config_command=config_command)
        -
        -    def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"):
        -        return super().exit_config_mode(exit_config=exit_config)
        -
        -    def enable(self, *args, **kwargs):
        -        """No enable mode on NetApp."""
        -        pass
        -
        -    def check_enable_mode(self, *args, **kwargs):
        -        pass
        +        self,
        +        config_command: str = "set -privilege diagnostic -confirmations off",
        +        pattern: str = "",
        +        re_flags: int = 0,
        +    ) -> str:
        +        return super().config_mode(
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
        +        )
         
        -    def exit_enable_mode(self, *args, **kwargs):
        -        pass
        + def exit_config_mode( + self, + exit_config: str = "set -privilege admin -confirmations off", + pattern: str = "", + ) -> str: + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)

        Ancestors

        Methods

        -
        -def enable(self, *args, **kwargs) -
        -
        -

        No enable mode on NetApp.

        -
        -Source code -
        def enable(self, *args, **kwargs):
        -    """No enable mode on NetApp."""
        -    pass
        -
        -
        def send_command_with_y(self, *args, **kwargs)
        @@ -243,10 +210,10 @@

        Methods

        Source code -
        def send_command_with_y(self, *args, **kwargs):
        -    output = self.send_command_timing(*args, **kwargs)
        +
        def send_command_with_y(self, *args: Any, **kwargs: Any) -> str:
        +    output = self._send_command_timing_str(*args, **kwargs)
             if "{y|n}" in output:
        -        output += self.send_command_timing(
        +        output += self._send_command_timing_str(
                     "y", strip_prompt=False, strip_command=False
                 )
             return output
        @@ -259,7 +226,7 @@

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.set_base_prompt()
             cmd = self.RETURN + "rows 0" + self.RETURN
        @@ -275,11 +242,11 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • exit_enable_mode
      • @@ -287,9 +254,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -301,6 +268,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -338,7 +306,6 @@

        Index

      • NetAppcDotSSH

        diff --git a/docs/netmiko/netapp/netapp_cdot_ssh.html b/docs/netmiko/netapp/netapp_cdot_ssh.html index 0f29d8757..52a907e5c 100644 --- a/docs/netmiko/netapp/netapp_cdot_ssh.html +++ b/docs/netmiko/netapp/netapp_cdot_ssh.html @@ -22,44 +22,46 @@

        Module netmiko.netapp.netapp_cdot_ssh

        Source code -
        from netmiko.base_connection import BaseConnection
        +
        from typing import Any
         
        +from netmiko.no_enable import NoEnable
        +from netmiko.base_connection import BaseConnection
         
        -class NetAppcDotSSH(BaseConnection):
        -    def session_preparation(self):
        +
        +class NetAppcDotSSH(NoEnable, BaseConnection):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.set_base_prompt()
                 cmd = self.RETURN + "rows 0" + self.RETURN
                 self.disable_paging(command=cmd)
         
        -    def send_command_with_y(self, *args, **kwargs):
        -        output = self.send_command_timing(*args, **kwargs)
        +    def send_command_with_y(self, *args: Any, **kwargs: Any) -> str:
        +        output = self._send_command_timing_str(*args, **kwargs)
                 if "{y|n}" in output:
        -            output += self.send_command_timing(
        +            output += self._send_command_timing_str(
                         "y", strip_prompt=False, strip_command=False
                     )
                 return output
         
        -    def check_config_mode(self, check_string="*>"):
        -        return super().check_config_mode(check_string=check_string)
        +    def check_config_mode(self, check_string: str = "*>", pattern: str = "") -> bool:
        +        return super().check_config_mode(check_string=check_string, pattern=pattern)
         
             def config_mode(
        -        self, config_command="set -privilege diagnostic -confirmations off"
        -    ):
        -        return super().config_mode(config_command=config_command)
        -
        -    def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"):
        -        return super().exit_config_mode(exit_config=exit_config)
        -
        -    def enable(self, *args, **kwargs):
        -        """No enable mode on NetApp."""
        -        pass
        -
        -    def check_enable_mode(self, *args, **kwargs):
        -        pass
        +        self,
        +        config_command: str = "set -privilege diagnostic -confirmations off",
        +        pattern: str = "",
        +        re_flags: int = 0,
        +    ) -> str:
        +        return super().config_mode(
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
        +        )
         
        -    def exit_enable_mode(self, *args, **kwargs):
        -        pass
        + def exit_config_mode( + self, + exit_config: str = "set -privilege admin -confirmations off", + pattern: str = "", + ) -> str: + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
        @@ -73,197 +75,164 @@

        Classes

        class NetAppcDotSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
        -

        Defines vendor independent methods.

        -

        Otherwise method left as a stub method.

        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code -
        class NetAppcDotSSH(BaseConnection):
        -    def session_preparation(self):
        +
        class NetAppcDotSSH(NoEnable, BaseConnection):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.set_base_prompt()
                 cmd = self.RETURN + "rows 0" + self.RETURN
                 self.disable_paging(command=cmd)
         
        -    def send_command_with_y(self, *args, **kwargs):
        -        output = self.send_command_timing(*args, **kwargs)
        +    def send_command_with_y(self, *args: Any, **kwargs: Any) -> str:
        +        output = self._send_command_timing_str(*args, **kwargs)
                 if "{y|n}" in output:
        -            output += self.send_command_timing(
        +            output += self._send_command_timing_str(
                         "y", strip_prompt=False, strip_command=False
                     )
                 return output
         
        -    def check_config_mode(self, check_string="*>"):
        -        return super().check_config_mode(check_string=check_string)
        +    def check_config_mode(self, check_string: str = "*>", pattern: str = "") -> bool:
        +        return super().check_config_mode(check_string=check_string, pattern=pattern)
         
             def config_mode(
        -        self, config_command="set -privilege diagnostic -confirmations off"
        -    ):
        -        return super().config_mode(config_command=config_command)
        -
        -    def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"):
        -        return super().exit_config_mode(exit_config=exit_config)
        -
        -    def enable(self, *args, **kwargs):
        -        """No enable mode on NetApp."""
        -        pass
        -
        -    def check_enable_mode(self, *args, **kwargs):
        -        pass
        +        self,
        +        config_command: str = "set -privilege diagnostic -confirmations off",
        +        pattern: str = "",
        +        re_flags: int = 0,
        +    ) -> str:
        +        return super().config_mode(
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
        +        )
         
        -    def exit_enable_mode(self, *args, **kwargs):
        -        pass
        + def exit_config_mode( + self, + exit_config: str = "set -privilege admin -confirmations off", + pattern: str = "", + ) -> str: + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)

        Ancestors

        Methods

        -
        -def enable(self, *args, **kwargs) -
        -
        -

        No enable mode on NetApp.

        -
        -Source code -
        def enable(self, *args, **kwargs):
        -    """No enable mode on NetApp."""
        -    pass
        -
        -
        def send_command_with_y(self, *args, **kwargs)
        @@ -271,10 +240,10 @@

        Methods

        Source code -
        def send_command_with_y(self, *args, **kwargs):
        -    output = self.send_command_timing(*args, **kwargs)
        +
        def send_command_with_y(self, *args: Any, **kwargs: Any) -> str:
        +    output = self._send_command_timing_str(*args, **kwargs)
             if "{y|n}" in output:
        -        output += self.send_command_timing(
        +        output += self._send_command_timing_str(
                     "y", strip_prompt=False, strip_command=False
                 )
             return output
        @@ -287,7 +256,7 @@

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self.set_base_prompt()
             cmd = self.RETURN + "rows 0" + self.RETURN
        @@ -303,11 +272,11 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • exit_enable_mode
      • @@ -315,9 +284,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -329,6 +298,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -361,7 +331,6 @@

        Index

      • NetAppcDotSSH

        diff --git a/docs/netmiko/netgear/index.html b/docs/netmiko/netgear/index.html index c46881b16..a78c2f82b 100644 --- a/docs/netmiko/netgear/index.html +++ b/docs/netmiko/netgear/index.html @@ -53,144 +53,117 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      • -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class NetgearProSafeSSH(CiscoSSHConnection):
             """ProSafe OS support"""
         
        -    def __init__(self, **kwargs):
        +    def __init__(self, **kwargs: Any) -> None:
                 if kwargs.get("default_enter") is None:
                     kwargs["default_enter"] = "\r"
                 return super().__init__(**kwargs)
         
        -    def session_preparation(self):
        -        """ProSafe OS requires enabe mode to disable paging."""
        +    def session_preparation(self) -> None:
        +        """ProSafe OS requires enable mode to disable paging."""
                 self._test_channel_read()
                 self.set_base_prompt()
                 self.enable()
        @@ -200,18 +173,30 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string="(Config)#"): - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"\)\#"): - return super().config_mode(config_command=config_command, pattern=pattern) - - def exit_config_mode(self, exit_config="exit", pattern=r"\#"): + def check_config_mode( + self, check_string: str = "(Config)#", pattern: str = "" + ) -> bool: + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\)\#", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"\#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( - self, save_cmd="write memory confirm", confirm=False, confirm_response="" - ): + self, + save_cmd: str = "write memory confirm", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() """ProSafe doesn't allow saving whilst within configuration mode""" if self.check_config_mode(): @@ -233,11 +218,11 @@

        Methods

        def session_preparation(self)
        -

        ProSafe OS requires enabe mode to disable paging.

        +

        ProSafe OS requires enable mode to disable paging.

        Source code -
        def session_preparation(self):
        -    """ProSafe OS requires enabe mode to disable paging."""
        +
        def session_preparation(self) -> None:
        +    """ProSafe OS requires enable mode to disable paging."""
             self._test_channel_read()
             self.set_base_prompt()
             self.enable()
        @@ -257,9 +242,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -270,9 +254,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -284,6 +268,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • diff --git a/docs/netmiko/netgear/netgear_prosafe_ssh.html b/docs/netmiko/netgear/netgear_prosafe_ssh.html index 7f10089a6..d7927eddc 100644 --- a/docs/netmiko/netgear/netgear_prosafe_ssh.html +++ b/docs/netmiko/netgear/netgear_prosafe_ssh.html @@ -25,19 +25,21 @@

        Module netmiko.netgear.netgear_prosafe_ssh

        Source code
        """ProSafe OS support"""
         import time
        +from typing import Any
        +
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
         
         class NetgearProSafeSSH(CiscoSSHConnection):
             """ProSafe OS support"""
         
        -    def __init__(self, **kwargs):
        +    def __init__(self, **kwargs: Any) -> None:
                 if kwargs.get("default_enter") is None:
                     kwargs["default_enter"] = "\r"
                 return super().__init__(**kwargs)
         
        -    def session_preparation(self):
        -        """ProSafe OS requires enabe mode to disable paging."""
        +    def session_preparation(self) -> None:
        +        """ProSafe OS requires enable mode to disable paging."""
                 self._test_channel_read()
                 self.set_base_prompt()
                 self.enable()
        @@ -47,18 +49,30 @@ 

        Module netmiko.netgear.netgear_prosafe_ssh

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string="(Config)#"): - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"\)\#"): - return super().config_mode(config_command=config_command, pattern=pattern) - - def exit_config_mode(self, exit_config="exit", pattern=r"\#"): + def check_config_mode( + self, check_string: str = "(Config)#", pattern: str = "" + ) -> bool: + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\)\#", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"\#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( - self, save_cmd="write memory confirm", confirm=False, confirm_response="" - ): + self, + save_cmd: str = "write memory confirm", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() """ProSafe doesn't allow saving whilst within configuration mode""" if self.check_config_mode(): @@ -88,144 +102,117 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class NetgearProSafeSSH(CiscoSSHConnection):
             """ProSafe OS support"""
         
        -    def __init__(self, **kwargs):
        +    def __init__(self, **kwargs: Any) -> None:
                 if kwargs.get("default_enter") is None:
                     kwargs["default_enter"] = "\r"
                 return super().__init__(**kwargs)
         
        -    def session_preparation(self):
        -        """ProSafe OS requires enabe mode to disable paging."""
        +    def session_preparation(self) -> None:
        +        """ProSafe OS requires enable mode to disable paging."""
                 self._test_channel_read()
                 self.set_base_prompt()
                 self.enable()
        @@ -235,18 +222,30 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string="(Config)#"): - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"\)\#"): - return super().config_mode(config_command=config_command, pattern=pattern) - - def exit_config_mode(self, exit_config="exit", pattern=r"\#"): + def check_config_mode( + self, check_string: str = "(Config)#", pattern: str = "" + ) -> bool: + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\)\#", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) + + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"\#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( - self, save_cmd="write memory confirm", confirm=False, confirm_response="" - ): + self, + save_cmd: str = "write memory confirm", + confirm: bool = False, + confirm_response: str = "", + ) -> str: self.enable() """ProSafe doesn't allow saving whilst within configuration mode""" if self.check_config_mode(): @@ -268,11 +267,11 @@

        Methods

        def session_preparation(self)
        -

        ProSafe OS requires enabe mode to disable paging.

        +

        ProSafe OS requires enable mode to disable paging.

        Source code -
        def session_preparation(self):
        -    """ProSafe OS requires enabe mode to disable paging."""
        +
        def session_preparation(self) -> None:
        +    """ProSafe OS requires enable mode to disable paging."""
             self._test_channel_read()
             self.set_base_prompt()
             self.enable()
        @@ -292,9 +291,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -305,9 +303,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -319,6 +317,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • diff --git a/docs/netmiko/no_config.html b/docs/netmiko/no_config.html new file mode 100644 index 000000000..90deeb026 --- /dev/null +++ b/docs/netmiko/no_config.html @@ -0,0 +1,189 @@ + + + + + + +netmiko.no_config API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.no_config

        +
        +
        +
        +Source code +
        class NoConfig:
        +    """
        +    Class for platforms that have no config mode.
        +
        +    check_config_mode returns True as the expectation is that configuration commands
        +    can be executed directly. So in your current state, you are in "config mode" i.e.
        +    you can make configuration changes.
        +
        +    If you truly cannot make any configuration changes to device then you should probably
        +    overwrite check_config_mode in the platform specific driver and return False.
        +    """
        +
        +    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
        +        return True
        +
        +    def config_mode(
        +        self, config_command: str = "", pattern: str = "", re_flags: int = 0
        +    ) -> str:
        +        return ""
        +
        +    def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str:
        +        return ""
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class NoConfig +(*args, **kwargs) +
        +
        +

        Class for platforms that have no config mode.

        +

        check_config_mode returns True as the expectation is that configuration commands +can be executed directly. So in your current state, you are in "config mode" i.e. +you can make configuration changes.

        +

        If you truly cannot make any configuration changes to device then you should probably +overwrite check_config_mode in the platform specific driver and return False.

        +
        +Source code +
        class NoConfig:
        +    """
        +    Class for platforms that have no config mode.
        +
        +    check_config_mode returns True as the expectation is that configuration commands
        +    can be executed directly. So in your current state, you are in "config mode" i.e.
        +    you can make configuration changes.
        +
        +    If you truly cannot make any configuration changes to device then you should probably
        +    overwrite check_config_mode in the platform specific driver and return False.
        +    """
        +
        +    def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
        +        return True
        +
        +    def config_mode(
        +        self, config_command: str = "", pattern: str = "", re_flags: int = 0
        +    ) -> str:
        +        return ""
        +
        +    def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str:
        +        return ""
        +
        +

        Subclasses

        + +

        Methods

        +
        +
        +def check_config_mode(self, check_string='', pattern='') +
        +
        +
        +
        +Source code +
        def check_config_mode(self, check_string: str = "", pattern: str = "") -> bool:
        +    return True
        +
        +
        +
        +def config_mode(self, config_command='', pattern='', re_flags=0) +
        +
        +
        +
        +Source code +
        def config_mode(
        +    self, config_command: str = "", pattern: str = "", re_flags: int = 0
        +) -> str:
        +    return ""
        +
        +
        +
        +def exit_config_mode(self, exit_config='', pattern='') +
        +
        +
        +
        +Source code +
        def exit_config_mode(self, exit_config: str = "", pattern: str = "") -> str:
        +    return ""
        +
        +
        +
        +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file diff --git a/docs/netmiko/no_enable.html b/docs/netmiko/no_enable.html new file mode 100644 index 000000000..6e122505c --- /dev/null +++ b/docs/netmiko/no_enable.html @@ -0,0 +1,221 @@ + + + + + + +netmiko.no_enable API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.no_enable

        +
        +
        +
        +Source code +
        from typing import Optional
        +import re
        +
        +
        +class NoEnable:
        +    """
        +    Class for platforms that have no enable mode.
        +
        +    Netmiko translates the meaning of "enable" mode to be a proxy for "can
        +    go into config mode". In other words, that you ultimately have privileges
        +    to execute configuration changes.
        +
        +    The expectation on platforms that have no method for elevating privileges
        +    is that the standard default privileges allow configuration changes.
        +
        +    Consequently check_enable_mode returns True by default for platforms that
        +    don't explicitly support enable mode.
        +    """
        +
        +    def check_enable_mode(self, check_string: str = "") -> bool:
        +        return True
        +
        +    def enable(
        +        self,
        +        cmd: str = "",
        +        pattern: str = "",
        +        enable_pattern: Optional[str] = None,
        +        re_flags: int = re.IGNORECASE,
        +    ) -> str:
        +        return ""
        +
        +    def exit_enable_mode(self, exit_command: str = "") -> str:
        +        return ""
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class NoEnable +(*args, **kwargs) +
        +
        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        +
        +Source code +
        class NoEnable:
        +    """
        +    Class for platforms that have no enable mode.
        +
        +    Netmiko translates the meaning of "enable" mode to be a proxy for "can
        +    go into config mode". In other words, that you ultimately have privileges
        +    to execute configuration changes.
        +
        +    The expectation on platforms that have no method for elevating privileges
        +    is that the standard default privileges allow configuration changes.
        +
        +    Consequently check_enable_mode returns True by default for platforms that
        +    don't explicitly support enable mode.
        +    """
        +
        +    def check_enable_mode(self, check_string: str = "") -> bool:
        +        return True
        +
        +    def enable(
        +        self,
        +        cmd: str = "",
        +        pattern: str = "",
        +        enable_pattern: Optional[str] = None,
        +        re_flags: int = re.IGNORECASE,
        +    ) -> str:
        +        return ""
        +
        +    def exit_enable_mode(self, exit_command: str = "") -> str:
        +        return ""
        +
        +

        Subclasses

        + +

        Methods

        +
        +
        +def check_enable_mode(self, check_string='') +
        +
        +
        +
        +Source code +
        def check_enable_mode(self, check_string: str = "") -> bool:
        +    return True
        +
        +
        +
        +def enable(self, cmd='', pattern='', enable_pattern=None, re_flags=) +
        +
        +
        +
        +Source code +
        def enable(
        +    self,
        +    cmd: str = "",
        +    pattern: str = "",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
        +    return ""
        +
        +
        +
        +def exit_enable_mode(self, exit_command='') +
        +
        +
        +
        +Source code +
        def exit_enable_mode(self, exit_command: str = "") -> str:
        +    return ""
        +
        +
        +
        +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file diff --git a/docs/netmiko/nokia/index.html b/docs/netmiko/nokia/index.html index 189b8a826..7693616a1 100644 --- a/docs/netmiko/nokia/index.html +++ b/docs/netmiko/nokia/index.html @@ -49,7 +49,7 @@

        Classes

        class NokiaSrosFileTransfer -(ssh_conn, source_file, dest_file, hash_supported=False, **kwargs) +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0, progress=None, progress4=None, hash_supported=False)

        Class to manage SCP file transfer and associated SSH control channel.

        @@ -57,13 +57,30 @@

        Classes

        Source code
        class NokiaSrosFileTransfer(BaseFileTransfer):
             def __init__(
        -        self, ssh_conn, source_file, dest_file, hash_supported=False, **kwargs
        -    ):
        +        self,
        +        ssh_conn: BaseConnection,
        +        source_file: str,
        +        dest_file: str,
        +        file_system: Optional[str] = None,
        +        direction: str = "put",
        +        socket_timeout: float = 10.0,
        +        progress: Optional[Callable[..., Any]] = None,
        +        progress4: Optional[Callable[..., Any]] = None,
        +        hash_supported: bool = False,
        +    ) -> None:
                 super().__init__(
        -            ssh_conn, source_file, dest_file, hash_supported=hash_supported, **kwargs
        +            ssh_conn=ssh_conn,
        +            source_file=source_file,
        +            dest_file=dest_file,
        +            file_system=file_system,
        +            direction=direction,
        +            socket_timeout=socket_timeout,
        +            progress=progress,
        +            progress4=progress4,
        +            hash_supported=hash_supported,
                 )
         
        -    def _file_cmd_prefix(self):
        +    def _file_cmd_prefix(self) -> str:
                 """
                 Allow MD-CLI to execute file operations by using classical CLI.
         
        @@ -71,17 +88,20 @@ 

        Classes

        """ return "//" if "@" in self.ssh_ctl_chan.base_prompt else "" - def remote_space_available(self, search_pattern=r"(\d+)\s+\w+\s+free"): + def remote_space_available( + self, search_pattern: str = r"(\d+)\s+\w+\s+free" + ) -> int: """Return space available on remote device.""" # Sample text for search_pattern. # " 3 Dir(s) 961531904 bytes free." remote_cmd = self._file_cmd_prefix() + "file dir {}".format(self.file_system) - remote_output = self.ssh_ctl_chan.send_command(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) match = re.search(search_pattern, remote_output) + assert match is not None return int(match.group(1)) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if destination file exists (returns boolean).""" if self.direction == "put": @@ -99,8 +119,12 @@

        Classes

        raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd=None, remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: @@ -108,11 +132,13 @@

        Classes

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Unexpected value for self.direction") if not remote_cmd: remote_cmd = self._file_cmd_prefix() + "file dir {}/{}".format( self.file_system, remote_file ) - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "File Not Found" in remote_out: raise IOError("Unable to find file on remote system") @@ -130,7 +156,7 @@

        Classes

        file_size = int(match.group(1)) return file_size - def verify_file(self): + def verify_file(self) -> bool: """Verify the file has been transferred correctly based on filesize.""" if self.direction == "put": return os.stat(self.source_file).st_size == self.remote_file_size( @@ -141,17 +167,20 @@

        Classes

        self.remote_file_size(remote_file=self.source_file) == os.stat(self.dest_file).st_size ) + else: + raise ValueError("Unexpected value of self.direction") - def file_md5(self, **kwargs): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def process_md5(self, **kwargs): + @staticmethod + def process_md5(md5_output: str, pattern: str = "") -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def compare_md5(self, **kwargs): + def compare_md5(self) -> bool: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def remote_md5(self, **kwargs): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.")

        Ancestors

        @@ -167,7 +196,7 @@

        Methods

        Check if destination file exists (returns boolean).

        Source code -
        def check_file_exists(self, remote_cmd=""):
        +
        def check_file_exists(self, remote_cmd: str = "") -> bool:
             """Check if destination file exists (returns boolean)."""
         
             if self.direction == "put":
        @@ -184,7 +213,9 @@ 

        Methods

        else: raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": - return os.path.exists(self.dest_file)
        + return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction")
        @@ -194,7 +225,7 @@

        Methods

        Verify the file has been transferred correctly based on filesize.

        Source code -
        def verify_file(self):
        +
        def verify_file(self) -> bool:
             """Verify the file has been transferred correctly based on filesize."""
             if self.direction == "put":
                 return os.stat(self.source_file).st_size == self.remote_file_size(
        @@ -204,7 +235,9 @@ 

        Methods

        return ( self.remote_file_size(remote_file=self.source_file) == os.stat(self.dest_file).st_size - )
        + ) + else: + raise ValueError("Unexpected value of self.direction")
      • @@ -233,7 +266,7 @@

        Inherited members

        class NokiaSrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Nokia SR OS SSH driver.

        @@ -241,131 +274,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -387,7 +393,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -400,9 +405,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -414,6 +419,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -430,7 +436,7 @@

        Inherited members

        class NokiaSrosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Nokia SR OS Telnet driver.

        @@ -438,131 +444,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -584,7 +563,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -597,9 +575,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -611,6 +589,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/nokia/nokia_sros.html b/docs/netmiko/nokia/nokia_sros.html index 9b1b55578..ad7f7f1ac 100644 --- a/docs/netmiko/nokia/nokia_sros.html +++ b/docs/netmiko/nokia/nokia_sros.html @@ -33,6 +33,7 @@

        Module netmiko.nokia.nokia_sros

        import re import os import time +from typing import Any, Optional, Union, Sequence, TextIO, Callable from netmiko import log from netmiko.base_connection import BaseConnection @@ -60,7 +61,7 @@

        Module netmiko.nokia.nokia_sros

        - check_enable_mode() """ - def session_preparation(self): + def session_preparation(self) -> None: self._test_channel_read() self.set_base_prompt() # "@" indicates model-driven CLI (vs Classical CLI) @@ -82,16 +83,17 @@

        Module netmiko.nokia.nokia_sros

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """Remove the > when navigating into the different config level.""" cur_base_prompt = super().set_base_prompt(*args, **kwargs) match = re.search(r"\*?(.*?)(>.*)*#", cur_base_prompt) if match: # strip off >... from base_prompt; strip off leading * - self.base_prompt = match.group(1) - return self.base_prompt + self.base_prompt: str = match.group(1) - def _disable_complete_on_space(self): + return self.base_prompt + + def _disable_complete_on_space(self) -> str: """ SR-OS tries to auto complete commands when you type a "space" character. @@ -105,39 +107,55 @@

        Module netmiko.nokia.nokia_sros

        time.sleep(delay_factor * 0.1) return self.read_channel() - def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enable SR OS administrative mode""" if "@" not in self.base_prompt: cmd = "enable-admin" return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) - def check_enable_mode(self, check_string="in admin mode"): + def check_enable_mode(self, check_string: str = "in admin mode") -> bool: """Check if in enable mode.""" cmd = "enable" if "@" not in self.base_prompt: cmd = "enable-admin" self.write_channel(self.normalize_cmd(cmd)) - output = self.read_until_prompt_or_pattern(pattern="ssword") + output = self.read_until_prompt_or_pattern( + pattern="ssword", read_entire_line=True + ) if "ssword" in output: self.write_channel(self.RETURN) # send ENTER to pass the password prompt - self.read_until_prompt() + self.read_until_prompt(read_entire_line=True) return check_string in output - def exit_enable_mode(self, *args, **kwargs): + def exit_enable_mode(self, *args: Any, **kwargs: Any) -> str: """Nokia SR OS does not have a notion of exiting administrative mode""" return "" - def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["): + def config_mode( + self, + config_command: str = "edit-config exclusive", + pattern: str = "", + re_flags: int = 0, + ) -> str: """Enable config edit-mode for Nokia SR OS""" output = "" + if not pattern: + pattern = rf"\(ex\)\[.*{self.base_prompt}.*$" + re_flags = re.DOTALL # Only model-driven CLI supports config-mode if "@" in self.base_prompt: output += super().config_mode( - config_command=config_command, pattern=pattern + config_command=config_command, pattern=pattern, re_flags=re_flags ) return output - def exit_config_mode(self, *args, **kwargs): + def exit_config_mode(self, *args: Any, **kwargs: Any) -> str: """Disable config edit-mode for Nokia SR OS""" output = self._exit_all() # Model-driven CLI @@ -150,13 +168,16 @@

        Module netmiko.nokia.nokia_sros

        self.write_channel(self.normalize_cmd(cmd)) if self.global_cmd_verify is not False: output += self.read_until_pattern(pattern=re.escape(cmd)) + output += self.read_until_prompt(read_entire_line=True) else: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output - def check_config_mode(self, check_string=r"(ex)[", pattern=r"@"): + def check_config_mode( + self, check_string: str = r"(ex)[", pattern: str = r"@" + ) -> bool: """Check config mode for Nokia SR OS""" if "@" not in self.base_prompt: # Classical CLI @@ -165,11 +186,16 @@

        Module netmiko.nokia.nokia_sros

        # Model-driven CLI look for "exclusive" return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Persist configuration to cflash for Nokia SR OS""" - return self.send_command(command_string="/admin save", expect_string=r"#") - - def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs): + return self._send_command_str(command_string="/admin save", expect_string=r"#") + + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = None, + **kwargs: Any, + ) -> str: """Model driven CLI requires you not exit from configuration mode.""" if exit_config_mode is None: # Set to False if model-driven CLI @@ -178,7 +204,7 @@

        Module netmiko.nokia.nokia_sros

        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def commit(self, *args, **kwargs): + def commit(self, *args: Any, **kwargs: Any) -> str: """Activate changes from private candidate for Nokia SR OS""" output = self._exit_all() if "@" in self.base_prompt and "*(ex)[" in output: @@ -193,7 +219,7 @@

        Module netmiko.nokia.nokia_sros

        output += new_output return output - def _exit_all(self): + def _exit_all(self) -> str: """Return to the 'root' context.""" output = "" exit_cmd = "exit all" @@ -201,11 +227,12 @@

        Module netmiko.nokia.nokia_sros

        # Make sure you read until you detect the command echo (avoid getting out of sync) if self.global_cmd_verify is not False: output += self.read_until_pattern(pattern=re.escape(exit_cmd)) + output += self.read_until_prompt(read_entire_line=True) else: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) return output - def _discard(self): + def _discard(self) -> str: """Discard changes from private candidate for Nokia SR OS""" output = "" if "@" in self.base_prompt: @@ -215,11 +242,11 @@

        Module netmiko.nokia.nokia_sros

        if self.global_cmd_verify is not False: new_output += self.read_until_pattern(pattern=re.escape(cmd)) if "@" not in new_output: - new_output += self.read_until_prompt() + new_output += self.read_until_prompt(read_entire_line=True) output += new_output return output - def strip_prompt(self, *args, **kwargs): + def strip_prompt(self, *args: Any, **kwargs: Any) -> str: """Strip prompt from the output.""" output = super().strip_prompt(*args, **kwargs) if "@" in self.base_prompt: @@ -229,7 +256,7 @@

        Module netmiko.nokia.nokia_sros

        else: return output - def cleanup(self, command="logout"): + def cleanup(self, command: str = "logout") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -256,13 +283,30 @@

        Module netmiko.nokia.nokia_sros

        class NokiaSrosFileTransfer(BaseFileTransfer): def __init__( - self, ssh_conn, source_file, dest_file, hash_supported=False, **kwargs - ): + self, + ssh_conn: BaseConnection, + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = False, + ) -> None: super().__init__( - ssh_conn, source_file, dest_file, hash_supported=hash_supported, **kwargs + ssh_conn=ssh_conn, + source_file=source_file, + dest_file=dest_file, + file_system=file_system, + direction=direction, + socket_timeout=socket_timeout, + progress=progress, + progress4=progress4, + hash_supported=hash_supported, ) - def _file_cmd_prefix(self): + def _file_cmd_prefix(self) -> str: """ Allow MD-CLI to execute file operations by using classical CLI. @@ -270,17 +314,20 @@

        Module netmiko.nokia.nokia_sros

        """ return "//" if "@" in self.ssh_ctl_chan.base_prompt else "" - def remote_space_available(self, search_pattern=r"(\d+)\s+\w+\s+free"): + def remote_space_available( + self, search_pattern: str = r"(\d+)\s+\w+\s+free" + ) -> int: """Return space available on remote device.""" # Sample text for search_pattern. # " 3 Dir(s) 961531904 bytes free." remote_cmd = self._file_cmd_prefix() + "file dir {}".format(self.file_system) - remote_output = self.ssh_ctl_chan.send_command(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) match = re.search(search_pattern, remote_output) + assert match is not None return int(match.group(1)) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if destination file exists (returns boolean).""" if self.direction == "put": @@ -298,8 +345,12 @@

        Module netmiko.nokia.nokia_sros

        raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd=None, remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: @@ -307,11 +358,13 @@

        Module netmiko.nokia.nokia_sros

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Unexpected value for self.direction") if not remote_cmd: remote_cmd = self._file_cmd_prefix() + "file dir {}/{}".format( self.file_system, remote_file ) - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "File Not Found" in remote_out: raise IOError("Unable to find file on remote system") @@ -329,7 +382,7 @@

        Module netmiko.nokia.nokia_sros

        file_size = int(match.group(1)) return file_size - def verify_file(self): + def verify_file(self) -> bool: """Verify the file has been transferred correctly based on filesize.""" if self.direction == "put": return os.stat(self.source_file).st_size == self.remote_file_size( @@ -340,17 +393,20 @@

        Module netmiko.nokia.nokia_sros

        self.remote_file_size(remote_file=self.source_file) == os.stat(self.dest_file).st_size ) + else: + raise ValueError("Unexpected value of self.direction") - def file_md5(self, **kwargs): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def process_md5(self, **kwargs): + @staticmethod + def process_md5(md5_output: str, pattern: str = "") -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def compare_md5(self, **kwargs): + def compare_md5(self) -> bool: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def remote_md5(self, **kwargs): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.")
        @@ -365,7 +421,7 @@

        Classes

        class NokiaSros -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Implement methods for interacting with Nokia SR OS devices @@ -387,131 +443,104 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -536,7 +565,7 @@

        Classes

        - check_enable_mode() """ - def session_preparation(self): + def session_preparation(self) -> None: self._test_channel_read() self.set_base_prompt() # "@" indicates model-driven CLI (vs Classical CLI) @@ -558,16 +587,17 @@

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def set_base_prompt(self, *args, **kwargs): + def set_base_prompt(self, *args: Any, **kwargs: Any) -> str: """Remove the > when navigating into the different config level.""" cur_base_prompt = super().set_base_prompt(*args, **kwargs) match = re.search(r"\*?(.*?)(>.*)*#", cur_base_prompt) if match: # strip off >... from base_prompt; strip off leading * - self.base_prompt = match.group(1) - return self.base_prompt + self.base_prompt: str = match.group(1) + + return self.base_prompt - def _disable_complete_on_space(self): + def _disable_complete_on_space(self) -> str: """ SR-OS tries to auto complete commands when you type a "space" character. @@ -581,39 +611,55 @@

        Classes

        time.sleep(delay_factor * 0.1) return self.read_channel() - def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "enable", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enable SR OS administrative mode""" if "@" not in self.base_prompt: cmd = "enable-admin" return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) - def check_enable_mode(self, check_string="in admin mode"): + def check_enable_mode(self, check_string: str = "in admin mode") -> bool: """Check if in enable mode.""" cmd = "enable" if "@" not in self.base_prompt: cmd = "enable-admin" self.write_channel(self.normalize_cmd(cmd)) - output = self.read_until_prompt_or_pattern(pattern="ssword") + output = self.read_until_prompt_or_pattern( + pattern="ssword", read_entire_line=True + ) if "ssword" in output: self.write_channel(self.RETURN) # send ENTER to pass the password prompt - self.read_until_prompt() + self.read_until_prompt(read_entire_line=True) return check_string in output - def exit_enable_mode(self, *args, **kwargs): + def exit_enable_mode(self, *args: Any, **kwargs: Any) -> str: """Nokia SR OS does not have a notion of exiting administrative mode""" return "" - def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["): + def config_mode( + self, + config_command: str = "edit-config exclusive", + pattern: str = "", + re_flags: int = 0, + ) -> str: """Enable config edit-mode for Nokia SR OS""" output = "" + if not pattern: + pattern = rf"\(ex\)\[.*{self.base_prompt}.*$" + re_flags = re.DOTALL # Only model-driven CLI supports config-mode if "@" in self.base_prompt: output += super().config_mode( - config_command=config_command, pattern=pattern + config_command=config_command, pattern=pattern, re_flags=re_flags ) return output - def exit_config_mode(self, *args, **kwargs): + def exit_config_mode(self, *args: Any, **kwargs: Any) -> str: """Disable config edit-mode for Nokia SR OS""" output = self._exit_all() # Model-driven CLI @@ -626,13 +672,16 @@

        Classes

        self.write_channel(self.normalize_cmd(cmd)) if self.global_cmd_verify is not False: output += self.read_until_pattern(pattern=re.escape(cmd)) + output += self.read_until_prompt(read_entire_line=True) else: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output - def check_config_mode(self, check_string=r"(ex)[", pattern=r"@"): + def check_config_mode( + self, check_string: str = r"(ex)[", pattern: str = r"@" + ) -> bool: """Check config mode for Nokia SR OS""" if "@" not in self.base_prompt: # Classical CLI @@ -641,11 +690,16 @@

        Classes

        # Model-driven CLI look for "exclusive" return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Persist configuration to cflash for Nokia SR OS""" - return self.send_command(command_string="/admin save", expect_string=r"#") - - def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs): + return self._send_command_str(command_string="/admin save", expect_string=r"#") + + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = None, + **kwargs: Any, + ) -> str: """Model driven CLI requires you not exit from configuration mode.""" if exit_config_mode is None: # Set to False if model-driven CLI @@ -654,7 +708,7 @@

        Classes

        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def commit(self, *args, **kwargs): + def commit(self, *args: Any, **kwargs: Any) -> str: """Activate changes from private candidate for Nokia SR OS""" output = self._exit_all() if "@" in self.base_prompt and "*(ex)[" in output: @@ -669,7 +723,7 @@

        Classes

        output += new_output return output - def _exit_all(self): + def _exit_all(self) -> str: """Return to the 'root' context.""" output = "" exit_cmd = "exit all" @@ -677,11 +731,12 @@

        Classes

        # Make sure you read until you detect the command echo (avoid getting out of sync) if self.global_cmd_verify is not False: output += self.read_until_pattern(pattern=re.escape(exit_cmd)) + output += self.read_until_prompt(read_entire_line=True) else: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) return output - def _discard(self): + def _discard(self) -> str: """Discard changes from private candidate for Nokia SR OS""" output = "" if "@" in self.base_prompt: @@ -691,11 +746,11 @@

        Classes

        if self.global_cmd_verify is not False: new_output += self.read_until_pattern(pattern=re.escape(cmd)) if "@" not in new_output: - new_output += self.read_until_prompt() + new_output += self.read_until_prompt(read_entire_line=True) output += new_output return output - def strip_prompt(self, *args, **kwargs): + def strip_prompt(self, *args: Any, **kwargs: Any) -> str: """Strip prompt from the output.""" output = super().strip_prompt(*args, **kwargs) if "@" in self.base_prompt: @@ -705,7 +760,7 @@

        Classes

        else: return output - def cleanup(self, command="logout"): + def cleanup(self, command: str = "logout") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -735,7 +790,9 @@

        Methods

        Check config mode for Nokia SR OS

        Source code -
        def check_config_mode(self, check_string=r"(ex)[", pattern=r"@"):
        +
        def check_config_mode(
        +    self, check_string: str = r"(ex)[", pattern: str = r"@"
        +) -> bool:
             """Check config mode for Nokia SR OS"""
             if "@" not in self.base_prompt:
                 # Classical CLI
        @@ -752,16 +809,18 @@ 

        Methods

        Check if in enable mode.

        Source code -
        def check_enable_mode(self, check_string="in admin mode"):
        +
        def check_enable_mode(self, check_string: str = "in admin mode") -> bool:
             """Check if in enable mode."""
             cmd = "enable"
             if "@" not in self.base_prompt:
                 cmd = "enable-admin"
             self.write_channel(self.normalize_cmd(cmd))
        -    output = self.read_until_prompt_or_pattern(pattern="ssword")
        +    output = self.read_until_prompt_or_pattern(
        +        pattern="ssword", read_entire_line=True
        +    )
             if "ssword" in output:
                 self.write_channel(self.RETURN)  # send ENTER to pass the password prompt
        -        self.read_until_prompt()
        +        self.read_until_prompt(read_entire_line=True)
             return check_string in output
        @@ -772,7 +831,7 @@

        Methods

        Gracefully exit the SSH session.

        Source code -
        def cleanup(self, command="logout"):
        +
        def cleanup(self, command: str = "logout") -> None:
             """Gracefully exit the SSH session."""
             try:
                 # The pattern="" forces use of send_command_timing
        @@ -792,7 +851,7 @@ 

        Methods

        Activate changes from private candidate for Nokia SR OS

        Source code -
        def commit(self, *args, **kwargs):
        +
        def commit(self, *args: Any, **kwargs: Any) -> str:
             """Activate changes from private candidate for Nokia SR OS"""
             output = self._exit_all()
             if "@" in self.base_prompt and "*(ex)[" in output:
        @@ -809,31 +868,45 @@ 

        Methods

        -def config_mode(self, config_command='edit-config exclusive', pattern='\\(ex\\)\\[') +def config_mode(self, config_command='edit-config exclusive', pattern='', re_flags=0)

        Enable config edit-mode for Nokia SR OS

        Source code -
        def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
        +
        def config_mode(
        +    self,
        +    config_command: str = "edit-config exclusive",
        +    pattern: str = "",
        +    re_flags: int = 0,
        +) -> str:
             """Enable config edit-mode for Nokia SR OS"""
             output = ""
        +    if not pattern:
        +        pattern = rf"\(ex\)\[.*{self.base_prompt}.*$"
        +        re_flags = re.DOTALL
             # Only model-driven CLI supports config-mode
             if "@" in self.base_prompt:
                 output += super().config_mode(
        -            config_command=config_command, pattern=pattern
        +            config_command=config_command, pattern=pattern, re_flags=re_flags
                 )
             return output
        -def enable(self, cmd='enable', pattern='ssword', re_flags=) +def enable(self, cmd='enable', pattern='ssword', enable_pattern=None, re_flags=)

        Enable SR OS administrative mode

        Source code -
        def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE):
        +
        def enable(
        +    self,
        +    cmd: str = "enable",
        +    pattern: str = "ssword",
        +    enable_pattern: Optional[str] = None,
        +    re_flags: int = re.IGNORECASE,
        +) -> str:
             """Enable SR OS administrative mode"""
             if "@" not in self.base_prompt:
                 cmd = "enable-admin"
        @@ -847,7 +920,7 @@ 

        Methods

        Disable config edit-mode for Nokia SR OS

        Source code -
        def exit_config_mode(self, *args, **kwargs):
        +
        def exit_config_mode(self, *args: Any, **kwargs: Any) -> str:
             """Disable config edit-mode for Nokia SR OS"""
             output = self._exit_all()
             # Model-driven CLI
        @@ -860,8 +933,9 @@ 

        Methods

        self.write_channel(self.normalize_cmd(cmd)) if self.global_cmd_verify is not False: output += self.read_until_pattern(pattern=re.escape(cmd)) + output += self.read_until_prompt(read_entire_line=True) else: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output
        @@ -874,7 +948,7 @@

        Methods

        Nokia SR OS does not have a notion of exiting administrative mode

        Source code -
        def exit_enable_mode(self, *args, **kwargs):
        +
        def exit_enable_mode(self, *args: Any, **kwargs: Any) -> str:
             """Nokia SR OS does not have a notion of exiting administrative mode"""
             return ""
        @@ -886,9 +960,9 @@

        Methods

        Persist configuration to cflash for Nokia SR OS

        Source code -
        def save_config(self, *args, **kwargs):
        +
        def save_config(self, *args: Any, **kwargs: Any) -> str:
             """Persist configuration to cflash for Nokia SR OS"""
        -    return self.send_command(command_string="/admin save", expect_string=r"#")
        + return self._send_command_str(command_string="/admin save", expect_string=r"#")
        @@ -898,7 +972,12 @@

        Methods

        Model driven CLI requires you not exit from configuration mode.

        Source code -
        def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs):
        +
        def send_config_set(
        +    self,
        +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +    exit_config_mode: bool = None,
        +    **kwargs: Any,
        +) -> str:
             """Model driven CLI requires you not exit from configuration mode."""
             if exit_config_mode is None:
                 # Set to False if model-driven CLI
        @@ -915,14 +994,15 @@ 

        Methods

        Remove the > when navigating into the different config level.

        Source code -
        def set_base_prompt(self, *args, **kwargs):
        +
        def set_base_prompt(self, *args: Any, **kwargs: Any) -> str:
             """Remove the > when navigating into the different config level."""
             cur_base_prompt = super().set_base_prompt(*args, **kwargs)
             match = re.search(r"\*?(.*?)(>.*)*#", cur_base_prompt)
             if match:
                 # strip off >... from base_prompt; strip off leading *
        -        self.base_prompt = match.group(1)
        -        return self.base_prompt
        + self.base_prompt: str = match.group(1) + + return self.base_prompt
        @@ -932,7 +1012,7 @@

        Methods

        Strip prompt from the output.

        Source code -
        def strip_prompt(self, *args, **kwargs):
        +
        def strip_prompt(self, *args: Any, **kwargs: Any) -> str:
             """Strip prompt from the output."""
             output = super().strip_prompt(*args, **kwargs)
             if "@" in self.base_prompt:
        @@ -949,7 +1029,6 @@ 

        Inherited members

      • BaseConnection:
        • clear_buffer
        • -
        • close_session_log
        • disable_paging
        • disconnect
        • establish_connection
        • @@ -957,9 +1036,9 @@

          Inherited members

        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -969,6 +1048,7 @@

          Inherited members

        • send_command_expect
        • send_command_timing
        • send_config_from_file
        • +
        • send_multiline
        • session_preparation
        • set_terminal_width
        • special_login_handler
        • @@ -983,7 +1063,7 @@

          Inherited members

          class NokiaSrosFileTransfer -(ssh_conn, source_file, dest_file, hash_supported=False, **kwargs) +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0, progress=None, progress4=None, hash_supported=False)

          Class to manage SCP file transfer and associated SSH control channel.

          @@ -991,13 +1071,30 @@

          Inherited members

          Source code
          class NokiaSrosFileTransfer(BaseFileTransfer):
               def __init__(
          -        self, ssh_conn, source_file, dest_file, hash_supported=False, **kwargs
          -    ):
          +        self,
          +        ssh_conn: BaseConnection,
          +        source_file: str,
          +        dest_file: str,
          +        file_system: Optional[str] = None,
          +        direction: str = "put",
          +        socket_timeout: float = 10.0,
          +        progress: Optional[Callable[..., Any]] = None,
          +        progress4: Optional[Callable[..., Any]] = None,
          +        hash_supported: bool = False,
          +    ) -> None:
                   super().__init__(
          -            ssh_conn, source_file, dest_file, hash_supported=hash_supported, **kwargs
          +            ssh_conn=ssh_conn,
          +            source_file=source_file,
          +            dest_file=dest_file,
          +            file_system=file_system,
          +            direction=direction,
          +            socket_timeout=socket_timeout,
          +            progress=progress,
          +            progress4=progress4,
          +            hash_supported=hash_supported,
                   )
           
          -    def _file_cmd_prefix(self):
          +    def _file_cmd_prefix(self) -> str:
                   """
                   Allow MD-CLI to execute file operations by using classical CLI.
           
          @@ -1005,17 +1102,20 @@ 

          Inherited members

          """ return "//" if "@" in self.ssh_ctl_chan.base_prompt else "" - def remote_space_available(self, search_pattern=r"(\d+)\s+\w+\s+free"): + def remote_space_available( + self, search_pattern: str = r"(\d+)\s+\w+\s+free" + ) -> int: """Return space available on remote device.""" # Sample text for search_pattern. # " 3 Dir(s) 961531904 bytes free." remote_cmd = self._file_cmd_prefix() + "file dir {}".format(self.file_system) - remote_output = self.ssh_ctl_chan.send_command(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) match = re.search(search_pattern, remote_output) + assert match is not None return int(match.group(1)) - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if destination file exists (returns boolean).""" if self.direction == "put": @@ -1033,8 +1133,12 @@

          Inherited members

          raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd=None, remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: @@ -1042,11 +1146,13 @@

          Inherited members

          remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file + else: + raise ValueError("Unexpected value for self.direction") if not remote_cmd: remote_cmd = self._file_cmd_prefix() + "file dir {}/{}".format( self.file_system, remote_file ) - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) if "File Not Found" in remote_out: raise IOError("Unable to find file on remote system") @@ -1064,7 +1170,7 @@

          Inherited members

          file_size = int(match.group(1)) return file_size - def verify_file(self): + def verify_file(self) -> bool: """Verify the file has been transferred correctly based on filesize.""" if self.direction == "put": return os.stat(self.source_file).st_size == self.remote_file_size( @@ -1075,17 +1181,20 @@

          Inherited members

          self.remote_file_size(remote_file=self.source_file) == os.stat(self.dest_file).st_size ) + else: + raise ValueError("Unexpected value of self.direction") - def file_md5(self, **kwargs): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def process_md5(self, **kwargs): + @staticmethod + def process_md5(md5_output: str, pattern: str = "") -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def compare_md5(self, **kwargs): + def compare_md5(self) -> bool: raise AttributeError("SR-OS does not support an MD5-hash operation.") - def remote_md5(self, **kwargs): + def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str: raise AttributeError("SR-OS does not support an MD5-hash operation.")
      • Ancestors

        @@ -1101,7 +1210,7 @@

        Methods

        Check if destination file exists (returns boolean).

        Source code -
        def check_file_exists(self, remote_cmd=""):
        +
        def check_file_exists(self, remote_cmd: str = "") -> bool:
             """Check if destination file exists (returns boolean)."""
         
             if self.direction == "put":
        @@ -1118,7 +1227,9 @@ 

        Methods

        else: raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": - return os.path.exists(self.dest_file)
        + return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction")
        @@ -1128,7 +1239,7 @@

        Methods

        Verify the file has been transferred correctly based on filesize.

        Source code -
        def verify_file(self):
        +
        def verify_file(self) -> bool:
             """Verify the file has been transferred correctly based on filesize."""
             if self.direction == "put":
                 return os.stat(self.source_file).st_size == self.remote_file_size(
        @@ -1138,7 +1249,9 @@ 

        Methods

        return ( self.remote_file_size(remote_file=self.source_file) == os.stat(self.dest_file).st_size - )
        + ) + else: + raise ValueError("Unexpected value of self.direction")
        @@ -1167,7 +1280,7 @@

        Inherited members

        class NokiaSrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Nokia SR OS SSH driver.

        @@ -1175,131 +1288,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -1321,7 +1407,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -1334,9 +1419,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1348,6 +1433,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -1364,7 +1450,7 @@

        Inherited members

        class NokiaSrosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Nokia SR OS Telnet driver.

        @@ -1372,131 +1458,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -1518,7 +1577,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -1531,9 +1589,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -1545,6 +1603,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/oneaccess/index.html b/docs/netmiko/oneaccess/index.html index 595a997e6..612cc8cd3 100644 --- a/docs/netmiko/oneaccess/index.html +++ b/docs/netmiko/oneaccess/index.html @@ -69,9 +69,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -82,9 +81,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -96,6 +95,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -136,9 +136,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -149,9 +148,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -163,6 +162,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/oneaccess/oneaccess_oneos.html b/docs/netmiko/oneaccess/oneaccess_oneos.html index 053679cf2..1d89ad497 100644 --- a/docs/netmiko/oneaccess/oneaccess_oneos.html +++ b/docs/netmiko/oneaccess/oneaccess_oneos.html @@ -24,18 +24,20 @@

        Module netmiko.oneaccess.oneaccess_oneos

        Source code
        """Netmiko driver for OneAccess ONEOS"""
        -from netmiko.cisco_base_connection import CiscoBaseConnection
         import time
        +from typing import Any
        +
        +from netmiko.cisco_base_connection import CiscoBaseConnection
         
         
         class OneaccessOneOSBase(CiscoBaseConnection):
        -    def __init__(self, *args, **kwargs):
        +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                 """Init connection - similar as Cisco"""
                 default_enter = kwargs.get("default_enter")
                 kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                 super().__init__(*args, **kwargs)
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare connection - disable paging"""
                 self._test_channel_read()
                 self.set_base_prompt()
        @@ -45,7 +47,9 @@ 

        Module netmiko.oneaccess.oneaccess_oneos

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Save config: write mem""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -79,13 +83,13 @@

        Classes

        Source code
        class OneaccessOneOSBase(CiscoBaseConnection):
        -    def __init__(self, *args, **kwargs):
        +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                 """Init connection - similar as Cisco"""
                 default_enter = kwargs.get("default_enter")
                 kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                 super().__init__(*args, **kwargs)
         
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare connection - disable paging"""
                 self._test_channel_read()
                 self.set_base_prompt()
        @@ -95,7 +99,9 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Save config: write mem""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -120,7 +126,9 @@

        Methods

        Save config: write mem

        Source code -
        def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
        +) -> str:
             """Save config: write mem"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -134,7 +142,7 @@ 

        Methods

        Prepare connection - disable paging

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare connection - disable paging"""
             self._test_channel_read()
             self.set_base_prompt()
        @@ -154,9 +162,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -167,9 +174,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -180,6 +187,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -219,9 +227,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -232,9 +239,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -246,6 +253,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -286,9 +294,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -299,9 +306,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -313,6 +320,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/ovs/index.html b/docs/netmiko/ovs/index.html index 09ad98cdd..b4c57ddae 100644 --- a/docs/netmiko/ovs/index.html +++ b/docs/netmiko/ovs/index.html @@ -45,7 +45,7 @@

        Classes

        class OvsLinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -53,131 +53,104 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -199,7 +172,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -212,9 +184,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -226,6 +198,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/ovs/ovs_linux_ssh.html b/docs/netmiko/ovs/ovs_linux_ssh.html index db0c5126d..848615588 100644 --- a/docs/netmiko/ovs/ovs_linux_ssh.html +++ b/docs/netmiko/ovs/ovs_linux_ssh.html @@ -40,7 +40,7 @@

        Classes

        class OvsLinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -48,131 +48,104 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -194,7 +167,6 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • config_mode
      • disable_paging
      • @@ -207,9 +179,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -221,6 +193,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/paloalto/index.html b/docs/netmiko/paloalto/index.html index b7d0f4ecd..bea5de377 100644 --- a/docs/netmiko/paloalto/index.html +++ b/docs/netmiko/paloalto/index.html @@ -45,7 +45,7 @@

        Classes

        class PaloAltoPanosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Implement methods for interacting with PaloAlto devices.

        @@ -56,140 +56,132 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class PaloAltoPanosSSH(PaloAltoPanosBase):
        -    pass
        + def _build_ssh_client(self) -> SSHClient: + """Prepare for Paramiko SSH connection.""" + # Create instance of SSHClient object + # If not using SSH keys, we use noauth + + if not self.use_keys: + remote_conn_pre: SSHClient = SSHClient_interactive() + else: + remote_conn_pre = SSHClient() + + # Load host_keys for better SSH security + if self.system_host_keys: + remote_conn_pre.load_system_host_keys() + if self.alt_host_keys and path.isfile(self.alt_key_file): + remote_conn_pre.load_host_keys(self.alt_key_file) + + # Default is to automatically add untrusted hosts (make sure appropriate for your env) + remote_conn_pre.set_missing_host_key_policy(self.key_policy) + return remote_conn_pre

        Ancestors

        Inherited members

        @@ -197,36 +189,36 @@

        Inherited members

      • PaloAltoPanosBase:
      • class PaloAltoPanosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Implement methods for interacting with PaloAlto devices.

        @@ -255,131 +247,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -389,6 +354,7 @@

        Inherited members

        Ancestors

        Inherited members

        @@ -396,36 +362,36 @@

        Inherited members

      • PaloAltoPanosBase:
        • check_config_mode
        • -
        • check_enable_mode
        • +
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • commit
        • config_mode
        • disable_paging
        • disconnect
        • -
        • enable
        • +
        • enable
        • establish_connection
        • exit_config_mode
        • -
        • exit_enable_mode
        • -
        • find_prompt
        • +
        • exit_enable_mode
        • +
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • run_ttp
        • save_config
        • select_delay_factor
        • -
        • send_command
        • -
        • send_command_expect
        • +
        • send_command
        • +
        • send_command_expect
        • send_command_timing
        • send_config_from_file
        • send_config_set
        • +
        • send_multiline
        • session_preparation
        • set_base_prompt
        • set_terminal_width
        • diff --git a/docs/netmiko/paloalto/paloalto_panos.html b/docs/netmiko/paloalto/paloalto_panos.html index e90cc228a..782396800 100644 --- a/docs/netmiko/paloalto/paloalto_panos.html +++ b/docs/netmiko/paloalto/paloalto_panos.html @@ -22,12 +22,58 @@

          Module netmiko.paloalto.paloalto_panos

          Source code -
          import time
          +
          from typing import Optional, List, Any, Tuple
           import re
          -from netmiko.base_connection import BaseConnection
          +import warnings
          +from os import path
          +from paramiko import SSHClient, Transport
           
          +from netmiko.no_enable import NoEnable
          +from netmiko.base_connection import BaseConnection, DELAY_FACTOR_DEPR_SIMPLE_MSG
           
          -class PaloAltoPanosBase(BaseConnection):
          +
          +class SSHClient_interactive(SSHClient):
          +    """Set noauth when manually handling SSH authentication."""
          +
          +    def pa_banner_handler(
          +        self, title: str, instructions: str, prompt_list: List[Tuple[str, bool]]
          +    ) -> List[str]:
          +
          +        resp = []
          +        for prompt, echo in prompt_list:
          +            if "Do you accept" in prompt:
          +                resp.append("yes")
          +            elif "ssword" in prompt:
          +                assert isinstance(self.password, str)
          +                resp.append(self.password)
          +        return resp
          +
          +    def _auth(self, username: str, password: str, *args: Any) -> None:
          +        """
          +        _auth: args as of aug-2021
          +        self,
          +        username,
          +        password,
          +        pkey,
          +        key_filenames,
          +        allow_agent,
          +        look_for_keys,
          +        gss_auth,
          +        gss_kex,
          +        gss_deleg_creds,
          +        gss_host,
          +        passphrase,
          +        """
          +
          +        # Just gets the password up to the pa_banner_handler
          +        self.password = password
          +        transport = self.get_transport()
          +        assert isinstance(transport, Transport)
          +        transport.auth_interactive(username, handler=self.pa_banner_handler)
          +        return
          +
          +
          +class PaloAltoPanosBase(NoEnable, BaseConnection):
               """
               Implement methods for interacting with PaloAlto devices.
           
          @@ -35,7 +81,7 @@ 

          Module netmiko.paloalto.paloalto_panos

          methods. Overrides several methods for PaloAlto-specific compatibility. """ - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. @@ -43,49 +89,55 @@

          Module netmiko.paloalto.paloalto_panos

          Set the base prompt for interaction ('>'). """ self.ansi_escape_codes = True - self._test_channel_read() - self.set_base_prompt(delay_factor=20) + self._test_channel_read(pattern=r"[>#]") + self.disable_paging( + command="set cli scripting-mode on", cmd_verify=False, pattern=r" on" + ) + self.set_terminal_width( + command="set cli terminal width 500", pattern=r"set cli terminal width 500" + ) self.disable_paging(command="set cli pager off") - self.disable_paging(command="set cli scripting-mode on") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() + self.set_base_prompt() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass + # PA devices can be really slow--try to make sure we are caught up + self.write_channel("show admins\n") + self._test_channel_read(pattern=r"Client") + self._test_channel_read(pattern=r"[>#]") - def enable(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass + def find_prompt( + self, delay_factor: float = 5.0, pattern: Optional[str] = None + ) -> str: + """PA devices can be very slow to respond (in certain situations)""" + return super().find_prompt(delay_factor=delay_factor, pattern=pattern) - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass - - def check_config_mode(self, check_string="]"): + def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = r"#", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def commit( self, - comment=None, - force=False, - partial=False, - device_and_network=False, - policy_and_objects=False, - vsys="", - no_vsys=False, - delay_factor=0.1, - ): + comment: str = "", + force: bool = False, + partial: bool = False, + device_and_network: bool = False, + policy_and_objects: bool = False, + vsys: str = "", + no_vsys: bool = False, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -99,8 +151,13 @@

          Module netmiko.paloalto.paloalto_panos

          (device_and_network or policy_and_objects or vsys or no_vsys) and not partial: Exception + + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if ( device_and_network or policy_and_objects or vsys or no_vsys @@ -132,24 +189,25 @@

          Module netmiko.paloalto.paloalto_panos

          # Enter config mode (if necessary) output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, expect_string="100%", - delay_factor=delay_factor, + read_timeout=read_timeout, ) + output += self.exit_config_mode() if commit_marker not in output.lower(): raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def strip_command(self, command_string, output): + def strip_command(self, command_string: str, output: str) -> str: """Strip command_string from output string.""" output_list = output.split(command_string) return self.RESPONSE_RETURN.join(output_list) - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output.""" response_list = a_string.split(self.RESPONSE_RETURN) new_response_list = [] @@ -160,7 +218,7 @@

          Module netmiko.paloalto.paloalto_panos

          output = self.RESPONSE_RETURN.join(new_response_list) return self.strip_context_items(output) - def strip_context_items(self, a_string): + def strip_context_items(self, a_string: str) -> str: """Strip PaloAlto-specific output. PaloAlto will also put a configuration context: @@ -179,16 +237,7 @@

          Module netmiko.paloalto.paloalto_panos

          return a_string - def send_command_expect(self, *args, **kwargs): - """Palo Alto requires an extra delay""" - return self.send_command(*args, **kwargs) - - def send_command(self, *args, **kwargs): - """Palo Alto requires an extra delay""" - kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5) - return super().send_command(*args, **kwargs) - - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -202,7 +251,25 @@

          Module netmiko.paloalto.paloalto_panos

          class PaloAltoPanosSSH(PaloAltoPanosBase): - pass + def _build_ssh_client(self) -> SSHClient: + """Prepare for Paramiko SSH connection.""" + # Create instance of SSHClient object + # If not using SSH keys, we use noauth + + if not self.use_keys: + remote_conn_pre: SSHClient = SSHClient_interactive() + else: + remote_conn_pre = SSHClient() + + # Load host_keys for better SSH security + if self.system_host_keys: + remote_conn_pre.load_system_host_keys() + if self.alt_host_keys and path.isfile(self.alt_key_file): + remote_conn_pre.load_host_keys(self.alt_key_file) + + # Default is to automatically add untrusted hosts (make sure appropriate for your env) + remote_conn_pre.set_missing_host_key_policy(self.key_policy) + return remote_conn_pre class PaloAltoPanosTelnet(PaloAltoPanosBase): @@ -220,7 +287,7 @@

          Classes

          class PaloAltoPanosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

          Implement methods for interacting with PaloAlto devices.

          @@ -231,135 +298,108 @@

          Classes

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
          -

          ). -:type default_enter: str

          +

          ).

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

          ) -:type response_return: str

          +

          )

              :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                       to select smallest of global and specific. Sets default global_delay_factor to .1
          -            (default: False)
          -    :type fast_cli: boolean
          +            (default: True)
           
               :param session_log: File path or BufferedIOBase subclass object to write the session log to.
          -    :type session_log: str
           
               :param session_log_record_writes: The session log generally only records channel reads due
                       to eliminate command duplication due to command echo. You can enable this if you
                       want to record both channel reads and channel writes in the log (default: False).
          -    :type session_log_record_writes: boolean
           
               :param session_log_file_mode: "write" or "append" for session_log file mode
                       (default: "write")
          -    :type session_log_file_mode: str
           
               :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                       (default: False)
          -    :type allow_auto_change: bool
           
               :param encoding: Encoding to be used when writing bytes to the output channel.
                       (default: ascii)
          -    :type encoding: str
           
               :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                       communication to the target host (default: None).
          -    :type sock: socket
           
               :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                       (default: None). Global attribute takes precedence over function `cmd_verify`
                       argument. Value of `None` indicates to use function `cmd_verify` argument.
          -    :type global_cmd_verify: bool|None
           
               :param auto_connect: Control whether Netmiko automatically establishes the connection as
                       part of the object creation (default: True).
          -    :type auto_connect: bool
          +
          +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
          +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
          +            eliminated in Netmiko 5.x (default: False).
           
          Source code -
          class PaloAltoPanosBase(BaseConnection):
          +
          class PaloAltoPanosBase(NoEnable, BaseConnection):
               """
               Implement methods for interacting with PaloAlto devices.
           
          @@ -367,7 +407,7 @@ 

          Classes

          methods. Overrides several methods for PaloAlto-specific compatibility. """ - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. @@ -375,49 +415,55 @@

          Classes

          Set the base prompt for interaction ('>'). """ self.ansi_escape_codes = True - self._test_channel_read() - self.set_base_prompt(delay_factor=20) + self._test_channel_read(pattern=r"[>#]") + self.disable_paging( + command="set cli scripting-mode on", cmd_verify=False, pattern=r" on" + ) + self.set_terminal_width( + command="set cli terminal width 500", pattern=r"set cli terminal width 500" + ) self.disable_paging(command="set cli pager off") - self.disable_paging(command="set cli scripting-mode on") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() + self.set_base_prompt() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass + # PA devices can be really slow--try to make sure we are caught up + self.write_channel("show admins\n") + self._test_channel_read(pattern=r"Client") + self._test_channel_read(pattern=r"[>#]") - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on PaloAlto.""" - pass + def find_prompt( + self, delay_factor: float = 5.0, pattern: Optional[str] = None + ) -> str: + """PA devices can be very slow to respond (in certain situations)""" + return super().find_prompt(delay_factor=delay_factor, pattern=pattern) - def check_config_mode(self, check_string="]"): + def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = r"#", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def commit( self, - comment=None, - force=False, - partial=False, - device_and_network=False, - policy_and_objects=False, - vsys="", - no_vsys=False, - delay_factor=0.1, - ): + comment: str = "", + force: bool = False, + partial: bool = False, + device_and_network: bool = False, + policy_and_objects: bool = False, + vsys: str = "", + no_vsys: bool = False, + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -431,8 +477,13 @@

          Classes

          (device_and_network or policy_and_objects or vsys or no_vsys) and not partial: Exception + + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if ( device_and_network or policy_and_objects or vsys or no_vsys @@ -464,24 +515,25 @@

          Classes

          # Enter config mode (if necessary) output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, expect_string="100%", - delay_factor=delay_factor, + read_timeout=read_timeout, ) + output += self.exit_config_mode() if commit_marker not in output.lower(): raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output - def strip_command(self, command_string, output): + def strip_command(self, command_string: str, output: str) -> str: """Strip command_string from output string.""" output_list = output.split(command_string) return self.RESPONSE_RETURN.join(output_list) - def strip_prompt(self, a_string): + def strip_prompt(self, a_string: str) -> str: """Strip the trailing router prompt from the output.""" response_list = a_string.split(self.RESPONSE_RETURN) new_response_list = [] @@ -492,7 +544,7 @@

          Classes

          output = self.RESPONSE_RETURN.join(new_response_list) return self.strip_context_items(output) - def strip_context_items(self, a_string): + def strip_context_items(self, a_string: str) -> str: """Strip PaloAlto-specific output. PaloAlto will also put a configuration context: @@ -511,16 +563,7 @@

          Classes

          return a_string - def send_command_expect(self, *args, **kwargs): - """Palo Alto requires an extra delay""" - return self.send_command(*args, **kwargs) - - def send_command(self, *args, **kwargs): - """Palo Alto requires an extra delay""" - kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5) - return super().send_command(*args, **kwargs) - - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -534,6 +577,7 @@

          Classes

          Ancestors

          Subclasses

          @@ -544,27 +588,15 @@

          Subclasses

          Methods

          -def check_config_mode(self, check_string=']') +def check_config_mode(self, check_string=']', pattern='')

          Checks if the device is in configuration mode or not.

          Source code -
          def check_config_mode(self, check_string="]"):
          +
          def check_config_mode(self, check_string: str = "]", pattern: str = "") -> bool:
               """Checks if the device is in configuration mode or not."""
          -    return super().check_config_mode(check_string=check_string)
          -
          -
          -
          -def check_enable_mode(self, *args, **kwargs) -
          -
          -

          No enable mode on PaloAlto.

          -
          -Source code -
          def check_enable_mode(self, *args, **kwargs):
          -    """No enable mode on PaloAlto."""
          -    pass
          + return super().check_config_mode(check_string=check_string, pattern=pattern)
          @@ -574,7 +606,7 @@

          Methods

          Gracefully exit the SSH session.

          Source code -
          def cleanup(self, command="exit"):
          +
          def cleanup(self, command: str = "exit") -> None:
               """Gracefully exit the SSH session."""
               try:
                   # The pattern="" forces use of send_command_timing
          @@ -588,7 +620,7 @@ 

          Methods

      • -def commit(self, comment=None, force=False, partial=False, device_and_network=False, policy_and_objects=False, vsys='', no_vsys=False, delay_factor=0.1) +def commit(self, comment='', force=False, partial=False, device_and_network=False, policy_and_objects=False, vsys='', no_vsys=False, read_timeout=120.0, delay_factor=None)

        Commit the candidate configuration.

        @@ -599,20 +631,22 @@

        Methods

        command_string = commit (device_and_network or policy_and_objects or vsys or no_vsys) and not partial: -Exception

        +Exception

        +

        delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

        Source code
        def commit(
             self,
        -    comment=None,
        -    force=False,
        -    partial=False,
        -    device_and_network=False,
        -    policy_and_objects=False,
        -    vsys="",
        -    no_vsys=False,
        -    delay_factor=0.1,
        -):
        +    comment: str = "",
        +    force: bool = False,
        +    partial: bool = False,
        +    device_and_network: bool = False,
        +    policy_and_objects: bool = False,
        +    vsys: str = "",
        +    no_vsys: bool = False,
        +    read_timeout: float = 120.0,
        +    delay_factor: Optional[float] = None,
        +) -> str:
             """
             Commit the candidate configuration.
         
        @@ -626,8 +660,13 @@ 

        Methods

        (device_and_network or policy_and_objects or vsys or no_vsys) and not partial: Exception + + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) if ( device_and_network or policy_and_objects or vsys or no_vsys @@ -659,13 +698,14 @@

        Methods

        # Enter config mode (if necessary) output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, expect_string="100%", - delay_factor=delay_factor, + read_timeout=read_timeout, ) + output += self.exit_config_mode() if commit_marker not in output.lower(): raise ValueError(f"Commit failed with the following errors:\n\n{output}") @@ -673,27 +713,19 @@

        Methods

        -def config_mode(self, config_command='configure') +def config_mode(self, config_command='configure', pattern='#', re_flags=0)

        Enter configuration mode.

        Source code -
        def config_mode(self, config_command="configure"):
        +
        def config_mode(
        +    self, config_command: str = "configure", pattern: str = r"#", re_flags: int = 0
        +) -> str:
             """Enter configuration mode."""
        -    return super().config_mode(config_command=config_command)
        -
        -
        -
        -def enable(self, *args, **kwargs) -
        -
        -

        No enable mode on PaloAlto.

        -
        -Source code -
        def enable(self, *args, **kwargs):
        -    """No enable mode on PaloAlto."""
        -    pass
        + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
        @@ -703,46 +735,23 @@

        Methods

        Exit configuration mode.

        Source code -
        def exit_config_mode(self, exit_config="exit", pattern=r">"):
        +
        def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str:
             """Exit configuration mode."""
             return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
        -
        -def exit_enable_mode(self, *args, **kwargs) -
        -
        -

        No enable mode on PaloAlto.

        -
        -Source code -
        def exit_enable_mode(self, *args, **kwargs):
        -    """No enable mode on PaloAlto."""
        -    pass
        -
        -
        -
        -def send_command(self, *args, **kwargs) +
        +def find_prompt(self, delay_factor=5.0, pattern=None)
        -

        Palo Alto requires an extra delay

        +

        PA devices can be very slow to respond (in certain situations)

        Source code -
        def send_command(self, *args, **kwargs):
        -    """Palo Alto requires an extra delay"""
        -    kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5)
        -    return super().send_command(*args, **kwargs)
        -
        -
        -
        -def send_command_expect(self, *args, **kwargs) -
        -
        -

        Palo Alto requires an extra delay

        -
        -Source code -
        def send_command_expect(self, *args, **kwargs):
        -    """Palo Alto requires an extra delay"""
        -    return self.send_command(*args, **kwargs)
        +
        def find_prompt(
        +    self, delay_factor: float = 5.0, pattern: Optional[str] = None
        +) -> str:
        +    """PA devices can be very slow to respond (in certain situations)"""
        +    return super().find_prompt(delay_factor=delay_factor, pattern=pattern)
        @@ -754,7 +763,7 @@

        Methods

        Set the base prompt for interaction ('>').

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """
             Prepare the session after the connection has been established.
         
        @@ -762,13 +771,20 @@ 

        Methods

        Set the base prompt for interaction ('>'). """ self.ansi_escape_codes = True - self._test_channel_read() - self.set_base_prompt(delay_factor=20) + self._test_channel_read(pattern=r"[>#]") + self.disable_paging( + command="set cli scripting-mode on", cmd_verify=False, pattern=r" on" + ) + self.set_terminal_width( + command="set cli terminal width 500", pattern=r"set cli terminal width 500" + ) self.disable_paging(command="set cli pager off") - self.disable_paging(command="set cli scripting-mode on") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer()
        + self.set_base_prompt() + + # PA devices can be really slow--try to make sure we are caught up + self.write_channel("show admins\n") + self._test_channel_read(pattern=r"Client") + self._test_channel_read(pattern=r"[>#]")
        @@ -778,7 +794,7 @@

        Methods

        Strip command_string from output string.

        Source code -
        def strip_command(self, command_string, output):
        +
        def strip_command(self, command_string: str, output: str) -> str:
             """Strip command_string from output string."""
             output_list = output.split(command_string)
             return self.RESPONSE_RETURN.join(output_list)
        @@ -794,7 +810,7 @@

        Methods

        This method removes those lines.

        Source code -
        def strip_context_items(self, a_string):
        +
        def strip_context_items(self, a_string: str) -> str:
             """Strip PaloAlto-specific output.
         
             PaloAlto will also put a configuration context:
        @@ -821,7 +837,7 @@ 

        Methods

        Strip the trailing router prompt from the output.

        Source code -
        def strip_prompt(self, a_string):
        +
        def strip_prompt(self, a_string: str) -> str:
             """Strip the trailing router prompt from the output."""
             response_list = a_string.split(self.RESPONSE_RETURN)
             new_response_list = []
        @@ -838,27 +854,31 @@ 

        Inherited members

        • BaseConnection:
            +
          • check_enable_mode
          • clear_buffer
          • -
          • close_session_log
          • disable_paging
          • disconnect
          • +
          • enable
          • establish_connection
          • -
          • find_prompt
          • +
          • exit_enable_mode
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • run_ttp
          • save_config
          • select_delay_factor
          • +
          • send_command
          • +
          • send_command_expect
          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • set_base_prompt
          • set_terminal_width
          • special_login_handler
          • @@ -872,7 +892,7 @@

            Inherited members

            class PaloAltoPanosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Implement methods for interacting with PaloAlto devices.

            @@ -883,140 +903,132 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class PaloAltoPanosSSH(PaloAltoPanosBase):
        -    pass
        + def _build_ssh_client(self) -> SSHClient: + """Prepare for Paramiko SSH connection.""" + # Create instance of SSHClient object + # If not using SSH keys, we use noauth + + if not self.use_keys: + remote_conn_pre: SSHClient = SSHClient_interactive() + else: + remote_conn_pre = SSHClient() + + # Load host_keys for better SSH security + if self.system_host_keys: + remote_conn_pre.load_system_host_keys() + if self.alt_host_keys and path.isfile(self.alt_key_file): + remote_conn_pre.load_host_keys(self.alt_key_file) + + # Default is to automatically add untrusted hosts (make sure appropriate for your env) + remote_conn_pre.set_missing_host_key_policy(self.key_policy) + return remote_conn_pre

        Ancestors

        Inherited members

        @@ -1024,36 +1036,36 @@

        Inherited members

      • PaloAltoPanosBase:
        • check_config_mode
        • -
        • check_enable_mode
        • +
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • commit
        • config_mode
        • disable_paging
        • disconnect
        • -
        • enable
        • +
        • enable
        • establish_connection
        • exit_config_mode
        • -
        • exit_enable_mode
        • -
        • find_prompt
        • +
        • exit_enable_mode
        • +
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • run_ttp
        • save_config
        • select_delay_factor
        • -
        • send_command
        • -
        • send_command_expect
        • +
        • send_command
        • +
        • send_command_expect
        • send_command_timing
        • send_config_from_file
        • send_config_set
        • +
        • send_multiline
        • session_preparation
        • set_base_prompt
        • set_terminal_width
        • @@ -1071,7 +1083,7 @@

          Inherited members

          class PaloAltoPanosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

          Implement methods for interacting with PaloAlto devices.

          @@ -1082,131 +1094,104 @@

          Inherited members

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      • -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -1216,6 +1201,7 @@

        Inherited members

        Ancestors

        Inherited members

        @@ -1223,36 +1209,36 @@

        Inherited members

      • PaloAltoPanosBase: +
        +class SSHClient_interactive +
        +
        +

        Set noauth when manually handling SSH authentication.

        +

        Create a new SSHClient.

        +
        +Source code +
        class SSHClient_interactive(SSHClient):
        +    """Set noauth when manually handling SSH authentication."""
        +
        +    def pa_banner_handler(
        +        self, title: str, instructions: str, prompt_list: List[Tuple[str, bool]]
        +    ) -> List[str]:
        +
        +        resp = []
        +        for prompt, echo in prompt_list:
        +            if "Do you accept" in prompt:
        +                resp.append("yes")
        +            elif "ssword" in prompt:
        +                assert isinstance(self.password, str)
        +                resp.append(self.password)
        +        return resp
        +
        +    def _auth(self, username: str, password: str, *args: Any) -> None:
        +        """
        +        _auth: args as of aug-2021
        +        self,
        +        username,
        +        password,
        +        pkey,
        +        key_filenames,
        +        allow_agent,
        +        look_for_keys,
        +        gss_auth,
        +        gss_kex,
        +        gss_deleg_creds,
        +        gss_host,
        +        passphrase,
        +        """
        +
        +        # Just gets the password up to the pa_banner_handler
        +        self.password = password
        +        transport = self.get_transport()
        +        assert isinstance(transport, Transport)
        +        transport.auth_interactive(username, handler=self.pa_banner_handler)
        +        return
        +
        +

        Ancestors

        +
          +
        • paramiko.client.SSHClient
        • +
        • paramiko.util.ClosingContextManager
        • +
        +

        Methods

        +
        +
        +def pa_banner_handler(self, title, instructions, prompt_list) +
        +
        +
        +
        +Source code +
        def pa_banner_handler(
        +    self, title: str, instructions: str, prompt_list: List[Tuple[str, bool]]
        +) -> List[str]:
        +
        +    resp = []
        +    for prompt, echo in prompt_list:
        +        if "Do you accept" in prompt:
        +            resp.append("yes")
        +        elif "ssword" in prompt:
        +            assert isinstance(self.password, str)
        +            resp.append(self.password)
        +    return resp
        +
        +
        +
        +
        @@ -1288,15 +1352,11 @@

        Index

        PaloAltoPanosBase

      diff --git a/docs/netmiko/pluribus/index.html b/docs/netmiko/pluribus/index.html index c2fdcc9ea..3f5d5306a 100644 --- a/docs/netmiko/pluribus/index.html +++ b/docs/netmiko/pluribus/index.html @@ -49,236 +49,32 @@

      Classes

      (*args, **kwargs)
      -

      Common methods for Pluribus.

      -
          Initialize attributes for establishing connection to target device.
      -
      -    :param ip: IP address of target device. Not required if `host` is
      -        provided.
      -    :type ip: str
      -
      -    :param host: Hostname of target device. Not required if `ip` is
      -            provided.
      -    :type host: str
      -
      -    :param username: Username to authenticate against target device if
      -            required.
      -    :type username: str
      -
      -    :param password: Password to authenticate against target device if
      -            required.
      -    :type password: str
      -
      -    :param secret: The enable password if target device requires one.
      -    :type secret: str
      -
      -    :param port: The destination port used to connect to the target
      -            device.
      -    :type port: int or None
      -
      -    :param device_type: Class selection based on device type.
      -    :type device_type: str
      -
      -    :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
      -
      -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
      -
      -    :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
      -
      -    :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
      -
      -    :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
      -
      -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
      -            decryption if not specified.
      -    :type passphrase: str
      -
      -    :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
      -
      -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
      -            means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
      -
      -    :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
      -            alt_key_file.
      -    :type alt_host_keys: bool
      -
      -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
      -
      -    :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
      -
      -    :param timeout: Connection timeout.
      -    :type timeout: float
      -
      -    :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
      -
      -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
      -
      -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
      -
      -    :param 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).
      -    :type keepalive: int
      -
      -    :param default_enter: Character(s) to send to correspond to enter key (default:
      -
      -

      ). -:type default_enter: str

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

      ) -:type response_return: str

      -
          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
      -            to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      -
      -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
      -
      -    :param session_log_record_writes: The session log generally only records channel reads due
      -            to eliminate command duplication due to command echo. You can enable this if you
      -            want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
      -
      -    :param session_log_file_mode: "write" or "append" for session_log file mode
      -            (default: "write")
      -    :type session_log_file_mode: str
      -
      -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
      -            (default: False)
      -    :type allow_auto_change: bool
      -
      -    :param encoding: Encoding to be used when writing bytes to the output channel.
      -            (default: ascii)
      -    :type encoding: str
      -
      -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
      -            communication to the target host (default: None).
      -    :type sock: socket
      -
      -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      -            (default: None). Global attribute takes precedence over function `cmd_verify`
      -            argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
      -
      -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      -            part of the object creation (default: True).
      -    :type auto_connect: bool
      -
      +

      Common methods for Pluribus.

      Source code -
      class PluribusSSH(BaseConnection):
      +
      class PluribusSSH(NoConfig, BaseConnection):
           """Common methods for Pluribus."""
       
      -    def __init__(self, *args, **kwargs):
      +    def __init__(self, *args: Any, **kwargs: Any) -> None:
               super().__init__(*args, **kwargs)
               self._config_mode = False
       
      -    def disable_paging(self, command="pager off", delay_factor=1):
      -        """Make sure paging is disabled."""
      -        return super().disable_paging(command=command, delay_factor=delay_factor)
      -
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the netmiko session."""
               self._test_channel_read()
               self.set_base_prompt()
               self.disable_paging()
               # Clear the read buffer
               time.sleep(0.3 * self.global_delay_factor)
      -        self.clear_buffer()
      -
      -    def check_config_mode(self, *args, **kwargs):
      -        """
      -        Pluribus devices don't have a config mode.
      -        Therefore it can be considered as always in config mode.
      -        """
      -        return self._config_mode
      -
      -    def config_mode(self, *args, **kwargs):
      -        """No special actions to enter in config mode."""
      -        self._config_mode = True
      -        return ""
      -
      -    def exit_config_mode(self, *args, **kwargs):
      -        """No special actions to exit config mode."""
      -        self._config_mode = False
      -        return ""
      + self.clear_buffer()

      Ancestors

      Methods

      -
      -def check_config_mode(self, *args, **kwargs) -
      -
      -

      Pluribus devices don't have a config mode. -Therefore it can be considered as always in config mode.

      -
      -Source code -
      def check_config_mode(self, *args, **kwargs):
      -    """
      -    Pluribus devices don't have a config mode.
      -    Therefore it can be considered as always in config mode.
      -    """
      -    return self._config_mode
      -
      -
      -
      -def config_mode(self, *args, **kwargs) -
      -
      -

      No special actions to enter in config mode.

      -
      -Source code -
      def config_mode(self, *args, **kwargs):
      -    """No special actions to enter in config mode."""
      -    self._config_mode = True
      -    return ""
      -
      -
      -
      -def disable_paging(self, command='pager off', delay_factor=1) -
      -
      -

      Make sure paging is disabled.

      -
      -Source code -
      def disable_paging(self, command="pager off", delay_factor=1):
      -    """Make sure paging is disabled."""
      -    return super().disable_paging(command=command, delay_factor=delay_factor)
      -
      -
      -
      -def exit_config_mode(self, *args, **kwargs) -
      -
      -

      No special actions to exit config mode.

      -
      -Source code -
      def exit_config_mode(self, *args, **kwargs):
      -    """No special actions to exit config mode."""
      -    self._config_mode = False
      -    return ""
      -
      -
      def session_preparation(self)
      @@ -286,7 +82,7 @@

      Methods

      Prepare the netmiko session.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the netmiko session."""
           self._test_channel_read()
           self.set_base_prompt()
      @@ -301,22 +97,25 @@ 

      Inherited members

      @@ -78,236 +60,32 @@

      Classes

      (*args, **kwargs)
      -

      Common methods for Pluribus.

      -
          Initialize attributes for establishing connection to target device.
      -
      -    :param ip: IP address of target device. Not required if `host` is
      -        provided.
      -    :type ip: str
      -
      -    :param host: Hostname of target device. Not required if `ip` is
      -            provided.
      -    :type host: str
      -
      -    :param username: Username to authenticate against target device if
      -            required.
      -    :type username: str
      -
      -    :param password: Password to authenticate against target device if
      -            required.
      -    :type password: str
      -
      -    :param secret: The enable password if target device requires one.
      -    :type secret: str
      -
      -    :param port: The destination port used to connect to the target
      -            device.
      -    :type port: int or None
      -
      -    :param device_type: Class selection based on device type.
      -    :type device_type: str
      -
      -    :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
      -
      -    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
      -
      -    :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
      -
      -    :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
      -
      -    :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
      -
      -    :param passphrase: Passphrase to use for encrypted key; password will be used for key
      -            decryption if not specified.
      -    :type passphrase: str
      -
      -    :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
      -
      -    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
      -            means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
      -
      -    :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      -    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
      -            alt_key_file.
      -    :type alt_host_keys: bool
      -
      -    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
      -
      -    :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
      -
      -    :param timeout: Connection timeout.
      -    :type timeout: float
      -
      -    :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
      -
      -    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
      -
      -    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
      -
      -    :param 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).
      -    :type keepalive: int
      -
      -    :param default_enter: Character(s) to send to correspond to enter key (default:
      -
      -

      ). -:type default_enter: str

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

      ) -:type response_return: str

      -
          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
      -            to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      -
      -    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
      -
      -    :param session_log_record_writes: The session log generally only records channel reads due
      -            to eliminate command duplication due to command echo. You can enable this if you
      -            want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
      -
      -    :param session_log_file_mode: "write" or "append" for session_log file mode
      -            (default: "write")
      -    :type session_log_file_mode: str
      -
      -    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
      -            (default: False)
      -    :type allow_auto_change: bool
      -
      -    :param encoding: Encoding to be used when writing bytes to the output channel.
      -            (default: ascii)
      -    :type encoding: str
      -
      -    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
      -            communication to the target host (default: None).
      -    :type sock: socket
      -
      -    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      -            (default: None). Global attribute takes precedence over function `cmd_verify`
      -            argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
      -
      -    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      -            part of the object creation (default: True).
      -    :type auto_connect: bool
      -
      +

      Common methods for Pluribus.

      Source code -
      class PluribusSSH(BaseConnection):
      +
      class PluribusSSH(NoConfig, BaseConnection):
           """Common methods for Pluribus."""
       
      -    def __init__(self, *args, **kwargs):
      +    def __init__(self, *args: Any, **kwargs: Any) -> None:
               super().__init__(*args, **kwargs)
               self._config_mode = False
       
      -    def disable_paging(self, command="pager off", delay_factor=1):
      -        """Make sure paging is disabled."""
      -        return super().disable_paging(command=command, delay_factor=delay_factor)
      -
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the netmiko session."""
               self._test_channel_read()
               self.set_base_prompt()
               self.disable_paging()
               # Clear the read buffer
               time.sleep(0.3 * self.global_delay_factor)
      -        self.clear_buffer()
      -
      -    def check_config_mode(self, *args, **kwargs):
      -        """
      -        Pluribus devices don't have a config mode.
      -        Therefore it can be considered as always in config mode.
      -        """
      -        return self._config_mode
      -
      -    def config_mode(self, *args, **kwargs):
      -        """No special actions to enter in config mode."""
      -        self._config_mode = True
      -        return ""
      -
      -    def exit_config_mode(self, *args, **kwargs):
      -        """No special actions to exit config mode."""
      -        self._config_mode = False
      -        return ""
      + self.clear_buffer()

      Ancestors

      Methods

      -
      -def check_config_mode(self, *args, **kwargs) -
      -
      -

      Pluribus devices don't have a config mode. -Therefore it can be considered as always in config mode.

      -
      -Source code -
      def check_config_mode(self, *args, **kwargs):
      -    """
      -    Pluribus devices don't have a config mode.
      -    Therefore it can be considered as always in config mode.
      -    """
      -    return self._config_mode
      -
      -
      -
      -def config_mode(self, *args, **kwargs) -
      -
      -

      No special actions to enter in config mode.

      -
      -Source code -
      def config_mode(self, *args, **kwargs):
      -    """No special actions to enter in config mode."""
      -    self._config_mode = True
      -    return ""
      -
      -
      -
      -def disable_paging(self, command='pager off', delay_factor=1) -
      -
      -

      Make sure paging is disabled.

      -
      -Source code -
      def disable_paging(self, command="pager off", delay_factor=1):
      -    """Make sure paging is disabled."""
      -    return super().disable_paging(command=command, delay_factor=delay_factor)
      -
      -
      -
      -def exit_config_mode(self, *args, **kwargs) -
      -
      -

      No special actions to exit config mode.

      -
      -Source code -
      def exit_config_mode(self, *args, **kwargs):
      -    """No special actions to exit config mode."""
      -    self._config_mode = False
      -    return ""
      -
      -
      def session_preparation(self)
      @@ -315,7 +93,7 @@

      Methods

      Prepare the netmiko session.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the netmiko session."""
           self._test_channel_read()
           self.set_base_prompt()
      @@ -330,22 +108,25 @@ 

      Inherited members

      • BaseConnection:
          +
        • check_config_mode
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • commit
        • +
        • config_mode
        • +
        • disable_paging
        • disconnect
        • enable
        • establish_connection
        • +
        • exit_config_mode
        • exit_enable_mode
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -357,6 +138,7 @@

          Inherited members

        • send_command_timing
        • send_config_from_file
        • send_config_set
        • +
        • send_multiline
        • set_base_prompt
        • set_terminal_width
        • special_login_handler
        • @@ -389,10 +171,6 @@

          Index

        • PluribusSSH

        • diff --git a/docs/netmiko/quanta/index.html b/docs/netmiko/quanta/index.html index 4d8e221c6..abfa144d1 100644 --- a/docs/netmiko/quanta/index.html +++ b/docs/netmiko/quanta/index.html @@ -45,7 +45,7 @@

          Classes

          class QuantaMeshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

          Base Class for cisco-like behavior.

          @@ -53,149 +53,127 @@

          Classes

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class QuantaMeshSSH(CiscoSSHConnection):
      -    def disable_paging(self, command="no pager", delay_factor=1):
      -        """Disable paging"""
      -        return super().disable_paging(command=command)
      -
      -    def config_mode(self, config_command="configure"):
      -        """Enter configuration mode."""
      -        return super().config_mode(config_command=config_command)
      +    def session_preparation(self) -> None:
      +        self._test_channel_read()
      +        self.set_base_prompt()
      +        self.set_terminal_width()
      +        self.disable_paging("no pager")
      +
      +    def config_mode(
      +        self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
      +    ) -> str:
      +        return super().config_mode(
      +            config_command=config_command, pattern=pattern, re_flags=re_flags
      +        )
       
           def save_config(
               self,
      -        cmd="copy running-config startup-config",
      -        confirm=False,
      -        confirm_response="",
      -    ):
      +        cmd: str = "copy running-config startup-config",
      +        confirm: bool = False,
      +        confirm_response: str = "",
      +    ) -> str:
               """Saves Config"""
               return super().save_config(
                   cmd=cmd, confirm=confirm, confirm_response=confirm_response
      @@ -209,30 +187,6 @@ 

      Ancestors

    Methods

    -
    -def config_mode(self, config_command='configure') -
    -
    -

    Enter configuration mode.

    -
    -Source code -
    def config_mode(self, config_command="configure"):
    -    """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    -
    -
    -
    -def disable_paging(self, command='no pager', delay_factor=1) -
    -
    -

    Disable paging

    -
    -Source code -
    def disable_paging(self, command="no pager", delay_factor=1):
    -    """Disable paging"""
    -    return super().disable_paging(command=command)
    -
    -
    def save_config(self, cmd='copy running-config startup-config', confirm=False, confirm_response='')
    @@ -242,10 +196,10 @@

    Methods

    Source code
    def save_config(
         self,
    -    cmd="copy running-config startup-config",
    -    confirm=False,
    -    confirm_response="",
    -):
    +    cmd: str = "copy running-config startup-config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -261,8 +215,9 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • +
  • disable_paging
  • disconnect
  • enable
  • establish_connection
  • @@ -272,9 +227,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -285,6 +240,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -323,8 +279,6 @@

    Index

  • QuantaMeshSSH

  • diff --git a/docs/netmiko/quanta/quanta_mesh_ssh.html b/docs/netmiko/quanta/quanta_mesh_ssh.html index e13d85053..e89fd5363 100644 --- a/docs/netmiko/quanta/quanta_mesh_ssh.html +++ b/docs/netmiko/quanta/quanta_mesh_ssh.html @@ -26,20 +26,25 @@

    Module netmiko.quanta.quanta_mesh_ssh

    class QuantaMeshSSH(CiscoSSHConnection): - def disable_paging(self, command="no pager", delay_factor=1): - """Disable paging""" - return super().disable_paging(command=command) - - def config_mode(self, config_command="configure"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + def session_preparation(self) -> None: + self._test_channel_read() + self.set_base_prompt() + self.set_terminal_width() + self.disable_paging("no pager") + + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) def save_config( self, - cmd="copy running-config startup-config", - confirm=False, - confirm_response="", - ): + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -57,7 +62,7 @@

    Classes

    class QuantaMeshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Base Class for cisco-like behavior.

    @@ -65,149 +70,127 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class QuantaMeshSSH(CiscoSSHConnection):
    -    def disable_paging(self, command="no pager", delay_factor=1):
    -        """Disable paging"""
    -        return super().disable_paging(command=command)
    -
    -    def config_mode(self, config_command="configure"):
    -        """Enter configuration mode."""
    -        return super().config_mode(config_command=config_command)
    +    def session_preparation(self) -> None:
    +        self._test_channel_read()
    +        self.set_base_prompt()
    +        self.set_terminal_width()
    +        self.disable_paging("no pager")
    +
    +    def config_mode(
    +        self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
    +    ) -> str:
    +        return super().config_mode(
    +            config_command=config_command, pattern=pattern, re_flags=re_flags
    +        )
     
         def save_config(
             self,
    -        cmd="copy running-config startup-config",
    -        confirm=False,
    -        confirm_response="",
    -    ):
    +        cmd: str = "copy running-config startup-config",
    +        confirm: bool = False,
    +        confirm_response: str = "",
    +    ) -> str:
             """Saves Config"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -221,30 +204,6 @@ 

    Ancestors

    Methods

    -
    -def config_mode(self, config_command='configure') -
    -
    -

    Enter configuration mode.

    -
    -Source code -
    def config_mode(self, config_command="configure"):
    -    """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    -
    -
    -
    -def disable_paging(self, command='no pager', delay_factor=1) -
    -
    -

    Disable paging

    -
    -Source code -
    def disable_paging(self, command="no pager", delay_factor=1):
    -    """Disable paging"""
    -    return super().disable_paging(command=command)
    -
    -
    def save_config(self, cmd='copy running-config startup-config', confirm=False, confirm_response='')
    @@ -254,10 +213,10 @@

    Methods

    Source code
    def save_config(
         self,
    -    cmd="copy running-config startup-config",
    -    confirm=False,
    -    confirm_response="",
    -):
    +    cmd: str = "copy running-config startup-config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves Config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -273,8 +232,9 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • +
  • disable_paging
  • disconnect
  • enable
  • establish_connection
  • @@ -284,9 +244,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -297,6 +257,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -330,8 +291,6 @@

    Index

  • QuantaMeshSSH

  • diff --git a/docs/netmiko/rad/index.html b/docs/netmiko/rad/index.html index 825e20b77..1d449b3f4 100644 --- a/docs/netmiko/rad/index.html +++ b/docs/netmiko/rad/index.html @@ -54,138 +54,111 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class RadETXSSH(RadETXBase):
         """RAD ETX SSH Support."""
     
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             # Found that a global_delay_factor of 2 is needed at minimum for SSH to the Rad ETX.
             kwargs.setdefault("global_delay_factor", 2)
             return super().__init__(**kwargs)
    @@ -193,6 +166,7 @@

    Classes

    Ancestors

    Inherited members

    @@ -200,25 +174,24 @@

    Inherited members

  • RadETXBase:
    • check_config_mode
    • -
    • check_enable_mode
    • +
    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • disconnect
    • -
    • enable
    • +
    • enable
    • establish_connection
    • exit_config_mode
    • -
    • exit_enable_mode
    • +
    • exit_enable_mode
    • find_prompt
    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -230,6 +203,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -246,7 +220,7 @@

      Inherited members

      class RadETXTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      RAD ETX Telnet Support.

      @@ -254,131 +228,104 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
  • -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -386,8 +333,14 @@

    Inherited members

    """RAD ETX Telnet Support.""" def telnet_login( - self, username_pattern=r"(?:user>)", alt_prompt_term=r"#\s*$", **kwargs - ): + self, + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r"#\s*$", + username_pattern: str = r"(?:user>)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """ RAD presents with the following on login @@ -398,19 +351,23 @@

    Inherited members

    self.TELNET_RETURN = self.RETURN return super().telnet_login( username_pattern=username_pattern, - alt_prompt_terminator=alt_prompt_term, - **kwargs + alt_prompt_terminator=alt_prompt_terminator, + pri_prompt_terminator=pri_prompt_terminator, + pwd_pattern=pwd_pattern, + delay_factor=delay_factor, + max_loops=max_loops, )

    Ancestors

    Methods

    -def telnet_login(self, username_pattern='(?:user>)', alt_prompt_term='#\\s*$', **kwargs) +def telnet_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='#\\s*$', username_pattern='(?:user>)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)

    RAD presents with the following on login

    @@ -419,8 +376,14 @@

    Methods

    Source code
    def telnet_login(
    -    self, username_pattern=r"(?:user>)", alt_prompt_term=r"#\s*$", **kwargs
    -):
    +    self,
    +    pri_prompt_terminator: str = r"#\s*$",
    +    alt_prompt_terminator: str = r"#\s*$",
    +    username_pattern: str = r"(?:user>)",
    +    pwd_pattern: str = r"assword",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 20,
    +) -> str:
         """
         RAD presents with the following on login
     
    @@ -431,8 +394,11 @@ 

    Methods

    self.TELNET_RETURN = self.RETURN return super().telnet_login( username_pattern=username_pattern, - alt_prompt_terminator=alt_prompt_term, - **kwargs + alt_prompt_terminator=alt_prompt_terminator, + pri_prompt_terminator=pri_prompt_terminator, + pwd_pattern=pwd_pattern, + delay_factor=delay_factor, + max_loops=max_loops, )
    @@ -442,25 +408,24 @@

    Inherited members

  • RadETXBase:
    • check_config_mode
    • -
    • check_enable_mode
    • +
    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • disconnect
    • -
    • enable
    • +
    • enable
    • establish_connection
    • exit_config_mode
    • -
    • exit_enable_mode
    • +
    • exit_enable_mode
    • find_prompt
    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -472,6 +437,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • diff --git a/docs/netmiko/rad/rad_etx.html b/docs/netmiko/rad/rad_etx.html index ca2a9d06c..234846db8 100644 --- a/docs/netmiko/rad/rad_etx.html +++ b/docs/netmiko/rad/rad_etx.html @@ -23,13 +23,16 @@

      Module netmiko.rad.rad_etx

      Source code
      import time
      +from typing import Any
      +
      +from netmiko.no_enable import NoEnable
       from netmiko.base_connection import BaseConnection
       
       
      -class RadETXBase(BaseConnection):
      +class RadETXBase(NoEnable, BaseConnection):
           """RAD ETX Support, Tested on RAD 203AX, 205A and 220A."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               self._test_channel_read()
               self.set_base_prompt()
               self.disable_paging(command="config term length 0")
      @@ -37,37 +40,36 @@ 

      Module netmiko.rad.rad_etx

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="admin save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "admin save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using admin save.""" if confirm: - output = self.send_command_timing(command_string=cmd) + output = self._send_command_timing_str(command_string=cmd) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self._send_command_timing_str(confirm_response) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self._send_command_timing_str(self.RETURN) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) return output - def check_enable_mode(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def enable(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def config_mode(self, config_command="config", pattern=">config"): + def config_mode( + self, + config_command: str = "config", + pattern: str = ">config", + re_flags: int = 0, + ) -> str: """Enter into configuration mode on remote device.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def check_config_mode(self, check_string=">config", pattern=""): + def check_config_mode( + self, check_string: str = ">config", pattern: str = "" + ) -> bool: """ Checks if the device is in configuration mode or not. @@ -75,7 +77,9 @@

      Module netmiko.rad.rad_etx

      """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def exit_config_mode(self, exit_config="exit all", pattern="#"): + def exit_config_mode( + self, exit_config: str = "exit all", pattern: str = "#" + ) -> str: """Exit from configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) @@ -83,7 +87,7 @@

      Module netmiko.rad.rad_etx

      class RadETXSSH(RadETXBase): """RAD ETX SSH Support.""" - def __init__(self, **kwargs): + def __init__(self, **kwargs: Any) -> None: # Found that a global_delay_factor of 2 is needed at minimum for SSH to the Rad ETX. kwargs.setdefault("global_delay_factor", 2) return super().__init__(**kwargs) @@ -93,8 +97,14 @@

      Module netmiko.rad.rad_etx

      """RAD ETX Telnet Support.""" def telnet_login( - self, username_pattern=r"(?:user>)", alt_prompt_term=r"#\s*$", **kwargs - ): + self, + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r"#\s*$", + username_pattern: str = r"(?:user>)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """ RAD presents with the following on login @@ -105,8 +115,11 @@

      Module netmiko.rad.rad_etx

      self.TELNET_RETURN = self.RETURN return super().telnet_login( username_pattern=username_pattern, - alt_prompt_terminator=alt_prompt_term, - **kwargs + alt_prompt_terminator=alt_prompt_terminator, + pri_prompt_terminator=pri_prompt_terminator, + pwd_pattern=pwd_pattern, + delay_factor=delay_factor, + max_loops=max_loops, )
      @@ -121,7 +134,7 @@

      Classes

      class RadETXBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      RAD ETX Support, Tested on RAD 203AX, 205A and 220A.

      @@ -129,138 +142,111 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code -
      class RadETXBase(BaseConnection):
      +
      class RadETXBase(NoEnable, BaseConnection):
           """RAD ETX Support, Tested on RAD 203AX, 205A and 220A."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               self._test_channel_read()
               self.set_base_prompt()
               self.disable_paging(command="config term length 0")
      @@ -268,37 +254,36 @@ 

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="admin save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "admin save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using admin save.""" if confirm: - output = self.send_command_timing(command_string=cmd) + output = self._send_command_timing_str(command_string=cmd) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self._send_command_timing_str(confirm_response) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self._send_command_timing_str(self.RETURN) else: # Some devices are slow so match on trailing-prompt if you can - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) return output - def check_enable_mode(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def enable(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """The Rad ETX software does not have an enable.""" - pass - - def config_mode(self, config_command="config", pattern=">config"): + def config_mode( + self, + config_command: str = "config", + pattern: str = ">config", + re_flags: int = 0, + ) -> str: """Enter into configuration mode on remote device.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def check_config_mode(self, check_string=">config", pattern=""): + def check_config_mode( + self, check_string: str = ">config", pattern: str = "" + ) -> bool: """ Checks if the device is in configuration mode or not. @@ -306,12 +291,15 @@

      Classes

      """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def exit_config_mode(self, exit_config="exit all", pattern="#"): + def exit_config_mode( + self, exit_config: str = "exit all", pattern: str = "#" + ) -> str: """Exit from configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern)

      Ancestors

      Subclasses

      @@ -329,7 +317,9 @@

      Methods

      Rad config starts with baseprompt>config.

      Source code -
      def check_config_mode(self, check_string=">config", pattern=""):
      +
      def check_config_mode(
      +    self, check_string: str = ">config", pattern: str = ""
      +) -> bool:
           """
           Checks if the device is in configuration mode or not.
       
      @@ -338,40 +328,23 @@ 

      Methods

      return super().check_config_mode(check_string=check_string, pattern=pattern)
      -
      -def check_enable_mode(self, *args, **kwargs) -
      -
      -

      The Rad ETX software does not have an enable.

      -
      -Source code -
      def check_enable_mode(self, *args, **kwargs):
      -    """The Rad ETX software does not have an enable."""
      -    pass
      -
      -
      -def config_mode(self, config_command='config', pattern='>config') +def config_mode(self, config_command='config', pattern='>config', re_flags=0)

      Enter into configuration mode on remote device.

      Source code -
      def config_mode(self, config_command="config", pattern=">config"):
      +
      def config_mode(
      +    self,
      +    config_command: str = "config",
      +    pattern: str = ">config",
      +    re_flags: int = 0,
      +) -> str:
           """Enter into configuration mode on remote device."""
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      -
      -
      -
      -def enable(self, *args, **kwargs) -
      -
      -

      The Rad ETX software does not have an enable.

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """The Rad ETX software does not have an enable."""
      -    pass
      + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
      @@ -381,23 +354,13 @@

      Methods

      Exit from configuration mode.

      Source code -
      def exit_config_mode(self, exit_config="exit all", pattern="#"):
      +
      def exit_config_mode(
      +    self, exit_config: str = "exit all", pattern: str = "#"
      +) -> str:
           """Exit from configuration mode."""
           return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
      -
      -def exit_enable_mode(self, *args, **kwargs) -
      -
      -

      The Rad ETX software does not have an enable.

      -
      -Source code -
      def exit_enable_mode(self, *args, **kwargs):
      -    """The Rad ETX software does not have an enable."""
      -    pass
      -
      -
      def save_config(self, cmd='admin save', confirm=False, confirm_response='')
      @@ -405,18 +368,20 @@

      Methods

      Saves Config Using admin save.

      Source code -
      def save_config(self, cmd="admin save", confirm=False, confirm_response=""):
      +
      def save_config(
      +    self, cmd: str = "admin save", confirm: bool = False, confirm_response: str = ""
      +) -> str:
           """Saves Config Using admin save."""
           if confirm:
      -        output = self.send_command_timing(command_string=cmd)
      +        output = self._send_command_timing_str(command_string=cmd)
               if confirm_response:
      -            output += self.send_command_timing(confirm_response)
      +            output += self._send_command_timing_str(confirm_response)
               else:
                   # Send enter by default
      -            output += self.send_command_timing(self.RETURN)
      +            output += self._send_command_timing_str(self.RETURN)
           else:
               # Some devices are slow so match on trailing-prompt if you can
      -        output = self.send_command(command_string=cmd)
      +        output = self._send_command_str(command_string=cmd)
           return output
      @@ -425,20 +390,22 @@

      Inherited members

      • BaseConnection:
          +
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • commit
        • disable_paging
        • disconnect
        • +
        • enable
        • establish_connection
        • +
        • exit_enable_mode
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -449,6 +416,7 @@

          Inherited members

        • send_command_timing
        • send_config_from_file
        • send_config_set
        • +
        • send_multiline
        • session_preparation
        • set_base_prompt
        • set_terminal_width
        • @@ -473,138 +441,111 @@

          Inherited members

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
          -

          ). -:type default_enter: str

          +

          ).

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

          ) -:type response_return: str

          +

          )

              :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                       to select smallest of global and specific. Sets default global_delay_factor to .1
          -            (default: False)
          -    :type fast_cli: boolean
          +            (default: True)
           
               :param session_log: File path or BufferedIOBase subclass object to write the session log to.
          -    :type session_log: str
           
               :param session_log_record_writes: The session log generally only records channel reads due
                       to eliminate command duplication due to command echo. You can enable this if you
                       want to record both channel reads and channel writes in the log (default: False).
          -    :type session_log_record_writes: boolean
           
               :param session_log_file_mode: "write" or "append" for session_log file mode
                       (default: "write")
          -    :type session_log_file_mode: str
           
               :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                       (default: False)
          -    :type allow_auto_change: bool
           
               :param encoding: Encoding to be used when writing bytes to the output channel.
                       (default: ascii)
          -    :type encoding: str
           
               :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                       communication to the target host (default: None).
          -    :type sock: socket
           
               :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                       (default: None). Global attribute takes precedence over function `cmd_verify`
                       argument. Value of `None` indicates to use function `cmd_verify` argument.
          -    :type global_cmd_verify: bool|None
           
               :param auto_connect: Control whether Netmiko automatically establishes the connection as
                       part of the object creation (default: True).
          -    :type auto_connect: bool
          +
          +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
          +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
          +            eliminated in Netmiko 5.x (default: False).
           
          Source code
          class RadETXSSH(RadETXBase):
               """RAD ETX SSH Support."""
           
          -    def __init__(self, **kwargs):
          +    def __init__(self, **kwargs: Any) -> None:
                   # Found that a global_delay_factor of 2 is needed at minimum for SSH to the Rad ETX.
                   kwargs.setdefault("global_delay_factor", 2)
                   return super().__init__(**kwargs)
          @@ -612,6 +553,7 @@

          Inherited members

          Ancestors

          Inherited members

          @@ -619,25 +561,24 @@

          Inherited members

        • RadETXBase:
          • check_config_mode
          • -
          • check_enable_mode
          • +
          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • config_mode
          • disable_paging
          • disconnect
          • -
          • enable
          • +
          • enable
          • establish_connection
          • exit_config_mode
          • -
          • exit_enable_mode
          • +
          • exit_enable_mode
          • find_prompt
          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -649,6 +590,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -665,7 +607,7 @@

            Inherited members

            class RadETXTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            RAD ETX Telnet Support.

            @@ -673,131 +615,104 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code @@ -805,8 +720,14 @@

            Inherited members

            """RAD ETX Telnet Support.""" def telnet_login( - self, username_pattern=r"(?:user>)", alt_prompt_term=r"#\s*$", **kwargs - ): + self, + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r"#\s*$", + username_pattern: str = r"(?:user>)", + pwd_pattern: str = r"assword", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: """ RAD presents with the following on login @@ -817,19 +738,23 @@

            Inherited members

            self.TELNET_RETURN = self.RETURN return super().telnet_login( username_pattern=username_pattern, - alt_prompt_terminator=alt_prompt_term, - **kwargs + alt_prompt_terminator=alt_prompt_terminator, + pri_prompt_terminator=pri_prompt_terminator, + pwd_pattern=pwd_pattern, + delay_factor=delay_factor, + max_loops=max_loops, )

            Ancestors

            Methods

            -def telnet_login(self, username_pattern='(?:user>)', alt_prompt_term='#\\s*$', **kwargs) +def telnet_login(self, pri_prompt_terminator='#\\s*$', alt_prompt_terminator='#\\s*$', username_pattern='(?:user>)', pwd_pattern='assword', delay_factor=1.0, max_loops=20)

            RAD presents with the following on login

            @@ -838,8 +763,14 @@

            Methods

            Source code
            def telnet_login(
            -    self, username_pattern=r"(?:user>)", alt_prompt_term=r"#\s*$", **kwargs
            -):
            +    self,
            +    pri_prompt_terminator: str = r"#\s*$",
            +    alt_prompt_terminator: str = r"#\s*$",
            +    username_pattern: str = r"(?:user>)",
            +    pwd_pattern: str = r"assword",
            +    delay_factor: float = 1.0,
            +    max_loops: int = 20,
            +) -> str:
                 """
                 RAD presents with the following on login
             
            @@ -850,8 +781,11 @@ 

            Methods

            self.TELNET_RETURN = self.RETURN return super().telnet_login( username_pattern=username_pattern, - alt_prompt_terminator=alt_prompt_term, - **kwargs + alt_prompt_terminator=alt_prompt_terminator, + pri_prompt_terminator=pri_prompt_terminator, + pwd_pattern=pwd_pattern, + delay_factor=delay_factor, + max_loops=max_loops, )
            @@ -861,25 +795,24 @@

            Inherited members

          • RadETXBase:
            • check_config_mode
            • -
            • check_enable_mode
            • +
            • check_enable_mode
            • cleanup
            • clear_buffer
            • -
            • close_session_log
            • commit
            • config_mode
            • disable_paging
            • disconnect
            • -
            • enable
            • +
            • enable
            • establish_connection
            • exit_config_mode
            • -
            • exit_enable_mode
            • +
            • exit_enable_mode
            • find_prompt
            • is_alive
            • normalize_cmd
            • normalize_linefeeds
            • -
            • open_session_log
            • paramiko_cleanup
            • read_channel
            • +
            • read_channel_timing
            • read_until_pattern
            • read_until_prompt
            • read_until_prompt_or_pattern
            • @@ -891,6 +824,7 @@

              Inherited members

            • send_command_timing
            • send_config_from_file
            • send_config_set
            • +
            • send_multiline
            • session_preparation
            • set_base_prompt
            • set_terminal_width
            • @@ -922,13 +856,10 @@

              Index

              • RadETXBase

                -
                  + diff --git a/docs/netmiko/raisecom/index.html b/docs/netmiko/raisecom/index.html index 68c39301b..d41a2d803 100644 --- a/docs/netmiko/raisecom/index.html +++ b/docs/netmiko/raisecom/index.html @@ -46,7 +46,7 @@

                  Classes

                  class RaisecomRoapSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Base Class for cisco-like behavior.

                  @@ -54,136 +54,109 @@

                  Classes

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RaisecomRoapSSH(RaisecomRoapBase):
                  -    def special_login_handler(self, delay_factor=1):
                  +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
                           """
                           Raisecom presents with the following on login (in certain OS versions)
                           Login: user
                  @@ -199,6 +172,7 @@ 

                  Classes

                  if "Login:" in output: self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert self.password is not None self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -216,7 +190,7 @@

                  Ancestors

                  Methods

                  -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

                  Raisecom presents with the following on login (in certain OS versions) @@ -224,7 +198,7 @@

                  Methods

                  Password:****

                  Source code -
                  def special_login_handler(self, delay_factor=1):
                  +
                  def special_login_handler(self, delay_factor: float = 1.0) -> None:
                       """
                       Raisecom presents with the following on login (in certain OS versions)
                       Login: user
                  @@ -240,6 +214,7 @@ 

                  Methods

                  if "Login:" in output: self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert self.password is not None self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -258,9 +233,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -271,9 +245,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -285,6 +259,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • @@ -300,7 +275,7 @@

                  Inherited members

                  class RaisecomRoapTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Base Class for cisco-like behavior.

                  @@ -308,137 +283,110 @@

                  Inherited members

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RaisecomRoapTelnet(RaisecomRoapBase):
                       @staticmethod
                  -    def _process_option(telnet_sock, cmd, opt):
                  +    def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None:
                           """
                           enable ECHO, SGA, set window size to [500, 50]
                           """
                  @@ -459,15 +407,16 @@ 

                  Inherited members

                  def telnet_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(Login|Username)", - pwd_pattern=r"Password", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(Login|Username)", + pwd_pattern: str = r"Password", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) delay_factor = self.select_delay_factor(delay_factor) time.sleep(1 * delay_factor) @@ -489,6 +438,7 @@

                  Inherited members

                  # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): + assert self.password is not None self.write_channel(self.password + self.TELNET_RETURN) time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -539,9 +489,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -552,9 +501,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -566,6 +515,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • diff --git a/docs/netmiko/raisecom/raisecom_roap.html b/docs/netmiko/raisecom/raisecom_roap.html index 856c614e7..2fce28543 100644 --- a/docs/netmiko/raisecom/raisecom_roap.html +++ b/docs/netmiko/raisecom/raisecom_roap.html @@ -25,12 +25,14 @@

                  Module netmiko.raisecom.raisecom_roap

                  from netmiko.cisco_base_connection import CiscoBaseConnection
                   import re
                   import time
                  -from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, ECHO, SGA, NAWS
                  -from netmiko.ssh_exception import NetmikoAuthenticationException
                  +from socket import socket
                  +
                  +from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, ECHO, SGA, NAWS, Telnet
                  +from netmiko.exceptions import NetmikoAuthenticationException
                   
                   
                   class RaisecomRoapBase(CiscoBaseConnection):
                  -    def session_preparation(self):
                  +    def session_preparation(self) -> None:
                           """Prepare the session after the connection has been established."""
                           self._test_channel_read(pattern=r"[>#]")
                           self.set_base_prompt()
                  @@ -40,15 +42,18 @@ 

                  Module netmiko.raisecom.raisecom_roap

                  time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( - self, cmd="write startup-config", confirm=False, confirm_response="" - ): + self, + cmd: str = "write startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config.""" self.exit_config_mode() self.enable() @@ -58,7 +63,7 @@

                  Module netmiko.raisecom.raisecom_roap

                  class RaisecomRoapSSH(RaisecomRoapBase): - def special_login_handler(self, delay_factor=1): + def special_login_handler(self, delay_factor: float = 1.0) -> None: """ Raisecom presents with the following on login (in certain OS versions) Login: user @@ -74,6 +79,7 @@

                  Module netmiko.raisecom.raisecom_roap

                  if "Login:" in output: self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert self.password is not None self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -85,7 +91,7 @@

                  Module netmiko.raisecom.raisecom_roap

                  class RaisecomRoapTelnet(RaisecomRoapBase): @staticmethod - def _process_option(telnet_sock, cmd, opt): + def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None: """ enable ECHO, SGA, set window size to [500, 50] """ @@ -106,15 +112,16 @@

                  Module netmiko.raisecom.raisecom_roap

                  def telnet_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(Login|Username)", - pwd_pattern=r"Password", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(Login|Username)", + pwd_pattern: str = r"Password", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) delay_factor = self.select_delay_factor(delay_factor) time.sleep(1 * delay_factor) @@ -136,6 +143,7 @@

                  Module netmiko.raisecom.raisecom_roap

                  # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): + assert self.password is not None self.write_channel(self.password + self.TELNET_RETURN) time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -184,7 +192,7 @@

                  Classes

                  class RaisecomRoapBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Base Class for cisco-like behavior.

                  @@ -192,136 +200,109 @@

                  Classes

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RaisecomRoapBase(CiscoBaseConnection):
                  -    def session_preparation(self):
                  +    def session_preparation(self) -> None:
                           """Prepare the session after the connection has been established."""
                           self._test_channel_read(pattern=r"[>#]")
                           self.set_base_prompt()
                  @@ -331,15 +312,18 @@ 

                  Classes

                  time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( - self, cmd="write startup-config", confirm=False, confirm_response="" - ): + self, + cmd: str = "write startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves Config.""" self.exit_config_mode() self.enable() @@ -366,7 +350,7 @@

                  Methods

                  Checks if the device is in configuration mode or not.

                  Source code -
                  def check_config_mode(self, check_string=")#", pattern="#"):
                  +
                  def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
                       """
                       Checks if the device is in configuration mode or not.
                       """
                  @@ -380,7 +364,7 @@ 

                  Methods

                  Prepare the session after the connection has been established.

                  Source code -
                  def session_preparation(self):
                  +
                  def session_preparation(self) -> None:
                       """Prepare the session after the connection has been established."""
                       self._test_channel_read(pattern=r"[>#]")
                       self.set_base_prompt()
                  @@ -399,9 +383,8 @@ 

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -412,9 +395,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -426,6 +409,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • set_base_prompt
                • set_terminal_width
                • special_login_handler
                • @@ -441,7 +425,7 @@

                  Inherited members

                  class RaisecomRoapSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Base Class for cisco-like behavior.

                  @@ -449,136 +433,109 @@

                  Inherited members

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RaisecomRoapSSH(RaisecomRoapBase):
                  -    def special_login_handler(self, delay_factor=1):
                  +    def special_login_handler(self, delay_factor: float = 1.0) -> None:
                           """
                           Raisecom presents with the following on login (in certain OS versions)
                           Login: user
                  @@ -594,6 +551,7 @@ 

                  Inherited members

                  if "Login:" in output: self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert self.password is not None self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -611,7 +569,7 @@

                  Ancestors

                  Methods

                  -def special_login_handler(self, delay_factor=1) +def special_login_handler(self, delay_factor=1.0)

                  Raisecom presents with the following on login (in certain OS versions) @@ -619,7 +577,7 @@

                  Methods

                  Password:****

                  Source code -
                  def special_login_handler(self, delay_factor=1):
                  +
                  def special_login_handler(self, delay_factor: float = 1.0) -> None:
                       """
                       Raisecom presents with the following on login (in certain OS versions)
                       Login: user
                  @@ -635,6 +593,7 @@ 

                  Methods

                  if "Login:" in output: self.write_channel(self.username + self.RETURN) elif "Password:" in output: + assert self.password is not None self.write_channel(self.password + self.RETURN) break time.sleep(delay_factor * 1) @@ -653,9 +612,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -666,9 +624,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -680,6 +638,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • @@ -695,7 +654,7 @@

                  Inherited members

                  class RaisecomRoapTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Base Class for cisco-like behavior.

                  @@ -703,137 +662,110 @@

                  Inherited members

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RaisecomRoapTelnet(RaisecomRoapBase):
                       @staticmethod
                  -    def _process_option(telnet_sock, cmd, opt):
                  +    def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None:
                           """
                           enable ECHO, SGA, set window size to [500, 50]
                           """
                  @@ -854,15 +786,16 @@ 

                  Inherited members

                  def telnet_login( self, - pri_prompt_terminator=r"#\s*$", - alt_prompt_terminator=r">\s*$", - username_pattern=r"(Login|Username)", - pwd_pattern=r"Password", - delay_factor=1, - max_loops=20, - ): + pri_prompt_terminator: str = r"#\s*$", + alt_prompt_terminator: str = r">\s*$", + username_pattern: str = r"(Login|Username)", + pwd_pattern: str = r"Password", + delay_factor: float = 1.0, + max_loops: int = 20, + ) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) delay_factor = self.select_delay_factor(delay_factor) time.sleep(1 * delay_factor) @@ -884,6 +817,7 @@

                  Inherited members

                  # Search for password pattern / send password if re.search(pwd_pattern, output, flags=re.I): + assert self.password is not None self.write_channel(self.password + self.TELNET_RETURN) time.sleep(0.5 * delay_factor) output = self.read_channel() @@ -934,9 +868,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -947,9 +880,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -961,6 +894,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • diff --git a/docs/netmiko/ruckus/index.html b/docs/netmiko/ruckus/index.html index af23054e6..cec5ffe17 100644 --- a/docs/netmiko/ruckus/index.html +++ b/docs/netmiko/ruckus/index.html @@ -46,7 +46,7 @@

                  Classes

                  class RuckusFastironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Ruckus FastIron aka ICX support.

                  @@ -54,131 +54,104 @@

                  Classes

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code @@ -200,9 +173,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -213,9 +185,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -227,6 +199,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • @@ -251,141 +224,114 @@

                  Inherited members

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RuckusFastironTelnet(RuckusFastironBase):
                  -    def __init__(self, *args, **kwargs):
                  +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                           default_enter = kwargs.get("default_enter")
                           kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                           super().__init__(*args, **kwargs)
                   
                  -    def _process_option(self, tsocket, command, option):
                  +    def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None:
                           """
                           Ruckus FastIron/ICX does not always echo commands to output by default.
                           If server expresses interest in 'ECHO' option, then reply back with 'DO
                  @@ -398,8 +344,9 @@ 

                  Inherited members

                  elif command in (WILL, WONT): tsocket.sendall(IAC + DONT + option) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs)
                  @@ -418,9 +365,8 @@

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • enable
                • @@ -431,9 +377,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -445,6 +391,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • session_preparation
                • set_base_prompt
                • set_terminal_width
                • diff --git a/docs/netmiko/ruckus/ruckus_fastiron.html b/docs/netmiko/ruckus/ruckus_fastiron.html index ef80ee44c..12ac11086 100644 --- a/docs/netmiko/ruckus/ruckus_fastiron.html +++ b/docs/netmiko/ruckus/ruckus_fastiron.html @@ -24,14 +24,17 @@

                  Module netmiko.ruckus.ruckus_fastiron

                  Source code
                  import re
                   import time
                  -from telnetlib import DO, DONT, ECHO, IAC, WILL, WONT
                  +from socket import socket
                  +from typing import Optional, Any
                  +
                  +from telnetlib import DO, DONT, ECHO, IAC, WILL, WONT, Telnet
                   from netmiko.cisco_base_connection import CiscoSSHConnection
                   
                   
                   class RuckusFastironBase(CiscoSSHConnection):
                       """Ruckus FastIron aka ICX support."""
                   
                  -    def session_preparation(self):
                  +    def session_preparation(self) -> None:
                           """FastIron requires to be enable mode to disable paging."""
                           self._test_channel_read()
                           self.set_base_prompt()
                  @@ -42,8 +45,12 @@ 

                  Module netmiko.ruckus.ruckus_fastiron

                  self.clear_buffer() def enable( - self, cmd="enable", pattern=r"(ssword|User Name)", re_flags=re.IGNORECASE - ): + self, + cmd: str = "enable", + pattern: str = r"(ssword|User Name)", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode. With RADIUS can prompt for User Name SSH@Lab-ICX7250>en @@ -58,23 +65,23 @@

                  Module netmiko.ruckus.ruckus_fastiron

                  while i < count: self.write_channel(self.normalize_cmd(cmd)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "User Name" in new_data: self.write_channel(self.normalize_cmd(self.username)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - new_data = self.read_until_prompt() + new_data = self.read_until_prompt(read_entire_line=True) output += new_data if not re.search( r"error.*incorrect.*password", new_data, flags=re.I ): - return output + break time.sleep(1) i += 1 @@ -86,7 +93,11 @@

                  Module netmiko.ruckus.ruckus_fastiron

                  ) raise ValueError(msg) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + return output + + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -94,12 +105,12 @@

                  Module netmiko.ruckus.ruckus_fastiron

                  class RuckusFastironTelnet(RuckusFastironBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs) - def _process_option(self, tsocket, command, option): + def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None: """ Ruckus FastIron/ICX does not always echo commands to output by default. If server expresses interest in 'ECHO' option, then reply back with 'DO @@ -112,8 +123,9 @@

                  Module netmiko.ruckus.ruckus_fastiron

                  elif command in (WILL, WONT): tsocket.sendall(IAC + DONT + option) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs) @@ -133,7 +145,7 @@

                  Classes

                  class RuckusFastironBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

                  Ruckus FastIron aka ICX support.

                  @@ -141,138 +153,111 @@

                  Classes

                  :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
                  -

                  ). -:type default_enter: str

                  +

                  ).

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

                  ) -:type response_return: str

                  +

                  )

                      :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                               to select smallest of global and specific. Sets default global_delay_factor to .1
                  -            (default: False)
                  -    :type fast_cli: boolean
                  +            (default: True)
                   
                       :param session_log: File path or BufferedIOBase subclass object to write the session log to.
                  -    :type session_log: str
                   
                       :param session_log_record_writes: The session log generally only records channel reads due
                               to eliminate command duplication due to command echo. You can enable this if you
                               want to record both channel reads and channel writes in the log (default: False).
                  -    :type session_log_record_writes: boolean
                   
                       :param session_log_file_mode: "write" or "append" for session_log file mode
                               (default: "write")
                  -    :type session_log_file_mode: str
                   
                       :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                               (default: False)
                  -    :type allow_auto_change: bool
                   
                       :param encoding: Encoding to be used when writing bytes to the output channel.
                               (default: ascii)
                  -    :type encoding: str
                   
                       :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                               communication to the target host (default: None).
                  -    :type sock: socket
                   
                       :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                               (default: None). Global attribute takes precedence over function `cmd_verify`
                               argument. Value of `None` indicates to use function `cmd_verify` argument.
                  -    :type global_cmd_verify: bool|None
                   
                       :param auto_connect: Control whether Netmiko automatically establishes the connection as
                               part of the object creation (default: True).
                  -    :type auto_connect: bool
                  +
                  +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
                  +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
                  +            eliminated in Netmiko 5.x (default: False).
                   
                  Source code
                  class RuckusFastironBase(CiscoSSHConnection):
                       """Ruckus FastIron aka ICX support."""
                   
                  -    def session_preparation(self):
                  +    def session_preparation(self) -> None:
                           """FastIron requires to be enable mode to disable paging."""
                           self._test_channel_read()
                           self.set_base_prompt()
                  @@ -283,8 +268,12 @@ 

                  Classes

                  self.clear_buffer() def enable( - self, cmd="enable", pattern=r"(ssword|User Name)", re_flags=re.IGNORECASE - ): + self, + cmd: str = "enable", + pattern: str = r"(ssword|User Name)", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """Enter enable mode. With RADIUS can prompt for User Name SSH@Lab-ICX7250>en @@ -299,23 +288,23 @@

                  Classes

                  while i < count: self.write_channel(self.normalize_cmd(cmd)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "User Name" in new_data: self.write_channel(self.normalize_cmd(self.username)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - new_data = self.read_until_prompt() + new_data = self.read_until_prompt(read_entire_line=True) output += new_data if not re.search( r"error.*incorrect.*password", new_data, flags=re.I ): - return output + break time.sleep(1) i += 1 @@ -327,7 +316,11 @@

                  Classes

                  ) raise ValueError(msg) - def save_config(self, cmd="write mem", confirm=False, confirm_response=""): + return output + + def save_config( + self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -347,7 +340,7 @@

                  Subclasses

                  Methods

                  -def enable(self, cmd='enable', pattern='(ssword|User Name)', re_flags=) +def enable(self, cmd='enable', pattern='(ssword|User Name)', enable_pattern=None, re_flags=)

                  Enter enable mode. @@ -359,8 +352,12 @@

                  Methods

                  Source code
                  def enable(
                  -    self, cmd="enable", pattern=r"(ssword|User Name)", re_flags=re.IGNORECASE
                  -):
                  +    self,
                  +    cmd: str = "enable",
                  +    pattern: str = r"(ssword|User Name)",
                  +    enable_pattern: Optional[str] = None,
                  +    re_flags: int = re.IGNORECASE,
                  +) -> str:
                       """Enter enable mode.
                       With RADIUS can prompt for User Name
                       SSH@Lab-ICX7250>en
                  @@ -375,23 +372,23 @@ 

                  Methods

                  while i < count: self.write_channel(self.normalize_cmd(cmd)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "User Name" in new_data: self.write_channel(self.normalize_cmd(self.username)) new_data = self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - new_data = self.read_until_prompt() + new_data = self.read_until_prompt(read_entire_line=True) output += new_data if not re.search( r"error.*incorrect.*password", new_data, flags=re.I ): - return output + break time.sleep(1) i += 1 @@ -401,7 +398,9 @@

                  Methods

                  "Failed to enter enable mode. Please ensure you pass " "the 'secret' argument to ConnectHandler." ) - raise ValueError(msg)
                  + raise ValueError(msg) + + return output
                  @@ -411,7 +410,9 @@

                  Methods

                  Saves configuration.

                  Source code -
                  def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
                  +
                  def save_config(
                  +    self, cmd: str = "write mem", confirm: bool = False, confirm_response: str = ""
                  +) -> str:
                       """Saves configuration."""
                       return super().save_config(
                           cmd=cmd, confirm=confirm, confirm_response=confirm_response
                  @@ -425,7 +426,7 @@ 

                  Methods

                  FastIron requires to be enable mode to disable paging.

                  Source code -
                  def session_preparation(self):
                  +
                  def session_preparation(self) -> None:
                       """FastIron requires to be enable mode to disable paging."""
                       self._test_channel_read()
                       self.set_base_prompt()
                  @@ -445,9 +446,8 @@ 

                  Inherited members

                • check_enable_mode
                • cleanup
                • clear_buffer
                • -
                • close_session_log
                • commit
                • -
                • config_mode
                • +
                • config_mode
                • disable_paging
                • disconnect
                • establish_connection
                • @@ -457,9 +457,9 @@

                  Inherited members

                • is_alive
                • normalize_cmd
                • normalize_linefeeds
                • -
                • open_session_log
                • paramiko_cleanup
                • read_channel
                • +
                • read_channel_timing
                • read_until_pattern
                • read_until_prompt
                • read_until_prompt_or_pattern
                • @@ -470,6 +470,7 @@

                  Inherited members

                • send_command_timing
                • send_config_from_file
                • send_config_set
                • +
                • send_multiline
                • set_base_prompt
                • set_terminal_width
                • special_login_handler
                • @@ -485,7 +486,7 @@

                  Inherited members

          • class RuckusFastironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Ruckus FastIron aka ICX support.

            @@ -493,131 +494,104 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code @@ -639,9 +613,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -652,9 +625,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -666,6 +639,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -690,141 +664,114 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class RuckusFastironTelnet(RuckusFastironBase):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     default_enter = kwargs.get("default_enter")
                     kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                     super().__init__(*args, **kwargs)
             
            -    def _process_option(self, tsocket, command, option):
            +    def _process_option(self, tsocket: socket, command: bytes, option: bytes) -> None:
                     """
                     Ruckus FastIron/ICX does not always echo commands to output by default.
                     If server expresses interest in 'ECHO' option, then reply back with 'DO
            @@ -837,8 +784,9 @@ 

            Inherited members

            elif command in (WILL, WONT): tsocket.sendall(IAC + DONT + option) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs)
            @@ -857,9 +805,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -870,9 +817,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -884,6 +831,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • diff --git a/docs/netmiko/ruijie/index.html b/docs/netmiko/ruijie/index.html index b4b99f115..ec693b736 100644 --- a/docs/netmiko/ruijie/index.html +++ b/docs/netmiko/ruijie/index.html @@ -45,7 +45,7 @@

            Classes

            class RuijieOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Base Class for cisco-like behavior.

            @@ -53,131 +53,104 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code @@ -199,9 +172,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -212,9 +184,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -226,6 +198,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -250,136 +223,109 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class RuijieOSTelnet(RuijieOSBase):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     default_enter = kwargs.get("default_enter")
                     kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                     super().__init__(*args, **kwargs)
            @@ -398,9 +344,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -411,9 +356,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -425,6 +370,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • diff --git a/docs/netmiko/ruijie/ruijie_os.html b/docs/netmiko/ruijie/ruijie_os.html index e32fa7aaf..8d281c753 100644 --- a/docs/netmiko/ruijie/ruijie_os.html +++ b/docs/netmiko/ruijie/ruijie_os.html @@ -24,12 +24,14 @@

            Module netmiko.ruijie.ruijie_os

            Source code
            """Ruijie RGOS Support"""
            -from netmiko.cisco_base_connection import CiscoBaseConnection
             import time
            +from typing import Any
            +
            +from netmiko.cisco_base_connection import CiscoBaseConnection
             
             
             class RuijieOSBase(CiscoBaseConnection):
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
            @@ -41,7 +43,9 @@ 

            Module netmiko.ruijie.ruijie_os

            time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Save config: write""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -54,7 +58,7 @@

            Module netmiko.ruijie.ruijie_os

            class RuijieOSTelnet(RuijieOSBase): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter super().__init__(*args, **kwargs)
            @@ -71,7 +75,7 @@

            Classes

            class RuijieOSBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Base Class for cisco-like behavior.

            @@ -79,136 +83,109 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default: -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class RuijieOSBase(CiscoBaseConnection):
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read(pattern=r"[>#]")
                     self.set_base_prompt()
            @@ -220,7 +197,9 @@ 

            Classes

            time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Save config: write""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -245,7 +224,9 @@

            Methods

            Save config: write

            Source code -
            def save_config(self, cmd="write", confirm=False, confirm_response=""):
            +
            def save_config(
            +    self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
            +) -> str:
                 """Save config: write"""
                 return super().save_config(
                     cmd=cmd, confirm=confirm, confirm_response=confirm_response
            @@ -259,7 +240,7 @@ 

            Methods

            Prepare the session after the connection has been established.

            Source code -
            def session_preparation(self):
            +
            def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
            @@ -281,9 +262,8 @@ 

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -294,9 +274,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -307,6 +287,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • set_base_prompt
          • set_terminal_width
          • special_login_handler
          • @@ -322,7 +303,7 @@

            Inherited members

            class RuijieOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Base Class for cisco-like behavior.

            @@ -330,131 +311,104 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code @@ -476,9 +430,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -489,9 +442,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -503,6 +456,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • @@ -527,136 +481,109 @@

            Inherited members

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
            -

            ). -:type default_enter: str

            +

            ).

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

            ) -:type response_return: str

            +

            )

                :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                         to select smallest of global and specific. Sets default global_delay_factor to .1
            -            (default: False)
            -    :type fast_cli: boolean
            +            (default: True)
             
                 :param session_log: File path or BufferedIOBase subclass object to write the session log to.
            -    :type session_log: str
             
                 :param session_log_record_writes: The session log generally only records channel reads due
                         to eliminate command duplication due to command echo. You can enable this if you
                         want to record both channel reads and channel writes in the log (default: False).
            -    :type session_log_record_writes: boolean
             
                 :param session_log_file_mode: "write" or "append" for session_log file mode
                         (default: "write")
            -    :type session_log_file_mode: str
             
                 :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                         (default: False)
            -    :type allow_auto_change: bool
             
                 :param encoding: Encoding to be used when writing bytes to the output channel.
                         (default: ascii)
            -    :type encoding: str
             
                 :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                         communication to the target host (default: None).
            -    :type sock: socket
             
                 :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                         (default: None). Global attribute takes precedence over function `cmd_verify`
                         argument. Value of `None` indicates to use function `cmd_verify` argument.
            -    :type global_cmd_verify: bool|None
             
                 :param auto_connect: Control whether Netmiko automatically establishes the connection as
                         part of the object creation (default: True).
            -    :type auto_connect: bool
            +
            +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
            +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
            +            eliminated in Netmiko 5.x (default: False).
             
            Source code
            class RuijieOSTelnet(RuijieOSBase):
            -    def __init__(self, *args, **kwargs):
            +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                     default_enter = kwargs.get("default_enter")
                     kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
                     super().__init__(*args, **kwargs)
            @@ -675,9 +602,8 @@

            Inherited members

          • check_enable_mode
          • cleanup
          • clear_buffer
          • -
          • close_session_log
          • commit
          • -
          • config_mode
          • +
          • config_mode
          • disable_paging
          • disconnect
          • enable
          • @@ -688,9 +614,9 @@

            Inherited members

          • is_alive
          • normalize_cmd
          • normalize_linefeeds
          • -
          • open_session_log
          • paramiko_cleanup
          • read_channel
          • +
          • read_channel_timing
          • read_until_pattern
          • read_until_prompt
          • read_until_prompt_or_pattern
          • @@ -702,6 +628,7 @@

            Inherited members

          • send_command_timing
          • send_config_from_file
          • send_config_set
          • +
          • send_multiline
          • session_preparation
          • set_base_prompt
          • set_terminal_width
          • diff --git a/docs/netmiko/scp_functions.html b/docs/netmiko/scp_functions.html index 4c0256873..2287195d7 100644 --- a/docs/netmiko/scp_functions.html +++ b/docs/netmiko/scp_functions.html @@ -32,13 +32,24 @@

            Module netmiko.scp_functions

            SCP requires a separate SSH connection for a control channel. """ -from netmiko import FileTransfer, InLineTransfer +from typing import AnyStr, Optional, Callable, Any, Dict +from typing import TYPE_CHECKING +from netmiko.scp_handler import BaseFileTransfer +from netmiko.ssh_dispatcher import FileTransfer +from netmiko.cisco.cisco_ios import InLineTransfer +if TYPE_CHECKING: + from netmiko.base_connection import BaseConnection -def progress_bar(filename, size, sent, peername=None): + +def progress_bar( + filename: AnyStr, size: int, sent: int, peername: Optional[str] = None +) -> None: max_width = 50 if isinstance(filename, bytes): - filename = filename.decode() + filename_str = filename.decode() + else: + filename_str = filename clear_screen = chr(27) + "[2J" terminating_char = "|" @@ -49,9 +60,9 @@

            Module netmiko.scp_functions

            progress = hash_count * ">" if peername is None: - header_msg = f"Transferring file: {filename}\n" + header_msg = f"Transferring file: {filename_str}\n" else: - header_msg = f"Transferring file to {peername}: {filename}\n" + header_msg = f"Transferring file to {peername}: {filename_str}\n" msg = f"{progress:<50}{terminating_char:1} ({percent_str})" print(clear_screen) @@ -59,7 +70,7 @@

            Module netmiko.scp_functions

            print(msg) -def verifyspace_and_transferfile(scp_transfer): +def verifyspace_and_transferfile(scp_transfer: BaseFileTransfer) -> None: """Verify space and transfer file.""" if not scp_transfer.verify_space_available(): raise ValueError("Insufficient space available on remote device") @@ -67,19 +78,19 @@

            Module netmiko.scp_functions

            def file_transfer( - ssh_conn, - source_file, - dest_file, - file_system=None, - direction="put", - disable_md5=False, - inline_transfer=False, - overwrite_file=False, - socket_timeout=10.0, - progress=None, - progress4=None, - verify_file=None, -): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + disable_md5: bool = False, + inline_transfer: bool = False, + overwrite_file: bool = False, + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + verify_file: Optional[bool] = None, +) -> Dict[str, bool]: """Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices. inline_transfer ONLY SUPPORTS TEXT FILES and will not support binary file transfers. @@ -129,7 +140,11 @@

            Module netmiko.scp_functions

            if file_system is not None: scp_args["file_system"] = file_system - TransferClass = InLineTransfer if inline_transfer else FileTransfer + TransferClass: Callable[..., BaseFileTransfer] + if inline_transfer: + TransferClass = InLineTransfer + else: + TransferClass = FileTransfer with TransferClass(**scp_args) as scp_transfer: if scp_transfer.check_file_exists(): @@ -190,19 +205,19 @@

            Functions

            Source code
            def file_transfer(
            -    ssh_conn,
            -    source_file,
            -    dest_file,
            -    file_system=None,
            -    direction="put",
            -    disable_md5=False,
            -    inline_transfer=False,
            -    overwrite_file=False,
            -    socket_timeout=10.0,
            -    progress=None,
            -    progress4=None,
            -    verify_file=None,
            -):
            +    ssh_conn: "BaseConnection",
            +    source_file: str,
            +    dest_file: str,
            +    file_system: Optional[str] = None,
            +    direction: str = "put",
            +    disable_md5: bool = False,
            +    inline_transfer: bool = False,
            +    overwrite_file: bool = False,
            +    socket_timeout: float = 10.0,
            +    progress: Optional[Callable[..., Any]] = None,
            +    progress4: Optional[Callable[..., Any]] = None,
            +    verify_file: Optional[bool] = None,
            +) -> Dict[str, bool]:
                 """Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices.
             
                 inline_transfer ONLY SUPPORTS TEXT FILES and will not support binary file transfers.
            @@ -252,7 +267,11 @@ 

            Functions

            if file_system is not None: scp_args["file_system"] = file_system - TransferClass = InLineTransfer if inline_transfer else FileTransfer + TransferClass: Callable[..., BaseFileTransfer] + if inline_transfer: + TransferClass = InLineTransfer + else: + TransferClass = FileTransfer with TransferClass(**scp_args) as scp_transfer: if scp_transfer.check_file_exists(): @@ -299,10 +318,14 @@

            Functions

            Source code -
            def progress_bar(filename, size, sent, peername=None):
            +
            def progress_bar(
            +    filename: AnyStr, size: int, sent: int, peername: Optional[str] = None
            +) -> None:
                 max_width = 50
                 if isinstance(filename, bytes):
            -        filename = filename.decode()
            +        filename_str = filename.decode()
            +    else:
            +        filename_str = filename
                 clear_screen = chr(27) + "[2J"
                 terminating_char = "|"
             
            @@ -313,9 +336,9 @@ 

            Functions

            progress = hash_count * ">" if peername is None: - header_msg = f"Transferring file: {filename}\n" + header_msg = f"Transferring file: {filename_str}\n" else: - header_msg = f"Transferring file to {peername}: {filename}\n" + header_msg = f"Transferring file to {peername}: {filename_str}\n" msg = f"{progress:<50}{terminating_char:1} ({percent_str})" print(clear_screen) @@ -330,7 +353,7 @@

            Functions

            Verify space and transfer file.

            Source code -
            def verifyspace_and_transferfile(scp_transfer):
            +
            def verifyspace_and_transferfile(scp_transfer: BaseFileTransfer) -> None:
                 """Verify space and transfer file."""
                 if not scp_transfer.verify_space_available():
                     raise ValueError("Insufficient space available on remote device")
            diff --git a/docs/netmiko/scp_handler.html b/docs/netmiko/scp_handler.html
            index 4a49cc433..83dd64efd 100644
            --- a/docs/netmiko/scp_handler.html
            +++ b/docs/netmiko/scp_handler.html
            @@ -23,7 +23,6 @@ 

            Module netmiko.scp_handler

            Netmiko SCP operations.

            Supports file get and file put operations.

            SCP requires a separate SSH connection for a control channel.

            -

            Currently only supports Cisco IOS and Cisco ASA.

            Source code
            """
            @@ -32,15 +31,19 @@ 

            Module netmiko.scp_handler

            Supports file get and file put operations. SCP requires a separate SSH connection for a control channel. - -Currently only supports Cisco IOS and Cisco ASA. """ +from typing import Callable, Optional, Any, Type +from typing import TYPE_CHECKING +from types import TracebackType import re import os import hashlib import scp -import platform +import sys + +if TYPE_CHECKING: + from netmiko.base_connection import BaseConnection class SCPConn(object): @@ -50,14 +53,20 @@

            Module netmiko.scp_handler

            Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn, socket_timeout=10.0, progress=None, progress4=None): + def __init__( + self, + ssh_conn: "BaseConnection", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + ) -> None: self.ssh_ctl_chan = ssh_conn self.socket_timeout = socket_timeout self.progress = progress self.progress4 = progress4 self.establish_scp_conn() - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: """Establish the secure copy connection.""" ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() @@ -69,26 +78,19 @@

            Module netmiko.scp_handler

            progress4=self.progress4, ) - def scp_transfer_file(self, source_file, dest_file): + def scp_transfer_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP (for backwards compatibility).""" self.scp_client.put(source_file, dest_file) - def scp_get_file(self, source_file, dest_file): + def scp_get_file(self, source_file: str, dest_file: str) -> None: """Get file using SCP.""" - platform = self.ssh_ctl_chan.device_type - if "cisco_ios" in platform or "cisco_xe" in platform: - try: - self.scp_client.get(source_file, dest_file) - except EOFError: - pass - else: - self.scp_client.get(source_file, dest_file) + self.scp_client.get(source_file, dest_file) - def scp_put_file(self, source_file, dest_file): + def scp_put_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP.""" self.scp_client.put(source_file, dest_file) - def close(self): + def close(self) -> None: """Close the SCP connection.""" self.scp_conn.close() @@ -98,16 +100,16 @@

            Module netmiko.scp_handler

            def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system=None, - direction="put", - socket_timeout=10.0, - progress=None, - progress4=None, - hash_supported=True, - ): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file @@ -140,16 +142,21 @@

            Module netmiko.scp_handler

            else: raise ValueError("Invalid direction specified") - def __enter__(self): + def __enter__(self) -> "BaseFileTransfer": """Context manager setup""" self.establish_scp_conn() return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """Context manager cleanup.""" self.close_scp_chan() - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: """Establish SCP connection.""" self.scp_conn = SCPConn( self.ssh_ctl_chan, @@ -158,25 +165,31 @@

            Module netmiko.scp_handler

            progress4=self.progress4, ) - def close_scp_chan(self): + def close_scp_chan(self) -> None: """Close the SCP connection to the remote network device.""" self.scp_conn.close() - self.scp_conn = None + del self.scp_conn - def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): + def remote_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> int: """Return space available on remote device.""" remote_cmd = f"dir {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) match = re.search(search_pattern, remote_output) - if "kbytes" in match.group(0) or "Kbytes" in match.group(0): - return int(match.group(1)) * 1000 - return int(match.group(1)) + if match: + if "kbytes" in match.group(0) or "Kbytes" in match.group(0): + return int(match.group(1)) * 1000 + return int(match.group(1)) + else: + msg = ( + f"pattern: {search_pattern} not detected in output:\n\n{remote_output}" + ) + raise ValueError(msg) - def _remote_space_available_unix(self, search_pattern=""): + def _remote_space_available_unix(self, search_pattern: str = "") -> int: """Return space available on *nix system (BSD/Linux).""" self.ssh_ctl_chan._enter_shell() remote_cmd = f"/bin/df -k {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command( + remote_output = self.ssh_ctl_chan._send_command_str( remote_cmd, expect_string=r"[\$#]" ) @@ -207,9 +220,9 @@

            Module netmiko.scp_handler

            self.ssh_ctl_chan._return_cli() return int(space_available) * 1024 - def local_space_available(self): + def local_space_available(self) -> int: """Return space available on local filesystem.""" - if platform.system() == "Windows": + if sys.platform == "win32": import ctypes free_bytes = ctypes.c_ulonglong(0) @@ -221,7 +234,7 @@

            Module netmiko.scp_handler

            destination_stats = os.statvfs(".") return destination_stats.f_bsize * destination_stats.f_bavail - def verify_space_available(self, search_pattern=r"(\d+) \w+ free"): + def verify_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> bool: """Verify sufficient space is available on destination file system (return boolean).""" if self.direction == "put": space_avail = self.remote_space_available(search_pattern=search_pattern) @@ -231,12 +244,12 @@

            Module netmiko.scp_handler

            return True return False - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"dir {self.file_system}/{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( "Error opening" in remote_out @@ -250,21 +263,27 @@

            Module netmiko.scp_handler

            raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def _check_file_exists_unix(self, remote_cmd=""): + def _check_file_exists_unix(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": self.ssh_ctl_chan._enter_shell() - remote_cmd = f"ls {self.file_system}" - remote_out = self.ssh_ctl_chan.send_command( + remote_cmd = f"/bin/ls {self.file_system}" + remote_out = self.ssh_ctl_chan._send_command_str( remote_cmd, expect_string=r"[\$#]" ) self.ssh_ctl_chan._return_cli() return self.dest_file in remote_out elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -273,11 +292,12 @@

            Module netmiko.scp_handler

            remote_file = self.source_file if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) # Strip out "Directory of flash:/filename line - remote_out = re.split(r"Directory of .*", remote_out) - remote_out = "".join(remote_out) + remote_out_lines = re.split(r"Directory of .*", remote_out) + remote_out = "".join(remote_out_lines) # Match line containing file name + assert isinstance(remote_file, str) escape_file_name = re.escape(remote_file) pattern = r".*({}).*".format(escape_file_name) match = re.search(pattern, remote_out) @@ -293,7 +313,9 @@

            Module netmiko.scp_handler

            else: return int(file_size) - def _remote_file_size_unix(self, remote_cmd="", remote_file=None): + def _remote_file_size_unix( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -302,10 +324,12 @@

            Module netmiko.scp_handler

            remote_file = self.source_file remote_file = f"{self.file_system}/{remote_file}" if not remote_cmd: - remote_cmd = f"ls -l {remote_file}" + remote_cmd = f"/bin/ls -l {remote_file}" self.ssh_ctl_chan._enter_shell() - remote_out = self.ssh_ctl_chan.send_command(remote_cmd, expect_string=r"[\$#]") + remote_out = self.ssh_ctl_chan._send_command_str( + remote_cmd, expect_string=r"[\$#]" + ) self.ssh_ctl_chan._return_cli() if "No such file or directory" in remote_out: @@ -324,7 +348,7 @@

            Module netmiko.scp_handler

            "Search pattern not found for remote file size during SCP transfer." ) - def file_md5(self, file_name, add_newline=False): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file. add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in @@ -347,7 +371,7 @@

            Module netmiko.scp_handler

            return file_hash.hexdigest() @staticmethod - def process_md5(md5_output, pattern=r"=\s+(\S+)"): + def process_md5(md5_output: str, pattern: str = r"=\s+(\S+)") -> str: """ Process the string to retrieve the MD5 hash @@ -361,7 +385,7 @@

            Module netmiko.scp_handler

            else: raise ValueError(f"Invalid output from MD5 command: {md5_output}") - def compare_md5(self): + def compare_md5(self) -> bool: """Compare md5 of file on network device to md5 of local file.""" if self.direction == "put": remote_md5 = self.remote_md5() @@ -369,8 +393,12 @@

            Module netmiko.scp_handler

            elif self.direction == "get": local_md5 = self.file_md5(self.dest_file) return self.source_md5 == local_md5 + else: + raise ValueError("Unexpected value for self.direction") - def remote_md5(self, base_cmd="verify /md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: """Calculate remote MD5 and returns the hash. This command can be CPU intensive on the remote device. @@ -381,56 +409,50 @@

            Module netmiko.scp_handler

            elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def transfer_file(self): + def transfer_file(self) -> None: """SCP transfer file.""" if self.direction == "put": self.put_file() elif self.direction == "get": self.get_file() + else: + raise ValueError("Unexpected value for self.direction in transfer_file") - def get_file(self): + def get_file(self) -> None: """SCP copy the file from the remote device to local system.""" source_file = f"{self.file_system}/{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close() - def put_file(self): + def put_file(self) -> None: """SCP copy the file from the local system to the remote device.""" destination = f"{self.file_system}/{self.dest_file}" self.scp_conn.scp_transfer_file(self.source_file, destination) # Must close the SCP connection to get the file written (flush) self.scp_conn.close() - def verify_file(self): + def verify_file(self) -> bool: """Verify the file has been transferred correctly.""" return self.compare_md5() - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "ip scp server enable") -> None: """ Enable SCP on remote device. Defaults to Cisco IOS command """ - if cmd is None: - cmd = ["ip scp server enable"] - elif not hasattr(cmd, "__iter__"): - cmd = [cmd] self.ssh_ctl_chan.send_config_set(cmd) - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "no ip scp server enable") -> None: """ Disable SCP on remote device. Defaults to Cisco IOS command """ - if cmd is None: - cmd = ["no ip scp server enable"] - elif not hasattr(cmd, "__iter__"): - cmd = [cmd] self.ssh_ctl_chan.send_config_set(cmd)
            @@ -456,16 +478,16 @@

            Classes

            def __init__( self, - ssh_conn, - source_file, - dest_file, - file_system=None, - direction="put", - socket_timeout=10.0, - progress=None, - progress4=None, - hash_supported=True, - ): + ssh_conn: "BaseConnection", + source_file: str, + dest_file: str, + file_system: Optional[str] = None, + direction: str = "put", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + hash_supported: bool = True, + ) -> None: self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file @@ -498,16 +520,21 @@

            Classes

            else: raise ValueError("Invalid direction specified") - def __enter__(self): + def __enter__(self) -> "BaseFileTransfer": """Context manager setup""" self.establish_scp_conn() return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """Context manager cleanup.""" self.close_scp_chan() - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: """Establish SCP connection.""" self.scp_conn = SCPConn( self.ssh_ctl_chan, @@ -516,25 +543,31 @@

            Classes

            progress4=self.progress4, ) - def close_scp_chan(self): + def close_scp_chan(self) -> None: """Close the SCP connection to the remote network device.""" self.scp_conn.close() - self.scp_conn = None + del self.scp_conn - def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): + def remote_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> int: """Return space available on remote device.""" remote_cmd = f"dir {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd) match = re.search(search_pattern, remote_output) - if "kbytes" in match.group(0) or "Kbytes" in match.group(0): - return int(match.group(1)) * 1000 - return int(match.group(1)) + if match: + if "kbytes" in match.group(0) or "Kbytes" in match.group(0): + return int(match.group(1)) * 1000 + return int(match.group(1)) + else: + msg = ( + f"pattern: {search_pattern} not detected in output:\n\n{remote_output}" + ) + raise ValueError(msg) - def _remote_space_available_unix(self, search_pattern=""): + def _remote_space_available_unix(self, search_pattern: str = "") -> int: """Return space available on *nix system (BSD/Linux).""" self.ssh_ctl_chan._enter_shell() remote_cmd = f"/bin/df -k {self.file_system}" - remote_output = self.ssh_ctl_chan.send_command( + remote_output = self.ssh_ctl_chan._send_command_str( remote_cmd, expect_string=r"[\$#]" ) @@ -565,9 +598,9 @@

            Classes

            self.ssh_ctl_chan._return_cli() return int(space_available) * 1024 - def local_space_available(self): + def local_space_available(self) -> int: """Return space available on local filesystem.""" - if platform.system() == "Windows": + if sys.platform == "win32": import ctypes free_bytes = ctypes.c_ulonglong(0) @@ -579,7 +612,7 @@

            Classes

            destination_stats = os.statvfs(".") return destination_stats.f_bsize * destination_stats.f_bavail - def verify_space_available(self, search_pattern=r"(\d+) \w+ free"): + def verify_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> bool: """Verify sufficient space is available on destination file system (return boolean).""" if self.direction == "put": space_avail = self.remote_space_available(search_pattern=search_pattern) @@ -589,12 +622,12 @@

            Classes

            return True return False - def check_file_exists(self, remote_cmd=""): + def check_file_exists(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: remote_cmd = f"dir {self.file_system}/{self.dest_file}" - remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( "Error opening" in remote_out @@ -608,21 +641,27 @@

            Classes

            raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def _check_file_exists_unix(self, remote_cmd=""): + def _check_file_exists_unix(self, remote_cmd: str = "") -> bool: """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": self.ssh_ctl_chan._enter_shell() - remote_cmd = f"ls {self.file_system}" - remote_out = self.ssh_ctl_chan.send_command( + remote_cmd = f"/bin/ls {self.file_system}" + remote_out = self.ssh_ctl_chan._send_command_str( remote_cmd, expect_string=r"[\$#]" ) self.ssh_ctl_chan._return_cli() return self.dest_file in remote_out elif self.direction == "get": return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction") - def remote_file_size(self, remote_cmd="", remote_file=None): + def remote_file_size( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -631,11 +670,12 @@

            Classes

            remote_file = self.source_file if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) # Strip out "Directory of flash:/filename line - remote_out = re.split(r"Directory of .*", remote_out) - remote_out = "".join(remote_out) + remote_out_lines = re.split(r"Directory of .*", remote_out) + remote_out = "".join(remote_out_lines) # Match line containing file name + assert isinstance(remote_file, str) escape_file_name = re.escape(remote_file) pattern = r".*({}).*".format(escape_file_name) match = re.search(pattern, remote_out) @@ -651,7 +691,9 @@

            Classes

            else: return int(file_size) - def _remote_file_size_unix(self, remote_cmd="", remote_file=None): + def _remote_file_size_unix( + self, remote_cmd: str = "", remote_file: Optional[str] = None + ) -> int: """Get the file size of the remote file.""" if remote_file is None: if self.direction == "put": @@ -660,10 +702,12 @@

            Classes

            remote_file = self.source_file remote_file = f"{self.file_system}/{remote_file}" if not remote_cmd: - remote_cmd = f"ls -l {remote_file}" + remote_cmd = f"/bin/ls -l {remote_file}" self.ssh_ctl_chan._enter_shell() - remote_out = self.ssh_ctl_chan.send_command(remote_cmd, expect_string=r"[\$#]") + remote_out = self.ssh_ctl_chan._send_command_str( + remote_cmd, expect_string=r"[\$#]" + ) self.ssh_ctl_chan._return_cli() if "No such file or directory" in remote_out: @@ -682,7 +726,7 @@

            Classes

            "Search pattern not found for remote file size during SCP transfer." ) - def file_md5(self, file_name, add_newline=False): + def file_md5(self, file_name: str, add_newline: bool = False) -> str: """Compute MD5 hash of file. add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in @@ -705,7 +749,7 @@

            Classes

            return file_hash.hexdigest() @staticmethod - def process_md5(md5_output, pattern=r"=\s+(\S+)"): + def process_md5(md5_output: str, pattern: str = r"=\s+(\S+)") -> str: """ Process the string to retrieve the MD5 hash @@ -719,7 +763,7 @@

            Classes

            else: raise ValueError(f"Invalid output from MD5 command: {md5_output}") - def compare_md5(self): + def compare_md5(self) -> bool: """Compare md5 of file on network device to md5 of local file.""" if self.direction == "put": remote_md5 = self.remote_md5() @@ -727,8 +771,12 @@

            Classes

            elif self.direction == "get": local_md5 = self.file_md5(self.dest_file) return self.source_md5 == local_md5 + else: + raise ValueError("Unexpected value for self.direction") - def remote_md5(self, base_cmd="verify /md5", remote_file=None): + def remote_md5( + self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None + ) -> str: """Calculate remote MD5 and returns the hash. This command can be CPU intensive on the remote device. @@ -739,56 +787,50 @@

            Classes

            elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5 - def transfer_file(self): + def transfer_file(self) -> None: """SCP transfer file.""" if self.direction == "put": self.put_file() elif self.direction == "get": self.get_file() + else: + raise ValueError("Unexpected value for self.direction in transfer_file") - def get_file(self): + def get_file(self) -> None: """SCP copy the file from the remote device to local system.""" source_file = f"{self.file_system}/{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close() - def put_file(self): + def put_file(self) -> None: """SCP copy the file from the local system to the remote device.""" destination = f"{self.file_system}/{self.dest_file}" self.scp_conn.scp_transfer_file(self.source_file, destination) # Must close the SCP connection to get the file written (flush) self.scp_conn.close() - def verify_file(self): + def verify_file(self) -> bool: """Verify the file has been transferred correctly.""" return self.compare_md5() - def enable_scp(self, cmd=None): + def enable_scp(self, cmd: str = "ip scp server enable") -> None: """ Enable SCP on remote device. Defaults to Cisco IOS command """ - if cmd is None: - cmd = ["ip scp server enable"] - elif not hasattr(cmd, "__iter__"): - cmd = [cmd] self.ssh_ctl_chan.send_config_set(cmd) - def disable_scp(self, cmd=None): + def disable_scp(self, cmd: str = "no ip scp server enable") -> None: """ Disable SCP on remote device. Defaults to Cisco IOS command """ - if cmd is None: - cmd = ["no ip scp server enable"] - elif not hasattr(cmd, "__iter__"): - cmd = [cmd] self.ssh_ctl_chan.send_config_set(cmd)

            Subclasses

            @@ -796,6 +838,7 @@

            Subclasses

          • CiscoFileTransfer
          • CienaSaosFileTransfer
          • DellOS10FileTransfer
          • +
          • ExtremeExosFileTransfer
          • JuniperFileTransfer
          • NokiaSrosFileTransfer
          @@ -812,7 +855,7 @@

          Static methods

          Source code
          @staticmethod
          -def process_md5(md5_output, pattern=r"=\s+(\S+)"):
          +def process_md5(md5_output: str, pattern: str = r"=\s+(\S+)") -> str:
               """
               Process the string to retrieve the MD5 hash
           
          @@ -837,12 +880,12 @@ 

          Methods

          Check if the dest_file already exists on the file system (return boolean).

          Source code -
          def check_file_exists(self, remote_cmd=""):
          +
          def check_file_exists(self, remote_cmd: str = "") -> bool:
               """Check if the dest_file already exists on the file system (return boolean)."""
               if self.direction == "put":
                   if not remote_cmd:
                       remote_cmd = f"dir {self.file_system}/{self.dest_file}"
          -        remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd)
          +        remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd)
                   search_string = r"Directory of .*{0}".format(self.dest_file)
                   if (
                       "Error opening" in remote_out
          @@ -855,7 +898,9 @@ 

          Methods

          else: raise ValueError("Unexpected output from check_file_exists") elif self.direction == "get": - return os.path.exists(self.dest_file)
          + return os.path.exists(self.dest_file) + else: + raise ValueError("Unexpected value for self.direction")
          @@ -865,10 +910,10 @@

          Methods

          Close the SCP connection to the remote network device.

          Source code -
          def close_scp_chan(self):
          +
          def close_scp_chan(self) -> None:
               """Close the SCP connection to the remote network device."""
               self.scp_conn.close()
          -    self.scp_conn = None
          + del self.scp_conn
          @@ -878,55 +923,49 @@

          Methods

          Compare md5 of file on network device to md5 of local file.

          Source code -
          def compare_md5(self):
          +
          def compare_md5(self) -> bool:
               """Compare md5 of file on network device to md5 of local file."""
               if self.direction == "put":
                   remote_md5 = self.remote_md5()
                   return self.source_md5 == remote_md5
               elif self.direction == "get":
                   local_md5 = self.file_md5(self.dest_file)
          -        return self.source_md5 == local_md5
          + return self.source_md5 == local_md5 + else: + raise ValueError("Unexpected value for self.direction")
          -def disable_scp(self, cmd=None) +def disable_scp(self, cmd='no ip scp server enable')

          Disable SCP on remote device.

          Defaults to Cisco IOS command

          Source code -
          def disable_scp(self, cmd=None):
          +
          def disable_scp(self, cmd: str = "no ip scp server enable") -> None:
               """
               Disable SCP on remote device.
           
               Defaults to Cisco IOS command
               """
          -    if cmd is None:
          -        cmd = ["no ip scp server enable"]
          -    elif not hasattr(cmd, "__iter__"):
          -        cmd = [cmd]
               self.ssh_ctl_chan.send_config_set(cmd)
          -def enable_scp(self, cmd=None) +def enable_scp(self, cmd='ip scp server enable')

          Enable SCP on remote device.

          Defaults to Cisco IOS command

          Source code -
          def enable_scp(self, cmd=None):
          +
          def enable_scp(self, cmd: str = "ip scp server enable") -> None:
               """
               Enable SCP on remote device.
           
               Defaults to Cisco IOS command
               """
          -    if cmd is None:
          -        cmd = ["ip scp server enable"]
          -    elif not hasattr(cmd, "__iter__"):
          -        cmd = [cmd]
               self.ssh_ctl_chan.send_config_set(cmd)
          @@ -937,7 +976,7 @@

          Methods

          Establish SCP connection.

          Source code -
          def establish_scp_conn(self):
          +
          def establish_scp_conn(self) -> None:
               """Establish SCP connection."""
               self.scp_conn = SCPConn(
                   self.ssh_ctl_chan,
          @@ -963,7 +1002,7 @@ 

          Args

      Source code -
      def file_md5(self, file_name, add_newline=False):
      +
      def file_md5(self, file_name: str, add_newline: bool = False) -> str:
           """Compute MD5 hash of file.
       
           add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in
      @@ -993,7 +1032,7 @@ 

      Args

      SCP copy the file from the remote device to local system.

      Source code -
      def get_file(self):
      +
      def get_file(self) -> None:
           """SCP copy the file from the remote device to local system."""
           source_file = f"{self.file_system}/{self.source_file}"
           self.scp_conn.scp_get_file(source_file, self.dest_file)
      @@ -1007,9 +1046,9 @@ 

      Args

      Return space available on local filesystem.

      Source code -
      def local_space_available(self):
      +
      def local_space_available(self) -> int:
           """Return space available on local filesystem."""
      -    if platform.system() == "Windows":
      +    if sys.platform == "win32":
               import ctypes
       
               free_bytes = ctypes.c_ulonglong(0)
      @@ -1029,7 +1068,7 @@ 

      Args

      SCP copy the file from the local system to the remote device.

      Source code -
      def put_file(self):
      +
      def put_file(self) -> None:
           """SCP copy the file from the local system to the remote device."""
           destination = f"{self.file_system}/{self.dest_file}"
           self.scp_conn.scp_transfer_file(self.source_file, destination)
      @@ -1044,7 +1083,9 @@ 

      Args

      Get the file size of the remote file.

      Source code -
      def remote_file_size(self, remote_cmd="", remote_file=None):
      +
      def remote_file_size(
      +    self, remote_cmd: str = "", remote_file: Optional[str] = None
      +) -> int:
           """Get the file size of the remote file."""
           if remote_file is None:
               if self.direction == "put":
      @@ -1053,11 +1094,12 @@ 

      Args

      remote_file = self.source_file if not remote_cmd: remote_cmd = f"dir {self.file_system}/{remote_file}" - remote_out = self.ssh_ctl_chan.send_command(remote_cmd) + remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd) # Strip out "Directory of flash:/filename line - remote_out = re.split(r"Directory of .*", remote_out) - remote_out = "".join(remote_out) + remote_out_lines = re.split(r"Directory of .*", remote_out) + remote_out = "".join(remote_out_lines) # Match line containing file name + assert isinstance(remote_file, str) escape_file_name = re.escape(remote_file) pattern = r".*({}).*".format(escape_file_name) match = re.search(pattern, remote_out) @@ -1082,7 +1124,9 @@

      Args

      This command can be CPU intensive on the remote device.

      Source code -
      def remote_md5(self, base_cmd="verify /md5", remote_file=None):
      +
      def remote_md5(
      +    self, base_cmd: str = "verify /md5", remote_file: Optional[str] = None
      +) -> str:
           """Calculate remote MD5 and returns the hash.
       
           This command can be CPU intensive on the remote device.
      @@ -1093,7 +1137,7 @@ 

      Args

      elif self.direction == "get": remote_file = self.source_file remote_md5_cmd = f"{base_cmd} {self.file_system}/{remote_file}" - dest_md5 = self.ssh_ctl_chan.send_command(remote_md5_cmd, max_loops=1500) + dest_md5 = self.ssh_ctl_chan._send_command_str(remote_md5_cmd, read_timeout=300) dest_md5 = self.process_md5(dest_md5) return dest_md5
      @@ -1105,14 +1149,20 @@

      Args

      Return space available on remote device.

      Source code -
      def remote_space_available(self, search_pattern=r"(\d+) \w+ free"):
      +
      def remote_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> int:
           """Return space available on remote device."""
           remote_cmd = f"dir {self.file_system}"
      -    remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd)
      +    remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd)
           match = re.search(search_pattern, remote_output)
      -    if "kbytes" in match.group(0) or "Kbytes" in match.group(0):
      -        return int(match.group(1)) * 1000
      -    return int(match.group(1))
      + if match: + if "kbytes" in match.group(0) or "Kbytes" in match.group(0): + return int(match.group(1)) * 1000 + return int(match.group(1)) + else: + msg = ( + f"pattern: {search_pattern} not detected in output:\n\n{remote_output}" + ) + raise ValueError(msg)
      @@ -1122,12 +1172,14 @@

      Args

      SCP transfer file.

      Source code -
      def transfer_file(self):
      +
      def transfer_file(self) -> None:
           """SCP transfer file."""
           if self.direction == "put":
               self.put_file()
           elif self.direction == "get":
      -        self.get_file()
      + self.get_file() + else: + raise ValueError("Unexpected value for self.direction in transfer_file")
      @@ -1137,7 +1189,7 @@

      Args

      Verify the file has been transferred correctly.

      Source code -
      def verify_file(self):
      +
      def verify_file(self) -> bool:
           """Verify the file has been transferred correctly."""
           return self.compare_md5()
      @@ -1149,7 +1201,7 @@

      Args

      Verify sufficient space is available on destination file system (return boolean).

      Source code -
      def verify_space_available(self, search_pattern=r"(\d+) \w+ free"):
      +
      def verify_space_available(self, search_pattern: str = r"(\d+) \w+ free") -> bool:
           """Verify sufficient space is available on destination file system (return boolean)."""
           if self.direction == "put":
               space_avail = self.remote_space_available(search_pattern=search_pattern)
      @@ -1178,14 +1230,20 @@ 

      Args

      Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn, socket_timeout=10.0, progress=None, progress4=None): + def __init__( + self, + ssh_conn: "BaseConnection", + socket_timeout: float = 10.0, + progress: Optional[Callable[..., Any]] = None, + progress4: Optional[Callable[..., Any]] = None, + ) -> None: self.ssh_ctl_chan = ssh_conn self.socket_timeout = socket_timeout self.progress = progress self.progress4 = progress4 self.establish_scp_conn() - def establish_scp_conn(self): + def establish_scp_conn(self) -> None: """Establish the secure copy connection.""" ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() @@ -1197,26 +1255,19 @@

      Args

      progress4=self.progress4, ) - def scp_transfer_file(self, source_file, dest_file): + def scp_transfer_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP (for backwards compatibility).""" self.scp_client.put(source_file, dest_file) - def scp_get_file(self, source_file, dest_file): + def scp_get_file(self, source_file: str, dest_file: str) -> None: """Get file using SCP.""" - platform = self.ssh_ctl_chan.device_type - if "cisco_ios" in platform or "cisco_xe" in platform: - try: - self.scp_client.get(source_file, dest_file) - except EOFError: - pass - else: - self.scp_client.get(source_file, dest_file) + self.scp_client.get(source_file, dest_file) - def scp_put_file(self, source_file, dest_file): + def scp_put_file(self, source_file: str, dest_file: str) -> None: """Put file using SCP.""" self.scp_client.put(source_file, dest_file) - def close(self): + def close(self) -> None: """Close the SCP connection.""" self.scp_conn.close()
      @@ -1229,7 +1280,7 @@

      Methods

      Close the SCP connection.

      Source code -
      def close(self):
      +
      def close(self) -> None:
           """Close the SCP connection."""
           self.scp_conn.close()
      @@ -1241,7 +1292,7 @@

      Methods

      Establish the secure copy connection.

      Source code -
      def establish_scp_conn(self):
      +
      def establish_scp_conn(self) -> None:
           """Establish the secure copy connection."""
           ssh_connect_params = self.ssh_ctl_chan._connect_params_dict()
           self.scp_conn = self.ssh_ctl_chan._build_ssh_client()
      @@ -1261,16 +1312,9 @@ 

      Methods

      Get file using SCP.

      Source code -
      def scp_get_file(self, source_file, dest_file):
      +
      def scp_get_file(self, source_file: str, dest_file: str) -> None:
           """Get file using SCP."""
      -    platform = self.ssh_ctl_chan.device_type
      -    if "cisco_ios" in platform or "cisco_xe" in platform:
      -        try:
      -            self.scp_client.get(source_file, dest_file)
      -        except EOFError:
      -            pass
      -    else:
      -        self.scp_client.get(source_file, dest_file)
      + self.scp_client.get(source_file, dest_file)
      @@ -1280,7 +1324,7 @@

      Methods

      Put file using SCP.

      Source code -
      def scp_put_file(self, source_file, dest_file):
      +
      def scp_put_file(self, source_file: str, dest_file: str) -> None:
           """Put file using SCP."""
           self.scp_client.put(source_file, dest_file)
      @@ -1292,7 +1336,7 @@

      Methods

      Put file using SCP (for backwards compatibility).

      Source code -
      def scp_transfer_file(self, source_file, dest_file):
      +
      def scp_transfer_file(self, source_file: str, dest_file: str) -> None:
           """Put file using SCP (for backwards compatibility)."""
           self.scp_client.put(source_file, dest_file)
      diff --git a/docs/netmiko/session_log.html b/docs/netmiko/session_log.html new file mode 100644 index 000000000..419f0ca7f --- /dev/null +++ b/docs/netmiko/session_log.html @@ -0,0 +1,279 @@ + + + + + + +netmiko.session_log API documentation + + + + + + + + + +
      +
      +
      +

      Module netmiko.session_log

      +
      +
      +
      +Source code +
      import io
      +from netmiko.utilities import write_bytes
      +from typing import Dict, Any, Union, Optional, TextIO
      +
      +
      +class SessionLog:
      +    def __init__(
      +        self,
      +        file_name: Optional[str] = None,
      +        buffered_io: Optional[io.BufferedIOBase] = None,
      +        file_mode: str = "write",
      +        file_encoding: str = "utf-8",
      +        no_log: Dict[str, Any] = None,
      +        record_writes: bool = False,
      +    ) -> None:
      +        if no_log is None:
      +            self.no_log = {}
      +        else:
      +            self.no_log = no_log
      +        self.file_name = file_name
      +        self.file_mode = file_mode
      +        self.file_encoding = file_encoding
      +        self.record_writes = record_writes
      +        self._session_log_close = False
      +
      +        # Actual file/file-handle/buffered-IO that will be written to.
      +        self.session_log: Union[io.BufferedIOBase, TextIO, None]
      +        if file_name is None and buffered_io:
      +            self.session_log = buffered_io
      +        else:
      +            self.session_log = None
      +
      +        # Ensures last write operations prior to disconnect are recorded.
      +        self.fin = False
      +
      +    def open(self) -> None:
      +        """Open the session_log file."""
      +        if self.file_name is None:
      +            return None
      +        if self.file_mode == "append":
      +            self.session_log = open(
      +                self.file_name, mode="a", encoding=self.file_encoding
      +            )
      +        else:
      +            self.session_log = open(
      +                self.file_name, mode="w", encoding=self.file_encoding
      +            )
      +        self._session_log_close = True
      +
      +    def close(self) -> None:
      +        """Close the session_log file (if it is a file that we opened)."""
      +        if self.session_log and self._session_log_close:
      +            self.session_log.close()
      +            self.session_log = None
      +
      +    def write(self, data: str) -> None:
      +        if self.session_log is not None and len(data) > 0:
      +            # Hide the password and secret in the session_log
      +            for hidden_data in self.no_log.values():
      +                data = data.replace(hidden_data, "********")
      +
      +            if isinstance(self.session_log, io.BufferedIOBase):
      +                self.session_log.write(write_bytes(data, encoding=self.file_encoding))
      +            else:
      +                self.session_log.write(data)
      +
      +            assert isinstance(self.session_log, io.BufferedIOBase) or isinstance(
      +                self.session_log, io.TextIOBase
      +            )
      +            self.session_log.flush()
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class SessionLog +(file_name=None, buffered_io=None, file_mode='write', file_encoding='utf-8', no_log=None, record_writes=False) +
      +
      +
      +
      +Source code +
      class SessionLog:
      +    def __init__(
      +        self,
      +        file_name: Optional[str] = None,
      +        buffered_io: Optional[io.BufferedIOBase] = None,
      +        file_mode: str = "write",
      +        file_encoding: str = "utf-8",
      +        no_log: Dict[str, Any] = None,
      +        record_writes: bool = False,
      +    ) -> None:
      +        if no_log is None:
      +            self.no_log = {}
      +        else:
      +            self.no_log = no_log
      +        self.file_name = file_name
      +        self.file_mode = file_mode
      +        self.file_encoding = file_encoding
      +        self.record_writes = record_writes
      +        self._session_log_close = False
      +
      +        # Actual file/file-handle/buffered-IO that will be written to.
      +        self.session_log: Union[io.BufferedIOBase, TextIO, None]
      +        if file_name is None and buffered_io:
      +            self.session_log = buffered_io
      +        else:
      +            self.session_log = None
      +
      +        # Ensures last write operations prior to disconnect are recorded.
      +        self.fin = False
      +
      +    def open(self) -> None:
      +        """Open the session_log file."""
      +        if self.file_name is None:
      +            return None
      +        if self.file_mode == "append":
      +            self.session_log = open(
      +                self.file_name, mode="a", encoding=self.file_encoding
      +            )
      +        else:
      +            self.session_log = open(
      +                self.file_name, mode="w", encoding=self.file_encoding
      +            )
      +        self._session_log_close = True
      +
      +    def close(self) -> None:
      +        """Close the session_log file (if it is a file that we opened)."""
      +        if self.session_log and self._session_log_close:
      +            self.session_log.close()
      +            self.session_log = None
      +
      +    def write(self, data: str) -> None:
      +        if self.session_log is not None and len(data) > 0:
      +            # Hide the password and secret in the session_log
      +            for hidden_data in self.no_log.values():
      +                data = data.replace(hidden_data, "********")
      +
      +            if isinstance(self.session_log, io.BufferedIOBase):
      +                self.session_log.write(write_bytes(data, encoding=self.file_encoding))
      +            else:
      +                self.session_log.write(data)
      +
      +            assert isinstance(self.session_log, io.BufferedIOBase) or isinstance(
      +                self.session_log, io.TextIOBase
      +            )
      +            self.session_log.flush()
      +
      +

      Methods

      +
      +
      +def close(self) +
      +
      +

      Close the session_log file (if it is a file that we opened).

      +
      +Source code +
      def close(self) -> None:
      +    """Close the session_log file (if it is a file that we opened)."""
      +    if self.session_log and self._session_log_close:
      +        self.session_log.close()
      +        self.session_log = None
      +
      +
      +
      +def open(self) +
      +
      +

      Open the session_log file.

      +
      +Source code +
      def open(self) -> None:
      +    """Open the session_log file."""
      +    if self.file_name is None:
      +        return None
      +    if self.file_mode == "append":
      +        self.session_log = open(
      +            self.file_name, mode="a", encoding=self.file_encoding
      +        )
      +    else:
      +        self.session_log = open(
      +            self.file_name, mode="w", encoding=self.file_encoding
      +        )
      +    self._session_log_close = True
      +
      +
      +
      +def write(self, data) +
      +
      +
      +
      +Source code +
      def write(self, data: str) -> None:
      +    if self.session_log is not None and len(data) > 0:
      +        # Hide the password and secret in the session_log
      +        for hidden_data in self.no_log.values():
      +            data = data.replace(hidden_data, "********")
      +
      +        if isinstance(self.session_log, io.BufferedIOBase):
      +            self.session_log.write(write_bytes(data, encoding=self.file_encoding))
      +        else:
      +            self.session_log.write(data)
      +
      +        assert isinstance(self.session_log, io.BufferedIOBase) or isinstance(
      +            self.session_log, io.TextIOBase
      +        )
      +        self.session_log.flush()
      +
      +
      +
      +
      +
      +
      +
      + +
      + + + + + \ No newline at end of file diff --git a/docs/netmiko/sixwind/index.html b/docs/netmiko/sixwind/index.html index e4fd355a5..68802591d 100644 --- a/docs/netmiko/sixwind/index.html +++ b/docs/netmiko/sixwind/index.html @@ -45,139 +45,119 @@

      Classes

      class SixwindOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
      -

      Base Class for cisco-like behavior.

      +

      Class for platforms that have no enable mode.

      +

      Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

      +

      The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

      +

      Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

          Initialize attributes for establishing connection to target device.
       
           :param ip: IP address of target device. Not required if `host` is
               provided.
      -    :type ip: str
       
           :param host: Hostname of target device. Not required if `ip` is
                   provided.
      -    :type host: str
       
           :param username: Username to authenticate against target device if
                   required.
      -    :type username: str
       
           :param password: Password to authenticate against target device if
                   required.
      -    :type password: str
       
           :param secret: The enable password if target device requires one.
      -    :type secret: str
       
           :param port: The destination port used to connect to the target
                   device.
      -    :type port: int or None
       
           :param device_type: Class selection based on device type.
      -    :type device_type: str
       
           :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
       
           :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
       
           :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
       
           :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
       
           :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
       
           :param passphrase: Passphrase to use for encrypted key; password will be used for key
                   decryption if not specified.
      -    :type passphrase: str
      +
      +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
      +            documentation for a description of the expected format.
       
           :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
       
           :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                   means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
       
           :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      +
           :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                   alt_key_file.
      -    :type alt_host_keys: bool
       
           :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
       
           :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
       
           :param timeout: Connection timeout.
      -    :type timeout: float
       
           :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
       
           :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
       
           :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
       
           :param 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).
      -    :type keepalive: int
       
           :param default_enter: Character(s) to send to correspond to enter key (default:
       
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -188,6 +168,7 @@

      Classes

      Ancestors

      @@ -196,25 +177,24 @@

      Inherited members

    • SixwindOSBase:
      • check_config_mode
      • -
      • check_enable_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • -
      • enable
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • -
      • exit_enable_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -226,6 +206,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/sixwind/sixwind_os.html b/docs/netmiko/sixwind/sixwind_os.html index 082d12150..71fbc3476 100644 --- a/docs/netmiko/sixwind/sixwind_os.html +++ b/docs/netmiko/sixwind/sixwind_os.html @@ -22,12 +22,16 @@

        Module netmiko.sixwind.sixwind_os

        Source code -
        import time
        +
        from typing import Optional, Any
        +import time
        +import warnings
        +from netmiko.no_enable import NoEnable
        +from netmiko.base_connection import DELAY_FACTOR_DEPR_SIMPLE_MSG
         from netmiko.cisco_base_connection import CiscoBaseConnection
         
         
        -class SixwindOSBase(CiscoBaseConnection):
        -    def session_preparation(self):
        +class SixwindOSBase(NoEnable, CiscoBaseConnection):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.ansi_escape_codes = True
                 self._test_channel_read()
        @@ -36,46 +40,63 @@ 

        Module netmiko.sixwind.sixwind_os

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def disable_paging(self, *args, **kwargs): + def disable_paging(self, *args: Any, **kwargs: Any) -> str: """6WIND requires no-pager at the end of command, not implemented at this time.""" pass def set_base_prompt( - self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) prompt = prompt.strip() self.base_prompt = prompt return self.base_prompt - def config_mode(self, config_command="edit running", pattern=""): - """Enter configuration mode.""" - - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, config_command: str = "edit running", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def commit(self, comment="", delay_factor=1): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. Raise an error and return the failure if the commit fails. + + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = "Failed to generate committed config" command_string = "commit" output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, expect_string=r"#", ) output += self.exit_config_mode() @@ -85,40 +106,28 @@

        Module netmiko.sixwind.sixwind_os

        return output - def exit_config_mode(self, exit_config="exit", pattern=r">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def check_config_mode(self, check_string="#", pattern=""): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks whether in configuration mode. Returns a boolean.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( - self, cmd="copy running startup", confirm=True, confirm_response="y" - ): + self, + cmd: str = "copy running startup", + confirm: bool = True, + confirm_response: str = "y", + ) -> str: """Save Config for 6WIND""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) - def check_enable_mode(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass - - def enable(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass - - def exit_enable_mode(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass - class SixwindOSSSH(SixwindOSBase): @@ -136,144 +145,124 @@

        Classes

        class SixwindOSBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
        -

        Base Class for cisco-like behavior.

        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

            Initialize attributes for establishing connection to target device.
         
             :param ip: IP address of target device. Not required if `host` is
                 provided.
        -    :type ip: str
         
             :param host: Hostname of target device. Not required if `ip` is
                     provided.
        -    :type host: str
         
             :param username: Username to authenticate against target device if
                     required.
        -    :type username: str
         
             :param password: Password to authenticate against target device if
                     required.
        -    :type password: str
         
             :param secret: The enable password if target device requires one.
        -    :type secret: str
         
             :param port: The destination port used to connect to the target
                     device.
        -    :type port: int or None
         
             :param device_type: Class selection based on device type.
        -    :type device_type: str
         
             :param verbose: Enable additional messages to standard output.
        -    :type verbose: bool
         
             :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        -    :type global_delay_factor: int
         
             :param use_keys: Connect to target device using SSH keys.
        -    :type use_keys: bool
         
             :param key_file: Filename path of the SSH key file to use.
        -    :type key_file: str
         
             :param pkey: SSH key object to use.
        -    :type pkey: paramiko.PKey
         
             :param passphrase: Passphrase to use for encrypted key; password will be used for key
                     decryption if not specified.
        -    :type passphrase: str
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
         
             :param allow_agent: Enable use of SSH key-agent.
        -    :type allow_agent: bool
         
             :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                     means unknown SSH host keys will be accepted).
        -    :type ssh_strict: bool
         
             :param system_host_keys: Load host keys from the users known_hosts file.
        -    :type system_host_keys: bool
        +
             :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                     alt_key_file.
        -    :type alt_host_keys: bool
         
             :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        -    :type alt_key_file: str
         
             :param ssh_config_file: File name of OpenSSH configuration file.
        -    :type ssh_config_file: str
         
             :param timeout: Connection timeout.
        -    :type timeout: float
         
             :param session_timeout: Set a timeout for parallel requests.
        -    :type session_timeout: float
         
             :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        -    :type auth_timeout: float
         
             :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        -    :type banner_timeout: float
         
             :param 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).
        -    :type keepalive: int
         
             :param default_enter: Character(s) to send to correspond to enter key (default:
         
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code -
        class SixwindOSBase(CiscoBaseConnection):
        -    def session_preparation(self):
        +
        class SixwindOSBase(NoEnable, CiscoBaseConnection):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self.ansi_escape_codes = True
                 self._test_channel_read()
        @@ -282,46 +271,63 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def disable_paging(self, *args, **kwargs): + def disable_paging(self, *args: Any, **kwargs: Any) -> str: """6WIND requires no-pager at the end of command, not implemented at this time.""" pass def set_base_prompt( - self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) prompt = prompt.strip() self.base_prompt = prompt return self.base_prompt - def config_mode(self, config_command="edit running", pattern=""): - """Enter configuration mode.""" - - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, config_command: str = "edit running", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def commit(self, comment="", delay_factor=1): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. Raise an error and return the failure if the commit fails. + + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = "Failed to generate committed config" command_string = "commit" output = self.config_mode() - output += self.send_command( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, expect_string=r"#", ) output += self.exit_config_mode() @@ -331,42 +337,31 @@

        Classes

        return output - def exit_config_mode(self, exit_config="exit", pattern=r">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str: """Exit configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def check_config_mode(self, check_string="#", pattern=""): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks whether in configuration mode. Returns a boolean.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config( - self, cmd="copy running startup", confirm=True, confirm_response="y" - ): + self, + cmd: str = "copy running startup", + confirm: bool = True, + confirm_response: str = "y", + ) -> str: """Save Config for 6WIND""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response - ) - - def check_enable_mode(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass - - def enable(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass - - def exit_enable_mode(self, *args, **kwargs): - """6WIND has no enable mode.""" - - pass
        + )

        Ancestors

        @@ -383,50 +378,48 @@

        Methods

        Checks whether in configuration mode. Returns a boolean.

        Source code -
        def check_config_mode(self, check_string="#", pattern=""):
        +
        def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
             """Checks whether in configuration mode. Returns a boolean."""
         
             return super().check_config_mode(check_string=check_string, pattern=pattern)
        -
        -def check_enable_mode(self, *args, **kwargs) -
        -
        -

        6WIND has no enable mode.

        -
        -Source code -
        def check_enable_mode(self, *args, **kwargs):
        -    """6WIND has no enable mode."""
        -
        -    pass
        -
        -
        -def commit(self, comment='', delay_factor=1) +def commit(self, comment='', read_timeout=120.0, delay_factor=None)

        Commit the candidate configuration.

        -

        Raise an error and return the failure if the commit fails.

        +

        Raise an error and return the failure if the commit fails.

        +

        delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

        Source code -
        def commit(self, comment="", delay_factor=1):
        +
        def commit(
        +    self,
        +    comment: str = "",
        +    read_timeout: float = 120.0,
        +    delay_factor: Optional[float] = None,
        +) -> str:
             """
             Commit the candidate configuration.
         
             Raise an error and return the failure if the commit fails.
        +
        +    delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.
        +
             """
         
        -    delay_factor = self.select_delay_factor(delay_factor)
        +    if delay_factor is not None:
        +        warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning)
        +
             error_marker = "Failed to generate committed config"
             command_string = "commit"
         
             output = self.config_mode()
        -    output += self.send_command(
        +    output += self._send_command_str(
                 command_string,
                 strip_prompt=False,
                 strip_command=False,
        -        delay_factor=delay_factor,
        +        read_timeout=read_timeout,
                 expect_string=r"#",
             )
             output += self.exit_config_mode()
        @@ -437,19 +430,6 @@ 

        Methods

        return output
    • -
      -def config_mode(self, config_command='edit running', pattern='') -
      -
      -

      Enter configuration mode.

      -
      -Source code -
      def config_mode(self, config_command="edit running", pattern=""):
      -    """Enter configuration mode."""
      -
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      -
      -
      def disable_paging(self, *args, **kwargs)
      @@ -457,24 +437,11 @@

      Methods

      6WIND requires no-pager at the end of command, not implemented at this time.

      Source code -
      def disable_paging(self, *args, **kwargs):
      +
      def disable_paging(self, *args: Any, **kwargs: Any) -> str:
           """6WIND requires no-pager at the end of command, not implemented at this time."""
           pass
      -
      -def enable(self, *args, **kwargs) -
      -
      -

      6WIND has no enable mode.

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """6WIND has no enable mode."""
      -
      -    pass
      -
      -
      def exit_config_mode(self, exit_config='exit', pattern='>')
      @@ -482,25 +449,12 @@

      Methods

      Exit configuration mode.

      Source code -
      def exit_config_mode(self, exit_config="exit", pattern=r">"):
      +
      def exit_config_mode(self, exit_config: str = "exit", pattern: str = r">") -> str:
           """Exit configuration mode."""
       
           return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
      -
      -def exit_enable_mode(self, *args, **kwargs) -
      -
      -

      6WIND has no enable mode.

      -
      -Source code -
      def exit_enable_mode(self, *args, **kwargs):
      -    """6WIND has no enable mode."""
      -
      -    pass
      -
      -
      def save_config(self, cmd='copy running startup', confirm=True, confirm_response='y')
      @@ -509,8 +463,11 @@

      Methods

      Source code
      def save_config(
      -    self, cmd="copy running startup", confirm=True, confirm_response="y"
      -):
      +    self,
      +    cmd: str = "copy running startup",
      +    confirm: bool = True,
      +    confirm_response: str = "y",
      +) -> str:
           """Save Config for 6WIND"""
       
           return super().save_config(
      @@ -525,7 +482,7 @@ 

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           self.ansi_escape_codes = True
           self._test_channel_read()
      @@ -536,21 +493,26 @@ 

      Methods

      -def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

      Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

      Source code
      def set_base_prompt(
      -    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
      -):
      +    self,
      +    pri_prompt_terminator: str = ">",
      +    alt_prompt_terminator: str = "#",
      +    delay_factor: float = 1.0,
      +    pattern: Optional[str] = None,
      +) -> str:
           """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
       
           prompt = super().set_base_prompt(
               pri_prompt_terminator=pri_prompt_terminator,
               alt_prompt_terminator=alt_prompt_terminator,
               delay_factor=delay_factor,
      +        pattern=pattern,
           )
           prompt = prompt.strip()
           self.base_prompt = prompt
      @@ -562,18 +524,21 @@ 

      Inherited members

      class SixwindOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
      -

      Base Class for cisco-like behavior.

      +

      Class for platforms that have no enable mode.

      +

      Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

      +

      The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

      +

      Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

          Initialize attributes for establishing connection to target device.
       
           :param ip: IP address of target device. Not required if `host` is
               provided.
      -    :type ip: str
       
           :param host: Hostname of target device. Not required if `ip` is
                   provided.
      -    :type host: str
       
           :param username: Username to authenticate against target device if
                   required.
      -    :type username: str
       
           :param password: Password to authenticate against target device if
                   required.
      -    :type password: str
       
           :param secret: The enable password if target device requires one.
      -    :type secret: str
       
           :param port: The destination port used to connect to the target
                   device.
      -    :type port: int or None
       
           :param device_type: Class selection based on device type.
      -    :type device_type: str
       
           :param verbose: Enable additional messages to standard output.
      -    :type verbose: bool
       
           :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
      -    :type global_delay_factor: int
       
           :param use_keys: Connect to target device using SSH keys.
      -    :type use_keys: bool
       
           :param key_file: Filename path of the SSH key file to use.
      -    :type key_file: str
       
           :param pkey: SSH key object to use.
      -    :type pkey: paramiko.PKey
       
           :param passphrase: Passphrase to use for encrypted key; password will be used for key
                   decryption if not specified.
      -    :type passphrase: str
      +
      +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
      +            documentation for a description of the expected format.
       
           :param allow_agent: Enable use of SSH key-agent.
      -    :type allow_agent: bool
       
           :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                   means unknown SSH host keys will be accepted).
      -    :type ssh_strict: bool
       
           :param system_host_keys: Load host keys from the users known_hosts file.
      -    :type system_host_keys: bool
      +
           :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                   alt_key_file.
      -    :type alt_host_keys: bool
       
           :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
      -    :type alt_key_file: str
       
           :param ssh_config_file: File name of OpenSSH configuration file.
      -    :type ssh_config_file: str
       
           :param timeout: Connection timeout.
      -    :type timeout: float
       
           :param session_timeout: Set a timeout for parallel requests.
      -    :type session_timeout: float
       
           :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
      -    :type auth_timeout: float
       
           :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
      -    :type banner_timeout: float
       
           :param 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).
      -    :type keepalive: int
       
           :param default_enter: Character(s) to send to correspond to enter key (default:
       
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -741,6 +687,7 @@

      Inherited members

      Ancestors

      @@ -749,25 +696,24 @@

      Inherited members

    • SixwindOSBase:
      • check_config_mode
      • -
      • check_enable_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • -
      • enable
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • -
      • exit_enable_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -779,6 +725,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -813,13 +760,9 @@

        Index

        SixwindOSBase

        • check_config_mode
        • -
        • check_enable_mode
        • commit
        • -
        • config_mode
        • disable_paging
        • -
        • enable
        • exit_config_mode
        • -
        • exit_enable_mode
        • save_config
        • session_preparation
        • set_base_prompt
        • diff --git a/docs/netmiko/snmp_autodetect.html b/docs/netmiko/snmp_autodetect.html index a565b98a2..819d62b05 100644 --- a/docs/netmiko/snmp_autodetect.html +++ b/docs/netmiko/snmp_autodetect.html @@ -58,6 +58,8 @@

          Example:

          Note, pysnmp is a required dependency for SNMPDetect and is intentionally not included in netmiko requirements. So installation of pysnmp might be required. """ +from typing import Optional, Dict +from typing.re import Pattern import re try: @@ -145,6 +147,11 @@

          Example:

          "expr": re.compile(r".*TiMOS.*"), "priority": 99, }, + "dell_powerconnect": { + "oid": ".1.3.6.1.2.1.1.1.0", + "expr": re.compile(r"PowerConnect.*", re.IGNORECASE), + "priority": 50, + }, } # Ensure all SNMP device types are supported by Netmiko @@ -203,7 +210,6 @@

          Example:

          encrypt_proto : str The SNMPv3 encryption protocol - Methods ------- autodetect() @@ -213,16 +219,16 @@

          Example:

          def __init__( self, - hostname, - snmp_version="v3", - snmp_port=161, - community=None, - user="", - auth_key="", - encrypt_key="", - auth_proto="sha", - encrypt_proto="aes128", - ): + hostname: str, + snmp_version: str = "v3", + snmp_port: int = 161, + community: Optional[str] = None, + user: str = "", + auth_key: str = "", + encrypt_key: str = "", + auth_proto: str = "sha", + encrypt_proto: str = "aes128", + ) -> None: # Check that the SNMP version is matching predefined type or raise ValueError if snmp_version == "v1" or snmp_version == "v2c": @@ -268,9 +274,9 @@

          Example:

          self.encrypt_key = encrypt_key self.auth_proto = self._snmp_v3_authentication[auth_proto] self.encryp_proto = self._snmp_v3_encryption[encrypt_proto] - self._response_cache = {} + self._response_cache: Dict[str, str] = {} - def _get_snmpv3(self, oid): + def _get_snmpv3(self, oid: str) -> str: """ Try to send an SNMP GET operation using SNMPv3 for the specified OID. @@ -305,7 +311,7 @@

          Example:

          return str(snmp_data[0][1]) return "" - def _get_snmpv2c(self, oid): + def _get_snmpv2c(self, oid: str) -> str: """ Try to send an SNMP GET operation using SNMPv2 for the specified OID. @@ -334,14 +340,14 @@

          Example:

          return str(snmp_data[0][1]) return "" - def _get_snmp(self, oid): + def _get_snmp(self, oid: str) -> str: """Wrapper for generic SNMP call.""" if self.snmp_version in ["v1", "v2c"]: return self._get_snmpv2c(oid) else: return self._get_snmpv3(oid) - def autodetect(self): + def autodetect(self) -> Optional[str]: """ Try to guess the device_type using SNMP GET based on the SNMP_MAPPER dict. The type which is returned is directly matching the name in *netmiko.ssh_dispatcher.CLASS_MAPPER_BASE* @@ -355,18 +361,18 @@

          Example:

          The name of the device_type that must be running. """ # Convert SNMP_MAPPER to a list and sort by priority - snmp_mapper_list = [] + snmp_mapper_orig = [] for k, v in SNMP_MAPPER.items(): - snmp_mapper_list.append({k: v}) + snmp_mapper_orig.append({k: v}) snmp_mapper_list = sorted( - snmp_mapper_list, key=lambda x: list(x.values())[0]["priority"] + snmp_mapper_orig, key=lambda x: list(x.values())[0]["priority"] # type: ignore ) snmp_mapper_list.reverse() for entry in snmp_mapper_list: for device_type, v in entry.items(): - oid = v["oid"] - regex = v["expr"] + oid: str = v["oid"] # type: ignore + regex: Pattern = v["expr"] # Used cache data if we already queryied this OID if self._response_cache.get(oid): @@ -377,6 +383,7 @@

          Example:

          # See if we had a match if re.search(regex, snmp_response): + assert isinstance(device_type, str) return device_type return None
    • @@ -493,7 +500,6 @@

      Methods

      encrypt_proto : str The SNMPv3 encryption protocol - Methods ------- autodetect() @@ -503,16 +509,16 @@

      Methods

      def __init__( self, - hostname, - snmp_version="v3", - snmp_port=161, - community=None, - user="", - auth_key="", - encrypt_key="", - auth_proto="sha", - encrypt_proto="aes128", - ): + hostname: str, + snmp_version: str = "v3", + snmp_port: int = 161, + community: Optional[str] = None, + user: str = "", + auth_key: str = "", + encrypt_key: str = "", + auth_proto: str = "sha", + encrypt_proto: str = "aes128", + ) -> None: # Check that the SNMP version is matching predefined type or raise ValueError if snmp_version == "v1" or snmp_version == "v2c": @@ -558,9 +564,9 @@

      Methods

      self.encrypt_key = encrypt_key self.auth_proto = self._snmp_v3_authentication[auth_proto] self.encryp_proto = self._snmp_v3_encryption[encrypt_proto] - self._response_cache = {} + self._response_cache: Dict[str, str] = {} - def _get_snmpv3(self, oid): + def _get_snmpv3(self, oid: str) -> str: """ Try to send an SNMP GET operation using SNMPv3 for the specified OID. @@ -595,7 +601,7 @@

      Methods

      return str(snmp_data[0][1]) return "" - def _get_snmpv2c(self, oid): + def _get_snmpv2c(self, oid: str) -> str: """ Try to send an SNMP GET operation using SNMPv2 for the specified OID. @@ -624,14 +630,14 @@

      Methods

      return str(snmp_data[0][1]) return "" - def _get_snmp(self, oid): + def _get_snmp(self, oid: str) -> str: """Wrapper for generic SNMP call.""" if self.snmp_version in ["v1", "v2c"]: return self._get_snmpv2c(oid) else: return self._get_snmpv3(oid) - def autodetect(self): + def autodetect(self) -> Optional[str]: """ Try to guess the device_type using SNMP GET based on the SNMP_MAPPER dict. The type which is returned is directly matching the name in *netmiko.ssh_dispatcher.CLASS_MAPPER_BASE* @@ -645,18 +651,18 @@

      Methods

      The name of the device_type that must be running. """ # Convert SNMP_MAPPER to a list and sort by priority - snmp_mapper_list = [] + snmp_mapper_orig = [] for k, v in SNMP_MAPPER.items(): - snmp_mapper_list.append({k: v}) + snmp_mapper_orig.append({k: v}) snmp_mapper_list = sorted( - snmp_mapper_list, key=lambda x: list(x.values())[0]["priority"] + snmp_mapper_orig, key=lambda x: list(x.values())[0]["priority"] # type: ignore ) snmp_mapper_list.reverse() for entry in snmp_mapper_list: for device_type, v in entry.items(): - oid = v["oid"] - regex = v["expr"] + oid: str = v["oid"] # type: ignore + regex: Pattern = v["expr"] # Used cache data if we already queryied this OID if self._response_cache.get(oid): @@ -667,6 +673,7 @@

      Methods

      # See if we had a match if re.search(regex, snmp_response): + assert isinstance(device_type, str) return device_type return None
      @@ -688,7 +695,7 @@

      Returns

  • Source code -
    def autodetect(self):
    +
    def autodetect(self) -> Optional[str]:
         """
         Try to guess the device_type using SNMP GET based on the SNMP_MAPPER dict. The type which
         is returned is directly matching the name in *netmiko.ssh_dispatcher.CLASS_MAPPER_BASE*
    @@ -702,18 +709,18 @@ 

    Returns

    The name of the device_type that must be running. """ # Convert SNMP_MAPPER to a list and sort by priority - snmp_mapper_list = [] + snmp_mapper_orig = [] for k, v in SNMP_MAPPER.items(): - snmp_mapper_list.append({k: v}) + snmp_mapper_orig.append({k: v}) snmp_mapper_list = sorted( - snmp_mapper_list, key=lambda x: list(x.values())[0]["priority"] + snmp_mapper_orig, key=lambda x: list(x.values())[0]["priority"] # type: ignore ) snmp_mapper_list.reverse() for entry in snmp_mapper_list: for device_type, v in entry.items(): - oid = v["oid"] - regex = v["expr"] + oid: str = v["oid"] # type: ignore + regex: Pattern = v["expr"] # Used cache data if we already queryied this OID if self._response_cache.get(oid): @@ -724,6 +731,7 @@

    Returns

    # See if we had a match if re.search(regex, snmp_response): + assert isinstance(device_type, str) return device_type return None
    diff --git a/docs/netmiko/sophos/index.html b/docs/netmiko/sophos/index.html index c1fdb11c3..6b7b0b883 100644 --- a/docs/netmiko/sophos/index.html +++ b/docs/netmiko/sophos/index.html @@ -45,144 +45,124 @@

    Classes

    class SophosSfosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class SophosSfosSSH(CiscoSSHConnection):
    -    def session_preparation(self):
    +
    class SophosSfosSSH(NoEnable, NoConfig, CiscoSSHConnection):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read()
             """
    @@ -208,114 +188,20 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on SFOS""" - return True - - def enable(self, *args, **kwargs): - """No enable mode on SFOS""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on SFOS""" - return "" - - def check_config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return False - - def config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return "" - - def exit_config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return "" - - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return True
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return ""
    -
    -
    def save_config(self, *args, **kwargs)
    @@ -323,7 +209,7 @@

    Methods

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -335,7 +221,7 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self._test_channel_read()
         """
    @@ -367,20 +253,25 @@ 

    Inherited members

    @@ -95,144 +75,124 @@

    Classes

    class SophosSfosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class SophosSfosSSH(CiscoSSHConnection):
    -    def session_preparation(self):
    +
    class SophosSfosSSH(NoEnable, NoConfig, CiscoSSHConnection):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read()
             """
    @@ -258,114 +218,20 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on SFOS""" - return True - - def enable(self, *args, **kwargs): - """No enable mode on SFOS""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on SFOS""" - return "" - - def check_config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return False - - def config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return "" - - def exit_config_mode(self, *args, **kwargs): - """No config mode on SFOS""" - return "" - - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """Not Implemented""" raise NotImplementedError

    Ancestors

    Methods

    -
    -def check_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def check_config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return False
    -
    -
    -
    -def check_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def check_enable_mode(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return True
    -
    -
    -
    -def config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return ""
    -
    -
    -
    -def enable(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return ""
    -
    -
    -
    -def exit_config_mode(self, *args, **kwargs) -
    -
    -

    No config mode on SFOS

    -
    -Source code -
    def exit_config_mode(self, *args, **kwargs):
    -    """No config mode on SFOS"""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    No enable mode on SFOS

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """No enable mode on SFOS"""
    -    return ""
    -
    -
    def save_config(self, *args, **kwargs)
    @@ -373,7 +239,7 @@

    Methods

    Not Implemented

    Source code -
    def save_config(self, *args, **kwargs):
    +
    def save_config(self, *args: Any, **kwargs: Any) -> str:
         """Not Implemented"""
         raise NotImplementedError
    @@ -385,7 +251,7 @@

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self._test_channel_read()
         """
    @@ -417,20 +283,25 @@ 

    Inherited members

    • CiscoSSHConnection:
        +
      • check_config_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • +
      • enable
      • establish_connection
      • +
      • exit_config_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -441,6 +312,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -472,13 +344,7 @@

        Index

        • SophosSfosSSH

          -
            -
          • check_config_mode
          • -
          • check_enable_mode
          • -
          • config_mode
          • -
          • enable
          • -
          • exit_config_mode
          • -
          • exit_enable_mode
          • + diff --git a/docs/netmiko/ssh_auth.html b/docs/netmiko/ssh_auth.html new file mode 100644 index 000000000..3d3fe4ce8 --- /dev/null +++ b/docs/netmiko/ssh_auth.html @@ -0,0 +1,101 @@ + + + + + + +netmiko.ssh_auth API documentation + + + + + + + + + +
            +
            +
            +

            Module netmiko.ssh_auth

            +
            +
            +
            +Source code +
            from typing import Any
            +from paramiko import SSHClient
            +
            +
            +class SSHClient_noauth(SSHClient):
            +    """Set noauth when manually handling SSH authentication."""
            +
            +    def _auth(self, username: str, *args: Any) -> None:
            +        transport = self.get_transport()
            +        assert transport is not None
            +        transport.auth_none(username)
            +        return
            +
            +
            +
            +
            +
            +
            +
            +
            +
            +

            Classes

            +
            +
            +class SSHClient_noauth +
            +
            +

            Set noauth when manually handling SSH authentication.

            +

            Create a new SSHClient.

            +
            +Source code +
            class SSHClient_noauth(SSHClient):
            +    """Set noauth when manually handling SSH authentication."""
            +
            +    def _auth(self, username: str, *args: Any) -> None:
            +        transport = self.get_transport()
            +        assert transport is not None
            +        transport.auth_none(username)
            +        return
            +
            +

            Ancestors

            +
              +
            • paramiko.client.SSHClient
            • +
            • paramiko.util.ClosingContextManager
            • +
            +
            +
            +
            +
            + +
            + + + + + \ No newline at end of file diff --git a/docs/netmiko/ssh_autodetect.html b/docs/netmiko/ssh_autodetect.html index b501cbe61..98438505d 100644 --- a/docs/netmiko/ssh_autodetect.html +++ b/docs/netmiko/ssh_autodetect.html @@ -99,8 +99,12 @@

            Netmiko connection creation section >>> remote_device['device_type'] = best_match >>> connection = ConnectHandler(**remote_device) """ +from typing import Any, List, Optional, Union, Dict import re import time + +import paramiko + from netmiko.ssh_dispatcher import ConnectHandler from netmiko.base_connection import BaseConnection @@ -108,7 +112,7 @@

            Netmiko connection creation section # 'dispatch' key is the SSHDetect method to call. dispatch key will be popped off dictionary # remaining keys indicate kwargs that will be passed to dispatch method. # Note, the 'cmd' needs to avoid output paging. -SSH_MAPPER_BASE = { +SSH_MAPPER_DICT = { "alcatel_aos": { "cmd": "show system", "search_patterns": [r"Alcatel-Lucent"], @@ -133,6 +137,12 @@

            Netmiko connection creation section "priority": 99, "dispatch": "_autodetect_std", }, + "ciena_saos": { + "cmd": "software show", + "search_patterns": [r"saos"], + "priority": 99, + "dispatch": "_autodetect_std", + }, "cisco_asa": { "cmd": "show version", "search_patterns": [r"Cisco Adaptive Security Appliance", r"Cisco ASA"], @@ -201,7 +211,7 @@

            Netmiko connection creation section }, "hp_comware": { "cmd": "display version", - "search_patterns": ["HPE Comware"], + "search_patterns": ["HPE Comware", "HP Comware"], "priority": 99, "dispatch": "_autodetect_std", }, @@ -231,6 +241,12 @@

            Netmiko connection creation section "priority": 99, "dispatch": "_autodetect_std", }, + "extreme_exos": { + "cmd": "show version", + "search_patterns": [r"ExtremeXOS"], + "priority": 99, + "dispatch": "_autodetect_std", + }, "extreme_netiron": { "cmd": "show version", "search_patterns": [r"(NetIron|MLX)"], @@ -243,6 +259,12 @@

            Netmiko connection creation section "priority": 99, "dispatch": "_autodetect_std", }, + "extreme_tierra": { + "cmd": "show version", + "search_patterns": [r"TierraOS Software"], + "priority": 99, + "dispatch": "_autodetect_std", + }, "ubiquiti_edgeswitch": { "cmd": "show version", "search_patterns": [r"EdgeSwitch"], @@ -255,6 +277,12 @@

            Netmiko connection creation section "search_patterns": [r"CISCO_WLC"], "priority": 99, }, + "cisco_wlc_85": { + "cmd": "show inventory", + "dispatch": "_autodetect_std", + "search_patterns": [r"Cisco Wireless Controller"], + "priority": 99, + }, "mellanox_mlnxos": { "cmd": "show version", "search_patterns": [r"Onyx", r"SX_PPC_M460EX"], @@ -287,16 +315,18 @@

            Netmiko connection creation section }, } -# Sort SSH_MAPPER_BASE such that the most common commands are first -cmd_count = {} -for k, v in SSH_MAPPER_BASE.items(): - count = cmd_count.setdefault(v["cmd"], 0) - cmd_count[v["cmd"]] = count + 1 +# Sort SSH_MAPPER_DICT such that the most common commands are first +cmd_count: Dict[str, int] = {} +for k, v in SSH_MAPPER_DICT.items(): + my_cmd = v["cmd"] + assert isinstance(my_cmd, str) + count = cmd_count.setdefault(my_cmd, 0) + cmd_count[my_cmd] = count + 1 cmd_count = {k: v for k, v in sorted(cmd_count.items(), key=lambda item: item[1])} -# SSH_MAPPER_BASE will be a list after this +# SSH_MAPPER_BASE is a list SSH_MAPPER_BASE = sorted( - SSH_MAPPER_BASE.items(), key=lambda item: int(cmd_count[item[1]["cmd"]]) + SSH_MAPPER_DICT.items(), key=lambda item: int(cmd_count[str(item[1]["cmd"])]) ) SSH_MAPPER_BASE.reverse() @@ -328,7 +358,7 @@

            Netmiko connection creation section Try to determine the device type. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: """ Constructor of the SSHDetect class """ @@ -340,10 +370,10 @@

            Netmiko connection creation section # Call the _test_channel_read() in base to clear initial data output = BaseConnection._test_channel_read(self.connection) self.initial_buffer = output - self.potential_matches = {} - self._results_cache = {} + self.potential_matches: Dict[str, int] = {} + self._results_cache: Dict[str, str] = {} - def autodetect(self): + def autodetect(self) -> Union[str, None]: """ Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE @@ -355,6 +385,7 @@

            Netmiko connection creation section for device_type, autodetect_dict in SSH_MAPPER_BASE: tmp_dict = autodetect_dict.copy() call_method = tmp_dict.pop("dispatch") + assert isinstance(call_method, str) autodetect_method = getattr(self, call_method) accuracy = autodetect_method(**tmp_dict) if accuracy: @@ -363,6 +394,10 @@

            Netmiko connection creation section best_match = sorted( self.potential_matches.items(), key=lambda t: t[1], reverse=True ) + # WLC needs two different auto-dectect solutions + if "cisco_wlc_85" in best_match[0]: + best_match[0] = ("cisco_wlc", 99) + self.connection.disconnect() return best_match[0][0] @@ -376,7 +411,7 @@

            Netmiko connection creation section self.connection.disconnect() return best_match[0][0] - def _send_command(self, cmd=""): + def _send_command(self, cmd: str = "") -> str: """ Handle reading/writing channel directly. It is also sanitizing the output received. @@ -392,11 +427,11 @@

            Netmiko connection creation section """ self.connection.write_channel(cmd + "\n") time.sleep(1) - output = self.connection._read_channel_timing() + output = self.connection.read_channel_timing() output = self.connection.strip_backspaces(output) return output - def _send_command_wrapper(self, cmd): + def _send_command_wrapper(self, cmd: str) -> str: """ Send command to the remote device with a caching feature to avoid sending the same command twice based on the SSH_MAPPER_BASE dict cmd key. @@ -420,8 +455,12 @@

            Netmiko connection creation section return cached_results def _autodetect_remote_version( - self, search_patterns=None, re_flags=re.IGNORECASE, priority=99, **kwargs - ): + self, + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + **kwargs: Any + ) -> int: """ Method to try auto-detect the device type, by matching a regular expression on the reported remote version of the SSH server. @@ -442,7 +481,10 @@

            Netmiko connection creation section return 0 try: - remote_version = self.connection.remote_conn.transport.remote_version + remote_conn = self.connection.remote_conn + assert isinstance(remote_conn, paramiko.Channel) + assert remote_conn.transport is not None + remote_version = remote_conn.transport.remote_version for pattern in invalid_responses: match = re.search(pattern, remote_version, flags=re.I) if match: @@ -456,8 +498,12 @@

            Netmiko connection creation section return 0 def _autodetect_std( - self, cmd="", search_patterns=None, re_flags=re.IGNORECASE, priority=99 - ): + self, + cmd: str = "", + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + ) -> int: """ Standard method to try to auto-detect the device type. This method will be called for each device_type present in SSH_MAPPER_BASE dict ('dispatch' key). It will attempt to send a @@ -482,6 +528,7 @@

            Netmiko connection creation section r"%Error", r"command not found", r"Syntax Error: unexpected argument", + r"% Unrecognized command found at", ] if not cmd or not search_patterns: return 0 @@ -567,7 +614,7 @@

            Methods

            Try to determine the device type. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: """ Constructor of the SSHDetect class """ @@ -579,10 +626,10 @@

            Methods

            # Call the _test_channel_read() in base to clear initial data output = BaseConnection._test_channel_read(self.connection) self.initial_buffer = output - self.potential_matches = {} - self._results_cache = {} + self.potential_matches: Dict[str, int] = {} + self._results_cache: Dict[str, str] = {} - def autodetect(self): + def autodetect(self) -> Union[str, None]: """ Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE @@ -594,6 +641,7 @@

            Methods

            for device_type, autodetect_dict in SSH_MAPPER_BASE: tmp_dict = autodetect_dict.copy() call_method = tmp_dict.pop("dispatch") + assert isinstance(call_method, str) autodetect_method = getattr(self, call_method) accuracy = autodetect_method(**tmp_dict) if accuracy: @@ -602,6 +650,10 @@

            Methods

            best_match = sorted( self.potential_matches.items(), key=lambda t: t[1], reverse=True ) + # WLC needs two different auto-dectect solutions + if "cisco_wlc_85" in best_match[0]: + best_match[0] = ("cisco_wlc", 99) + self.connection.disconnect() return best_match[0][0] @@ -615,7 +667,7 @@

            Methods

            self.connection.disconnect() return best_match[0][0] - def _send_command(self, cmd=""): + def _send_command(self, cmd: str = "") -> str: """ Handle reading/writing channel directly. It is also sanitizing the output received. @@ -631,11 +683,11 @@

            Methods

            """ self.connection.write_channel(cmd + "\n") time.sleep(1) - output = self.connection._read_channel_timing() + output = self.connection.read_channel_timing() output = self.connection.strip_backspaces(output) return output - def _send_command_wrapper(self, cmd): + def _send_command_wrapper(self, cmd: str) -> str: """ Send command to the remote device with a caching feature to avoid sending the same command twice based on the SSH_MAPPER_BASE dict cmd key. @@ -659,8 +711,12 @@

            Methods

            return cached_results def _autodetect_remote_version( - self, search_patterns=None, re_flags=re.IGNORECASE, priority=99, **kwargs - ): + self, + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + **kwargs: Any + ) -> int: """ Method to try auto-detect the device type, by matching a regular expression on the reported remote version of the SSH server. @@ -681,7 +737,10 @@

            Methods

            return 0 try: - remote_version = self.connection.remote_conn.transport.remote_version + remote_conn = self.connection.remote_conn + assert isinstance(remote_conn, paramiko.Channel) + assert remote_conn.transport is not None + remote_version = remote_conn.transport.remote_version for pattern in invalid_responses: match = re.search(pattern, remote_version, flags=re.I) if match: @@ -695,8 +754,12 @@

            Methods

            return 0 def _autodetect_std( - self, cmd="", search_patterns=None, re_flags=re.IGNORECASE, priority=99 - ): + self, + cmd: str = "", + search_patterns: Optional[List[str]] = None, + re_flags: int = re.IGNORECASE, + priority: int = 99, + ) -> int: """ Standard method to try to auto-detect the device type. This method will be called for each device_type present in SSH_MAPPER_BASE dict ('dispatch' key). It will attempt to send a @@ -721,6 +784,7 @@

            Methods

            r"%Error", r"command not found", r"Syntax Error: unexpected argument", + r"% Unrecognized command found at", ] if not cmd or not search_patterns: return 0 @@ -754,7 +818,7 @@

            Returns

    Source code -
    def autodetect(self):
    +
    def autodetect(self) -> Union[str, None]:
         """
         Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE
     
    @@ -766,6 +830,7 @@ 

    Returns

    for device_type, autodetect_dict in SSH_MAPPER_BASE: tmp_dict = autodetect_dict.copy() call_method = tmp_dict.pop("dispatch") + assert isinstance(call_method, str) autodetect_method = getattr(self, call_method) accuracy = autodetect_method(**tmp_dict) if accuracy: @@ -774,6 +839,10 @@

    Returns

    best_match = sorted( self.potential_matches.items(), key=lambda t: t[1], reverse=True ) + # WLC needs two different auto-dectect solutions + if "cisco_wlc_85" in best_match[0]: + best_match[0] = ("cisco_wlc", 99) + self.connection.disconnect() return best_match[0][0] diff --git a/docs/netmiko/supermicro/index.html b/docs/netmiko/supermicro/index.html index a95c7ef44..2e888cb54 100644 --- a/docs/netmiko/supermicro/index.html +++ b/docs/netmiko/supermicro/index.html @@ -45,139 +45,119 @@

    Classes

    class SmciSwitchSmisSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -187,6 +167,7 @@

    Classes

    Ancestors

    @@ -198,22 +179,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • -
  • enable
  • +
  • enable
  • establish_connection
  • exit_config_mode
  • -
  • exit_enable_mode
  • +
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -225,6 +205,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -241,139 +222,119 @@

    Inherited members

    class SmciSwitchSmisTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -383,6 +344,7 @@

    Inherited members

    Ancestors

    @@ -394,22 +356,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • -
  • enable
  • +
  • enable
  • establish_connection
  • exit_config_mode
  • -
  • exit_enable_mode
  • +
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -421,6 +382,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/supermicro/smci_smis.html b/docs/netmiko/supermicro/smci_smis.html index 55a55bcae..8a0bed97b 100644 --- a/docs/netmiko/supermicro/smci_smis.html +++ b/docs/netmiko/supermicro/smci_smis.html @@ -23,11 +23,12 @@

    Module netmiko.supermicro.smci_smis

    Source code
    from netmiko.cisco_base_connection import CiscoBaseConnection
    +from netmiko.no_enable import NoEnable
     import time
     
     
    -class SmciSwitchSmisBase(CiscoBaseConnection):
    -    def session_preparation(self):
    +class SmciSwitchSmisBase(NoEnable, CiscoBaseConnection):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
    @@ -39,21 +40,16 @@ 

    Module netmiko.supermicro.smci_smis

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string="#"): + def check_enable_mode(self, check_string: str = "#") -> bool: """Check if in enable mode. Return boolean.""" return super().check_enable_mode(check_string=check_string) - def enable(self, *args, **kwargs): - """Supermicro switch does not support enable-mode command""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """Supermicro switch does not support enable-mode command""" - return "" - def save_config( - self, cmd="write startup-config", confirm=False, confirm_response="" - ): + self, + cmd: str = "write startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Save config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -79,144 +75,124 @@

    Classes

    class SmciSwitchSmisBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code -
    class SmciSwitchSmisBase(CiscoBaseConnection):
    -    def session_preparation(self):
    +
    class SmciSwitchSmisBase(NoEnable, CiscoBaseConnection):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
    @@ -228,21 +204,16 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string="#"): + def check_enable_mode(self, check_string: str = "#") -> bool: """Check if in enable mode. Return boolean.""" return super().check_enable_mode(check_string=check_string) - def enable(self, *args, **kwargs): - """Supermicro switch does not support enable-mode command""" - return "" - - def exit_enable_mode(self, *args, **kwargs): - """Supermicro switch does not support enable-mode command""" - return "" - def save_config( - self, cmd="write startup-config", confirm=False, confirm_response="" - ): + self, + cmd: str = "write startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Save config""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -250,6 +221,7 @@

    Classes

    Ancestors

    @@ -260,30 +232,6 @@

    Subclasses

    Methods

    -
    -def enable(self, *args, **kwargs) -
    -
    -

    Supermicro switch does not support enable-mode command

    -
    -Source code -
    def enable(self, *args, **kwargs):
    -    """Supermicro switch does not support enable-mode command"""
    -    return ""
    -
    -
    -
    -def exit_enable_mode(self, *args, **kwargs) -
    -
    -

    Supermicro switch does not support enable-mode command

    -
    -Source code -
    def exit_enable_mode(self, *args, **kwargs):
    -    """Supermicro switch does not support enable-mode command"""
    -    return ""
    -
    -
    def save_config(self, cmd='write startup-config', confirm=False, confirm_response='')
    @@ -292,8 +240,11 @@

    Methods

    Source code
    def save_config(
    -    self, cmd="write startup-config", confirm=False, confirm_response=""
    -):
    +    self,
    +    cmd: str = "write startup-config",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Save config"""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -307,7 +258,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Prepare the session after the connection has been established."""
         self._test_channel_read(pattern=r"[>#]")
         self.set_base_prompt()
    @@ -329,20 +280,21 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • +
  • enable
  • establish_connection
  • exit_config_mode
  • +
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -353,6 +305,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -368,139 +321,119 @@

    Inherited members

    class SmciSwitchSmisSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -510,6 +443,7 @@

    Inherited members

    Ancestors

    @@ -521,22 +455,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • -
  • enable
  • +
  • enable
  • establish_connection
  • exit_config_mode
  • -
  • exit_enable_mode
  • +
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -548,6 +481,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -564,139 +498,119 @@

    Inherited members

    class SmciSwitchSmisTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)
    -

    Base Class for cisco-like behavior.

    +

    Class for platforms that have no enable mode.

    +

    Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

    +

    The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

    +

    Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        Initialize attributes for establishing connection to target device.
     
         :param ip: IP address of target device. Not required if `host` is
             provided.
    -    :type ip: str
     
         :param host: Hostname of target device. Not required if `ip` is
                 provided.
    -    :type host: str
     
         :param username: Username to authenticate against target device if
                 required.
    -    :type username: str
     
         :param password: Password to authenticate against target device if
                 required.
    -    :type password: str
     
         :param secret: The enable password if target device requires one.
    -    :type secret: str
     
         :param port: The destination port used to connect to the target
                 device.
    -    :type port: int or None
     
         :param device_type: Class selection based on device type.
    -    :type device_type: str
     
         :param verbose: Enable additional messages to standard output.
    -    :type verbose: bool
     
         :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
    -    :type global_delay_factor: int
     
         :param use_keys: Connect to target device using SSH keys.
    -    :type use_keys: bool
     
         :param key_file: Filename path of the SSH key file to use.
    -    :type key_file: str
     
         :param pkey: SSH key object to use.
    -    :type pkey: paramiko.PKey
     
         :param passphrase: Passphrase to use for encrypted key; password will be used for key
                 decryption if not specified.
    -    :type passphrase: str
    +
    +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
    +            documentation for a description of the expected format.
     
         :param allow_agent: Enable use of SSH key-agent.
    -    :type allow_agent: bool
     
         :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
                 means unknown SSH host keys will be accepted).
    -    :type ssh_strict: bool
     
         :param system_host_keys: Load host keys from the users known_hosts file.
    -    :type system_host_keys: bool
    +
         :param alt_host_keys: If `True` host keys will be loaded from the file specified in
                 alt_key_file.
    -    :type alt_host_keys: bool
     
         :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
    -    :type alt_key_file: str
     
         :param ssh_config_file: File name of OpenSSH configuration file.
    -    :type ssh_config_file: str
     
         :param timeout: Connection timeout.
    -    :type timeout: float
     
         :param session_timeout: Set a timeout for parallel requests.
    -    :type session_timeout: float
     
         :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
    -    :type auth_timeout: float
     
         :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
    -    :type banner_timeout: float
     
         :param 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).
    -    :type keepalive: int
     
         :param default_enter: Character(s) to send to correspond to enter key (default:
     
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -706,6 +620,7 @@

    Inherited members

    Ancestors

    @@ -717,22 +632,21 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • -
  • enable
  • +
  • enable
  • establish_connection
  • exit_config_mode
  • -
  • exit_enable_mode
  • +
  • exit_enable_mode
  • find_prompt
  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -744,6 +658,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -777,8 +692,6 @@

    Index

  • SmciSwitchSmisBase

    diff --git a/docs/netmiko/terminal_server/index.html b/docs/netmiko/terminal_server/index.html index 658cecf4d..a2f6147a1 100644 --- a/docs/netmiko/terminal_server/index.html +++ b/docs/netmiko/terminal_server/index.html @@ -46,7 +46,7 @@

    Classes

    class TerminalServerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Generic Terminal Server driver SSH.

    @@ -54,131 +54,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
  • -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -200,7 +173,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -213,9 +185,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -227,6 +199,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -243,7 +216,7 @@

    Inherited members

    class TerminalServerTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Generic Terminal Server driver telnet.

    @@ -251,142 +224,115 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TerminalServerTelnet(TerminalServer):
         """Generic Terminal Server driver telnet."""
     
    -    def telnet_login(self, *args, **kwargs):
    +    def telnet_login(self, *args: Any, **kwargs: Any) -> str:
             # Disable automatic handling of username and password when using terminal server driver
             pass
     
    -    def std_login(self, *args, **kwargs):
    +    def std_login(self, *args: Any, **kwargs: Any) -> str:
             return super().telnet_login(*args, **kwargs)

    Ancestors

    @@ -403,7 +349,7 @@

    Methods

    Source code -
    def std_login(self, *args, **kwargs):
    +
    def std_login(self, *args: Any, **kwargs: Any) -> str:
         return super().telnet_login(*args, **kwargs)
    @@ -416,7 +362,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -429,9 +374,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -443,6 +388,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/terminal_server/terminal_server.html b/docs/netmiko/terminal_server/terminal_server.html index fa98044c0..609ba1d99 100644 --- a/docs/netmiko/terminal_server/terminal_server.html +++ b/docs/netmiko/terminal_server/terminal_server.html @@ -24,6 +24,8 @@

    Module netmiko.terminal_server.terminal_server Source code
    """Generic Terminal Server driver."""
    +from typing import Any
    +
     from netmiko.base_connection import BaseConnection
     
     
    @@ -34,7 +36,7 @@ 

    Module netmiko.terminal_server.terminal_serverModule netmiko.terminal_server.terminal_server

    @@ -67,7 +69,7 @@

    Classes

    class TerminalServer -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Generic Terminal Server driver.

    @@ -77,131 +79,104 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -212,7 +187,7 @@

    Classes

    an exception. """ - def session_preparation(self): + def session_preparation(self) -> None: """Do nothing here; base_prompt is not set; paging is not disabled.""" pass
    @@ -234,7 +209,7 @@

    Methods

    Do nothing here; base_prompt is not set; paging is not disabled.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """Do nothing here; base_prompt is not set; paging is not disabled."""
         pass
    @@ -248,7 +223,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -261,9 +235,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -275,6 +249,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_base_prompt
  • set_terminal_width
  • special_login_handler
  • @@ -290,7 +265,7 @@

    Inherited members

    class TerminalServerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Generic Terminal Server driver SSH.

    @@ -298,131 +273,104 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -444,7 +392,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -457,9 +404,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -471,6 +418,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -487,7 +435,7 @@

    Inherited members

    class TerminalServerTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Generic Terminal Server driver telnet.

    @@ -495,142 +443,115 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TerminalServerTelnet(TerminalServer):
         """Generic Terminal Server driver telnet."""
     
    -    def telnet_login(self, *args, **kwargs):
    +    def telnet_login(self, *args: Any, **kwargs: Any) -> str:
             # Disable automatic handling of username and password when using terminal server driver
             pass
     
    -    def std_login(self, *args, **kwargs):
    +    def std_login(self, *args: Any, **kwargs: Any) -> str:
             return super().telnet_login(*args, **kwargs)

    Ancestors

    @@ -647,7 +568,7 @@

    Methods

    Source code -
    def std_login(self, *args, **kwargs):
    +
    def std_login(self, *args: Any, **kwargs: Any) -> str:
         return super().telnet_login(*args, **kwargs)
    @@ -660,7 +581,6 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • config_mode
  • disable_paging
  • @@ -673,9 +593,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -687,6 +607,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/tplink/index.html b/docs/netmiko/tplink/index.html index 920c2f37a..dd01b0d60 100644 --- a/docs/netmiko/tplink/index.html +++ b/docs/netmiko/tplink/index.html @@ -53,141 +53,113 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TPLinkJetStreamSSH(TPLinkJetStreamBase):
    -    def __init__(self, **kwargs):
    -        dsa._check_dsa_parameters = self._override_check_dsa_parameters
    -
    +    def __init__(self, **kwargs: Any) -> None:
    +        setattr(dsa, "_check_dsa_parameters", self._override_check_dsa_parameters)
             return super().__init__(**kwargs)
     
    -    def _override_check_dsa_parameters(self, parameters):
    +    def _override_check_dsa_parameters(self, parameters: DSAParameterNumbers) -> None:
             """
             Override check_dsa_parameters from cryptography's dsa.py
     
    @@ -226,9 +198,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -239,9 +210,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -253,6 +224,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -277,146 +249,119 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TPLinkJetStreamTelnet(TPLinkJetStreamBase):
         def telnet_login(
             self,
    -        pri_prompt_terminator="#",
    -        alt_prompt_terminator=">",
    -        username_pattern=r"User:",
    -        pwd_pattern=r"Password:",
    -        delay_factor=1,
    -        max_loops=60,
    -    ):
    +        pri_prompt_terminator: str = "#",
    +        alt_prompt_terminator: str = ">",
    +        username_pattern: str = r"User:",
    +        pwd_pattern: str = r"Password:",
    +        delay_factor: float = 1.0,
    +        max_loops: int = 60,
    +    ) -> str:
             """Telnet login: can be username/password or just password."""
    -        super().telnet_login(
    +        return super().telnet_login(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 username_pattern=username_pattern,
    @@ -435,7 +380,7 @@ 

    Ancestors

    Methods

    -def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>', username_pattern='User:', pwd_pattern='Password:', delay_factor=1, max_loops=60) +def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>', username_pattern='User:', pwd_pattern='Password:', delay_factor=1.0, max_loops=60)

    Telnet login: can be username/password or just password.

    @@ -443,15 +388,15 @@

    Methods

    Source code
    def telnet_login(
         self,
    -    pri_prompt_terminator="#",
    -    alt_prompt_terminator=">",
    -    username_pattern=r"User:",
    -    pwd_pattern=r"Password:",
    -    delay_factor=1,
    -    max_loops=60,
    -):
    +    pri_prompt_terminator: str = "#",
    +    alt_prompt_terminator: str = ">",
    +    username_pattern: str = r"User:",
    +    pwd_pattern: str = r"Password:",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 60,
    +) -> str:
         """Telnet login: can be username/password or just password."""
    -    super().telnet_login(
    +    return super().telnet_login(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             username_pattern=username_pattern,
    @@ -470,9 +415,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -483,9 +427,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -497,6 +441,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/tplink/tplink_jetstream.html b/docs/netmiko/tplink/tplink_jetstream.html index 36f53f13b..18e35708c 100644 --- a/docs/netmiko/tplink/tplink_jetstream.html +++ b/docs/netmiko/tplink/tplink_jetstream.html @@ -24,16 +24,18 @@

    Module netmiko.tplink.tplink_jetstream

    Source code
    import re
     import time
    +from typing import Any, Optional
     
     from cryptography.hazmat.primitives.asymmetric import dsa
    +from cryptography.hazmat.primitives.asymmetric.dsa import DSAParameterNumbers
     
     from netmiko import log
     from netmiko.cisco_base_connection import CiscoSSHConnection
    -from netmiko.ssh_exception import NetmikoTimeoutException
    +from netmiko.exceptions import NetmikoTimeoutException
     
     
     class TPLinkJetStreamBase(CiscoSSHConnection):
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             # TP-Link doesn't have a way to set terminal width which breaks cmd_verify
             if kwargs.get("global_cmd_verify") is None:
                 kwargs["global_cmd_verify"] = False
    @@ -42,7 +44,7 @@ 

    Module netmiko.tplink.tplink_jetstream

    kwargs["default_enter"] = "\r\n" return super().__init__(**kwargs) - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. """ @@ -57,7 +59,13 @@

    Module netmiko.tplink.tplink_jetstream

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def enable(self, cmd="", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """ TPLink JetStream requires you to first execute "enable" and then execute "enable-admin". This is necessary as "configure" is generally only available at "enable-admin" level @@ -82,21 +90,24 @@

    Module netmiko.tplink.tplink_jetstream

    self.write_channel(self.normalize_cmd(cmd)) try: output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) except NetmikoTimeoutException: raise ValueError(msg) if not self.check_enable_mode(): raise ValueError(msg) return output - def config_mode(self, config_command="configure"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r"#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#") -> str: """ Exit config mode. @@ -121,13 +132,19 @@

    Module netmiko.tplink.tplink_jetstream

    return output - def check_config_mode(self, check_string="(config", pattern=r"#"): + def check_config_mode( + self, check_string: str = "(config", pattern: str = r"#" + ) -> bool: """Check whether device is in configuration mode. Return a boolean.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def set_base_prompt( - self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """ Sets self.base_prompt @@ -143,16 +160,16 @@

    Module netmiko.tplink.tplink_jetstream

    pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) class TPLinkJetStreamSSH(TPLinkJetStreamBase): - def __init__(self, **kwargs): - dsa._check_dsa_parameters = self._override_check_dsa_parameters - + def __init__(self, **kwargs: Any) -> None: + setattr(dsa, "_check_dsa_parameters", self._override_check_dsa_parameters) return super().__init__(**kwargs) - def _override_check_dsa_parameters(self, parameters): + def _override_check_dsa_parameters(self, parameters: DSAParameterNumbers) -> None: """ Override check_dsa_parameters from cryptography's dsa.py @@ -180,15 +197,15 @@

    Module netmiko.tplink.tplink_jetstream

    class TPLinkJetStreamTelnet(TPLinkJetStreamBase): def telnet_login( self, - pri_prompt_terminator="#", - alt_prompt_terminator=">", - username_pattern=r"User:", - pwd_pattern=r"Password:", - delay_factor=1, - max_loops=60, - ): + pri_prompt_terminator: str = "#", + alt_prompt_terminator: str = ">", + username_pattern: str = r"User:", + pwd_pattern: str = r"Password:", + delay_factor: float = 1.0, + max_loops: int = 60, + ) -> str: """Telnet login: can be username/password or just password.""" - super().telnet_login( + return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -217,136 +234,109 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TPLinkJetStreamBase(CiscoSSHConnection):
    -    def __init__(self, **kwargs):
    +    def __init__(self, **kwargs: Any) -> None:
             # TP-Link doesn't have a way to set terminal width which breaks cmd_verify
             if kwargs.get("global_cmd_verify") is None:
                 kwargs["global_cmd_verify"] = False
    @@ -355,7 +345,7 @@ 

    Classes

    kwargs["default_enter"] = "\r\n" return super().__init__(**kwargs) - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. """ @@ -370,7 +360,13 @@

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def enable(self, cmd="", pattern="ssword", re_flags=re.IGNORECASE): + def enable( + self, + cmd: str = "", + pattern: str = "ssword", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: """ TPLink JetStream requires you to first execute "enable" and then execute "enable-admin". This is necessary as "configure" is generally only available at "enable-admin" level @@ -395,21 +391,24 @@

    Classes

    self.write_channel(self.normalize_cmd(cmd)) try: output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) except NetmikoTimeoutException: raise ValueError(msg) if not self.check_enable_mode(): raise ValueError(msg) return output - def config_mode(self, config_command="configure"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r"#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#") -> str: """ Exit config mode. @@ -434,13 +433,19 @@

    Classes

    return output - def check_config_mode(self, check_string="(config", pattern=r"#"): + def check_config_mode( + self, check_string: str = "(config", pattern: str = r"#" + ) -> bool: """Check whether device is in configuration mode. Return a boolean.""" return super().check_config_mode(check_string=check_string, pattern=pattern) def set_base_prompt( - self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = ">", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """ Sets self.base_prompt @@ -456,6 +461,7 @@

    Classes

    pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, )

    Ancestors

    @@ -478,25 +484,15 @@

    Methods

    Check whether device is in configuration mode. Return a boolean.

    Source code -
    def check_config_mode(self, check_string="(config", pattern=r"#"):
    +
    def check_config_mode(
    +    self, check_string: str = "(config", pattern: str = r"#"
    +) -> bool:
         """Check whether device is in configuration mode. Return a boolean."""
         return super().check_config_mode(check_string=check_string, pattern=pattern)
    - -
    -

    Enter configuration mode.

    -
    -Source code -
    def config_mode(self, config_command="configure"):
    -    """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    -
    -

    TPLink JetStream requires you to first execute "enable" and then execute "enable-admin". @@ -505,7 +501,13 @@

    Methods

    enable all functions.

    Source code -
    def enable(self, cmd="", pattern="ssword", re_flags=re.IGNORECASE):
    +
    def enable(
    +    self,
    +    cmd: str = "",
    +    pattern: str = "ssword",
    +    enable_pattern: Optional[str] = None,
    +    re_flags: int = re.IGNORECASE,
    +) -> str:
         """
         TPLink JetStream requires you to first execute "enable" and then execute "enable-admin".
         This is necessary as "configure" is generally only available at "enable-admin" level
    @@ -530,10 +532,10 @@ 

    Methods

    self.write_channel(self.normalize_cmd(cmd)) try: output += self.read_until_prompt_or_pattern( - pattern=pattern, re_flags=re_flags + pattern=pattern, re_flags=re_flags, read_entire_line=True ) self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) except NetmikoTimeoutException: raise ValueError(msg) if not self.check_enable_mode(): @@ -551,7 +553,7 @@

    Methods

    Consequently, need to keep checking and sending "exit".

    Source code -
    def exit_config_mode(self, exit_config="exit", pattern=r"#"):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#") -> str:
         """
         Exit config mode.
     
    @@ -584,7 +586,7 @@ 

    Methods

    Prepare the session after the connection has been established.

    Source code -
    def session_preparation(self):
    +
    def session_preparation(self) -> None:
         """
         Prepare the session after the connection has been established.
         """
    @@ -601,7 +603,7 @@ 

    Methods

    Sets self.base_prompt

    @@ -613,8 +615,12 @@

    Methods

    Source code
    def set_base_prompt(
    -    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
    -):
    +    self,
    +    pri_prompt_terminator: str = ">",
    +    alt_prompt_terminator: str = "#",
    +    delay_factor: float = 1.0,
    +    pattern: Optional[str] = None,
    +) -> str:
         """
         Sets self.base_prompt
     
    @@ -630,6 +636,7 @@ 

    Methods

    pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, )
    @@ -641,8 +648,8 @@

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • +
  • config_mode
  • disable_paging
  • disconnect
  • establish_connection
  • @@ -651,9 +658,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -665,6 +672,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • set_terminal_width
  • special_login_handler
  • strip_ansi_escape_codes
  • @@ -687,141 +695,113 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TPLinkJetStreamSSH(TPLinkJetStreamBase):
    -    def __init__(self, **kwargs):
    -        dsa._check_dsa_parameters = self._override_check_dsa_parameters
    -
    +    def __init__(self, **kwargs: Any) -> None:
    +        setattr(dsa, "_check_dsa_parameters", self._override_check_dsa_parameters)
             return super().__init__(**kwargs)
     
    -    def _override_check_dsa_parameters(self, parameters):
    +    def _override_check_dsa_parameters(self, parameters: DSAParameterNumbers) -> None:
             """
             Override check_dsa_parameters from cryptography's dsa.py
     
    @@ -860,9 +840,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -873,9 +852,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -887,6 +866,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -911,146 +891,119 @@

    Inherited members

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class TPLinkJetStreamTelnet(TPLinkJetStreamBase):
         def telnet_login(
             self,
    -        pri_prompt_terminator="#",
    -        alt_prompt_terminator=">",
    -        username_pattern=r"User:",
    -        pwd_pattern=r"Password:",
    -        delay_factor=1,
    -        max_loops=60,
    -    ):
    +        pri_prompt_terminator: str = "#",
    +        alt_prompt_terminator: str = ">",
    +        username_pattern: str = r"User:",
    +        pwd_pattern: str = r"Password:",
    +        delay_factor: float = 1.0,
    +        max_loops: int = 60,
    +    ) -> str:
             """Telnet login: can be username/password or just password."""
    -        super().telnet_login(
    +        return super().telnet_login(
                 pri_prompt_terminator=pri_prompt_terminator,
                 alt_prompt_terminator=alt_prompt_terminator,
                 username_pattern=username_pattern,
    @@ -1069,7 +1022,7 @@ 

    Ancestors

    Methods

    Telnet login: can be username/password or just password.

    @@ -1077,15 +1030,15 @@

    Methods

    Source code
    def telnet_login(
         self,
    -    pri_prompt_terminator="#",
    -    alt_prompt_terminator=">",
    -    username_pattern=r"User:",
    -    pwd_pattern=r"Password:",
    -    delay_factor=1,
    -    max_loops=60,
    -):
    +    pri_prompt_terminator: str = "#",
    +    alt_prompt_terminator: str = ">",
    +    username_pattern: str = r"User:",
    +    pwd_pattern: str = r"Password:",
    +    delay_factor: float = 1.0,
    +    max_loops: int = 60,
    +) -> str:
         """Telnet login: can be username/password or just password."""
    -    super().telnet_login(
    +    return super().telnet_login(
             pri_prompt_terminator=pri_prompt_terminator,
             alt_prompt_terminator=alt_prompt_terminator,
             username_pattern=username_pattern,
    @@ -1104,9 +1057,8 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • -
  • config_mode
  • +
  • config_mode
  • disable_paging
  • disconnect
  • enable
  • @@ -1117,9 +1069,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -1131,6 +1083,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • @@ -1162,9 +1115,8 @@

    Index

    • TPLinkJetStreamBase

      -
        +
        • check_config_mode
        • -
        • config_mode
        • enable
        • exit_config_mode
        • session_preparation
        • diff --git a/docs/netmiko/ubiquiti/edge_ssh.html b/docs/netmiko/ubiquiti/edge_ssh.html index 402cbea11..8383cee0a 100644 --- a/docs/netmiko/ubiquiti/edge_ssh.html +++ b/docs/netmiko/ubiquiti/edge_ssh.html @@ -35,7 +35,7 @@

          Module netmiko.ubiquiti.edge_ssh

          This is NOT for EdgeRouter devices. """ - def session_preparation(self): + def session_preparation(self) -> None: self._test_channel_read() self.set_base_prompt() self.enable() @@ -47,23 +47,32 @@

          Module netmiko.ubiquiti.edge_ssh

          time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#.*") -> str: """Exit configuration mode.""" - return super().exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -81,7 +90,7 @@

          Classes

          class UbiquitiEdgeSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

          Implements support for Ubiquity EdgeSwitch devices.

          @@ -91,131 +100,104 @@

          Classes

          :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code @@ -228,7 +210,7 @@

    Classes

    This is NOT for EdgeRouter devices. """ - def session_preparation(self): + def session_preparation(self) -> None: self._test_channel_read() self.set_base_prompt() self.enable() @@ -240,23 +222,32 @@

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#.*") -> str: """Exit configuration mode.""" - return super().exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -275,39 +266,43 @@

    Subclasses

    Methods

    -def check_config_mode(self, check_string=')#') +def check_config_mode(self, check_string=')#', pattern='')

    Checks if the device is in configuration mode or not.

    Source code -
    def check_config_mode(self, check_string=")#"):
    +
    def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
         """Checks if the device is in configuration mode or not."""
    -    return super().check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string, pattern=pattern)
    -def config_mode(self, config_command='configure') +def config_mode(self, config_command='configure', pattern='', re_flags=0)

    Enter configuration mode.

    Source code -
    def config_mode(self, config_command="configure"):
    +
    def config_mode(
    +    self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
    +) -> str:
         """Enter configuration mode."""
    -    return super().config_mode(config_command=config_command)
    + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
    -def exit_config_mode(self, exit_config='exit') +def exit_config_mode(self, exit_config='exit', pattern='#.*')

    Exit configuration mode.

    Source code -
    def exit_config_mode(self, exit_config="exit"):
    +
    def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#.*") -> str:
         """Exit configuration mode."""
    -    return super().exit_config_mode(exit_config=exit_config)
    + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
    @@ -317,7 +312,7 @@

    Methods

    Exit enable mode.

    Source code -
    def exit_enable_mode(self, exit_command="exit"):
    +
    def exit_enable_mode(self, exit_command: str = "exit") -> str:
         """Exit enable mode."""
         return super().exit_enable_mode(exit_command=exit_command)
    @@ -329,7 +324,12 @@

    Methods

    Saves configuration.

    Source code -
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
    +
    def save_config(
    +    self,
    +    cmd: str = "write memory",
    +    confirm: bool = False,
    +    confirm_response: str = "",
    +) -> str:
         """Saves configuration."""
         return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
    @@ -344,7 +344,6 @@ 

    Inherited members

  • check_enable_mode
  • cleanup
  • clear_buffer
  • -
  • close_session_log
  • commit
  • disable_paging
  • disconnect
  • @@ -354,9 +353,9 @@

    Inherited members

  • is_alive
  • normalize_cmd
  • normalize_linefeeds
  • -
  • open_session_log
  • paramiko_cleanup
  • read_channel
  • +
  • read_channel_timing
  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • @@ -367,6 +366,7 @@

    Inherited members

  • send_command_timing
  • send_config_from_file
  • send_config_set
  • +
  • send_multiline
  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • diff --git a/docs/netmiko/ubiquiti/edgerouter_ssh.html b/docs/netmiko/ubiquiti/edgerouter_ssh.html index b257382de..810feb636 100644 --- a/docs/netmiko/ubiquiti/edgerouter_ssh.html +++ b/docs/netmiko/ubiquiti/edgerouter_ssh.html @@ -29,7 +29,7 @@

    Module netmiko.ubiquiti.edgerouter_ssh

    class UbiquitiEdgeRouterSSH(VyOSSSH): """Implement methods for interacting with EdgeOS EdgeRouter network devices.""" - def session_preparation(self): + def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" self._test_channel_read() self.set_base_prompt() @@ -39,11 +39,13 @@

    Module netmiko.ubiquiti.edgerouter_ssh

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config.""" if confirm is True: raise ValueError("EdgeRouter does not support save_config confirmation.") - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) if "Done" not in output: raise ValueError(f"Save failed with following errors:\n\n{output}") return output
    @@ -60,7 +62,7 @@

    Classes

    class UbiquitiEdgeRouterSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

    Implement methods for interacting with EdgeOS EdgeRouter network devices.

    @@ -68,138 +70,111 @@

    Classes

    :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class UbiquitiEdgeRouterSSH(VyOSSSH):
         """Implement methods for interacting with EdgeOS EdgeRouter network devices."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read()
             self.set_base_prompt()
    @@ -209,11 +184,13 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config.""" if confirm is True: raise ValueError("EdgeRouter does not support save_config confirmation.") - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) if "Done" not in output: raise ValueError(f"Save failed with following errors:\n\n{output}") return output
    @@ -221,6 +198,7 @@

    Classes

    Ancestors

    • VyOSSSH
    • +
    • NoEnable
    • CiscoSSHConnection
    • CiscoBaseConnection
    • BaseConnection
    • @@ -234,11 +212,13 @@

      Methods

      Saves Config.

      Source code -
      def save_config(self, cmd="save", confirm=False, confirm_response=""):
      +
      def save_config(
      +    self, cmd: str = "save", confirm: bool = False, confirm_response: str = ""
      +) -> str:
           """Saves Config."""
           if confirm is True:
               raise ValueError("EdgeRouter does not support save_config confirmation.")
      -    output = self.send_command(command_string=cmd)
      +    output = self._send_command_str(command_string=cmd)
           if "Done" not in output:
               raise ValueError(f"Save failed with following errors:\n\n{output}")
           return output
      @@ -250,25 +230,24 @@

      Inherited members

    • VyOSSSH:
    • @@ -60,7 +59,7 @@

      Classes

      class UbiquitiEdgeRouterSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Implement methods for interacting with EdgeOS EdgeRouter network devices.

      @@ -68,138 +67,111 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    -

    ). -:type default_enter: str

    +

    ).

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

    ) -:type response_return: str

    +

    )

        :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                 to select smallest of global and specific. Sets default global_delay_factor to .1
    -            (default: False)
    -    :type fast_cli: boolean
    +            (default: True)
     
         :param session_log: File path or BufferedIOBase subclass object to write the session log to.
    -    :type session_log: str
     
         :param session_log_record_writes: The session log generally only records channel reads due
                 to eliminate command duplication due to command echo. You can enable this if you
                 want to record both channel reads and channel writes in the log (default: False).
    -    :type session_log_record_writes: boolean
     
         :param session_log_file_mode: "write" or "append" for session_log file mode
                 (default: "write")
    -    :type session_log_file_mode: str
     
         :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                 (default: False)
    -    :type allow_auto_change: bool
     
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
    -    :type encoding: str
     
         :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                 communication to the target host (default: None).
    -    :type sock: socket
     
         :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                 (default: None). Global attribute takes precedence over function `cmd_verify`
                 argument. Value of `None` indicates to use function `cmd_verify` argument.
    -    :type global_cmd_verify: bool|None
     
         :param auto_connect: Control whether Netmiko automatically establishes the connection as
                 part of the object creation (default: True).
    -    :type auto_connect: bool
    +
    +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
    +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
    +            eliminated in Netmiko 5.x (default: False).
     
    Source code
    class UbiquitiEdgeRouterSSH(VyOSSSH):
         """Implement methods for interacting with EdgeOS EdgeRouter network devices."""
     
    -    def session_preparation(self):
    +    def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read()
             self.set_base_prompt()
    @@ -209,11 +181,13 @@ 

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config.""" if confirm is True: raise ValueError("EdgeRouter does not support save_config confirmation.") - output = self.send_command(command_string=cmd) + output = self._send_command_str(command_string=cmd) if "Done" not in output: raise ValueError(f"Save failed with following errors:\n\n{output}") return output
    @@ -221,6 +195,7 @@

    Classes

    Ancestors

    • VyOSSSH
    • +
    • NoEnable
    • CiscoSSHConnection
    • CiscoBaseConnection
    • BaseConnection
    • @@ -234,11 +209,13 @@

      Methods

      Saves Config.

      Source code -
      def save_config(self, cmd="save", confirm=False, confirm_response=""):
      +
      def save_config(
      +    self, cmd: str = "save", confirm: bool = False, confirm_response: str = ""
      +) -> str:
           """Saves Config."""
           if confirm is True:
               raise ValueError("EdgeRouter does not support save_config confirmation.")
      -    output = self.send_command(command_string=cmd)
      +    output = self._send_command_str(command_string=cmd)
           if "Done" not in output:
               raise ValueError(f"Save failed with following errors:\n\n{output}")
           return output
      @@ -250,25 +227,24 @@

      Inherited members

    • VyOSSSH:
      • check_config_mode
      • -
      • check_enable_mode
      • +
      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • -
      • enable
      • +
      • enable
      • establish_connection
      • exit_config_mode
      • -
      • exit_enable_mode
      • +
      • exit_enable_mode
      • find_prompt
      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -279,6 +255,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -295,7 +272,7 @@

        Inherited members

        class UbiquitiEdgeSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Implements support for Ubiquity EdgeSwitch devices.

        @@ -305,131 +282,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    • -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -442,7 +392,7 @@

      Inherited members

      This is NOT for EdgeRouter devices. """ - def session_preparation(self): + def session_preparation(self) -> None: self._test_channel_read() self.set_base_prompt() self.enable() @@ -454,23 +404,32 @@

      Inherited members

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool: """Checks if the device is in configuration mode or not.""" - return super().check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure"): + def config_mode( + self, config_command: str = "configure", pattern: str = "", re_flags: int = 0 + ) -> str: """Enter configuration mode.""" - return super().config_mode(config_command=config_command) + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#.*") -> str: """Exit configuration mode.""" - return super().exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def exit_enable_mode(self, exit_command="exit"): + def exit_enable_mode(self, exit_command: str = "exit") -> str: """Exit enable mode.""" return super().exit_enable_mode(exit_command=exit_command) - def save_config(self, cmd="write memory", confirm=False, confirm_response=""): + def save_config( + self, + cmd: str = "write memory", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Saves configuration.""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -489,39 +448,43 @@

      Subclasses

      Methods

      -def check_config_mode(self, check_string=')#') +def check_config_mode(self, check_string=')#', pattern='')

      Checks if the device is in configuration mode or not.

      Source code -
      def check_config_mode(self, check_string=")#"):
      +
      def check_config_mode(self, check_string: str = ")#", pattern: str = "") -> bool:
           """Checks if the device is in configuration mode or not."""
      -    return super().check_config_mode(check_string=check_string)
      + return super().check_config_mode(check_string=check_string, pattern=pattern)
      -def config_mode(self, config_command='configure') +def config_mode(self, config_command='configure', pattern='', re_flags=0)

      Enter configuration mode.

      Source code -
      def config_mode(self, config_command="configure"):
      +
      def config_mode(
      +    self, config_command: str = "configure", pattern: str = "", re_flags: int = 0
      +) -> str:
           """Enter configuration mode."""
      -    return super().config_mode(config_command=config_command)
      + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + )
      -def exit_config_mode(self, exit_config='exit') +def exit_config_mode(self, exit_config='exit', pattern='#.*')

      Exit configuration mode.

      Source code -
      def exit_config_mode(self, exit_config="exit"):
      +
      def exit_config_mode(self, exit_config: str = "exit", pattern: str = r"#.*") -> str:
           """Exit configuration mode."""
      -    return super().exit_config_mode(exit_config=exit_config)
      + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
      @@ -531,7 +494,7 @@

      Methods

      Exit enable mode.

      Source code -
      def exit_enable_mode(self, exit_command="exit"):
      +
      def exit_enable_mode(self, exit_command: str = "exit") -> str:
           """Exit enable mode."""
           return super().exit_enable_mode(exit_command=exit_command)
      @@ -543,7 +506,12 @@

      Methods

      Saves configuration.

      Source code -
      def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
      +
      def save_config(
      +    self,
      +    cmd: str = "write memory",
      +    confirm: bool = False,
      +    confirm_response: str = "",
      +) -> str:
           """Saves configuration."""
           return super().save_config(
               cmd=cmd, confirm=confirm, confirm_response=confirm_response
      @@ -558,7 +526,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • disable_paging
    • disconnect
    • @@ -568,9 +535,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -581,6 +548,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -597,7 +565,7 @@

      Inherited members

      class UbiquitiUnifiSwitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Implements support for Ubiquity EdgeSwitch devices.

      @@ -607,136 +575,109 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class UbiquitiUnifiSwitchSSH(UbiquitiEdgeSSH):
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """
               Prepare the session after the connection has been established.
               When SSHing to a UniFi switch, the session initially starts at a Linux
      @@ -758,7 +699,7 @@ 

      Inherited members

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -792,7 +733,7 @@

      Methods

      environment.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """
           Prepare the session after the connection has been established.
           When SSHing to a UniFi switch, the session initially starts at a Linux
      @@ -824,7 +765,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • @@ -837,9 +777,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -851,6 +791,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • diff --git a/docs/netmiko/ubiquiti/unifiswitch_ssh.html b/docs/netmiko/ubiquiti/unifiswitch_ssh.html index b79ab6250..13ea4fe67 100644 --- a/docs/netmiko/ubiquiti/unifiswitch_ssh.html +++ b/docs/netmiko/ubiquiti/unifiswitch_ssh.html @@ -27,7 +27,7 @@

      Module netmiko.ubiquiti.unifiswitch_ssh

      class UbiquitiUnifiSwitchSSH(UbiquitiEdgeSSH): - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. When SSHing to a UniFi switch, the session initially starts at a Linux @@ -49,7 +49,7 @@

      Module netmiko.ubiquiti.unifiswitch_ssh

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -75,7 +75,7 @@

      Classes

      class UbiquitiUnifiSwitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Implements support for Ubiquity EdgeSwitch devices.

      @@ -85,136 +85,109 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class UbiquitiUnifiSwitchSSH(UbiquitiEdgeSSH):
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """
               Prepare the session after the connection has been established.
               When SSHing to a UniFi switch, the session initially starts at a Linux
      @@ -236,7 +209,7 @@ 

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def cleanup(self, command="exit"): + def cleanup(self, command: str = "exit") -> None: """Gracefully exit the SSH session.""" try: # The pattern="" forces use of send_command_timing @@ -270,7 +243,7 @@

      Methods

      environment.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """
           Prepare the session after the connection has been established.
           When SSHing to a UniFi switch, the session initially starts at a Linux
      @@ -302,7 +275,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • @@ -315,9 +287,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -329,6 +301,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • diff --git a/docs/netmiko/utilities.html b/docs/netmiko/utilities.html index 190c4020d..e70f045b6 100644 --- a/docs/netmiko/utilities.html +++ b/docs/netmiko/utilities.html @@ -24,6 +24,19 @@

      Module netmiko.utilities

      Source code
      """Miscellaneous utility functions."""
      +from typing import (
      +    Any,
      +    AnyStr,
      +    TypeVar,
      +    Callable,
      +    cast,
      +    Optional,
      +    Union,
      +    List,
      +    Dict,
      +    Tuple,
      +)
      +from typing import TYPE_CHECKING
       from glob import glob
       import sys
       import io
      @@ -31,10 +44,18 @@ 

      Module netmiko.utilities

      from pathlib import Path import functools from datetime import datetime -from netmiko._textfsm import _clitable as clitable -from netmiko._textfsm._clitable import CliTableError +from textfsm import clitable +from textfsm.clitable import CliTableError from netmiko import log +# For decorators +F = TypeVar("F", bound=Callable[..., Any]) + + +if TYPE_CHECKING: + from netmiko.base_connection import BaseConnection + from os import PathLike + try: from ttp import ttp @@ -53,10 +74,10 @@

      Module netmiko.utilities

      GENIE_INSTALLED = False # If we are on python < 3.7, we need to force the import of importlib.resources backport -try: - from importlib.resources import path as importresources_path -except ModuleNotFoundError: - from importlib_resources import path as importresources_path +if sys.version_info[:2] >= (3, 7): + import importlib.resources as pkg_resources +else: + import importlib_resources as pkg_resources try: import serial.tools.list_ports @@ -109,7 +130,7 @@

      Module netmiko.utilities

      NETMIKO_BASE_DIR = "~/.netmiko" -def load_yaml_file(yaml_file): +def load_yaml_file(yaml_file: Union[str, bytes, "PathLike[Any]"]) -> Any: """Read YAML file.""" try: import yaml @@ -119,16 +140,18 @@

      Module netmiko.utilities

      with io.open(yaml_file, "rt", encoding="utf-8") as fname: return yaml.safe_load(fname) except IOError: - sys.exit(f"Unable to open YAML file: {yaml_file}") + sys.exit("Unable to open YAML file") -def load_devices(file_name=None): +def load_devices(file_name: Union[str, bytes, "PathLike[Any]", None] = None) -> Any: """Find and load .netmiko.yml file.""" yaml_devices_file = find_cfg_file(file_name) return load_yaml_file(yaml_devices_file) -def find_cfg_file(file_name=None): +def find_cfg_file( + file_name: Union[str, bytes, "PathLike[Any]", None] = None +) -> Union[str, bytes, "PathLike[Any]"]: """ Search for netmiko_tools inventory file in the following order: NETMIKO_TOOLS_CFG environment variable @@ -137,9 +160,8 @@

      Module netmiko.utilities

      Look for file named: .netmiko.yml or netmiko.yml Also allow NETMIKO_TOOLS_CFG to point directly at a file """ - if file_name: - if os.path.isfile(file_name): - return file_name + if file_name and os.path.isfile(file_name): + return file_name optional_path = os.environ.get("NETMIKO_TOOLS_CFG", "") if os.path.isfile(optional_path): return optional_path @@ -156,7 +178,7 @@

      Module netmiko.utilities

      ) -def display_inventory(my_devices): +def display_inventory(my_devices: Dict[str, Union[List[str], Dict[str, Any]]]) -> None: """Print out inventory devices and groups.""" inventory_groups = ["all"] inventory_devices = [] @@ -180,7 +202,9 @@

      Module netmiko.utilities

      print() -def obtain_all_devices(my_devices): +def obtain_all_devices( + my_devices: Dict[str, Union[List[str], Dict[str, Any]]] +) -> Dict[str, Dict[str, Any]]: """Dynamically create 'all' group.""" new_devices = {} for device_name, device_or_group in my_devices.items(): @@ -190,20 +214,20 @@

      Module netmiko.utilities

      return new_devices -def obtain_netmiko_filename(device_name): +def obtain_netmiko_filename(device_name: str) -> str: """Create file name based on device_name.""" _, netmiko_full_dir = find_netmiko_dir() return f"{netmiko_full_dir}/{device_name}.txt" -def write_tmp_file(device_name, output): +def write_tmp_file(device_name: str, output: str) -> str: file_name = obtain_netmiko_filename(device_name) with open(file_name, "w") as f: f.write(output) return file_name -def ensure_dir_exists(verify_dir): +def ensure_dir_exists(verify_dir: str) -> None: """Ensure directory exists. Create if necessary.""" if not os.path.exists(verify_dir): # Doesn't exist create dir @@ -215,7 +239,7 @@

      Module netmiko.utilities

      raise ValueError(f"{verify_dir} is not a directory") -def find_netmiko_dir(): +def find_netmiko_dir() -> Tuple[str, str]: """Check environment first, then default dir""" try: netmiko_base_dir = os.environ["NETMIKO_DIR"] @@ -228,23 +252,21 @@

      Module netmiko.utilities

      return (netmiko_base_dir, netmiko_full_dir) -def write_bytes(out_data, encoding="ascii"): +def write_bytes(out_data: AnyStr, encoding: str = "ascii") -> bytes: """Legacy for Python2 and Python3 compatible byte stream.""" if sys.version_info[0] >= 3: - if isinstance(out_data, type("")): + if isinstance(out_data, str): if encoding == "utf-8": return out_data.encode("utf-8") else: return out_data.encode("ascii", "ignore") - elif isinstance(out_data, type(b"")): + elif isinstance(out_data, bytes): return out_data - msg = "Invalid value for out_data neither unicode nor byte string: {}".format( - out_data - ) + msg = f"Invalid value for out_data neither unicode nor byte string: {str(out_data)}" raise ValueError(msg) -def check_serial_port(name): +def check_serial_port(name: str) -> str: """returns valid COM Port.""" if not PYSERIAL_INSTALLED: @@ -256,7 +278,9 @@

      Module netmiko.utilities

      try: cdc = next(serial.tools.list_ports.grep(name)) - return cdc[0] + serial_port = cdc[0] + assert isinstance(serial_port, str) + return serial_port except StopIteration: msg = f"device {name} not found. " msg += "available devices are: " @@ -266,14 +290,14 @@

      Module netmiko.utilities

      raise ValueError(msg) -def get_template_dir(_skip_ntc_package=False): +def get_template_dir(_skip_ntc_package: bool = False) -> str: """ Find and return the directory containing the TextFSM index file. Order of preference is: 1) Find directory in `NET_TEXTFSM` Environment Variable. 2) Check for pip installed `ntc-templates` location in this environment. - 3) ~/ntc-templates/templates. + 3) ~/ntc-templates/ntc_templates/templates. If `index` file is not found in any of these locations, raise ValueError @@ -303,19 +327,21 @@

      Module netmiko.utilities

      else: # Try 'pip installed' ntc-templates try: - with importresources_path( - package="ntc_templates", resource="templates" + with pkg_resources.path( + package="ntc_templates", resource="parse.py" ) as posix_path: # Example: /opt/venv/netmiko/lib/python3.8/site-packages/ntc_templates/templates - template_dir = str(posix_path) + template_dir = str(posix_path.parent.joinpath("templates")) # This is for Netmiko automated testing if _skip_ntc_package: raise ModuleNotFoundError() except ModuleNotFoundError: - # Finally check in ~/ntc-templates/templates + # Finally check in ~/ntc-templates/ntc_templates/templates home_dir = os.path.expanduser("~") - template_dir = os.path.join(home_dir, "ntc-templates", "templates") + template_dir = os.path.join( + home_dir, "ntc-templates", "ntc_templates", "templates" + ) index = os.path.join(template_dir, "index") if not os.path.isdir(template_dir) or not os.path.isfile(index): @@ -323,33 +349,47 @@

      Module netmiko.utilities

      return os.path.abspath(template_dir) -def clitable_to_dict(cli_table): +def clitable_to_dict(cli_table: clitable.CliTable) -> List[Dict[str, str]]: """Converts TextFSM cli_table object to list of dictionaries.""" - objs = [] + return_list = [] for row in cli_table: temp_dict = {} for index, element in enumerate(row): temp_dict[cli_table.header[index].lower()] = element - objs.append(temp_dict) - return objs + return_list.append(temp_dict) + return return_list -def _textfsm_parse(textfsm_obj, raw_output, attrs, template_file=None): +def _textfsm_parse( + textfsm_obj: clitable.CliTable, + raw_output: str, + attrs: Dict[str, str], + template_file: Optional[str] = None, +) -> Union[str, List[Dict[str, str]]]: """Perform the actual TextFSM parsing using the CliTable object.""" + tfsm_parse: Callable[..., Any] = textfsm_obj.ParseCmd try: # Parse output through template if template_file is not None: - textfsm_obj.ParseCmd(raw_output, templates=template_file) + tfsm_parse(raw_output, templates=template_file) else: - textfsm_obj.ParseCmd(raw_output, attrs) + tfsm_parse(raw_output, attrs) + structured_data = clitable_to_dict(textfsm_obj) - output = raw_output if structured_data == [] else structured_data - return output + if structured_data == []: + return raw_output + else: + return structured_data except (FileNotFoundError, CliTableError): return raw_output -def get_structured_data(raw_output, platform=None, command=None, template=None): +def get_structured_data_textfsm( + raw_output: str, + platform: Optional[str] = None, + command: Optional[str] = None, + template: Optional[str] = None, +) -> Union[str, List[Dict[str, str]]]: """ Convert raw CLI output to structured data using TextFSM template. @@ -369,52 +409,64 @@

      Module netmiko.utilities

      template_dir = get_template_dir() index_file = os.path.join(template_dir, "index") textfsm_obj = clitable.CliTable(index_file, template_dir) - return _textfsm_parse(textfsm_obj, raw_output, attrs) + output = _textfsm_parse(textfsm_obj, raw_output, attrs) + + # Retry the output if "cisco_xe" and not structured data + if platform and "cisco_xe" in platform: + if not isinstance(output, list): + attrs["Platform"] = "cisco_ios" + output = _textfsm_parse(textfsm_obj, raw_output, attrs) + return output else: template_path = Path(os.path.expanduser(template)) template_file = template_path.name - template_dir = template_path.parents[0] + template_dir_alt = template_path.parents[0] # CliTable with no index will fall-back to a TextFSM parsing behavior - textfsm_obj = clitable.CliTable(template_dir=template_dir) + textfsm_obj = clitable.CliTable(template_dir=template_dir_alt) return _textfsm_parse( textfsm_obj, raw_output, attrs, template_file=template_file ) -def get_structured_data_ttp(raw_output, template=None): +# For compatibility +get_structured_data = get_structured_data_textfsm + + +def get_structured_data_ttp(raw_output: str, template: str) -> Union[str, List[Any]]: """ Convert raw CLI output to structured data using TTP template. You can use a straight TextFSM file i.e. specify "template" """ if not TTP_INSTALLED: - msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n" + msg = "\nTTP is not installed. Please PIP install ttp:\n\npip install ttp\n" raise ValueError(msg) try: - if template: - ttp_parser = ttp(data=raw_output, template=template) - ttp_parser.parse(one=True) - return ttp_parser.result(format="raw") + ttp_parser = ttp(data=raw_output, template=template) + ttp_parser.parse(one=True) + result: List[Any] = ttp_parser.result(format="raw") + return result except Exception: return raw_output -def run_ttp_template(connection, template, res_kwargs, **kwargs): +def run_ttp_template( + connection: "BaseConnection", + template: Union[str, bytes, "PathLike[Any]"], + res_kwargs: Dict[str, Any], + **kwargs: Any, +) -> Any: """ Helper function to run TTP template parsing. :param connection: Netmiko connection object - :type connection: obj :param template: TTP template - :type template: str :param res_kwargs: ``**res_kwargs`` arguments for TTP result method - :type res_kwargs: dict :param kwargs: ``**kwargs`` for TTP object instantiation - :type kwargs: dict """ if not TTP_INSTALLED: msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n" @@ -450,11 +502,11 @@

      Module netmiko.utilities

      continue # collect commands output from device - output = [ + out_list = [ getattr(connection, method)(command_string=command, **method_kwargs) for command in commands ] - output = "\n".join(output) + output = "\n".join(out_list) # add collected output to TTP parser object parser.add_input( @@ -467,7 +519,9 @@

      Module netmiko.utilities

      return parser.result(**res_kwargs) -def get_structured_data_genie(raw_output, platform, command): +def get_structured_data_genie( + raw_output: str, platform: str, command: str +) -> Union[str, Dict[str, Any]]: if not sys.version_info >= (3, 4): raise ValueError("Genie requires Python >= 3.4") @@ -492,8 +546,8 @@

      Module netmiko.utilities

      os = None # platform might be _ssh, _telnet, _serial strip that off if platform.count("_") > 1: - base_platform = platform.split("_")[:-1] - base_platform = "_".join(base_platform) + base_list = platform.split("_")[:-1] + base_platform = "_".join(base_list) else: base_platform = platform @@ -509,27 +563,73 @@

      Module netmiko.utilities

      try: # Test whether there is a parser for given command (return Exception if fails) get_parser(command, device) - parsed_output = device.parse(command, output=raw_output) + parsed_output: Dict[str, Any] = device.parse(command, output=raw_output) return parsed_output except Exception: return raw_output -def select_cmd_verify(func): +def structured_data_converter( + raw_data: str, + command: str, + platform: str, + use_textfsm: bool = False, + use_ttp: bool = False, + use_genie: bool = False, + textfsm_template: Optional[str] = None, + ttp_template: Optional[str] = None, +) -> Union[str, List[Any], Dict[str, Any]]: + """ + Try structured data converters in the following order: TextFSM, TTP, Genie. + + Return the first structured data found, else return the raw_data as-is. + """ + command = command.strip() + if use_textfsm: + structured_output_tfsm = get_structured_data_textfsm( + raw_data, platform=platform, command=command, template=textfsm_template + ) + if not isinstance(structured_output_tfsm, str): + return structured_output_tfsm + + if use_ttp: + if ttp_template is None: + msg = """ +The argument 'ttp_template=/path/to/template.ttp' must be set when use_ttp=True +""" + raise ValueError(msg) + else: + structured_output_ttp = get_structured_data_ttp( + raw_data, template=ttp_template + ) + + if not isinstance(structured_output_ttp, str): + return structured_output_ttp + + if use_genie: + structured_output_genie = get_structured_data_genie( + raw_data, platform=platform, command=command + ) + if not isinstance(structured_output_genie, str): + return structured_output_genie + return raw_data + + +def select_cmd_verify(func: F) -> F: """Override function cmd_verify argument with global setting.""" @functools.wraps(func) - def wrapper_decorator(self, *args, **kwargs): + def wrapper_decorator(self: "BaseConnection", *args: Any, **kwargs: Any) -> Any: if self.global_cmd_verify is not None: kwargs["cmd_verify"] = self.global_cmd_verify return func(self, *args, **kwargs) - return wrapper_decorator + return cast(F, wrapper_decorator) -def m_exec_time(func): +def m_exec_time(func: F) -> F: @functools.wraps(func) - def wrapper_decorator(self, *args, **kwargs): + def wrapper_decorator(self: Any, *args: Any, **kwargs: Any) -> Any: start_time = datetime.now() result = func(self, *args, **kwargs) end_time = datetime.now() @@ -537,19 +637,49 @@

      Module netmiko.utilities

      print(f"{method_name}: Elapsed time: {end_time - start_time}") return result - return wrapper_decorator + return cast(F, wrapper_decorator) -def f_exec_time(func): +def f_exec_time(func: F) -> F: @functools.wraps(func) - def wrapper_decorator(*args, **kwargs): + def wrapper_decorator(*args: Any, **kwargs: Any) -> Any: start_time = datetime.now() result = func(*args, **kwargs) end_time = datetime.now() print(f"Elapsed time: {end_time - start_time}") return result - return wrapper_decorator
      + return cast(F, wrapper_decorator) + + +def calc_old_timeout( + max_loops: Optional[int] = None, + delay_factor: Optional[float] = None, + loop_delay: float = 0.2, + old_timeout: int = 100, +) -> float: + """ + loop_delay is .2 in Netmiko 3.x + delay_factor would multiple the loop delay + Number of loops was typically 500 + + Thus each loop would sleep (loop_delay * delay_factor) seconds + That sleep would happen max_loops time + + Formula is (loop_delay * delay_factor) * max_loops + + There was a way Netmiko's self.timeout could override the default settings and essentially be + used to adjust max_loops (this was probably rarely used). + """ + if max_loops is None: + max_loops = 500 + if delay_factor is None: + delay_factor = 1.0 + # This is the logic for having self.timeout override max_loops + if delay_factor == 1 and max_loops == 500: + max_loops = int(old_timeout / loop_delay) + + return max_loops * loop_delay * delay_factor
      @@ -559,6 +689,50 @@

      Module netmiko.utilities

      Functions

      +
      +def calc_old_timeout(max_loops=None, delay_factor=None, loop_delay=0.2, old_timeout=100) +
      +
      +

      loop_delay is .2 in Netmiko 3.x +delay_factor would multiple the loop delay +Number of loops was typically 500

      +

      Thus each loop would sleep (loop_delay * delay_factor) seconds +That sleep would happen max_loops time

      +

      Formula is (loop_delay * delay_factor) * max_loops

      +

      There was a way Netmiko's self.timeout could override the default settings and essentially be +used to adjust max_loops (this was probably rarely used).

      +
      +Source code +
      def calc_old_timeout(
      +    max_loops: Optional[int] = None,
      +    delay_factor: Optional[float] = None,
      +    loop_delay: float = 0.2,
      +    old_timeout: int = 100,
      +) -> float:
      +    """
      +    loop_delay is .2 in Netmiko 3.x
      +    delay_factor would multiple the loop delay
      +    Number of loops was typically 500
      +
      +    Thus each loop would sleep (loop_delay * delay_factor) seconds
      +    That sleep would happen max_loops time
      +
      +    Formula is (loop_delay * delay_factor) * max_loops
      +
      +    There was a way Netmiko's self.timeout could override the default settings and essentially be
      +    used to adjust max_loops (this was probably rarely used).
      +    """
      +    if max_loops is None:
      +        max_loops = 500
      +    if delay_factor is None:
      +        delay_factor = 1.0
      +    # This is the logic for having self.timeout override max_loops
      +    if delay_factor == 1 and max_loops == 500:
      +        max_loops = int(old_timeout / loop_delay)
      +
      +    return max_loops * loop_delay * delay_factor
      +
      +
      def check_serial_port(name)
      @@ -566,7 +740,7 @@

      Functions

      returns valid COM Port.

      Source code -
      def check_serial_port(name):
      +
      def check_serial_port(name: str) -> str:
           """returns valid COM Port."""
       
           if not PYSERIAL_INSTALLED:
      @@ -578,7 +752,9 @@ 

      Functions

      try: cdc = next(serial.tools.list_ports.grep(name)) - return cdc[0] + serial_port = cdc[0] + assert isinstance(serial_port, str) + return serial_port except StopIteration: msg = f"device {name} not found. " msg += "available devices are: " @@ -595,15 +771,15 @@

      Functions

      Converts TextFSM cli_table object to list of dictionaries.

      Source code -
      def clitable_to_dict(cli_table):
      +
      def clitable_to_dict(cli_table: clitable.CliTable) -> List[Dict[str, str]]:
           """Converts TextFSM cli_table object to list of dictionaries."""
      -    objs = []
      +    return_list = []
           for row in cli_table:
               temp_dict = {}
               for index, element in enumerate(row):
                   temp_dict[cli_table.header[index].lower()] = element
      -        objs.append(temp_dict)
      -    return objs
      + return_list.append(temp_dict) + return return_list
      @@ -613,7 +789,7 @@

      Functions

      Print out inventory devices and groups.

      Source code -
      def display_inventory(my_devices):
      +
      def display_inventory(my_devices: Dict[str, Union[List[str], Dict[str, Any]]]) -> None:
           """Print out inventory devices and groups."""
           inventory_groups = ["all"]
           inventory_devices = []
      @@ -644,7 +820,7 @@ 

      Functions

      Ensure directory exists. Create if necessary.

      Source code -
      def ensure_dir_exists(verify_dir):
      +
      def ensure_dir_exists(verify_dir: str) -> None:
           """Ensure directory exists. Create if necessary."""
           if not os.path.exists(verify_dir):
               # Doesn't exist create dir
      @@ -663,16 +839,16 @@ 

      Functions

      Source code -
      def f_exec_time(func):
      +
      def f_exec_time(func: F) -> F:
           @functools.wraps(func)
      -    def wrapper_decorator(*args, **kwargs):
      +    def wrapper_decorator(*args: Any, **kwargs: Any) -> Any:
               start_time = datetime.now()
               result = func(*args, **kwargs)
               end_time = datetime.now()
               print(f"Elapsed time: {end_time - start_time}")
               return result
       
      -    return wrapper_decorator
      + return cast(F, wrapper_decorator)
      @@ -687,7 +863,9 @@

      Functions

      Also allow NETMIKO_TOOLS_CFG to point directly at a file

      Source code -
      def find_cfg_file(file_name=None):
      +
      def find_cfg_file(
      +    file_name: Union[str, bytes, "PathLike[Any]", None] = None
      +) -> Union[str, bytes, "PathLike[Any]"]:
           """
           Search for netmiko_tools inventory file in the following order:
           NETMIKO_TOOLS_CFG environment variable
      @@ -696,9 +874,8 @@ 

      Functions

      Look for file named: .netmiko.yml or netmiko.yml Also allow NETMIKO_TOOLS_CFG to point directly at a file """ - if file_name: - if os.path.isfile(file_name): - return file_name + if file_name and os.path.isfile(file_name): + return file_name optional_path = os.environ.get("NETMIKO_TOOLS_CFG", "") if os.path.isfile(optional_path): return optional_path @@ -722,7 +899,7 @@

      Functions

      Check environment first, then default dir

      Source code -
      def find_netmiko_dir():
      +
      def find_netmiko_dir() -> Tuple[str, str]:
           """Check environment first, then default dir"""
           try:
               netmiko_base_dir = os.environ["NETMIKO_DIR"]
      @@ -744,7 +921,12 @@ 

      Functions

      then you must use an CliTable index file.

      Source code -
      def get_structured_data(raw_output, platform=None, command=None, template=None):
      +
      def get_structured_data_textfsm(
      +    raw_output: str,
      +    platform: Optional[str] = None,
      +    command: Optional[str] = None,
      +    template: Optional[str] = None,
      +) -> Union[str, List[Dict[str, str]]]:
           """
           Convert raw CLI output to structured data using TextFSM template.
       
      @@ -764,13 +946,20 @@ 

      Functions

      template_dir = get_template_dir() index_file = os.path.join(template_dir, "index") textfsm_obj = clitable.CliTable(index_file, template_dir) - return _textfsm_parse(textfsm_obj, raw_output, attrs) + output = _textfsm_parse(textfsm_obj, raw_output, attrs) + + # Retry the output if "cisco_xe" and not structured data + if platform and "cisco_xe" in platform: + if not isinstance(output, list): + attrs["Platform"] = "cisco_ios" + output = _textfsm_parse(textfsm_obj, raw_output, attrs) + return output else: template_path = Path(os.path.expanduser(template)) template_file = template_path.name - template_dir = template_path.parents[0] + template_dir_alt = template_path.parents[0] # CliTable with no index will fall-back to a TextFSM parsing behavior - textfsm_obj = clitable.CliTable(template_dir=template_dir) + textfsm_obj = clitable.CliTable(template_dir=template_dir_alt) return _textfsm_parse( textfsm_obj, raw_output, attrs, template_file=template_file )
      @@ -783,7 +972,9 @@

      Functions

      Source code -
      def get_structured_data_genie(raw_output, platform, command):
      +
      def get_structured_data_genie(
      +    raw_output: str, platform: str, command: str
      +) -> Union[str, Dict[str, Any]]:
           if not sys.version_info >= (3, 4):
               raise ValueError("Genie requires Python >= 3.4")
       
      @@ -808,8 +999,8 @@ 

      Functions

      os = None # platform might be _ssh, _telnet, _serial strip that off if platform.count("_") > 1: - base_platform = platform.split("_")[:-1] - base_platform = "_".join(base_platform) + base_list = platform.split("_")[:-1] + base_platform = "_".join(base_list) else: base_platform = platform @@ -825,35 +1016,88 @@

      Functions

      try: # Test whether there is a parser for given command (return Exception if fails) get_parser(command, device) - parsed_output = device.parse(command, output=raw_output) + parsed_output: Dict[str, Any] = device.parse(command, output=raw_output) return parsed_output except Exception: return raw_output
      +
      +def get_structured_data_textfsm(raw_output, platform=None, command=None, template=None) +
      +
      +

      Convert raw CLI output to structured data using TextFSM template.

      +

      You can use a straight TextFSM file i.e. specify "template". If no template is specified, +then you must use an CliTable index file.

      +
      +Source code +
      def get_structured_data_textfsm(
      +    raw_output: str,
      +    platform: Optional[str] = None,
      +    command: Optional[str] = None,
      +    template: Optional[str] = None,
      +) -> Union[str, List[Dict[str, str]]]:
      +    """
      +    Convert raw CLI output to structured data using TextFSM template.
      +
      +    You can use a straight TextFSM file i.e. specify "template". If no template is specified,
      +    then you must use an CliTable index file.
      +    """
      +    if platform is None or command is None:
      +        attrs = {}
      +    else:
      +        attrs = {"Command": command, "Platform": platform}
      +
      +    if template is None:
      +        if attrs == {}:
      +            raise ValueError(
      +                "Either 'platform/command' or 'template' must be specified."
      +            )
      +        template_dir = get_template_dir()
      +        index_file = os.path.join(template_dir, "index")
      +        textfsm_obj = clitable.CliTable(index_file, template_dir)
      +        output = _textfsm_parse(textfsm_obj, raw_output, attrs)
      +
      +        # Retry the output if "cisco_xe" and not structured data
      +        if platform and "cisco_xe" in platform:
      +            if not isinstance(output, list):
      +                attrs["Platform"] = "cisco_ios"
      +                output = _textfsm_parse(textfsm_obj, raw_output, attrs)
      +        return output
      +    else:
      +        template_path = Path(os.path.expanduser(template))
      +        template_file = template_path.name
      +        template_dir_alt = template_path.parents[0]
      +        # CliTable with no index will fall-back to a TextFSM parsing behavior
      +        textfsm_obj = clitable.CliTable(template_dir=template_dir_alt)
      +        return _textfsm_parse(
      +            textfsm_obj, raw_output, attrs, template_file=template_file
      +        )
      +
      +
      -def get_structured_data_ttp(raw_output, template=None) +def get_structured_data_ttp(raw_output, template)

      Convert raw CLI output to structured data using TTP template.

      You can use a straight TextFSM file i.e. specify "template"

      Source code -
      def get_structured_data_ttp(raw_output, template=None):
      +
      def get_structured_data_ttp(raw_output: str, template: str) -> Union[str, List[Any]]:
           """
           Convert raw CLI output to structured data using TTP template.
       
           You can use a straight TextFSM file i.e. specify "template"
           """
           if not TTP_INSTALLED:
      -        msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n"
      +        msg = "\nTTP is not installed. Please PIP install ttp:\n\npip install ttp\n"
               raise ValueError(msg)
       
           try:
      -        if template:
      -            ttp_parser = ttp(data=raw_output, template=template)
      -            ttp_parser.parse(one=True)
      -            return ttp_parser.result(format="raw")
      +        ttp_parser = ttp(data=raw_output, template=template)
      +        ttp_parser.parse(one=True)
      +        result: List[Any] = ttp_parser.result(format="raw")
      +        return result
           except Exception:
               return raw_output
      @@ -866,19 +1110,19 @@

      Functions

      Order of preference is: 1) Find directory in NET_TEXTFSM Environment Variable. 2) Check for pip installed ntc-templates location in this environment. -3) ~/ntc-templates/templates.

      +3) ~/ntc-templates/ntc_templates/templates.

      If index file is not found in any of these locations, raise ValueError

      :return: directory containing the TextFSM index file

      Source code -
      def get_template_dir(_skip_ntc_package=False):
      +
      def get_template_dir(_skip_ntc_package: bool = False) -> str:
           """
           Find and return the directory containing the TextFSM index file.
       
           Order of preference is:
           1) Find directory in `NET_TEXTFSM` Environment Variable.
           2) Check for pip installed `ntc-templates` location in this environment.
      -    3) ~/ntc-templates/templates.
      +    3) ~/ntc-templates/ntc_templates/templates.
       
           If `index` file is not found in any of these locations, raise ValueError
       
      @@ -908,19 +1152,21 @@ 

      Functions

      else: # Try 'pip installed' ntc-templates try: - with importresources_path( - package="ntc_templates", resource="templates" + with pkg_resources.path( + package="ntc_templates", resource="parse.py" ) as posix_path: # Example: /opt/venv/netmiko/lib/python3.8/site-packages/ntc_templates/templates - template_dir = str(posix_path) + template_dir = str(posix_path.parent.joinpath("templates")) # This is for Netmiko automated testing if _skip_ntc_package: raise ModuleNotFoundError() except ModuleNotFoundError: - # Finally check in ~/ntc-templates/templates + # Finally check in ~/ntc-templates/ntc_templates/templates home_dir = os.path.expanduser("~") - template_dir = os.path.join(home_dir, "ntc-templates", "templates") + template_dir = os.path.join( + home_dir, "ntc-templates", "ntc_templates", "templates" + ) index = os.path.join(template_dir, "index") if not os.path.isdir(template_dir) or not os.path.isfile(index): @@ -935,7 +1181,7 @@

      Functions

      Find and load .netmiko.yml file.

      Source code -
      def load_devices(file_name=None):
      +
      def load_devices(file_name: Union[str, bytes, "PathLike[Any]", None] = None) -> Any:
           """Find and load .netmiko.yml file."""
           yaml_devices_file = find_cfg_file(file_name)
           return load_yaml_file(yaml_devices_file)
      @@ -948,7 +1194,7 @@

      Functions

      Read YAML file.

      Source code -
      def load_yaml_file(yaml_file):
      +
      def load_yaml_file(yaml_file: Union[str, bytes, "PathLike[Any]"]) -> Any:
           """Read YAML file."""
           try:
               import yaml
      @@ -958,7 +1204,7 @@ 

      Functions

      with io.open(yaml_file, "rt", encoding="utf-8") as fname: return yaml.safe_load(fname) except IOError: - sys.exit(f"Unable to open YAML file: {yaml_file}")
      + sys.exit("Unable to open YAML file")
      @@ -968,9 +1214,9 @@

      Functions

      Source code -
      def m_exec_time(func):
      +
      def m_exec_time(func: F) -> F:
           @functools.wraps(func)
      -    def wrapper_decorator(self, *args, **kwargs):
      +    def wrapper_decorator(self: Any, *args: Any, **kwargs: Any) -> Any:
               start_time = datetime.now()
               result = func(self, *args, **kwargs)
               end_time = datetime.now()
      @@ -978,7 +1224,7 @@ 

      Functions

      print(f"{method_name}: Elapsed time: {end_time - start_time}") return result - return wrapper_decorator
      + return cast(F, wrapper_decorator)
      @@ -988,7 +1234,9 @@

      Functions

      Dynamically create 'all' group.

      Source code -
      def obtain_all_devices(my_devices):
      +
      def obtain_all_devices(
      +    my_devices: Dict[str, Union[List[str], Dict[str, Any]]]
      +) -> Dict[str, Dict[str, Any]]:
           """Dynamically create 'all' group."""
           new_devices = {}
           for device_name, device_or_group in my_devices.items():
      @@ -1005,7 +1253,7 @@ 

      Functions

      Create file name based on device_name.

      Source code -
      def obtain_netmiko_filename(device_name):
      +
      def obtain_netmiko_filename(device_name: str) -> str:
           """Create file name based on device_name."""
           _, netmiko_full_dir = find_netmiko_dir()
           return f"{netmiko_full_dir}/{device_name}.txt"
      @@ -1016,31 +1264,28 @@

      Functions

      Helper function to run TTP template parsing.

      -

      :param connection: Netmiko connection object -:type connection: obj

      -

      :param template: TTP template -:type template: str

      -

      :param res_kwargs: **res_kwargs arguments for TTP result method -:type res_kwargs: dict

      -

      :param kwargs: **kwargs for TTP object instantiation -:type kwargs: dict

      +

      :param connection: Netmiko connection object

      +

      :param template: TTP template

      +

      :param res_kwargs: **res_kwargs arguments for TTP result method

      +

      :param kwargs: **kwargs for TTP object instantiation

      Source code -
      def run_ttp_template(connection, template, res_kwargs, **kwargs):
      +
      def run_ttp_template(
      +    connection: "BaseConnection",
      +    template: Union[str, bytes, "PathLike[Any]"],
      +    res_kwargs: Dict[str, Any],
      +    **kwargs: Any,
      +) -> Any:
           """
           Helper function to run TTP template parsing.
       
           :param connection: Netmiko connection object
      -    :type connection: obj
       
           :param template: TTP template
      -    :type template: str
       
           :param res_kwargs: ``**res_kwargs`` arguments for TTP result method
      -    :type res_kwargs: dict
       
           :param kwargs: ``**kwargs`` for TTP object instantiation
      -    :type kwargs: dict
           """
           if not TTP_INSTALLED:
               msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n"
      @@ -1076,11 +1321,11 @@ 

      Functions

      continue # collect commands output from device - output = [ + out_list = [ getattr(connection, method)(command_string=command, **method_kwargs) for command in commands ] - output = "\n".join(output) + output = "\n".join(out_list) # add collected output to TTP parser object parser.add_input( @@ -1100,16 +1345,70 @@

      Functions

      Override function cmd_verify argument with global setting.

      Source code -
      def select_cmd_verify(func):
      +
      def select_cmd_verify(func: F) -> F:
           """Override function cmd_verify argument with global setting."""
       
           @functools.wraps(func)
      -    def wrapper_decorator(self, *args, **kwargs):
      +    def wrapper_decorator(self: "BaseConnection", *args: Any, **kwargs: Any) -> Any:
               if self.global_cmd_verify is not None:
                   kwargs["cmd_verify"] = self.global_cmd_verify
               return func(self, *args, **kwargs)
       
      -    return wrapper_decorator
      + return cast(F, wrapper_decorator)
      +
      +
      +
      +def structured_data_converter(raw_data, command, platform, use_textfsm=False, use_ttp=False, use_genie=False, textfsm_template=None, ttp_template=None) +
      +
      +

      Try structured data converters in the following order: TextFSM, TTP, Genie.

      +

      Return the first structured data found, else return the raw_data as-is.

      +
      +Source code +
      def structured_data_converter(
      +    raw_data: str,
      +    command: str,
      +    platform: str,
      +    use_textfsm: bool = False,
      +    use_ttp: bool = False,
      +    use_genie: bool = False,
      +    textfsm_template: Optional[str] = None,
      +    ttp_template: Optional[str] = None,
      +) -> Union[str, List[Any], Dict[str, Any]]:
      +    """
      +    Try structured data converters in the following order: TextFSM, TTP, Genie.
      +
      +    Return the first structured data found, else return the raw_data as-is.
      +    """
      +    command = command.strip()
      +    if use_textfsm:
      +        structured_output_tfsm = get_structured_data_textfsm(
      +            raw_data, platform=platform, command=command, template=textfsm_template
      +        )
      +        if not isinstance(structured_output_tfsm, str):
      +            return structured_output_tfsm
      +
      +    if use_ttp:
      +        if ttp_template is None:
      +            msg = """
      +The argument 'ttp_template=/path/to/template.ttp' must be set when use_ttp=True
      +"""
      +            raise ValueError(msg)
      +        else:
      +            structured_output_ttp = get_structured_data_ttp(
      +                raw_data, template=ttp_template
      +            )
      +
      +        if not isinstance(structured_output_ttp, str):
      +            return structured_output_ttp
      +
      +    if use_genie:
      +        structured_output_genie = get_structured_data_genie(
      +            raw_data, platform=platform, command=command
      +        )
      +        if not isinstance(structured_output_genie, str):
      +            return structured_output_genie
      +    return raw_data
      @@ -1119,19 +1418,17 @@

      Functions

      Legacy for Python2 and Python3 compatible byte stream.

      Source code -
      def write_bytes(out_data, encoding="ascii"):
      +
      def write_bytes(out_data: AnyStr, encoding: str = "ascii") -> bytes:
           """Legacy for Python2 and Python3 compatible byte stream."""
           if sys.version_info[0] >= 3:
      -        if isinstance(out_data, type("")):
      +        if isinstance(out_data, str):
                   if encoding == "utf-8":
                       return out_data.encode("utf-8")
                   else:
                       return out_data.encode("ascii", "ignore")
      -        elif isinstance(out_data, type(b"")):
      +        elif isinstance(out_data, bytes):
                   return out_data
      -    msg = "Invalid value for out_data neither unicode nor byte string: {}".format(
      -        out_data
      -    )
      +    msg = f"Invalid value for out_data neither unicode nor byte string: {str(out_data)}"
           raise ValueError(msg)
      @@ -1142,7 +1439,7 @@

      Functions

      Source code -
      def write_tmp_file(device_name, output):
      +
      def write_tmp_file(device_name: str, output: str) -> str:
           file_name = obtain_netmiko_filename(device_name)
           with open(file_name, "w") as f:
               f.write(output)
      @@ -1167,6 +1464,7 @@ 

      Index

    • Functions

      diff --git a/docs/netmiko/vyos/index.html b/docs/netmiko/vyos/index.html index ef027acb5..c8acadf6d 100644 --- a/docs/netmiko/vyos/index.html +++ b/docs/netmiko/vyos/index.html @@ -45,7 +45,7 @@

      Classes

      class VyOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Implement methods for interacting with VyOS network devices.

      @@ -53,138 +53,111 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
    • -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code -
      class VyOSSSH(CiscoSSHConnection):
      +
      class VyOSSSH(NoEnable, CiscoSSHConnection):
           """Implement methods for interacting with VyOS network devices."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self._test_channel_read()
               self.set_base_prompt()
      @@ -194,42 +167,43 @@ 

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def check_config_mode(self, check_string="#"): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks if the device is in configuration mode""" - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"[edit]"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\[edit\]", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r"exit"): + def exit_config_mode( + self, exit_config: str = "exit", pattern: str = r"exit" + ) -> str: """Exit configuration mode""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output = self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Cannot exit: configuration modified" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "exit discard", strip_prompt=False, strip_command=False ) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output - def commit(self, comment="", delay_factor=0.1): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -241,8 +215,13 @@

      Classes

      comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = ["Failed to generate committed config", "Commit failed"] command_string = "commit" @@ -250,11 +229,11 @@

      Classes

      command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if any(x in output for x in error_marker): @@ -262,30 +241,54 @@

      Classes

      return output def set_base_prompt( - self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = "$", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" + + # VyOS can have a third terminator; switch to a pattern solution + if pattern is None: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + third_terminator = re.escape(">") + pattern = rf"({pri_term}|{alt_term}|{third_terminator})" + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) # Set prompt to user@hostname (remove two additional characters) self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """Remain in configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def save_config(self, *args, **kwargs): + def save_config( + self, + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Not Implemented""" raise NotImplementedError

      Ancestors

        +
      • NoEnable
      • CiscoSSHConnection
      • CiscoBaseConnection
      • BaseConnection
      • @@ -297,31 +300,19 @@

        Subclasses

        Methods

        -def check_config_mode(self, check_string='#') +def check_config_mode(self, check_string='#', pattern='')

        Checks if the device is in configuration mode

        Source code -
        def check_config_mode(self, check_string="#"):
        +
        def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
             """Checks if the device is in configuration mode"""
        -    return super().check_config_mode(check_string=check_string)
        -
        -
        -
        -def check_enable_mode(self, *args, **kwargs) -
        -
        -

        No enable mode on VyOS.

        -
        -Source code -
        def check_enable_mode(self, *args, **kwargs):
        -    """No enable mode on VyOS."""
        -    pass
        + return super().check_config_mode(check_string=check_string, pattern=pattern)
      -def commit(self, comment='', delay_factor=0.1) +def commit(self, comment='', read_timeout=120.0, delay_factor=None)

      Commit the candidate configuration.

      @@ -330,10 +321,16 @@

      Methods

      default: command_string = commit comment: -command_string = commit comment

      +command_string = commit comment

      +

      delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

      Source code -
      def commit(self, comment="", delay_factor=0.1):
      +
      def commit(
      +    self,
      +    comment: str = "",
      +    read_timeout: float = 120.0,
      +    delay_factor: Optional[float] = None,
      +) -> str:
           """
           Commit the candidate configuration.
       
      @@ -345,8 +342,13 @@ 

      Methods

      comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = ["Failed to generate committed config", "Commit failed"] command_string = "commit" @@ -354,11 +356,11 @@

      Methods

      command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if any(x in output for x in error_marker): @@ -366,30 +368,6 @@

      Methods

      return output
      -
      -def config_mode(self, config_command='configure', pattern='[edit]') -
      -
      -

      Enter configuration mode.

      -
      -Source code -
      def config_mode(self, config_command="configure", pattern=r"[edit]"):
      -    """Enter configuration mode."""
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      -
      -
      -
      -def enable(self, *args, **kwargs) -
      -
      -

      No enable mode on VyOS.

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """No enable mode on VyOS."""
      -    pass
      -
      -
      def exit_config_mode(self, exit_config='exit', pattern='exit')
      @@ -397,15 +375,17 @@

      Methods

      Exit configuration mode

      Source code -
      def exit_config_mode(self, exit_config="exit", pattern=r"exit"):
      +
      def exit_config_mode(
      +    self, exit_config: str = "exit", pattern: str = r"exit"
      +) -> str:
           """Exit configuration mode"""
           output = ""
           if self.check_config_mode():
      -        output = self.send_command_timing(
      +        output = self._send_command_timing_str(
                   exit_config, strip_prompt=False, strip_command=False
               )
               if "Cannot exit: configuration modified" in output:
      -            output += self.send_command_timing(
      +            output += self._send_command_timing_str(
                       "exit discard", strip_prompt=False, strip_command=False
                   )
               if self.check_config_mode():
      @@ -413,26 +393,19 @@ 

      Methods

      return output
      -
      -def exit_enable_mode(self, *args, **kwargs) -
      -
      -

      No enable mode on VyOS.

      -
      -Source code -
      def exit_enable_mode(self, *args, **kwargs):
      -    """No enable mode on VyOS."""
      -    pass
      -
      -
      -def save_config(self, *args, **kwargs) +def save_config(self, cmd='copy running-config startup-config', confirm=False, confirm_response='')

      Not Implemented

      Source code -
      def save_config(self, *args, **kwargs):
      +
      def save_config(
      +    self,
      +    cmd: str = "copy running-config startup-config",
      +    confirm: bool = False,
      +    confirm_response: str = "",
      +) -> str:
           """Not Implemented"""
           raise NotImplementedError
      @@ -444,7 +417,12 @@

      Methods

      Remain in configuration mode.

      Source code -
      def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
      +
      def send_config_set(
      +    self,
      +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
      +    exit_config_mode: bool = False,
      +    **kwargs: Any,
      +) -> str:
           """Remain in configuration mode."""
           return super().send_config_set(
               config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
      @@ -458,7 +436,7 @@ 

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           self._test_channel_read()
           self.set_base_prompt()
      @@ -470,20 +448,33 @@ 

      Methods

      -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

      Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

      Source code
      def set_base_prompt(
      -    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
      -):
      +    self,
      +    pri_prompt_terminator: str = "$",
      +    alt_prompt_terminator: str = "#",
      +    delay_factor: float = 1.0,
      +    pattern: Optional[str] = None,
      +) -> str:
           """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
      +
      +    # VyOS can have a third terminator; switch to a pattern solution
      +    if pattern is None:
      +        pri_term = re.escape(pri_prompt_terminator)
      +        alt_term = re.escape(alt_prompt_terminator)
      +        third_terminator = re.escape(">")
      +        pattern = rf"({pri_term}|{alt_term}|{third_terminator})"
      +
           prompt = super().set_base_prompt(
               pri_prompt_terminator=pri_prompt_terminator,
               alt_prompt_terminator=alt_prompt_terminator,
               delay_factor=delay_factor,
      +        pattern=pattern,
           )
           # Set prompt to user@hostname (remove two additional characters)
           self.base_prompt = prompt[:-2].strip()
      @@ -495,19 +486,22 @@ 

      Inherited members

      • CiscoSSHConnection:
          +
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • +
        • config_mode
        • disable_paging
        • disconnect
        • +
        • enable
        • establish_connection
        • +
        • exit_enable_mode
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -517,6 +511,7 @@

          Inherited members

        • send_command_expect
        • send_command_timing
        • send_config_from_file
        • +
        • send_multiline
        • set_terminal_width
        • special_login_handler
        • strip_ansi_escape_codes
        • @@ -554,12 +549,8 @@

          Index

          VyOSSSH

          • check_config_mode
          • -
          • check_enable_mode
          • commit
          • -
          • config_mode
          • -
          • enable
          • exit_config_mode
          • -
          • exit_enable_mode
          • save_config
          • send_config_set
          • session_preparation
          • diff --git a/docs/netmiko/vyos/vyos_ssh.html b/docs/netmiko/vyos/vyos_ssh.html index b713d8eb0..c7a3b4491 100644 --- a/docs/netmiko/vyos/vyos_ssh.html +++ b/docs/netmiko/vyos/vyos_ssh.html @@ -22,14 +22,19 @@

            Module netmiko.vyos.vyos_ssh

            Source code -
            import time
            +
            from typing import Optional, Union, Sequence, TextIO, Any
            +import time
            +import warnings
            +import re
            +from netmiko.no_enable import NoEnable
            +from netmiko.base_connection import DELAY_FACTOR_DEPR_SIMPLE_MSG
             from netmiko.cisco_base_connection import CiscoSSHConnection
             
             
            -class VyOSSSH(CiscoSSHConnection):
            +class VyOSSSH(NoEnable, CiscoSSHConnection):
                 """Implement methods for interacting with VyOS network devices."""
             
            -    def session_preparation(self):
            +    def session_preparation(self) -> None:
                     """Prepare the session after the connection has been established."""
                     self._test_channel_read()
                     self.set_base_prompt()
            @@ -39,42 +44,43 @@ 

            Module netmiko.vyos.vyos_ssh

            time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def check_config_mode(self, check_string="#"): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks if the device is in configuration mode""" - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"[edit]"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\[edit\]", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r"exit"): + def exit_config_mode( + self, exit_config: str = "exit", pattern: str = r"exit" + ) -> str: """Exit configuration mode""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output = self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Cannot exit: configuration modified" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "exit discard", strip_prompt=False, strip_command=False ) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output - def commit(self, comment="", delay_factor=0.1): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -86,8 +92,13 @@

            Module netmiko.vyos.vyos_ssh

            comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = ["Failed to generate committed config", "Commit failed"] command_string = "commit" @@ -95,11 +106,11 @@

            Module netmiko.vyos.vyos_ssh

            command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if any(x in output for x in error_marker): @@ -107,25 +118,48 @@

            Module netmiko.vyos.vyos_ssh

            return output def set_base_prompt( - self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = "$", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" + + # VyOS can have a third terminator; switch to a pattern solution + if pattern is None: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + third_terminator = re.escape(">") + pattern = rf"({pri_term}|{alt_term}|{third_terminator})" + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) # Set prompt to user@hostname (remove two additional characters) self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """Remain in configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def save_config(self, *args, **kwargs): + def save_config( + self, + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Not Implemented""" raise NotImplementedError
            @@ -141,7 +175,7 @@

            Classes

            class VyOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Implement methods for interacting with VyOS network devices.

            @@ -149,138 +183,111 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code -
      class VyOSSSH(CiscoSSHConnection):
      +
      class VyOSSSH(NoEnable, CiscoSSHConnection):
           """Implement methods for interacting with VyOS network devices."""
       
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self._test_channel_read()
               self.set_base_prompt()
      @@ -290,42 +297,43 @@ 

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def enable(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def exit_enable_mode(self, *args, **kwargs): - """No enable mode on VyOS.""" - pass - - def check_config_mode(self, check_string="#"): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks if the device is in configuration mode""" - return super().check_config_mode(check_string=check_string) - - def config_mode(self, config_command="configure", pattern=r"[edit]"): - """Enter configuration mode.""" - return super().config_mode(config_command=config_command, pattern=pattern) + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode( + self, + config_command: str = "configure", + pattern: str = r"\[edit\]", + re_flags: int = 0, + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern=r"exit"): + def exit_config_mode( + self, exit_config: str = "exit", pattern: str = r"exit" + ) -> str: """Exit configuration mode""" output = "" if self.check_config_mode(): - output = self.send_command_timing( + output = self._send_command_timing_str( exit_config, strip_prompt=False, strip_command=False ) if "Cannot exit: configuration modified" in output: - output += self.send_command_timing( + output += self._send_command_timing_str( "exit discard", strip_prompt=False, strip_command=False ) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") return output - def commit(self, comment="", delay_factor=0.1): + def commit( + self, + comment: str = "", + read_timeout: float = 120.0, + delay_factor: Optional[float] = None, + ) -> str: """ Commit the candidate configuration. @@ -337,8 +345,13 @@

      Classes

      comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = ["Failed to generate committed config", "Commit failed"] command_string = "commit" @@ -346,11 +359,11 @@

      Classes

      command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if any(x in output for x in error_marker): @@ -358,30 +371,54 @@

      Classes

      return output def set_base_prompt( - self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 - ): + self, + pri_prompt_terminator: str = "$", + alt_prompt_terminator: str = "#", + delay_factor: float = 1.0, + pattern: Optional[str] = None, + ) -> str: """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" + + # VyOS can have a third terminator; switch to a pattern solution + if pattern is None: + pri_term = re.escape(pri_prompt_terminator) + alt_term = re.escape(alt_prompt_terminator) + third_terminator = re.escape(">") + pattern = rf"({pri_term}|{alt_term}|{third_terminator})" + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, + pattern=pattern, ) # Set prompt to user@hostname (remove two additional characters) self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + def send_config_set( + self, + config_commands: Union[str, Sequence[str], TextIO, None] = None, + exit_config_mode: bool = False, + **kwargs: Any, + ) -> str: """Remain in configuration mode.""" return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) - def save_config(self, *args, **kwargs): + def save_config( + self, + cmd: str = "copy running-config startup-config", + confirm: bool = False, + confirm_response: str = "", + ) -> str: """Not Implemented""" raise NotImplementedError

      Ancestors

        +
      • NoEnable
      • CiscoSSHConnection
      • CiscoBaseConnection
      • BaseConnection
      • @@ -393,31 +430,19 @@

        Subclasses

        Methods

        -def check_config_mode(self, check_string='#') +def check_config_mode(self, check_string='#', pattern='')

        Checks if the device is in configuration mode

        Source code -
        def check_config_mode(self, check_string="#"):
        +
        def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
             """Checks if the device is in configuration mode"""
        -    return super().check_config_mode(check_string=check_string)
        -
        -
        -
        -def check_enable_mode(self, *args, **kwargs) -
        -
        -

        No enable mode on VyOS.

        -
        -Source code -
        def check_enable_mode(self, *args, **kwargs):
        -    """No enable mode on VyOS."""
        -    pass
        + return super().check_config_mode(check_string=check_string, pattern=pattern)
      -def commit(self, comment='', delay_factor=0.1) +def commit(self, comment='', read_timeout=120.0, delay_factor=None)

      Commit the candidate configuration.

      @@ -426,10 +451,16 @@

      Methods

      default: command_string = commit comment: -command_string = commit comment

      +command_string = commit comment

      +

      delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5.

      Source code -
      def commit(self, comment="", delay_factor=0.1):
      +
      def commit(
      +    self,
      +    comment: str = "",
      +    read_timeout: float = 120.0,
      +    delay_factor: Optional[float] = None,
      +) -> str:
           """
           Commit the candidate configuration.
       
      @@ -441,8 +472,13 @@ 

      Methods

      comment: command_string = commit comment <comment> + delay_factor: Deprecated in Netmiko 4.x. Will be eliminated in Netmiko 5. + """ - delay_factor = self.select_delay_factor(delay_factor) + + if delay_factor is not None: + warnings.warn(DELAY_FACTOR_DEPR_SIMPLE_MSG, DeprecationWarning) + error_marker = ["Failed to generate committed config", "Commit failed"] command_string = "commit" @@ -450,11 +486,11 @@

      Methods

      command_string += f' comment "{comment}"' output = self.config_mode() - output += self.send_command_expect( + output += self._send_command_str( command_string, strip_prompt=False, strip_command=False, - delay_factor=delay_factor, + read_timeout=read_timeout, ) if any(x in output for x in error_marker): @@ -462,30 +498,6 @@

      Methods

      return output
      -
      -def config_mode(self, config_command='configure', pattern='[edit]') -
      -
      -

      Enter configuration mode.

      -
      -Source code -
      def config_mode(self, config_command="configure", pattern=r"[edit]"):
      -    """Enter configuration mode."""
      -    return super().config_mode(config_command=config_command, pattern=pattern)
      -
      -
      -
      -def enable(self, *args, **kwargs) -
      -
      -

      No enable mode on VyOS.

      -
      -Source code -
      def enable(self, *args, **kwargs):
      -    """No enable mode on VyOS."""
      -    pass
      -
      -
      def exit_config_mode(self, exit_config='exit', pattern='exit')
      @@ -493,15 +505,17 @@

      Methods

      Exit configuration mode

      Source code -
      def exit_config_mode(self, exit_config="exit", pattern=r"exit"):
      +
      def exit_config_mode(
      +    self, exit_config: str = "exit", pattern: str = r"exit"
      +) -> str:
           """Exit configuration mode"""
           output = ""
           if self.check_config_mode():
      -        output = self.send_command_timing(
      +        output = self._send_command_timing_str(
                   exit_config, strip_prompt=False, strip_command=False
               )
               if "Cannot exit: configuration modified" in output:
      -            output += self.send_command_timing(
      +            output += self._send_command_timing_str(
                       "exit discard", strip_prompt=False, strip_command=False
                   )
               if self.check_config_mode():
      @@ -509,26 +523,19 @@ 

      Methods

      return output
      -
      -def exit_enable_mode(self, *args, **kwargs) -
      -
      -

      No enable mode on VyOS.

      -
      -Source code -
      def exit_enable_mode(self, *args, **kwargs):
      -    """No enable mode on VyOS."""
      -    pass
      -
      -
      -def save_config(self, *args, **kwargs) +def save_config(self, cmd='copy running-config startup-config', confirm=False, confirm_response='')

      Not Implemented

      Source code -
      def save_config(self, *args, **kwargs):
      +
      def save_config(
      +    self,
      +    cmd: str = "copy running-config startup-config",
      +    confirm: bool = False,
      +    confirm_response: str = "",
      +) -> str:
           """Not Implemented"""
           raise NotImplementedError
      @@ -540,7 +547,12 @@

      Methods

      Remain in configuration mode.

      Source code -
      def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
      +
      def send_config_set(
      +    self,
      +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
      +    exit_config_mode: bool = False,
      +    **kwargs: Any,
      +) -> str:
           """Remain in configuration mode."""
           return super().send_config_set(
               config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
      @@ -554,7 +566,7 @@ 

      Methods

      Prepare the session after the connection has been established.

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """Prepare the session after the connection has been established."""
           self._test_channel_read()
           self.set_base_prompt()
      @@ -566,20 +578,33 @@ 

      Methods

      -def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1) +def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#', delay_factor=1.0, pattern=None)

      Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.

      Source code
      def set_base_prompt(
      -    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1
      -):
      +    self,
      +    pri_prompt_terminator: str = "$",
      +    alt_prompt_terminator: str = "#",
      +    delay_factor: float = 1.0,
      +    pattern: Optional[str] = None,
      +) -> str:
           """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
      +
      +    # VyOS can have a third terminator; switch to a pattern solution
      +    if pattern is None:
      +        pri_term = re.escape(pri_prompt_terminator)
      +        alt_term = re.escape(alt_prompt_terminator)
      +        third_terminator = re.escape(">")
      +        pattern = rf"({pri_term}|{alt_term}|{third_terminator})"
      +
           prompt = super().set_base_prompt(
               pri_prompt_terminator=pri_prompt_terminator,
               alt_prompt_terminator=alt_prompt_terminator,
               delay_factor=delay_factor,
      +        pattern=pattern,
           )
           # Set prompt to user@hostname (remove two additional characters)
           self.base_prompt = prompt[:-2].strip()
      @@ -591,19 +616,22 @@ 

      Inherited members

      • CiscoSSHConnection:
          +
        • check_enable_mode
        • cleanup
        • clear_buffer
        • -
        • close_session_log
        • +
        • config_mode
        • disable_paging
        • disconnect
        • +
        • enable
        • establish_connection
        • +
        • exit_enable_mode
        • find_prompt
        • is_alive
        • normalize_cmd
        • normalize_linefeeds
        • -
        • open_session_log
        • paramiko_cleanup
        • read_channel
        • +
        • read_channel_timing
        • read_until_pattern
        • read_until_prompt
        • read_until_prompt_or_pattern
        • @@ -613,6 +641,7 @@

          Inherited members

        • send_command_expect
        • send_command_timing
        • send_config_from_file
        • +
        • send_multiline
        • set_terminal_width
        • special_login_handler
        • strip_ansi_escape_codes
        • @@ -645,12 +674,8 @@

          Index

          VyOSSSH

          • check_config_mode
          • -
          • check_enable_mode
          • commit
          • -
          • config_mode
          • -
          • enable
          • exit_config_mode
          • -
          • exit_enable_mode
          • save_config
          • send_config_set
          • session_preparation
          • diff --git a/docs/netmiko/watchguard/fireware_ssh.html b/docs/netmiko/watchguard/fireware_ssh.html index d47c6ab4f..8546dea8f 100644 --- a/docs/netmiko/watchguard/fireware_ssh.html +++ b/docs/netmiko/watchguard/fireware_ssh.html @@ -23,6 +23,8 @@

            Module netmiko.watchguard.fireware_ssh

            Source code
            import time
            +from typing import Any
            +
             from netmiko.base_connection import BaseConnection
             
             
            @@ -31,7 +33,7 @@ 

            Module netmiko.watchguard.fireware_ssh

            Implements methods for communicating with Watchguard Firebox firewalls. """ - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. @@ -43,19 +45,23 @@

            Module netmiko.watchguard.fireware_ssh

            time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure", pattern="#"): - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, config_command: str = "configure", pattern: str = r"\#", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern="#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """No save config on Watchguard.""" pass
            @@ -71,7 +77,7 @@

            Classes

            class WatchguardFirewareSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

            Implements methods for communicating with Watchguard Firebox firewalls.

            @@ -79,131 +85,104 @@

            Classes

            :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -212,7 +191,7 @@

      Classes

      Implements methods for communicating with Watchguard Firebox firewalls. """ - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. @@ -224,19 +203,23 @@

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure", pattern="#"): - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, config_command: str = "configure", pattern: str = r"\#", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern="#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """No save config on Watchguard.""" pass
      @@ -253,7 +236,7 @@

      Methods

      Checks if the device is in configuration mode or not.

      Source code -
      def check_config_mode(self, check_string=")#", pattern="#"):
      +
      def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
           """
           Checks if the device is in configuration mode or not.
           """
      @@ -267,7 +250,7 @@ 

      Methods

      No save config on Watchguard.

      Source code -
      def save_config(self, *args, **kwargs):
      +
      def save_config(self, *args: Any, **kwargs: Any) -> str:
           """No save config on Watchguard."""
           pass
      @@ -280,7 +263,7 @@

      Methods

      Set the base prompt for interaction ('#').

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """
           Prepare the session after the connection has been established.
       
      @@ -301,7 +284,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • @@ -314,9 +296,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -327,6 +309,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • diff --git a/docs/netmiko/watchguard/index.html b/docs/netmiko/watchguard/index.html index e0e24b391..083667d98 100644 --- a/docs/netmiko/watchguard/index.html +++ b/docs/netmiko/watchguard/index.html @@ -45,7 +45,7 @@

      Classes

      class WatchguardFirewareSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Implements methods for communicating with Watchguard Firebox firewalls.

      @@ -53,131 +53,104 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -186,7 +159,7 @@

      Classes

      Implements methods for communicating with Watchguard Firebox firewalls. """ - def session_preparation(self): + def session_preparation(self) -> None: """ Prepare the session after the connection has been established. @@ -198,19 +171,23 @@

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="configure", pattern="#"): - return super().config_mode(config_command=config_command, pattern=pattern) + def config_mode( + self, config_command: str = "configure", pattern: str = r"\#", re_flags: int = 0 + ) -> str: + return super().config_mode( + config_command=config_command, pattern=pattern, re_flags=re_flags + ) - def exit_config_mode(self, exit_config="exit", pattern="#"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = "#") -> str: return super().exit_config_mode(exit_config=exit_config, pattern=pattern) - def save_config(self, *args, **kwargs): + def save_config(self, *args: Any, **kwargs: Any) -> str: """No save config on Watchguard.""" pass
      @@ -227,7 +204,7 @@

      Methods

      Checks if the device is in configuration mode or not.

      Source code -
      def check_config_mode(self, check_string=")#", pattern="#"):
      +
      def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
           """
           Checks if the device is in configuration mode or not.
           """
      @@ -241,7 +218,7 @@ 

      Methods

      No save config on Watchguard.

      Source code -
      def save_config(self, *args, **kwargs):
      +
      def save_config(self, *args: Any, **kwargs: Any) -> str:
           """No save config on Watchguard."""
           pass
      @@ -254,7 +231,7 @@

      Methods

      Set the base prompt for interaction ('#').

      Source code -
      def session_preparation(self):
      +
      def session_preparation(self) -> None:
           """
           Prepare the session after the connection has been established.
       
      @@ -275,7 +252,6 @@ 

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • config_mode
    • disable_paging
    • @@ -288,9 +264,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -301,6 +277,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • set_base_prompt
    • set_terminal_width
    • special_login_handler
    • diff --git a/docs/netmiko/yamaha/index.html b/docs/netmiko/yamaha/index.html index 91890b3dd..e491543f5 100644 --- a/docs/netmiko/yamaha/index.html +++ b/docs/netmiko/yamaha/index.html @@ -46,7 +46,7 @@

      Classes

      class YamahaSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Yamaha SSH driver.

      @@ -54,131 +54,104 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code @@ -200,9 +173,8 @@

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • -
    • config_mode
    • +
    • config_mode
    • disable_paging
    • disconnect
    • enable
    • @@ -213,9 +185,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -227,6 +199,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • @@ -251,138 +224,111 @@

      Inherited members

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class YamahaTelnet(YamahaBase):
           """Yamaha Telnet driver."""
       
      -    def __init__(self, *args, **kwargs):
      +    def __init__(self, *args: Any, **kwargs: Any) -> None:
               default_enter = kwargs.get("default_enter")
               kwargs["default_enter"] = "\n" if default_enter is None else default_enter
               super().__init__(*args, **kwargs)
      @@ -400,9 +346,8 @@

      Inherited members

    • check_enable_mode
    • cleanup
    • clear_buffer
    • -
    • close_session_log
    • commit
    • -
    • config_mode
    • +
    • config_mode
    • disable_paging
    • disconnect
    • enable
    • @@ -413,9 +358,9 @@

      Inherited members

    • is_alive
    • normalize_cmd
    • normalize_linefeeds
    • -
    • open_session_log
    • paramiko_cleanup
    • read_channel
    • +
    • read_channel_timing
    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • @@ -427,6 +372,7 @@

      Inherited members

    • send_command_timing
    • send_config_from_file
    • send_config_set
    • +
    • send_multiline
    • session_preparation
    • set_base_prompt
    • set_terminal_width
    • diff --git a/docs/netmiko/yamaha/yamaha.html b/docs/netmiko/yamaha/yamaha.html index 5e8b974e5..44db311aa 100644 --- a/docs/netmiko/yamaha/yamaha.html +++ b/docs/netmiko/yamaha/yamaha.html @@ -22,12 +22,15 @@

      Module netmiko.yamaha.yamaha

      Source code -
      from netmiko.base_connection import BaseConnection
      -import time
      +
      import time
      +import re
      +from typing import Any, Optional
      +
      +from netmiko.base_connection import BaseConnection
       
       
       class YamahaBase(BaseConnection):
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
      @@ -35,13 +38,21 @@ 

      Module netmiko.yamaha.yamaha

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string="#"): + def check_enable_mode(self, check_string: str = "#") -> bool: return super().check_enable_mode(check_string=check_string) - def enable(self, cmd="administrator", pattern=r"Password", **kwargs): - return super().enable(cmd=cmd, pattern=pattern, **kwargs) - - def exit_enable_mode(self, exit_command="exit"): + def enable( + self, + cmd: str = "administrator", + pattern: str = r"Password", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: + return super().enable( + cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags + ) + + def exit_enable_mode(self, exit_command: str = "exit") -> str: """ When any changes have been made, the prompt 'Save new configuration ? (Y/N)' appears before exiting. Ignore this by entering 'N'. @@ -54,33 +65,39 @@

      Module netmiko.yamaha.yamaha

      if "(Y/N)" in output: self.write_channel("N") if self.base_prompt not in output: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output - def check_config_mode(self, check_string="#", pattern=""): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks if the device is in administrator mode or not.""" return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="administrator", pattern="ssword"): - """Enter into administrator mode and configure device.""" - return self.enable() + def config_mode( + self, + config_command: str = "administrator", + pattern: str = "Password", + re_flags: int = re.IGNORECASE, + ) -> str: + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) - def exit_config_mode(self, exit_config="exit", pattern=">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = ">") -> str: """ No action taken. Call 'exit_enable_mode()' to explicitly exit Administration Level. """ return "" - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config.""" if confirm is True: raise ValueError("Yamaha does not support save_config confirmation.") self.enable() # Some devices are slow so match on trailing-prompt if you can - return self.send_command(command_string=cmd) + return self._send_command_str(command_string=cmd) class YamahaSSH(YamahaBase): @@ -92,7 +109,7 @@

      Module netmiko.yamaha.yamaha

      class YamahaTelnet(YamahaBase): """Yamaha Telnet driver.""" - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: default_enter = kwargs.get("default_enter") kwargs["default_enter"] = "\n" if default_enter is None else default_enter super().__init__(*args, **kwargs)
      @@ -109,7 +126,7 @@

      Classes

      class YamahaBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

      Defines vendor independent methods.

      @@ -118,136 +135,109 @@

      Classes

      :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
      -

      ). -:type default_enter: str

      +

      ).

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

      ) -:type response_return: str

      +

      )

          :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                   to select smallest of global and specific. Sets default global_delay_factor to .1
      -            (default: False)
      -    :type fast_cli: boolean
      +            (default: True)
       
           :param session_log: File path or BufferedIOBase subclass object to write the session log to.
      -    :type session_log: str
       
           :param session_log_record_writes: The session log generally only records channel reads due
                   to eliminate command duplication due to command echo. You can enable this if you
                   want to record both channel reads and channel writes in the log (default: False).
      -    :type session_log_record_writes: boolean
       
           :param session_log_file_mode: "write" or "append" for session_log file mode
                   (default: "write")
      -    :type session_log_file_mode: str
       
           :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                   (default: False)
      -    :type allow_auto_change: bool
       
           :param encoding: Encoding to be used when writing bytes to the output channel.
                   (default: ascii)
      -    :type encoding: str
       
           :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                   communication to the target host (default: None).
      -    :type sock: socket
       
           :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                   (default: None). Global attribute takes precedence over function `cmd_verify`
                   argument. Value of `None` indicates to use function `cmd_verify` argument.
      -    :type global_cmd_verify: bool|None
       
           :param auto_connect: Control whether Netmiko automatically establishes the connection as
                   part of the object creation (default: True).
      -    :type auto_connect: bool
      +
      +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
      +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
      +            eliminated in Netmiko 5.x (default: False).
       
      Source code
      class YamahaBase(BaseConnection):
      -    def session_preparation(self):
      +    def session_preparation(self) -> None:
               """Prepare the session after the connection has been established."""
               self._test_channel_read(pattern=r"[>#]")
               self.set_base_prompt()
      @@ -255,13 +245,21 @@ 

      Classes

      time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_enable_mode(self, check_string="#"): + def check_enable_mode(self, check_string: str = "#") -> bool: return super().check_enable_mode(check_string=check_string) - def enable(self, cmd="administrator", pattern=r"Password", **kwargs): - return super().enable(cmd=cmd, pattern=pattern, **kwargs) - - def exit_enable_mode(self, exit_command="exit"): + def enable( + self, + cmd: str = "administrator", + pattern: str = r"Password", + enable_pattern: Optional[str] = None, + re_flags: int = re.IGNORECASE, + ) -> str: + return super().enable( + cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags + ) + + def exit_enable_mode(self, exit_command: str = "exit") -> str: """ When any changes have been made, the prompt 'Save new configuration ? (Y/N)' appears before exiting. Ignore this by entering 'N'. @@ -274,33 +272,39 @@

      Classes

      if "(Y/N)" in output: self.write_channel("N") if self.base_prompt not in output: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output - def check_config_mode(self, check_string="#", pattern=""): + def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool: """Checks if the device is in administrator mode or not.""" return super().check_config_mode(check_string=check_string, pattern=pattern) - def config_mode(self, config_command="administrator", pattern="ssword"): - """Enter into administrator mode and configure device.""" - return self.enable() + def config_mode( + self, + config_command: str = "administrator", + pattern: str = "Password", + re_flags: int = re.IGNORECASE, + ) -> str: + return self.enable(cmd=config_command, pattern=pattern, re_flags=re_flags) - def exit_config_mode(self, exit_config="exit", pattern=">"): + def exit_config_mode(self, exit_config: str = "exit", pattern: str = ">") -> str: """ No action taken. Call 'exit_enable_mode()' to explicitly exit Administration Level. """ return "" - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "save", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config.""" if confirm is True: raise ValueError("Yamaha does not support save_config confirmation.") self.enable() # Some devices are slow so match on trailing-prompt if you can - return self.send_command(command_string=cmd)
      + return self._send_command_str(command_string=cmd)

      Ancestors

        @@ -320,23 +324,11 @@

        Methods

        Checks if the device is in administrator mode or not.

        Source code -
        def check_config_mode(self, check_string="#", pattern=""):
        +
        def check_config_mode(self, check_string: str = "#", pattern: str = "") -> bool:
             """Checks if the device is in administrator mode or not."""
             return super().check_config_mode(check_string=check_string, pattern=pattern)
        -
        -def config_mode(self, config_command='administrator', pattern='ssword') -
        -
        -

        Enter into administrator mode and configure device.

        -
        -Source code -
        def config_mode(self, config_command="administrator", pattern="ssword"):
        -    """Enter into administrator mode and configure device."""
        -    return self.enable()
        -
        -
        def exit_config_mode(self, exit_config='exit', pattern='>')
        @@ -345,7 +337,7 @@

        Methods

        Level.

        Source code -
        def exit_config_mode(self, exit_config="exit", pattern=">"):
        +
        def exit_config_mode(self, exit_config: str = "exit", pattern: str = ">") -> str:
             """
             No action taken. Call 'exit_enable_mode()' to explicitly exit Administration
             Level.
        @@ -361,7 +353,7 @@ 

        Methods

        appears before exiting. Ignore this by entering 'N'.

        Source code -
        def exit_enable_mode(self, exit_command="exit"):
        +
        def exit_enable_mode(self, exit_command: str = "exit") -> str:
             """
             When any changes have been made, the prompt 'Save new configuration ? (Y/N)'
             appears before exiting. Ignore this by entering 'N'.
        @@ -374,7 +366,7 @@ 

        Methods

        if "(Y/N)" in output: self.write_channel("N") if self.base_prompt not in output: - output += self.read_until_prompt() + output += self.read_until_prompt(read_entire_line=True) if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output
        @@ -387,13 +379,15 @@

        Methods

        Saves Config.

        Source code -
        def save_config(self, cmd="save", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self, cmd: str = "save", confirm: bool = False, confirm_response: str = ""
        +) -> str:
             """Saves Config."""
             if confirm is True:
                 raise ValueError("Yamaha does not support save_config confirmation.")
             self.enable()
             # Some devices are slow so match on trailing-prompt if you can
        -    return self.send_command(command_string=cmd)
        + return self._send_command_str(command_string=cmd)
        @@ -403,7 +397,7 @@

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
        @@ -420,8 +414,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -430,9 +424,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -443,6 +437,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -458,7 +453,7 @@

        Inherited members

        class YamahaSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Yamaha SSH driver.

        @@ -466,131 +461,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -612,9 +580,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -625,9 +592,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -639,6 +606,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -663,138 +631,111 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class YamahaTelnet(YamahaBase):
             """Yamaha Telnet driver."""
         
        -    def __init__(self, *args, **kwargs):
        +    def __init__(self, *args: Any, **kwargs: Any) -> None:
                 default_enter = kwargs.get("default_enter")
                 kwargs["default_enter"] = "\n" if default_enter is None else default_enter
                 super().__init__(*args, **kwargs)
        @@ -812,9 +753,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -825,9 +765,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -839,6 +779,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -871,9 +812,8 @@

        Index

        • YamahaBase

          -
            +
            • check_config_mode
            • -
            • config_mode
            • exit_config_mode
            • exit_enable_mode
            • save_config
            • diff --git a/docs/netmiko/zte/index.html b/docs/netmiko/zte/index.html index 9bb3e5292..737071577 100644 --- a/docs/netmiko/zte/index.html +++ b/docs/netmiko/zte/index.html @@ -46,7 +46,7 @@

              Classes

              class ZteZxrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

              Base Class for cisco-like behavior.

              @@ -54,131 +54,104 @@

              Classes

              :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -199,9 +172,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -212,9 +184,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -226,6 +198,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -242,7 +215,7 @@

        Inherited members

        class ZteZxrosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -250,137 +223,110 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class ZteZxrosTelnet(ZteZxrosBase):
             @staticmethod
        -    def _process_option(telnet_sock, cmd, opt):
        +    def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None:
                 """
                 ZTE need manually reply DO ECHO to enable echo command.
                 enable ECHO, SGA, set window size to [500, 50]
        @@ -400,8 +346,9 @@ 

        Inherited members

        else: telnet_sock.sendall(IAC + WONT + opt) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs)
        @@ -419,9 +366,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -432,9 +378,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -446,6 +392,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/zte/zte_zxros.html b/docs/netmiko/zte/zte_zxros.html index 504f96f93..30039d1b7 100644 --- a/docs/netmiko/zte/zte_zxros.html +++ b/docs/netmiko/zte/zte_zxros.html @@ -22,13 +22,16 @@

        Module netmiko.zte.zte_zxros

        Source code -
        from netmiko.cisco_base_connection import CiscoBaseConnection
        -import time
        -from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, ECHO, SGA, NAWS
        +
        import time
        +from socket import socket
        +from typing import Any
        +
        +from netmiko.cisco_base_connection import CiscoBaseConnection
        +from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, ECHO, SGA, NAWS, Telnet
         
         
         class ZteZxrosBase(CiscoBaseConnection):
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
        @@ -37,13 +40,15 @@ 

        Module netmiko.zte.zte_zxros

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using Copy Run Start""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -56,7 +61,7 @@

        Module netmiko.zte.zte_zxros

        class ZteZxrosTelnet(ZteZxrosBase): @staticmethod - def _process_option(telnet_sock, cmd, opt): + def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None: """ ZTE need manually reply DO ECHO to enable echo command. enable ECHO, SGA, set window size to [500, 50] @@ -76,8 +81,9 @@

        Module netmiko.zte.zte_zxros

        else: telnet_sock.sendall(IAC + WONT + opt) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs)
        @@ -93,7 +99,7 @@

        Classes

        class ZteZxrosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -101,136 +107,109 @@

        Classes

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class ZteZxrosBase(CiscoBaseConnection):
        -    def session_preparation(self):
        +    def session_preparation(self) -> None:
                 """Prepare the session after the connection has been established."""
                 self._test_channel_read(pattern=r"[>#]")
                 self.set_base_prompt()
        @@ -239,13 +218,15 @@ 

        Classes

        time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def check_config_mode(self, check_string=")#", pattern="#"): + def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool: """ Checks if the device is in configuration mode or not. """ return super().check_config_mode(check_string=check_string, pattern=pattern) - def save_config(self, cmd="write", confirm=False, confirm_response=""): + def save_config( + self, cmd: str = "write", confirm: bool = False, confirm_response: str = "" + ) -> str: """Saves Config Using Copy Run Start""" return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response @@ -270,7 +251,7 @@

        Methods

        Checks if the device is in configuration mode or not.

        Source code -
        def check_config_mode(self, check_string=")#", pattern="#"):
        +
        def check_config_mode(self, check_string: str = ")#", pattern: str = "#") -> bool:
             """
             Checks if the device is in configuration mode or not.
             """
        @@ -284,7 +265,9 @@ 

        Methods

        Saves Config Using Copy Run Start

        Source code -
        def save_config(self, cmd="write", confirm=False, confirm_response=""):
        +
        def save_config(
        +    self, cmd: str = "write", confirm: bool = False, confirm_response: str = ""
        +) -> str:
             """Saves Config Using Copy Run Start"""
             return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
        @@ -298,7 +281,7 @@ 

        Methods

        Prepare the session after the connection has been established.

        Source code -
        def session_preparation(self):
        +
        def session_preparation(self) -> None:
             """Prepare the session after the connection has been established."""
             self._test_channel_read(pattern=r"[>#]")
             self.set_base_prompt()
        @@ -316,9 +299,8 @@ 

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -329,9 +311,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -342,6 +324,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • set_base_prompt
      • set_terminal_width
      • special_login_handler
      • @@ -357,7 +340,7 @@

        Inherited members

        class ZteZxrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -365,131 +348,104 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code @@ -510,9 +466,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -523,9 +478,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -537,6 +492,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • @@ -553,7 +509,7 @@

        Inherited members

        class ZteZxrosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False)

        Base Class for cisco-like behavior.

        @@ -561,137 +517,110 @@

        Inherited members

        :param ip: IP address of target device. Not required if `host` is provided. - :type ip: str :param host: Hostname of target device. Not required if `ip` is provided. - :type host: str :param username: Username to authenticate against target device if required. - :type username: str :param password: Password to authenticate against target device if required. - :type password: str :param secret: The enable password if target device requires one. - :type secret: str :param port: The destination port used to connect to the target device. - :type port: int or None :param device_type: Class selection based on device type. - :type device_type: str :param verbose: Enable additional messages to standard output. - :type verbose: bool :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1). - :type global_delay_factor: int :param use_keys: Connect to target device using SSH keys. - :type use_keys: bool :param key_file: Filename path of the SSH key file to use. - :type key_file: str :param pkey: SSH key object to use. - :type pkey: paramiko.PKey :param passphrase: Passphrase to use for encrypted key; password will be used for key decryption if not specified. - :type passphrase: str + + :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko + documentation for a description of the expected format. :param allow_agent: Enable use of SSH key-agent. - :type allow_agent: bool :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which means unknown SSH host keys will be accepted). - :type ssh_strict: bool :param system_host_keys: Load host keys from the users known_hosts file. - :type system_host_keys: bool + :param alt_host_keys: If `True` host keys will be loaded from the file specified in alt_key_file. - :type alt_host_keys: bool :param alt_key_file: SSH host key file to use (if alt_host_keys=True). - :type alt_key_file: str :param ssh_config_file: File name of OpenSSH configuration file. - :type ssh_config_file: str :param timeout: Connection timeout. - :type timeout: float :param session_timeout: Set a timeout for parallel requests. - :type session_timeout: float :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response. - :type auth_timeout: float :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko). - :type banner_timeout: float :param 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). - :type keepalive: int :param default_enter: Character(s) to send to correspond to enter key (default:
        -

        ). -:type default_enter: str

        +

        ).

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

        ) -:type response_return: str

        +

        )

            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
                     to select smallest of global and specific. Sets default global_delay_factor to .1
        -            (default: False)
        -    :type fast_cli: boolean
        +            (default: True)
         
             :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        -    :type session_log: str
         
             :param session_log_record_writes: The session log generally only records channel reads due
                     to eliminate command duplication due to command echo. You can enable this if you
                     want to record both channel reads and channel writes in the log (default: False).
        -    :type session_log_record_writes: boolean
         
             :param session_log_file_mode: "write" or "append" for session_log file mode
                     (default: "write")
        -    :type session_log_file_mode: str
         
             :param allow_auto_change: Allow automatic configuration changes for terminal settings.
                     (default: False)
        -    :type allow_auto_change: bool
         
             :param encoding: Encoding to be used when writing bytes to the output channel.
                     (default: ascii)
        -    :type encoding: str
         
             :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
                     communication to the target host (default: None).
        -    :type sock: socket
         
             :param global_cmd_verify: Control whether command echo verification is enabled or disabled
                     (default: None). Global attribute takes precedence over function `cmd_verify`
                     argument. Value of `None` indicates to use function `cmd_verify` argument.
        -    :type global_cmd_verify: bool|None
         
             :param auto_connect: Control whether Netmiko automatically establishes the connection as
                     part of the object creation (default: True).
        -    :type auto_connect: bool
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
         
        Source code
        class ZteZxrosTelnet(ZteZxrosBase):
             @staticmethod
        -    def _process_option(telnet_sock, cmd, opt):
        +    def _process_option(telnet_sock: socket, cmd: bytes, opt: bytes) -> None:
                 """
                 ZTE need manually reply DO ECHO to enable echo command.
                 enable ECHO, SGA, set window size to [500, 50]
        @@ -711,8 +640,9 @@ 

        Inherited members

        else: telnet_sock.sendall(IAC + WONT + opt) - def telnet_login(self, *args, **kwargs): + def telnet_login(self, *args: Any, **kwargs: Any) -> str: # set callback function to handle telnet options. + assert isinstance(self.remote_conn, Telnet) self.remote_conn.set_option_negotiation_callback(self._process_option) return super().telnet_login(*args, **kwargs)
        @@ -730,9 +660,8 @@

        Inherited members

      • check_enable_mode
      • cleanup
      • clear_buffer
      • -
      • close_session_log
      • commit
      • -
      • config_mode
      • +
      • config_mode
      • disable_paging
      • disconnect
      • enable
      • @@ -743,9 +672,9 @@

        Inherited members

      • is_alive
      • normalize_cmd
      • normalize_linefeeds
      • -
      • open_session_log
      • paramiko_cleanup
      • read_channel
      • +
      • read_channel_timing
      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • @@ -757,6 +686,7 @@

        Inherited members

      • send_command_timing
      • send_config_from_file
      • send_config_set
      • +
      • send_multiline
      • session_preparation
      • set_base_prompt
      • set_terminal_width
      • diff --git a/docs/netmiko/zyxel/index.html b/docs/netmiko/zyxel/index.html new file mode 100644 index 000000000..771c1a05e --- /dev/null +++ b/docs/netmiko/zyxel/index.html @@ -0,0 +1,322 @@ + + + + + + +netmiko.zyxel API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.zyxel

        +
        +
        +
        +Source code +
        from netmiko.zyxel.zyxel_ssh import ZyxelSSH
        +
        +
        +__all__ = ["ZyxelSSH"]
        +
        +
        +
        +

        Sub-modules

        +
        +
        netmiko.zyxel.zyxel_ssh
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class ZyxelSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
        +
        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        +
            Initialize attributes for establishing connection to target device.
        +
        +    :param ip: IP address of target device. Not required if `host` is
        +        provided.
        +
        +    :param host: Hostname of target device. Not required if `ip` is
        +            provided.
        +
        +    :param username: Username to authenticate against target device if
        +            required.
        +
        +    :param password: Password to authenticate against target device if
        +            required.
        +
        +    :param secret: The enable password if target device requires one.
        +
        +    :param port: The destination port used to connect to the target
        +            device.
        +
        +    :param device_type: Class selection based on device type.
        +
        +    :param verbose: Enable additional messages to standard output.
        +
        +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        +
        +    :param use_keys: Connect to target device using SSH keys.
        +
        +    :param key_file: Filename path of the SSH key file to use.
        +
        +    :param pkey: SSH key object to use.
        +
        +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
        +            decryption if not specified.
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
        +
        +    :param allow_agent: Enable use of SSH key-agent.
        +
        +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
        +            means unknown SSH host keys will be accepted).
        +
        +    :param system_host_keys: Load host keys from the users known_hosts file.
        +
        +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
        +            alt_key_file.
        +
        +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        +
        +    :param ssh_config_file: File name of OpenSSH configuration file.
        +
        +    :param timeout: Connection timeout.
        +
        +    :param session_timeout: Set a timeout for parallel requests.
        +
        +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        +
        +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        +
        +    :param 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).
        +
        +    :param default_enter: Character(s) to send to correspond to enter key (default:
        +
        +

        ).

        +
            :param response_return: Character(s) to use in normalized return data to represent
        +            enter key (default:
        +
        +

        )

        +
            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
        +            to select smallest of global and specific. Sets default global_delay_factor to .1
        +            (default: True)
        +
        +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        +
        +    :param session_log_record_writes: The session log generally only records channel reads due
        +            to eliminate command duplication due to command echo. You can enable this if you
        +            want to record both channel reads and channel writes in the log (default: False).
        +
        +    :param session_log_file_mode: "write" or "append" for session_log file mode
        +            (default: "write")
        +
        +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
        +            (default: False)
        +
        +    :param encoding: Encoding to be used when writing bytes to the output channel.
        +            (default: ascii)
        +
        +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
        +            communication to the target host (default: None).
        +
        +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
        +            (default: None). Global attribute takes precedence over function `cmd_verify`
        +            argument. Value of `None` indicates to use function `cmd_verify` argument.
        +
        +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
        +            part of the object creation (default: True).
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
        +
        +
        +Source code +
        class ZyxelSSH(NoEnable, NoConfig, CiscoSSHConnection):
        +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
        +        """No paging on Zyxel"""
        +        return ""
        +
        +    def send_config_set(
        +        self,
        +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +        exit_config_mode: bool = False,
        +        enter_config_mode: bool = False,
        +        **kwargs: Any
        +    ) -> str:
        +        """No config mode on Zyxel"""
        +        return super().send_config_set(
        +            config_commands=config_commands,
        +            exit_config_mode=exit_config_mode,
        +            enter_config_mode=enter_config_mode,
        +            **kwargs
        +        )
        +
        +    def session_preparation(self) -> None:
        +        super().session_preparation()
        +        # Zyxel switches output ansi codes
        +        self.ansi_escape_codes = True
        +
        +

        Ancestors

        + +

        Methods

        +
        +
        +def disable_paging(self, *args, **kwargs) +
        +
        +

        No paging on Zyxel

        +
        +Source code +
        def disable_paging(self, *args: Any, **kwargs: Any) -> str:
        +    """No paging on Zyxel"""
        +    return ""
        +
        +
        +
        +def send_config_set(self, config_commands=None, exit_config_mode=False, enter_config_mode=False, **kwargs) +
        +
        +

        No config mode on Zyxel

        +
        +Source code +
        def send_config_set(
        +    self,
        +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +    exit_config_mode: bool = False,
        +    enter_config_mode: bool = False,
        +    **kwargs: Any
        +) -> str:
        +    """No config mode on Zyxel"""
        +    return super().send_config_set(
        +        config_commands=config_commands,
        +        exit_config_mode=exit_config_mode,
        +        enter_config_mode=enter_config_mode,
        +        **kwargs
        +    )
        +
        +
        +
        +

        Inherited members

        + +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file diff --git a/docs/netmiko/zyxel/zyxel_ssh.html b/docs/netmiko/zyxel/zyxel_ssh.html new file mode 100644 index 000000000..6dd88ccac --- /dev/null +++ b/docs/netmiko/zyxel/zyxel_ssh.html @@ -0,0 +1,336 @@ + + + + + + +netmiko.zyxel.zyxel_ssh API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.zyxel.zyxel_ssh

        +
        +
        +
        +Source code +
        from typing import Any, Sequence, TextIO, Union
        +from netmiko.cisco_base_connection import CiscoSSHConnection
        +from netmiko.no_enable import NoEnable
        +from netmiko.no_config import NoConfig
        +
        +
        +class ZyxelSSH(NoEnable, NoConfig, CiscoSSHConnection):
        +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
        +        """No paging on Zyxel"""
        +        return ""
        +
        +    def send_config_set(
        +        self,
        +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +        exit_config_mode: bool = False,
        +        enter_config_mode: bool = False,
        +        **kwargs: Any
        +    ) -> str:
        +        """No config mode on Zyxel"""
        +        return super().send_config_set(
        +            config_commands=config_commands,
        +            exit_config_mode=exit_config_mode,
        +            enter_config_mode=enter_config_mode,
        +            **kwargs
        +        )
        +
        +    def session_preparation(self) -> None:
        +        super().session_preparation()
        +        # Zyxel switches output ansi codes
        +        self.ansi_escape_codes = True
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class ZyxelSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1.0, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, disabled_algorithms=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=10, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, read_timeout_override=None, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=True, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True, delay_factor_compat=False) +
        +
        +

        Class for platforms that have no enable mode.

        +

        Netmiko translates the meaning of "enable" mode to be a proxy for "can +go into config mode". In other words, that you ultimately have privileges +to execute configuration changes.

        +

        The expectation on platforms that have no method for elevating privileges +is that the standard default privileges allow configuration changes.

        +

        Consequently check_enable_mode returns True by default for platforms that +don't explicitly support enable mode.

        +
            Initialize attributes for establishing connection to target device.
        +
        +    :param ip: IP address of target device. Not required if `host` is
        +        provided.
        +
        +    :param host: Hostname of target device. Not required if `ip` is
        +            provided.
        +
        +    :param username: Username to authenticate against target device if
        +            required.
        +
        +    :param password: Password to authenticate against target device if
        +            required.
        +
        +    :param secret: The enable password if target device requires one.
        +
        +    :param port: The destination port used to connect to the target
        +            device.
        +
        +    :param device_type: Class selection based on device type.
        +
        +    :param verbose: Enable additional messages to standard output.
        +
        +    :param global_delay_factor: Multiplication factor affecting Netmiko delays (default: 1).
        +
        +    :param use_keys: Connect to target device using SSH keys.
        +
        +    :param key_file: Filename path of the SSH key file to use.
        +
        +    :param pkey: SSH key object to use.
        +
        +    :param passphrase: Passphrase to use for encrypted key; password will be used for key
        +            decryption if not specified.
        +
        +    :param disabled_algorithms: Dictionary of SSH algorithms to disable. Refer to the Paramiko
        +            documentation for a description of the expected format.
        +
        +    :param allow_agent: Enable use of SSH key-agent.
        +
        +    :param ssh_strict: Automatically reject unknown SSH host keys (default: False, which
        +            means unknown SSH host keys will be accepted).
        +
        +    :param system_host_keys: Load host keys from the users known_hosts file.
        +
        +    :param alt_host_keys: If `True` host keys will be loaded from the file specified in
        +            alt_key_file.
        +
        +    :param alt_key_file: SSH host key file to use (if alt_host_keys=True).
        +
        +    :param ssh_config_file: File name of OpenSSH configuration file.
        +
        +    :param timeout: Connection timeout.
        +
        +    :param session_timeout: Set a timeout for parallel requests.
        +
        +    :param auth_timeout: Set a timeout (in seconds) to wait for an authentication response.
        +
        +    :param banner_timeout: Set a timeout to wait for the SSH banner (pass to Paramiko).
        +
        +    :param 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).
        +
        +    :param default_enter: Character(s) to send to correspond to enter key (default:
        +
        +

        ).

        +
            :param response_return: Character(s) to use in normalized return data to represent
        +            enter key (default:
        +
        +

        )

        +
            :param fast_cli: Provide a way to optimize for performance. Converts select_delay_factor
        +            to select smallest of global and specific. Sets default global_delay_factor to .1
        +            (default: True)
        +
        +    :param session_log: File path or BufferedIOBase subclass object to write the session log to.
        +
        +    :param session_log_record_writes: The session log generally only records channel reads due
        +            to eliminate command duplication due to command echo. You can enable this if you
        +            want to record both channel reads and channel writes in the log (default: False).
        +
        +    :param session_log_file_mode: "write" or "append" for session_log file mode
        +            (default: "write")
        +
        +    :param allow_auto_change: Allow automatic configuration changes for terminal settings.
        +            (default: False)
        +
        +    :param encoding: Encoding to be used when writing bytes to the output channel.
        +            (default: ascii)
        +
        +    :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
        +            communication to the target host (default: None).
        +
        +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
        +            (default: None). Global attribute takes precedence over function `cmd_verify`
        +            argument. Value of `None` indicates to use function `cmd_verify` argument.
        +
        +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
        +            part of the object creation (default: True).
        +
        +    :param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko
        +            3.x behavior for delay_factor/global_delay_factor/max_loops. This argument will be
        +            eliminated in Netmiko 5.x (default: False).
        +
        +
        +Source code +
        class ZyxelSSH(NoEnable, NoConfig, CiscoSSHConnection):
        +    def disable_paging(self, *args: Any, **kwargs: Any) -> str:
        +        """No paging on Zyxel"""
        +        return ""
        +
        +    def send_config_set(
        +        self,
        +        config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +        exit_config_mode: bool = False,
        +        enter_config_mode: bool = False,
        +        **kwargs: Any
        +    ) -> str:
        +        """No config mode on Zyxel"""
        +        return super().send_config_set(
        +            config_commands=config_commands,
        +            exit_config_mode=exit_config_mode,
        +            enter_config_mode=enter_config_mode,
        +            **kwargs
        +        )
        +
        +    def session_preparation(self) -> None:
        +        super().session_preparation()
        +        # Zyxel switches output ansi codes
        +        self.ansi_escape_codes = True
        +
        +

        Ancestors

        + +

        Methods

        +
        +
        +def disable_paging(self, *args, **kwargs) +
        +
        +

        No paging on Zyxel

        +
        +Source code +
        def disable_paging(self, *args: Any, **kwargs: Any) -> str:
        +    """No paging on Zyxel"""
        +    return ""
        +
        +
        +
        +def send_config_set(self, config_commands=None, exit_config_mode=False, enter_config_mode=False, **kwargs) +
        +
        +

        No config mode on Zyxel

        +
        +Source code +
        def send_config_set(
        +    self,
        +    config_commands: Union[str, Sequence[str], TextIO, None] = None,
        +    exit_config_mode: bool = False,
        +    enter_config_mode: bool = False,
        +    **kwargs: Any
        +) -> str:
        +    """No config mode on Zyxel"""
        +    return super().send_config_set(
        +        config_commands=config_commands,
        +        exit_config_mode=exit_config_mode,
        +        enter_config_mode=enter_config_mode,
        +        **kwargs
        +    )
        +
        +
        +
        +

        Inherited members

        + +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file From 45501645e06743bd6341cfd6d2573f6c5f36d094 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 23 Mar 2022 11:01:17 -0700 Subject: [PATCH 2/2] Fix __all__ import for ubiquiti --- netmiko/ubiquiti/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/netmiko/ubiquiti/__init__.py b/netmiko/ubiquiti/__init__.py index f650a7a64..aa695a199 100644 --- a/netmiko/ubiquiti/__init__.py +++ b/netmiko/ubiquiti/__init__.py @@ -5,6 +5,5 @@ __all__ = [ "UbiquitiEdgeRouterSSH", "UbiquitiEdgeSSH", - "UnifiSwitchSSH", "UbiquitiUnifiSwitchSSH", ]