diff --git a/.gitignore b/.gitignore index 87013fb97..b8d9663f4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ docs/build/doctrees/ .DS_Store */.DS_Store +tests/cisco3-out.txt +tests/test.log diff --git a/.travis.yml b/.travis.yml index a0ec6c3eb..826a27ddb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,27 @@ --- language: python python: - - "2.7" - - "3.5" - "3.6" - "3.7" + - "3.8-dev" + - "nightly" +stages: + - lint + - test matrix: include: - - python: 3.6 - env: TOXENV=black - - python: 3.6 - env: TOXENV=pylama -install: - - pip install tox==3.13.1 tox-travis==0.12 -script: + - stage: lint + name: Black + python: 3.6 + env: TOXENV=black + - stage: lint + name: Pylama + python: 3.6 + env: TOXENV=pylama + allow_failures: + - python: 3.8-dev + - python: nightly +install: + - pip install tox==3.13.2 tox-travis==0.12 +script: - tox diff --git a/MANIFEST.in b/MANIFEST.in index a2cde7e16..0874c6ddf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include *.md include requirements.txt include LICENSE +recursive-include tests/ * diff --git a/PLATFORMS.md b/PLATFORMS.md index ce7516cf7..a45aa4ccc 100644 --- a/PLATFORMS.md +++ b/PLATFORMS.md @@ -30,6 +30,7 @@ - HPE Comware7 - Huawei - IP Infusion OcNOS +- Juniper ScreenOS - Mellanox - MikroTik RouterOS - MikroTik SwitchOS @@ -38,6 +39,7 @@ - Palo Alto PAN-OS - Pluribus - Ruckus ICX/FastIron +- Ruijie Networks - Ubiquiti EdgeSwitch - Vyatta VyOS diff --git a/README.md b/README.md index 6545acfe6..3fc64774c 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ For all code contributions, please ensure that you have ran `black` against the If you find an issue with Netmiko, then you can open an issue on this projects issue page here: [https://github.com/ktbyers/netmiko/issues](https://github.com/ktbyers/netmiko/issues). Please make sure you've read through the common issues and examples prior to opening an issue. Please only open issues for bugs, feature requests, or other topics related to development of Netmiko. If you simply have a question, join us on Slack... -If you have questions or would like to discuss Netmiko, a #netmiko channel exists in [this Slack](https://pynet.slack.com) workspace. To join, use [this invitation](https://join.slack.com/t/pynet/shared_invite/enQtNTA2MDI3NjU0MTM0LTQ5MjExNGNlNWIzMmRhOTZmNmZkNDA2Nzk4Y2Q1Y2RkMWNhZGEzM2Y5MjI0NDYxODkzM2M0ODIwYzFkMzVmZGY). Once you have entered the workspace, then you can join the #netmiko channel. +If you have questions or would like to discuss Netmiko, a #netmiko channel exists in [this Slack](https://pynet.slack.com) workspace. To join, use [this invitation](https://join.slack.com/t/pynet/shared_invite/enQtNTA2MDI3NjU0MTM0LTIyZDdhMTBlOWNmNDJhNjkxZTEyMDg3NTRkOWIxMTUwOTAzYmQ0ZjMwMGMyNTM4N2E1YzA3YWQ1MWFiOWM1YzU). Once you have entered the workspace, then you can join the #netmiko channel. --- diff --git a/docs/netmiko/a10/a10_ssh.html b/docs/netmiko/a10/a10_ssh.html index d0fd10928..aa7a6c4df 100644 --- a/docs/netmiko/a10/a10_ssh.html +++ b/docs/netmiko/a10/a10_ssh.html @@ -3,13 +3,13 @@ - + netmiko.a10.a10_ssh API documentation - + @@ -24,7 +24,6 @@

Module netmiko.a10.a10_ssh

Source code
"""A10 support."""
-from __future__ import unicode_literals
 import time
 from netmiko.cisco_base_connection import CiscoSSHConnection
 
@@ -62,7 +61,7 @@ 

Classes

class A10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

A10 support.

@@ -182,6 +181,10 @@

Classes

: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
Source code @@ -324,7 +327,7 @@

-

Generated by pdoc 0.6.2.

+

Generated by pdoc 0.6.3.

diff --git a/docs/netmiko/a10/index.html b/docs/netmiko/a10/index.html index fd8e9d33b..16a50412b 100644 --- a/docs/netmiko/a10/index.html +++ b/docs/netmiko/a10/index.html @@ -3,13 +3,13 @@ - + netmiko.a10 API documentation - + @@ -22,8 +22,7 @@

Module netmiko.a10

Source code -
from __future__ import unicode_literals
-from netmiko.a10.a10_ssh import A10SSH
+
from netmiko.a10.a10_ssh import A10SSH
 
 __all__ = ["A10SSH"]
@@ -46,7 +45,7 @@

Classes

class A10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

A10 support.

@@ -166,6 +165,10 @@

Classes

: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
Source code @@ -313,7 +316,7 @@

A10SSH diff --git a/docs/netmiko/accedian/accedian_ssh.html b/docs/netmiko/accedian/accedian_ssh.html index 90c10bc49..9c0a0bd93 100644 --- a/docs/netmiko/accedian/accedian_ssh.html +++ b/docs/netmiko/accedian/accedian_ssh.html @@ -3,13 +3,13 @@ - + netmiko.accedian.accedian_ssh API documentation - + @@ -22,8 +22,7 @@

Module netmiko.accedian.accedian_ssh

Source code -
from __future__ import unicode_literals
-import time
+
import time
 from netmiko.cisco_base_connection import CiscoSSHConnection
 
 
@@ -60,7 +59,7 @@ 

Module netmiko.accedian.accedian_ssh

self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -83,7 +82,7 @@

Classes

class AccedianSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

Base Class for cisco-like behavior.

@@ -203,6 +202,10 @@

Classes

: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
Source code @@ -239,7 +242,7 @@

Classes

self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -317,7 +320,7 @@

Methods

self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -401,7 +404,7 @@

-

Generated by pdoc 0.6.2.

+

Generated by pdoc 0.6.3.

diff --git a/docs/netmiko/accedian/index.html b/docs/netmiko/accedian/index.html index aea7b2150..b1d16b129 100644 --- a/docs/netmiko/accedian/index.html +++ b/docs/netmiko/accedian/index.html @@ -3,13 +3,13 @@ - + netmiko.accedian API documentation - + @@ -45,7 +45,7 @@

Classes

class AccedianSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

Base Class for cisco-like behavior.

@@ -165,6 +165,10 @@

Classes

: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
Source code @@ -201,7 +205,7 @@

Classes

self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -279,7 +283,7 @@

Methods

self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -368,7 +372,7 @@

-

Generated by pdoc 0.6.2.

+

Generated by pdoc 0.6.3.

diff --git a/docs/netmiko/alcatel/alcatel_aos_ssh.html b/docs/netmiko/alcatel/alcatel_aos_ssh.html index 2097da0d7..b79843822 100644 --- a/docs/netmiko/alcatel/alcatel_aos_ssh.html +++ b/docs/netmiko/alcatel/alcatel_aos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.alcatel.alcatel_aos_ssh API documentation - + @@ -24,8 +24,6 @@

Module netmiko.alcatel.alcatel_aos_ssh

Source code
"""Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8)."""
-from __future__ import print_function
-from __future__ import unicode_literals
 import time
 from netmiko.cisco_base_connection import CiscoSSHConnection
 
@@ -69,7 +67,7 @@ 

Module netmiko.alcatel.alcatel_aos_ssh

self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
@@ -85,7 +83,7 @@

Classes

class AlcatelAosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

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

@@ -205,6 +203,10 @@

Classes

: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
Source code @@ -247,7 +249,7 @@

Classes

self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
@@ -342,7 +344,7 @@

Methods

self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )

@@ -423,7 +425,7 @@

-

Generated by pdoc 0.6.2.

+

Generated by pdoc 0.6.3.

diff --git a/docs/netmiko/alcatel/index.html b/docs/netmiko/alcatel/index.html index 7515e9971..7f35988da 100644 --- a/docs/netmiko/alcatel/index.html +++ b/docs/netmiko/alcatel/index.html @@ -3,13 +3,13 @@ - + netmiko.alcatel API documentation - + @@ -22,11 +22,9 @@

Module netmiko.alcatel

Source code -
from __future__ import unicode_literals
-from netmiko.alcatel.alcatel_sros_ssh import AlcatelSrosSSH
-from netmiko.alcatel.alcatel_aos_ssh import AlcatelAosSSH
+
from netmiko.alcatel.alcatel_aos_ssh import AlcatelAosSSH
 
-__all__ = ["AlcatelSrosSSH", "AlcatelAosSSH"]
+__all__ = ["AlcatelAosSSH"]
@@ -36,10 +34,6 @@

Sub-modules

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

-
netmiko.alcatel.alcatel_sros_ssh
-
-

Alcatel-Lucent SROS support.

-

@@ -51,7 +45,7 @@

Classes

class AlcatelAosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

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

@@ -171,6 +165,10 @@

Classes

: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
Source code @@ -213,7 +211,7 @@

Classes

self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
@@ -308,7 +306,7 @@

Methods

self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )

@@ -355,361 +353,6 @@

Inherited members

-
-class AlcatelSrosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') -
-
-

Alcatel-Lucent SROS 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
-
-
-Source code -
class AlcatelSrosSSH(CiscoSSHConnection):
-    """Alcatel-Lucent SROS support."""
-
-    def session_preparation(self):
-        self._test_channel_read()
-        self.set_base_prompt()
-        self.disable_paging(command="environment no more")
-        # Clear the read buffer
-        time.sleep(0.3 * self.global_delay_factor)
-        self.clear_buffer()
-
-    def set_base_prompt(self, *args, **kwargs):
-        """Remove the > when navigating into the different config level."""
-        cur_base_prompt = super(AlcatelSrosSSH, self).set_base_prompt(*args, **kwargs)
-        match = re.search(r"(.*)(>.*)*#", cur_base_prompt)
-        if match:
-            # strip off >... from base_prompt
-            self.base_prompt = match.group(1)
-            return self.base_prompt
-
-    def enable(self, cmd="enable-admin", pattern="ssword", re_flags=re.IGNORECASE):
-        """Enter enable mode."""
-        return super(AlcatelSrosSSH, self).enable(
-            cmd=cmd, pattern=pattern, re_flags=re_flags
-        )
-
-    def check_enable_mode(self, check_string="CLI Already in admin mode"):
-        """Check whether we are in enable-admin mode.
-         SROS requires us to do this:
-        *A:HOSTNAME# enable-admin
-        MINOR: CLI Already in admin mode.
-        *A:HOSTNAME#
-        *A:HOSTNAME# enable-admin
-        Password:
-        MINOR: CLI Invalid password.
-        *A:HOSTNAME#
-        """
-        output = self.send_command_timing("enable-admin")
-        if re.search(r"ssword", output):
-            # Just hit enter as we don't actually want to enter enable here
-            self.write_channel(self.normalize_cmd(self.RETURN))
-            self.read_until_prompt()
-            return False
-        elif check_string in output:
-            return True
-        raise ValueError("Unexpected response in check_enable_mode() method")
-
-    def exit_enable_mode(self, exit_command=""):
-        """No corresponding exit of enable mode on SROS."""
-        pass
-
-    def config_mode(self, config_command="configure", pattern="#"):
-        """ Enter into configuration mode on SROS device."""
-        return super(AlcatelSrosSSH, self).config_mode(
-            config_command=config_command, pattern=pattern
-        )
-
-    def exit_config_mode(self, exit_config="exit all", pattern="#"):
-        """ Exit from configuration mode."""
-        return super(AlcatelSrosSSH, self).exit_config_mode(
-            exit_config=exit_config, pattern=pattern
-        )
-
-    def check_config_mode(self, check_string="config", pattern="#"):
-        """ Checks if the device is in configuration mode or not. """
-        return super(AlcatelSrosSSH, self).check_config_mode(
-            check_string=check_string, pattern=pattern
-        )
-
-    def save_config(self, *args, **kwargs):
-        """Not Implemented"""
-        raise NotImplementedError
-
-

Ancestors

- -

Methods

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

Checks if the device is in configuration mode or not.

-
-Source code -
def check_config_mode(self, check_string="config", pattern="#"):
-    """ Checks if the device is in configuration mode or not. """
-    return super(AlcatelSrosSSH, self).check_config_mode(
-        check_string=check_string, pattern=pattern
-    )
-
-
-
-def check_enable_mode(self, check_string='CLI Already in admin mode') -
-
-

Check whether we are in enable-admin mode. -SROS requires us to do this: -A:HOSTNAME# enable-admin -MINOR: CLI Already in admin mode. -A:HOSTNAME# -A:HOSTNAME# enable-admin -Password: -MINOR: CLI Invalid password. -A:HOSTNAME#

-
-Source code -
def check_enable_mode(self, check_string="CLI Already in admin mode"):
-    """Check whether we are in enable-admin mode.
-     SROS requires us to do this:
-    *A:HOSTNAME# enable-admin
-    MINOR: CLI Already in admin mode.
-    *A:HOSTNAME#
-    *A:HOSTNAME# enable-admin
-    Password:
-    MINOR: CLI Invalid password.
-    *A:HOSTNAME#
-    """
-    output = self.send_command_timing("enable-admin")
-    if re.search(r"ssword", output):
-        # Just hit enter as we don't actually want to enter enable here
-        self.write_channel(self.normalize_cmd(self.RETURN))
-        self.read_until_prompt()
-        return False
-    elif check_string in output:
-        return True
-    raise ValueError("Unexpected response in check_enable_mode() method")
-
-
-
-def config_mode(self, config_command='configure', pattern='#') -
-
-

Enter into configuration mode on SROS device.

-
-Source code -
def config_mode(self, config_command="configure", pattern="#"):
-    """ Enter into configuration mode on SROS device."""
-    return super(AlcatelSrosSSH, self).config_mode(
-        config_command=config_command, pattern=pattern
-    )
-
-
-
-def exit_enable_mode(self, exit_command='') -
-
-

No corresponding exit of enable mode on SROS.

-
-Source code -
def exit_enable_mode(self, exit_command=""):
-    """No corresponding exit of enable mode on SROS."""
-    pass
-
-
-
-def save_config(self, *args, **kwargs) -
-
-

Not Implemented

-
-Source code -
def save_config(self, *args, **kwargs):
-    """Not Implemented"""
-    raise NotImplementedError
-
-
-
-def set_base_prompt(self, *args, **kwargs) -
-
-

Remove the > when navigating into the different config level.

-
-Source code -
def set_base_prompt(self, *args, **kwargs):
-    """Remove the > when navigating into the different config level."""
-    cur_base_prompt = super(AlcatelSrosSSH, self).set_base_prompt(*args, **kwargs)
-    match = re.search(r"(.*)(>.*)*#", cur_base_prompt)
-    if match:
-        # strip off >... from base_prompt
-        self.base_prompt = match.group(1)
-        return self.base_prompt
-
-
-
-

Inherited members

- -
@@ -727,7 +370,6 @@

Index

  • Sub-modules

  • Classes

    @@ -744,24 +386,13 @@

    save_config

  • -
  • -

    AlcatelSrosSSH

    - -
  • diff --git a/docs/netmiko/apresia/apresia_aeos.html b/docs/netmiko/apresia/apresia_aeos.html index 2af2245af..71fbdac74 100644 --- a/docs/netmiko/apresia/apresia_aeos.html +++ b/docs/netmiko/apresia/apresia_aeos.html @@ -3,13 +3,13 @@ - + netmiko.apresia.apresia_aeos API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.apresia.apresia_aeos

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -33,7 +32,6 @@ 

    Module netmiko.apresia.apresia_aeos

    self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.disable_paging() - self.set_terminal_width(command="terminal width 511") # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() @@ -47,10 +45,6 @@

    Module netmiko.apresia.apresia_aeos

    self.send_config_set("terminal length 0") self.exit_enable_mode() - def set_terminal_width(self, command="", delay_factor=1): - """No terminal width command mode on AEOS""" - pass - class ApresiaAeosSSH(ApresiaAeosBase): pass @@ -60,7 +54,7 @@

    Module netmiko.apresia.apresia_aeos

    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(ApresiaAeosTelnet, self).__init__(*args, **kwargs)
    + super().__init__(*args, **kwargs)
    @@ -74,7 +68,7 @@

    Classes

    class ApresiaAeosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -194,6 +188,10 @@

    Classes

    :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
    Source code @@ -203,7 +201,6 @@

    Classes

    self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.disable_paging() - self.set_terminal_width(command="terminal width 511") # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() @@ -215,11 +212,7 @@

    Classes

    if self.allow_auto_change and "terminal length 0" not in output: self.send_config_set("terminal length 0") - self.exit_enable_mode() - - def set_terminal_width(self, command="", delay_factor=1): - """No terminal width command mode on AEOS""" - pass + self.exit_enable_mode()

    Ancestors

      @@ -246,24 +239,11 @@

      Methods

      self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.disable_paging() - self.set_terminal_width(command="terminal width 511") # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) self.clear_buffer()
    -
    -def set_terminal_width(self, command='', delay_factor=1) -
    -
    -

    No terminal width command mode on AEOS

    -
    -Source code -
    def set_terminal_width(self, command="", delay_factor=1):
    -    """No terminal width command mode on AEOS"""
    -    pass
    -
    -

    Inherited members

    @@ -1389,7 +1407,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/cisco/cisco_nxos_ssh.html b/docs/netmiko/cisco/cisco_nxos_ssh.html index 1a0573f22..4bd1e3182 100644 --- a/docs/netmiko/cisco/cisco_nxos_ssh.html +++ b/docs/netmiko/cisco/cisco_nxos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.cisco.cisco_nxos_ssh API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.cisco.cisco_nxos_ssh

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import re
    +
    import re
     import time
     import os
     from netmiko.cisco_base_connection import CiscoSSHConnection
    @@ -50,9 +48,7 @@ 

    Module netmiko.cisco.cisco_nxos_ssh

    def check_config_mode(self, check_string=")#", pattern="#"): """Checks if the device is in configuration mode or not.""" - return super(CiscoNxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) class CiscoNxosFileTransfer(CiscoFileTransfer): @@ -65,6 +61,7 @@

    Module netmiko.cisco.cisco_nxos_ssh

    dest_file, file_system="bootflash:", direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file @@ -85,11 +82,13 @@

    Module netmiko.cisco.cisco_nxos_ssh

    else: raise ValueError("Invalid direction specified") + self.socket_timeout = socket_timeout + def check_file_exists(self, remote_cmd=""): """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: @@ -110,7 +109,7 @@

    Module netmiko.cisco.cisco_nxos_ssh

    remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Match line containing file name @@ -137,9 +136,7 @@

    Module netmiko.cisco.cisco_nxos_ssh

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}{} md5sum".format( - base_cmd, self.file_system, remote_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() def enable_scp(self, cmd=None): @@ -160,7 +157,7 @@

    Classes

    class CiscoNxosFileTransfer -(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put') +(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0)

    Cisco NXOS SCP File Transfer driver.

    @@ -176,6 +173,7 @@

    Classes

    dest_file, file_system="bootflash:", direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file @@ -196,11 +194,13 @@

    Classes

    else: raise ValueError("Invalid direction specified") + self.socket_timeout = socket_timeout + def check_file_exists(self, remote_cmd=""): """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: @@ -221,7 +221,7 @@

    Classes

    remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Match line containing file name @@ -248,9 +248,7 @@

    Classes

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}{} md5sum".format( - base_cmd, self.file_system, remote_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() def enable_scp(self, cmd=None): @@ -306,7 +304,7 @@

    Inherited members

    class CiscoNxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -426,6 +424,10 @@

    Inherited members

    :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
    Source code @@ -448,9 +450,7 @@

    Inherited members

    def check_config_mode(self, check_string=")#", pattern="#"): """Checks if the device is in configuration mode or not.""" - return super(CiscoNxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - )
    + return super().check_config_mode(check_string=check_string, pattern=pattern)

    Ancestors

    @@ -874,7 +771,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/cisco/cisco_xr.html b/docs/netmiko/cisco/cisco_xr.html index 24746979b..268905888 100644 --- a/docs/netmiko/cisco/cisco_xr.html +++ b/docs/netmiko/cisco/cisco_xr.html @@ -3,13 +3,13 @@ - + netmiko.cisco.cisco_xr API documentation - + @@ -22,12 +22,9 @@

    Module netmiko.cisco.cisco_xr

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import time
    +
    import time
     import re
     from netmiko.cisco_base_connection import CiscoBaseConnection, CiscoFileTransfer
    -from netmiko.py23_compat import text_type
     
     
     class CiscoXrBase(CiscoBaseConnection):
    @@ -41,10 +38,10 @@ 

    Module netmiko.cisco.cisco_xr

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """IOS-XR requires you not exit from configuration mode.""" - return super(CiscoXrBase, self).send_config_set( - config_commands=config_commands, exit_config_mode=False, **kwargs + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def commit( @@ -95,26 +92,26 @@

    Module netmiko.cisco.cisco_xr

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' - label = text_type(label) + label = str(label) error_marker = "Failed to" alt_error_marker = "One or more commits have occurred from other" # Select proper command string based on arguments provided if label: if comment: - command_string = "commit label {} comment {}".format(label, comment) + command_string = f"commit label {label} comment {comment}" elif confirm: command_string = "commit label {} confirmed {}".format( - label, text_type(confirm_delay) + label, str(confirm_delay) ) else: - command_string = "commit label {}".format(label) + command_string = f"commit label {label}" elif confirm: - command_string = "commit confirmed {}".format(text_type(confirm_delay)) + command_string = f"commit confirmed {str(confirm_delay)}" elif comment: - command_string = "commit comment {}".format(comment) + command_string = f"commit comment {comment}" else: command_string = "commit" @@ -127,17 +124,13 @@

    Module netmiko.cisco.cisco_xr

    delay_factor=delay_factor, ) if error_marker in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(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 ) - raise ValueError( - "Commit failed with the following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output @@ -201,7 +194,7 @@

    Module netmiko.cisco.cisco_xr

    if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def remote_md5(self, base_cmd="show md5 file", remote_file=None): """ @@ -215,7 +208,7 @@

    Module netmiko.cisco.cisco_xr

    elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -238,7 +231,7 @@

    Classes

    class CiscoXrBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -358,6 +351,10 @@

    Classes

    :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
    Source code @@ -372,10 +369,10 @@

    Classes

    time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """IOS-XR requires you not exit from configuration mode.""" - return super(CiscoXrBase, self).send_config_set( - config_commands=config_commands, exit_config_mode=False, **kwargs + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def commit( @@ -426,26 +423,26 @@

    Classes

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' - label = text_type(label) + label = str(label) error_marker = "Failed to" alt_error_marker = "One or more commits have occurred from other" # Select proper command string based on arguments provided if label: if comment: - command_string = "commit label {} comment {}".format(label, comment) + command_string = f"commit label {label} comment {comment}" elif confirm: command_string = "commit label {} confirmed {}".format( - label, text_type(confirm_delay) + label, str(confirm_delay) ) else: - command_string = "commit label {}".format(label) + command_string = f"commit label {label}" elif confirm: - command_string = "commit confirmed {}".format(text_type(confirm_delay)) + command_string = f"commit confirmed {str(confirm_delay)}" elif comment: - command_string = "commit comment {}".format(comment) + command_string = f"commit comment {comment}" else: command_string = "commit" @@ -458,17 +455,13 @@

    Classes

    delay_factor=delay_factor, ) if error_marker in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(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 ) - raise ValueError( - "Commit failed with the following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output @@ -618,26 +611,26 @@

    Methods

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' - label = text_type(label) + label = str(label) error_marker = "Failed to" alt_error_marker = "One or more commits have occurred from other" # Select proper command string based on arguments provided if label: if comment: - command_string = "commit label {} comment {}".format(label, comment) + command_string = f"commit label {label} comment {comment}" elif confirm: command_string = "commit label {} confirmed {}".format( - label, text_type(confirm_delay) + label, str(confirm_delay) ) else: - command_string = "commit label {}".format(label) + command_string = f"commit label {label}" elif confirm: - command_string = "commit confirmed {}".format(text_type(confirm_delay)) + command_string = f"commit confirmed {str(confirm_delay)}" elif comment: - command_string = "commit comment {}".format(comment) + command_string = f"commit comment {comment}" else: command_string = "commit" @@ -650,17 +643,13 @@

    Methods

    delay_factor=delay_factor, ) if error_marker in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(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 ) - raise ValueError( - "Commit failed with the following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output
    @@ -701,16 +690,16 @@

    Methods

    -def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs) +def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs)

    IOS-XR requires you not exit from configuration mode.

    Source code -
    def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs):
    +
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
         """IOS-XR requires you not exit from configuration mode."""
    -    return super(CiscoXrBase, self).send_config_set(
    -        config_commands=config_commands, exit_config_mode=False, **kwargs
    +    return super().send_config_set(
    +        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
         )
    @@ -777,7 +766,7 @@

    Inherited members

    class CiscoXrFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

    Cisco IOS-XR SCP File Transfer driver.

    @@ -798,7 +787,7 @@

    Inherited members

    if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def remote_md5(self, base_cmd="show md5 file", remote_file=None): """ @@ -812,7 +801,7 @@

    Inherited members

    elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -853,7 +842,7 @@

    show md5 file /bootflash:/boot/g if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}")

    @@ -876,7 +865,7 @@

    show md5 file /bootflash:/boot/g elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -908,7 +897,7 @@

    Inherited members

    class CiscoXrSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco XR SSH driver.

    @@ -1028,6 +1017,10 @@

    Inherited members

    :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
    Source code @@ -1092,7 +1085,7 @@

    Inherited members

    class CiscoXrTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco XR Telnet driver.

    @@ -1212,6 +1205,10 @@

    Inherited members

    :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
    Source code @@ -1320,7 +1317,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/cisco/index.html b/docs/netmiko/cisco/index.html index 6a61fb124..d92757e57 100644 --- a/docs/netmiko/cisco/index.html +++ b/docs/netmiko/cisco/index.html @@ -3,13 +3,13 @@ - + netmiko.cisco API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.cisco

    Source code -
    from __future__ import unicode_literals
    -from netmiko.cisco.cisco_ios import (
    +
    from netmiko.cisco.cisco_ios import (
         CiscoIosBase,
         CiscoIosSSH,
         CiscoIosTelnet,
    @@ -102,7 +101,7 @@ 

    Classes

    class CiscoAsaFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

    Cisco ASA SCP File Transfer driver.

    @@ -145,7 +144,7 @@

    Inherited members

    class CiscoAsaSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Subclass specific to Cisco ASA.

    @@ -265,6 +264,10 @@

    Inherited members

    :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
    Source code @@ -296,7 +299,7 @@

    Inherited members

    If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. """ - output = super(CiscoAsaSSH, self).send_command_timing(*args, **kwargs) + output = super().send_command_timing(*args, **kwargs) if len(args) >= 1: command_string = args[0] else: @@ -320,7 +323,7 @@

    Inherited members

    if len(args) <= 1: expect_string = kwargs.get("expect_string", "#") kwargs["expect_string"] = expect_string - output = super(CiscoAsaSSH, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) if "changeto" in command_string: self.set_base_prompt() @@ -339,7 +342,7 @@

    Inherited members

    This switch of ASA contexts can occur in configuration mode. If this happens the trailing '(config*' needs stripped off. """ - cur_base_prompt = super(CiscoAsaSSH, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) match = re.search(r"(.*)\(conf.*", cur_base_prompt) if match: # strip off (conf.* from base_prompt @@ -374,7 +377,7 @@

    Inherited members

    def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves Config""" - return super(CiscoAsaSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -432,7 +435,7 @@

    Methods

    Source code
    def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
         """Saves Config"""
    -    return super(CiscoAsaSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )

    @@ -460,7 +463,7 @@

    Methods

    if len(args) <= 1: expect_string = kwargs.get("expect_string", "#") kwargs["expect_string"] = expect_string - output = super(CiscoAsaSSH, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) if "changeto" in command_string: self.set_base_prompt() @@ -493,7 +496,7 @@

    Methods

    If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. """ - output = super(CiscoAsaSSH, self).send_command_timing(*args, **kwargs) + output = super().send_command_timing(*args, **kwargs) if len(args) >= 1: command_string = args[0] else: @@ -549,7 +552,7 @@

    Methods

    This switch of ASA contexts can occur in configuration mode. If this happens the trailing '(config*' needs stripped off. """ - cur_base_prompt = super(CiscoAsaSSH, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) match = re.search(r"(.*)\(conf.*", cur_base_prompt) if match: # strip off (conf.* from base_prompt @@ -602,7 +605,7 @@

    Inherited members

    class CiscoIosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Common Methods for IOS (both SSH and telnet).

    @@ -722,6 +725,10 @@

    Inherited members

    :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
    Source code @@ -744,13 +751,11 @@

    Inherited members

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoIosBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves Config Using Copy Run Start""" - return super(CiscoIosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -778,7 +783,7 @@

    Methods

    Source code
    def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
         """Saves Config Using Copy Run Start"""
    -    return super(CiscoIosBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -850,7 +855,7 @@

    Inherited members

    class CiscoIosFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

    Cisco IOS SCP File Transfer driver.

    @@ -897,7 +902,7 @@

    Inherited members

    class CiscoIosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco IOS SSH driver.

    @@ -1017,6 +1022,10 @@

    Inherited members

    :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
    Source code @@ -1081,7 +1090,7 @@

    Inherited members

    class CiscoIosSerial -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco IOS Serial driver.

    @@ -1201,6 +1210,10 @@

    Inherited members

    :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
    Source code @@ -1265,7 +1278,7 @@

    Inherited members

    class CiscoIosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco IOS Telnet driver.

    @@ -1385,6 +1398,10 @@

    Inherited members

    :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
    Source code @@ -1449,7 +1466,7 @@

    Inherited members

    class CiscoNxosFileTransfer -(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put') +(ssh_conn, source_file, dest_file, file_system='bootflash:', direction='put', socket_timeout=10.0)

    Cisco NXOS SCP File Transfer driver.

    @@ -1465,6 +1482,7 @@

    Inherited members

    dest_file, file_system="bootflash:", direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file @@ -1485,11 +1503,13 @@

    Inherited members

    else: raise ValueError("Invalid direction specified") + self.socket_timeout = socket_timeout + def check_file_exists(self, remote_cmd=""): """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: @@ -1510,7 +1530,7 @@

    Inherited members

    remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Match line containing file name @@ -1537,9 +1557,7 @@

    Inherited members

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}{} md5sum".format( - base_cmd, self.file_system, remote_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() def enable_scp(self, cmd=None): @@ -1595,7 +1613,7 @@

    Inherited members

    class CiscoNxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -1715,6 +1733,10 @@

    Inherited members

    :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
    Source code @@ -1737,9 +1759,7 @@

    Inherited members

    def check_config_mode(self, check_string=")#", pattern="#"): """Checks if the device is in configuration mode or not.""" - return super(CiscoNxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern)

    Ancestors

    @@ -1847,7 +1865,7 @@

    Inherited members

    class CiscoS300SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Support for Cisco SG300 series of devices.

    @@ -1970,6 +1988,10 @@

    Inherited members

    :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
    Source code @@ -1994,7 +2016,7 @@

    Inherited members

    time.sleep(0.3 * self.global_delay_factor) def save_config(self, cmd="write memory", confirm=True, confirm_response="Y"): - return super(CiscoS300SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -2194,6 +2216,10 @@

    Inherited members

    :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
    Source code @@ -2201,7 +2227,7 @@

    Inherited members

    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(CiscoTpTcCeSSH, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def disable_paging(self, *args, **kwargs): """Paging is disabled by default.""" @@ -2252,13 +2278,6 @@

    Inherited members

    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. - - command_string = command to execute - expect_string = pattern to search for uses re.search (use raw strings) - delay_factor = decrease the initial delay before we start looking for data - max_loops = number of iterations before we give up and raise an exception - strip_prompt = strip the trailing prompt from the output - strip_command = strip the leading command from the output """ if len(args) >= 2: expect_string = args[1] @@ -2269,7 +2288,7 @@

    Inherited members

    expect_string = self.RETURN + expect_string + self.RETURN kwargs.setdefault("expect_string", expect_string) - output = super(CiscoSSHConnection, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) return output def save_config(self, *args, **kwargs): @@ -2326,13 +2345,7 @@

    Methods

    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.

    -

    command_string = command to execute -expect_string = pattern to search for uses re.search (use raw strings) -delay_factor = decrease the initial delay before we start looking for data -max_loops = number of iterations before we give up and raise an exception -strip_prompt = strip the trailing prompt from the output -strip_command = strip the leading command from the output

    +detected. The current network device prompt will be determined automatically.

    Source code
    def send_command(self, *args, **kwargs):
    @@ -2341,13 +2354,6 @@ 

    Methods

    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. - - command_string = command to execute - expect_string = pattern to search for uses re.search (use raw strings) - delay_factor = decrease the initial delay before we start looking for data - max_loops = number of iterations before we give up and raise an exception - strip_prompt = strip the trailing prompt from the output - strip_command = strip the leading command from the output """ if len(args) >= 2: expect_string = args[1] @@ -2358,7 +2364,7 @@

    Methods

    expect_string = self.RETURN + expect_string + self.RETURN kwargs.setdefault("expect_string", expect_string) - output = super(CiscoSSHConnection, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) return output
    @@ -2471,7 +2477,7 @@

    Inherited members

    class CiscoWlcSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Netmiko Cisco WLC support.

    @@ -2591,6 +2597,10 @@

    Inherited members

    :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
    Source code @@ -2689,8 +2699,8 @@

    Inherited members

    try: self.set_base_prompt() except ValueError: - msg = "Authentication failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Authentication failed: {self.host}" + raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") # Clear the read buffer @@ -2705,59 +2715,33 @@

    Inherited members

    """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).check_config_mode(check_string, pattern) + return super().check_config_mode(check_string, pattern) def config_mode(self, config_command="config", pattern=""): """Enter into config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).config_mode(config_command, pattern) + return super().config_mode(config_command, pattern) def exit_config_mode(self, exit_config="exit", pattern=""): """Exit config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).exit_config_mode(exit_config, pattern) + return super().exit_config_mode(exit_config, pattern) 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, + exit_config_mode=False, + enter_config_mode=False, + **kwargs, ): - """ - 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. - - Does not automatically exit/enter configuration mode. - """ - delay_factor = self.select_delay_factor(delay_factor) - if config_commands is None: - return "" - elif isinstance(config_commands, string_types): - config_commands = (config_commands,) - - if not hasattr(config_commands, "__iter__"): - raise ValueError("Invalid argument passed into send_config_set") - - # Send config commands - for cmd in config_commands: - self.write_channel(self.normalize_cmd(cmd)) - time.sleep(delay_factor * 0.5) - - # Gather output - output = self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops + return super().send_config_set( + config_commands=config_commands, + exit_config_mode=exit_config_mode, + enter_config_mode=enter_config_mode, + **kwargs, ) - output = self._sanitize_output(output) - log.debug("{}".format(output)) - return output def save_config(self, cmd="save config", confirm=True, confirm_response="y"): """Saves Config.""" @@ -2791,7 +2775,7 @@

    Methods

    """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).check_config_mode(check_string, pattern) + return super().check_config_mode(check_string, pattern)
    @@ -2817,7 +2801,7 @@

    Methods

    """Enter into config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).config_mode(config_command, pattern)
    + return super().config_mode(config_command, pattern)
    @@ -2831,7 +2815,7 @@

    Methods

    """Exit config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).exit_config_mode(exit_config, pattern)
    + return super().exit_config_mode(exit_config, pattern)
    @@ -2921,57 +2905,6 @@

    Methods

    return output
    -
    -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) -
    -
    -

    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.

    -

    Does not automatically exit/enter configuration mode.

    -
    -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,
    -):
    -    """
    -    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.
    -
    -    Does not automatically exit/enter configuration mode.
    -    """
    -    delay_factor = self.select_delay_factor(delay_factor)
    -    if config_commands is None:
    -        return ""
    -    elif isinstance(config_commands, string_types):
    -        config_commands = (config_commands,)
    -
    -    if not hasattr(config_commands, "__iter__"):
    -        raise ValueError("Invalid argument passed into send_config_set")
    -
    -    # Send config commands
    -    for cmd in config_commands:
    -        self.write_channel(self.normalize_cmd(cmd))
    -        time.sleep(delay_factor * 0.5)
    -
    -    # Gather output
    -    output = self._read_channel_timing(
    -        delay_factor=delay_factor, max_loops=max_loops
    -    )
    -    output = self._sanitize_output(output)
    -    log.debug("{}".format(output))
    -    return output
    -
    -
    def session_preparation(self)
    @@ -2991,8 +2924,8 @@

    Methods

    try: self.set_base_prompt() except ValueError: - msg = "Authentication failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Authentication failed: {self.host}" + raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") # Clear the read buffer @@ -3070,6 +3003,7 @@

    Inherited members

  • send_command_expect
  • send_command_timing
  • send_config_from_file
  • +
  • send_config_set
  • set_base_prompt
  • set_terminal_width
  • strip_ansi_escape_codes
  • @@ -3084,7 +3018,7 @@

    Inherited members

    class CiscoXrFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

    Cisco IOS-XR SCP File Transfer driver.

    @@ -3105,7 +3039,7 @@

    Inherited members

    if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def remote_md5(self, base_cmd="show md5 file", remote_file=None): """ @@ -3119,7 +3053,7 @@

    Inherited members

    elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -3160,7 +3094,7 @@

    show md5 file /bootflash:/boot/g if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}")

    @@ -3183,7 +3117,7 @@

    show md5 file /bootflash:/boot/g elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -3215,7 +3149,7 @@

    Inherited members

    class CiscoXrSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco XR SSH driver.

    @@ -3335,6 +3269,10 @@

    Inherited members

    :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
    Source code @@ -3399,7 +3337,7 @@

    Inherited members

    class CiscoXrTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Cisco XR Telnet driver.

    @@ -3519,6 +3457,10 @@

    Inherited members

    :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
    Source code @@ -3583,7 +3525,7 @@

    Inherited members

    class InLineTransfer -(ssh_conn, source_file=None, dest_file=None, file_system=None, direction='put', source_config=None) +(ssh_conn, source_file=None, dest_file=None, file_system=None, direction='put', source_config=None, socket_timeout=10.0)

    Use TCL on Cisco IOS to directly transfer file.

    @@ -3600,6 +3542,7 @@

    Inherited members

    file_system=None, direction="put", source_config=None, + socket_timeout=10.0, ): if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -3626,6 +3569,8 @@

    Inherited members

    else: self.file_system = file_system + self.socket_timeout = socket_timeout + @staticmethod def _read_file(file_name): with io.open(file_name, "rt", encoding="utf-8") as f: @@ -3633,7 +3578,7 @@

    Inherited members

    @staticmethod def _tcl_newline_rationalize(tcl_string): - """ + 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 will convert the "\r" to a "\n" i.e. you will see a "\n" inside the file on the @@ -3665,9 +3610,7 @@

    Inherited members

    ) for pattern in cmd_failed: if pattern in output: - raise ValueError( - "Failed to enter tclsh mode on router: {}".format(output) - ) + raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output def _exit_tcl_mode(self): @@ -3698,10 +3641,7 @@

    Inherited members

    return hashlib.md5(file_contents).hexdigest() def config_md5(self, source_config): - """Compute MD5 hash of file.""" - file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + return super().file_md5(source_config, add_newline=True) def put_file(self): curlybrace = r"{" @@ -3772,12 +3712,24 @@

    Methods

    def config_md5(self, source_config)
    -

    Compute MD5 hash of file.

    +
    Source code
    def config_md5(self, source_config):
    +    return super().file_md5(source_config, add_newline=True)
    +
    +
    +
    +def file_md5(self, file_name) +
    +
    +

    Compute MD5 hash of file.

    +
    +Source code +
    def file_md5(self, file_name):
         """Compute MD5 hash of file."""
    -    file_contents = source_config + "\n"  # Cisco IOS automatically adds this
    +    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()
    @@ -3793,7 +3745,6 @@

    Inherited members

  • disable_scp
  • enable_scp
  • establish_scp_conn
  • -
  • file_md5
  • get_file
  • local_space_available
  • process_md5
  • @@ -3910,7 +3861,6 @@

    exit_config_mode
  • save_config
  • send_command_w_enter
  • -
  • send_config_set
  • session_preparation
  • special_login_handler
  • @@ -3932,6 +3882,7 @@

    InLineTransfer

    @@ -3940,7 +3891,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/cisco_base_connection.html b/docs/netmiko/cisco_base_connection.html index 38baba940..b7a472ecf 100644 --- a/docs/netmiko/cisco_base_connection.html +++ b/docs/netmiko/cisco_base_connection.html @@ -3,13 +3,13 @@ - + netmiko.cisco_base_connection API documentation - + @@ -24,10 +24,9 @@

    Module netmiko.cisco_base_connection

    Source code
    """CiscoBaseConnection is netmiko SSH class for Cisco and Cisco-like platforms."""
    -from __future__ import unicode_literals
     from netmiko.base_connection import BaseConnection
     from netmiko.scp_handler import BaseFileTransfer
    -from netmiko.ssh_exception import NetMikoAuthenticationException
    +from netmiko.ssh_exception import NetmikoAuthenticationException
     import re
     import time
     
    @@ -37,21 +36,15 @@ 

    Module netmiko.cisco_base_connection

    def check_enable_mode(self, check_string="#"): """Check if in enable mode. Return boolean.""" - return super(CiscoBaseConnection, self).check_enable_mode( - check_string=check_string - ) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(CiscoBaseConnection, self).enable( - cmd=cmd, pattern=pattern, re_flags=re_flags - ) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def exit_enable_mode(self, exit_command="disable"): """Exits enable (privileged exec) mode.""" - return super(CiscoBaseConnection, self).exit_enable_mode( - exit_command=exit_command - ) + return super().exit_enable_mode(exit_command=exit_command) def check_config_mode(self, check_string=")#", pattern=""): """ @@ -59,9 +52,7 @@

    Module netmiko.cisco_base_connection

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoBaseConnection, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def config_mode(self, config_command="config term", pattern=""): """ @@ -71,15 +62,11 @@

    Module netmiko.cisco_base_connection

    """ if not pattern: pattern = re.escape(self.base_prompt[:16]) - return super(CiscoBaseConnection, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="end", pattern="#"): """Exit from configuration mode.""" - return super(CiscoBaseConnection, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, @@ -165,7 +152,7 @@

    Module netmiko.cisco_base_connection

    msg = "Login failed - Password required, but none set: {}".format( self.host ) - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) # Check if proper data received if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -178,8 +165,8 @@

    Module netmiko.cisco_base_connection

    i += 1 except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -192,8 +179,8 @@

    Module netmiko.cisco_base_connection

    return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) def cleanup(self): """Gracefully exit the SSH session.""" @@ -214,7 +201,7 @@

    Module netmiko.cisco_base_connection

    if match: file_system = match.group(1) # Test file_system - cmd = "dir {}".format(file_system) + cmd = f"dir {file_system}" output = self.send_command_expect(cmd) if "% Invalid" in output or "%Error:" in output: raise ValueError( @@ -238,15 +225,23 @@

    Module netmiko.cisco_base_connection

    """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self.send_command_timing( + command_string=cmd, strip_prompt=False, strip_command=False + ) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self.send_command_timing( + confirm_response, strip_prompt=False, strip_command=False + ) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self.send_command_timing( + 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(command_string=cmd) + output = self.send_command( + command_string=cmd, strip_prompt=False, strip_command=False + ) return output @@ -269,7 +264,7 @@

    Classes

    class CiscoBaseConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -389,6 +384,10 @@

    Classes

    :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
    Source code @@ -397,21 +396,15 @@

    Classes

    def check_enable_mode(self, check_string="#"): """Check if in enable mode. Return boolean.""" - return super(CiscoBaseConnection, self).check_enable_mode( - check_string=check_string - ) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(CiscoBaseConnection, self).enable( - cmd=cmd, pattern=pattern, re_flags=re_flags - ) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def exit_enable_mode(self, exit_command="disable"): """Exits enable (privileged exec) mode.""" - return super(CiscoBaseConnection, self).exit_enable_mode( - exit_command=exit_command - ) + return super().exit_enable_mode(exit_command=exit_command) def check_config_mode(self, check_string=")#", pattern=""): """ @@ -419,9 +412,7 @@

    Classes

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoBaseConnection, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def config_mode(self, config_command="config term", pattern=""): """ @@ -431,15 +422,11 @@

    Classes

    """ if not pattern: pattern = re.escape(self.base_prompt[:16]) - return super(CiscoBaseConnection, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="end", pattern="#"): """Exit from configuration mode.""" - return super(CiscoBaseConnection, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, @@ -525,7 +512,7 @@

    Classes

    msg = "Login failed - Password required, but none set: {}".format( self.host ) - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) # Check if proper data received if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -538,8 +525,8 @@

    Classes

    i += 1 except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -552,8 +539,8 @@

    Classes

    return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) def cleanup(self): """Gracefully exit the SSH session.""" @@ -574,7 +561,7 @@

    Classes

    if match: file_system = match.group(1) # Test file_system - cmd = "dir {}".format(file_system) + cmd = f"dir {file_system}" output = self.send_command_expect(cmd) if "% Invalid" in output or "%Error:" in output: raise ValueError( @@ -598,15 +585,23 @@

    Classes

    """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self.send_command_timing( + command_string=cmd, strip_prompt=False, strip_command=False + ) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self.send_command_timing( + confirm_response, strip_prompt=False, strip_command=False + ) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self.send_command_timing( + 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(command_string=cmd) + output = self.send_command( + command_string=cmd, strip_prompt=False, strip_command=False + ) return output

    Ancestors

    @@ -622,6 +617,7 @@

    Subclasses

  • HuaweiBase
  • IpInfusionOcNOSBase
  • OneaccessOneOSBase
  • +
  • RuijieOSBase
  • Methods

    @@ -639,9 +635,7 @@

    Methods

    Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoBaseConnection, self).check_config_mode( - check_string=check_string, pattern=pattern - )
    + return super().check_config_mode(check_string=check_string, pattern=pattern)

    @@ -653,9 +647,7 @@

    Methods

    Source code
    def check_enable_mode(self, check_string="#"):
         """Check if in enable mode. Return boolean."""
    -    return super(CiscoBaseConnection, self).check_enable_mode(
    -        check_string=check_string
    -    )
    + return super().check_enable_mode(check_string=check_string)
    @@ -692,9 +684,7 @@

    Methods

    """ if not pattern: pattern = re.escape(self.base_prompt[:16]) - return super(CiscoBaseConnection, self).config_mode( - config_command=config_command, pattern=pattern - )
    + return super().config_mode(config_command=config_command, pattern=pattern)
    @@ -706,9 +696,7 @@

    Methods

    Source code
    def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE):
         """Enter enable mode."""
    -    return super(CiscoBaseConnection, self).enable(
    -        cmd=cmd, pattern=pattern, re_flags=re_flags
    -    )
    + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
    @@ -720,9 +708,7 @@

    Methods

    Source code
    def exit_config_mode(self, exit_config="end", pattern="#"):
         """Exit from configuration mode."""
    -    return super(CiscoBaseConnection, self).exit_config_mode(
    -        exit_config=exit_config, pattern=pattern
    -    )
    + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
    @@ -734,9 +720,7 @@

    Methods

    Source code
    def exit_enable_mode(self, exit_command="disable"):
         """Exits enable (privileged exec) mode."""
    -    return super(CiscoBaseConnection, self).exit_enable_mode(
    -        exit_command=exit_command
    -    )
    + return super().exit_enable_mode(exit_command=exit_command)
    @@ -755,15 +739,23 @@

    Methods

    """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self.send_command_timing( + command_string=cmd, strip_prompt=False, strip_command=False + ) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self.send_command_timing( + confirm_response, strip_prompt=False, strip_command=False + ) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self.send_command_timing( + 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(command_string=cmd) + output = self.send_command( + command_string=cmd, strip_prompt=False, strip_command=False + ) return output
    @@ -866,7 +858,7 @@

    Methods

    msg = "Login failed - Password required, but none set: {}".format( self.host ) - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) # Check if proper data received if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -879,8 +871,8 @@

    Methods

    i += 1 except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -893,8 +885,8 @@

    Methods

    return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) @@ -939,7 +931,7 @@

    Inherited members

    class CiscoFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

    Class to manage SCP file transfer and associated SSH control channel.

    @@ -988,7 +980,7 @@

    Inherited members

    class CiscoSSHConnection -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -1108,6 +1100,10 @@

    Inherited members

    :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
    Source code @@ -1123,13 +1119,11 @@

    Subclasses

    @@ -577,7 +579,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/dell/dell_os10_ssh.html b/docs/netmiko/dell/dell_os10_ssh.html index 13c79b0f1..c931489b1 100644 --- a/docs/netmiko/dell/dell_os10_ssh.html +++ b/docs/netmiko/dell/dell_os10_ssh.html @@ -3,13 +3,13 @@ - + netmiko.dell.dell_os10_ssh API documentation - + @@ -41,7 +41,7 @@

    Module netmiko.dell.dell_os10_ssh

    confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -50,16 +50,21 @@

    Module netmiko.dell.dell_os10_ssh

    """Dell EMC Networking OS10 SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/home/admin", + direction="put", + **kwargs, ): - if file_system is None: - file_system = "/home/admin" - super(DellOS10FileTransfer, self).__init__( + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) self.folder_name = "/config" @@ -70,7 +75,7 @@

    Module netmiko.dell.dell_os10_ssh

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_cmd = 'system "ls -l {}/{}"'.format(self.file_system, remote_file) + remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' remote_out = self.ssh_ctl_chan.send_command(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: @@ -83,7 +88,7 @@

    Module netmiko.dell.dell_os10_ssh

    def remote_space_available(self, search_pattern=r"(\d+) bytes free"): """Return space available on remote device.""" - remote_cmd = 'system "df {}"'.format(self.folder_name) + remote_cmd = f'system "df {self.folder_name}"' remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: @@ -104,7 +109,7 @@

    Module netmiko.dell.dell_os10_ssh

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -120,14 +125,14 @@

    Module netmiko.dell.dell_os10_ssh

    def put_file(self): """SCP copy the file from the local system to the remote device.""" - destination = "{}".format(self.dest_file) + 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): """SCP copy the file from the remote device to local system.""" - source_file = "{}".format(self.source_file) + source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close()
    @@ -143,7 +148,7 @@

    Classes

    class DellOS10FileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system='/home/admin', direction='put', **kwargs)

    Dell EMC Networking OS10 SCP File Transfer driver.

    @@ -153,16 +158,21 @@

    Classes

    """Dell EMC Networking OS10 SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/home/admin", + direction="put", + **kwargs, ): - if file_system is None: - file_system = "/home/admin" - super(DellOS10FileTransfer, self).__init__( + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) self.folder_name = "/config" @@ -173,7 +183,7 @@

    Classes

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_cmd = 'system "ls -l {}/{}"'.format(self.file_system, remote_file) + remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' remote_out = self.ssh_ctl_chan.send_command(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: @@ -186,7 +196,7 @@

    Classes

    def remote_space_available(self, search_pattern=r"(\d+) bytes free"): """Return space available on remote device.""" - remote_cmd = 'system "df {}"'.format(self.folder_name) + remote_cmd = f'system "df {self.folder_name}"' remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: @@ -207,7 +217,7 @@

    Classes

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -223,14 +233,14 @@

    Classes

    def put_file(self): """SCP copy the file from the local system to the remote device.""" - destination = "{}".format(self.dest_file) + 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): """SCP copy the file from the remote device to local system.""" - source_file = "{}".format(self.source_file) + source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close()
    @@ -254,7 +264,7 @@

    Methods

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -287,7 +297,7 @@

    Inherited members

    class DellOS10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell EMC Networking OS10 Driver - supports dellos10.

    @@ -407,6 +417,10 @@

    Inherited members

    :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
    Source code @@ -420,7 +434,7 @@

    Inherited members

    confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -446,7 +460,7 @@

    Methods

    confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -533,7 +547,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/dell/dell_powerconnect.html b/docs/netmiko/dell/dell_powerconnect.html index ebc2053ce..42405dba5 100644 --- a/docs/netmiko/dell/dell_powerconnect.html +++ b/docs/netmiko/dell/dell_powerconnect.html @@ -3,13 +3,13 @@ - + netmiko.dell.dell_powerconnect API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.dell.dell_powerconnect

    Source code
    """Dell PowerConnect Driver."""
    -from __future__ import unicode_literals
     from paramiko import SSHClient
     import time
     from os import path
    @@ -55,7 +54,7 @@ 

    Module netmiko.dell.dell_powerconnect

    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(DellPowerConnectBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -66,15 +65,11 @@

    Module netmiko.dell.dell_powerconnect

    def check_config_mode(self, check_string="(config)#"): """Checks if the device is in configuration mode""" - return super(DellPowerConnectBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="config"): """Enter configuration mode.""" - return super(DellPowerConnectBase, self).config_mode( - config_command=config_command - ) + return super().config_mode(config_command=config_command) class DellPowerConnectSSH(DellPowerConnectBase): @@ -150,7 +145,7 @@

    Classes

    class DellPowerConnectBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Driver.

    @@ -270,6 +265,10 @@

    Classes

    :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
    Source code @@ -291,7 +290,7 @@

    Classes

    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(DellPowerConnectBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -302,15 +301,11 @@

    Classes

    def check_config_mode(self, check_string="(config)#"): """Checks if the device is in configuration mode""" - return super(DellPowerConnectBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="config"): """Enter configuration mode.""" - return super(DellPowerConnectBase, self).config_mode( - config_command=config_command - )
    + return super().config_mode(config_command=config_command)

    Ancestors

      @@ -334,9 +329,7 @@

      Methods

      Source code
      def check_config_mode(self, check_string="(config)#"):
           """Checks if the device is in configuration mode"""
      -    return super(DellPowerConnectBase, self).check_config_mode(
      -        check_string=check_string
      -    )
      + return super().check_config_mode(check_string=check_string)

    @@ -348,9 +341,7 @@

    Methods

    Source code
    def config_mode(self, config_command="config"):
         """Enter configuration mode."""
    -    return super(DellPowerConnectBase, self).config_mode(
    -        config_command=config_command
    -    )
    + return super().config_mode(config_command=config_command)
    @@ -383,7 +374,7 @@

    Methods

    self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(DellPowerConnectBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -440,7 +431,7 @@

    Inherited members

    class DellPowerConnectSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Driver.

    @@ -562,6 +553,10 @@

    Inherited members

    :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
    Source code @@ -714,7 +709,7 @@

    Inherited members

    class DellPowerConnectTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Telnet Driver.

    @@ -834,6 +829,10 @@

    Inherited members

    :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
    Source code @@ -975,7 +974,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/dell/index.html b/docs/netmiko/dell/index.html index 66d4ccf0f..07484a7fb 100644 --- a/docs/netmiko/dell/index.html +++ b/docs/netmiko/dell/index.html @@ -3,13 +3,13 @@ - + netmiko.dell API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.dell

    Source code -
    from __future__ import unicode_literals
    -from netmiko.dell.dell_dnos6 import DellDNOS6SSH
    +
    from netmiko.dell.dell_dnos6 import DellDNOS6SSH
     from netmiko.dell.dell_dnos6 import DellDNOS6Telnet
     from netmiko.dell.dell_force10_ssh import DellForce10SSH
     from netmiko.dell.dell_os10_ssh import DellOS10SSH, DellOS10FileTransfer
    @@ -77,7 +76,7 @@ 

    Classes

    class DellDNOS6SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Driver.

    @@ -197,6 +196,10 @@

    Classes

    :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
    Source code @@ -260,7 +263,7 @@

    Inherited members

    class DellDNOS6Telnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Driver.

    @@ -380,6 +383,10 @@

    Inherited members

    :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
    Source code @@ -443,7 +450,7 @@

    Inherited members

    class DellForce10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell Force10 Driver - supports DNOS9.

    @@ -563,6 +570,10 @@

    Inherited members

    :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
    Source code @@ -576,7 +587,7 @@

    Inherited members

    confirm_response="", ): """Saves Config""" - return super(DellForce10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -602,7 +613,7 @@

    Methods

    confirm_response="", ): """Saves Config""" - return super(DellForce10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -657,7 +668,7 @@

    Inherited members

    class DellIsilonSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -778,6 +789,10 @@

    Inherited members

    :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
    Source code @@ -786,7 +801,7 @@

    Inherited members

    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Determine base prompt.""" - return super(DellIsilonSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -795,7 +810,7 @@

    Inherited members

    def strip_ansi_escape_codes(self, string_buffer): """Remove Null code""" output = re.sub(r"\x00", "", string_buffer) - return super(DellIsilonSSH, self).strip_ansi_escape_codes(output) + return super().strip_ansi_escape_codes(output) def session_preparation(self): """Prepare the session after the connection has been established.""" @@ -818,7 +833,7 @@

    Inherited members

    self.clear_buffer() def set_prompt(self, prompt_terminator="$"): - prompt = "PROMPT='%m{}'".format(prompt_terminator) + prompt = f"PROMPT='%m{prompt_terminator}'" command = self.RETURN + prompt + self.RETURN self.write_channel(command) @@ -839,7 +854,7 @@

    Inherited members

    pass def check_config_mode(self, check_string="#"): - return super(DellIsilonSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="sudo su"): """Attempt to become root.""" @@ -860,7 +875,7 @@

    Inherited members

    def exit_config_mode(self, exit_config="exit"): """Exit enable mode.""" - return super(DellIsilonSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config)

    Ancestors

      @@ -938,7 +953,7 @@

      Methods

      Source code
      def exit_config_mode(self, exit_config="exit"):
           """Exit enable mode."""
      -    return super(DellIsilonSSH, self).exit_config_mode(exit_config=exit_config)
      + return super().exit_config_mode(exit_config=exit_config)
    @@ -982,7 +997,7 @@

    Methods

    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Determine base prompt.""" - return super(DellIsilonSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -997,7 +1012,7 @@

    Methods

    Source code
    def set_prompt(self, prompt_terminator="$"):
    -    prompt = "PROMPT='%m{}'".format(prompt_terminator)
    +    prompt = f"PROMPT='%m{prompt_terminator}'"
         command = self.RETURN + prompt + self.RETURN
         self.write_channel(command)
    @@ -1012,7 +1027,7 @@

    Methods

    def strip_ansi_escape_codes(self, string_buffer):
         """Remove Null code"""
         output = re.sub(r"\x00", "", string_buffer)
    -    return super(DellIsilonSSH, self).strip_ansi_escape_codes(output)
    + return super().strip_ansi_escape_codes(output)
    @@ -1075,7 +1090,7 @@

    Inherited members

    class DellOS10FileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system='/home/admin', direction='put', **kwargs)

    Dell EMC Networking OS10 SCP File Transfer driver.

    @@ -1085,16 +1100,21 @@

    Inherited members

    """Dell EMC Networking OS10 SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/home/admin", + direction="put", + **kwargs, ): - if file_system is None: - file_system = "/home/admin" - super(DellOS10FileTransfer, self).__init__( + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) self.folder_name = "/config" @@ -1105,7 +1125,7 @@

    Inherited members

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_cmd = 'system "ls -l {}/{}"'.format(self.file_system, remote_file) + remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' remote_out = self.ssh_ctl_chan.send_command(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: @@ -1118,7 +1138,7 @@

    Inherited members

    def remote_space_available(self, search_pattern=r"(\d+) bytes free"): """Return space available on remote device.""" - remote_cmd = 'system "df {}"'.format(self.folder_name) + remote_cmd = f'system "df {self.folder_name}"' remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: @@ -1139,7 +1159,7 @@

    Inherited members

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -1155,14 +1175,14 @@

    Inherited members

    def put_file(self): """SCP copy the file from the local system to the remote device.""" - destination = "{}".format(self.dest_file) + 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): """SCP copy the file from the remote device to local system.""" - source_file = "{}".format(self.source_file) + source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close()
    @@ -1186,7 +1206,7 @@

    Methods

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -1219,7 +1239,7 @@

    Inherited members

    class DellOS10SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell EMC Networking OS10 Driver - supports dellos10.

    @@ -1339,6 +1359,10 @@

    Inherited members

    :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
    Source code @@ -1352,7 +1376,7 @@

    Inherited members

    confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -1378,7 +1402,7 @@

    Methods

    confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -1433,7 +1457,7 @@

    Inherited members

    class DellPowerConnectSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Driver.

    @@ -1555,6 +1579,10 @@

    Inherited members

    :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
    Source code @@ -1707,7 +1735,7 @@

    Inherited members

    class DellPowerConnectTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Dell PowerConnect Telnet Driver.

    @@ -1827,6 +1855,10 @@

    Inherited members

    :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
    Source code @@ -1969,7 +2001,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/eltex/eltex_esr_ssh.html b/docs/netmiko/eltex/eltex_esr_ssh.html new file mode 100644 index 000000000..98ba9b01e --- /dev/null +++ b/docs/netmiko/eltex/eltex_esr_ssh.html @@ -0,0 +1,552 @@ + + + + + + +netmiko.eltex.eltex_esr_ssh API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.eltex.eltex_esr_ssh

    +
    +
    +
    +Source code +
    import time
    +from netmiko.cisco_base_connection import CiscoSSHConnection
    +
    +
    +class EltexEsrSSH(CiscoSSHConnection):
    +    """Netmiko support for routers Eltex ESR."""
    +
    +    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.disable_paging(command="terminal datadump")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def config_mode(self, config_command="configure", pattern=r")#"):
    +        """Enter configuration mode."""
    +        return super().config_mode(config_command=config_command, pattern=pattern)
    +
    +    def check_config_mode(self, check_string="(config", pattern=""):
    +        """Checks whether in configuration mode. Returns a boolean."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Not Implemented (use commit() method)"""
    +        raise NotImplementedError
    +
    +    def commit(self, delay_factor=1):
    +        """
    +        Commit the candidate configuration.
    +        Commit the entered configuration.
    +        Raise an error and return the failure
    +        if the commit fails.
    +        default:
    +           command_string = commit
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't commit configuration"
    +        command_string = "commit"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Commit failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _confirm(self, delay_factor=1):
    +        """
    +        Confirm the candidate configuration.
    +        Raise an error and return the failure if the confirm fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Nothing to confirm in configuration"
    +        command_string = "confirm"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Confirm failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _restore(self, delay_factor=1):
    +        """
    +        Restore the candidate configuration.
    +
    +        Raise an error and return the failure if the restore fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't find backup of previous configuration!"
    +        command_string = "restore"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Restore failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class EltexEsrSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
    +
    +

    Netmiko support for routers Eltex ESR.

    +
        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
    +
    +
    +Source code +
    class EltexEsrSSH(CiscoSSHConnection):
    +    """Netmiko support for routers Eltex ESR."""
    +
    +    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.disable_paging(command="terminal datadump")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def config_mode(self, config_command="configure", pattern=r")#"):
    +        """Enter configuration mode."""
    +        return super().config_mode(config_command=config_command, pattern=pattern)
    +
    +    def check_config_mode(self, check_string="(config", pattern=""):
    +        """Checks whether in configuration mode. Returns a boolean."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Not Implemented (use commit() method)"""
    +        raise NotImplementedError
    +
    +    def commit(self, delay_factor=1):
    +        """
    +        Commit the candidate configuration.
    +        Commit the entered configuration.
    +        Raise an error and return the failure
    +        if the commit fails.
    +        default:
    +           command_string = commit
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't commit configuration"
    +        command_string = "commit"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Commit failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _confirm(self, delay_factor=1):
    +        """
    +        Confirm the candidate configuration.
    +        Raise an error and return the failure if the confirm fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Nothing to confirm in configuration"
    +        command_string = "confirm"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Confirm failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _restore(self, delay_factor=1):
    +        """
    +        Restore the candidate configuration.
    +
    +        Raise an error and return the failure if the restore fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't find backup of previous configuration!"
    +        command_string = "restore"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Restore failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string='(config', pattern='') +
    +
    +

    Checks whether in configuration mode. Returns a boolean.

    +
    +Source code +
    def check_config_mode(self, check_string="(config", pattern=""):
    +    """Checks whether in configuration mode. Returns a boolean."""
    +    return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def commit(self, delay_factor=1) +
    +
    +

    Commit the candidate configuration. +Commit the entered configuration. +Raise an error and return the failure +if the commit fails. +default: +command_string = commit

    +
    +Source code +
    def commit(self, delay_factor=1):
    +    """
    +    Commit the candidate configuration.
    +    Commit the entered configuration.
    +    Raise an error and return the failure
    +    if the commit fails.
    +    default:
    +       command_string = commit
    +    """
    +
    +    delay_factor = self.select_delay_factor(delay_factor)
    +    error_marker = "Can't commit configuration"
    +    command_string = "commit"
    +
    +    if self.check_config_mode():
    +        self.exit_config_mode()
    +
    +    output = self.send_command(
    +        command_string=command_string, delay_factor=delay_factor
    +    )
    +
    +    if error_marker in output:
    +        raise ValueError(
    +            "Commit failed with following errors:\n\n{}".format(output)
    +        )
    +    return output
    +
    +
    +
    +def config_mode(self, config_command='configure', pattern=')#') +
    +
    +

    Enter configuration mode.

    +
    +Source code +
    def config_mode(self, config_command="configure", pattern=r")#"):
    +    """Enter configuration mode."""
    +    return super().config_mode(config_command=config_command, pattern=pattern)
    +
    +
    +
    +def save_config(self, *args, **kwargs) +
    +
    +

    Not Implemented (use commit() method)

    +
    +Source code +
    def save_config(self, *args, **kwargs):
    +    """Not Implemented (use commit() method)"""
    +    raise NotImplementedError
    +
    +
    +
    +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.disable_paging(command="terminal datadump")
    +
    +    # Clear the read buffer
    +    time.sleep(0.3 * self.global_delay_factor)
    +    self.clear_buffer()
    +
    +
    +
    +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/eltex/eltex_ssh.html b/docs/netmiko/eltex/eltex_ssh.html index 3657c7168..57d582973 100644 --- a/docs/netmiko/eltex/eltex_ssh.html +++ b/docs/netmiko/eltex/eltex_ssh.html @@ -3,13 +3,13 @@ - + netmiko.eltex.eltex_ssh API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.eltex.eltex_ssh

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -56,7 +54,7 @@ 

    Classes

    class EltexSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -176,6 +174,10 @@

    Classes

    :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
    Source code @@ -310,7 +312,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/eltex/index.html b/docs/netmiko/eltex/index.html index 1aa293a27..6db1f552f 100644 --- a/docs/netmiko/eltex/index.html +++ b/docs/netmiko/eltex/index.html @@ -3,13 +3,13 @@ - + netmiko.eltex API documentation - + @@ -22,15 +22,19 @@

    Module netmiko.eltex

    Source code -
    from __future__ import unicode_literals
    -from netmiko.eltex.eltex_ssh import EltexSSH
    +
    from netmiko.eltex.eltex_ssh import EltexSSH
    +from netmiko.eltex.eltex_esr_ssh import EltexEsrSSH
     
    -__all__ = ["EltexSSH"]
    +__all__ = ["EltexSSH", "EltexEsrSSH"]

    Sub-modules

    +
    netmiko.eltex.eltex_esr_ssh
    +
    +
    +
    netmiko.eltex.eltex_ssh
    @@ -44,9 +48,385 @@

    Sub-modules

    Classes

    +
    +class EltexEsrSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
    +
    +

    Netmiko support for routers Eltex ESR.

    +
        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
    +
    +
    +Source code +
    class EltexEsrSSH(CiscoSSHConnection):
    +    """Netmiko support for routers Eltex ESR."""
    +
    +    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.disable_paging(command="terminal datadump")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def config_mode(self, config_command="configure", pattern=r")#"):
    +        """Enter configuration mode."""
    +        return super().config_mode(config_command=config_command, pattern=pattern)
    +
    +    def check_config_mode(self, check_string="(config", pattern=""):
    +        """Checks whether in configuration mode. Returns a boolean."""
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Not Implemented (use commit() method)"""
    +        raise NotImplementedError
    +
    +    def commit(self, delay_factor=1):
    +        """
    +        Commit the candidate configuration.
    +        Commit the entered configuration.
    +        Raise an error and return the failure
    +        if the commit fails.
    +        default:
    +           command_string = commit
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't commit configuration"
    +        command_string = "commit"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Commit failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _confirm(self, delay_factor=1):
    +        """
    +        Confirm the candidate configuration.
    +        Raise an error and return the failure if the confirm fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Nothing to confirm in configuration"
    +        command_string = "confirm"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Confirm failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +    def _restore(self, delay_factor=1):
    +        """
    +        Restore the candidate configuration.
    +
    +        Raise an error and return the failure if the restore fails.
    +        """
    +
    +        delay_factor = self.select_delay_factor(delay_factor)
    +        error_marker = "Can't find backup of previous configuration!"
    +        command_string = "restore"
    +
    +        if self.check_config_mode():
    +            self.exit_config_mode()
    +
    +        output = self.send_command(
    +            command_string=command_string, delay_factor=delay_factor
    +        )
    +
    +        if error_marker in output:
    +            raise ValueError(
    +                "Restore failed with following errors:\n\n{}".format(output)
    +            )
    +        return output
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string='(config', pattern='') +
    +
    +

    Checks whether in configuration mode. Returns a boolean.

    +
    +Source code +
    def check_config_mode(self, check_string="(config", pattern=""):
    +    """Checks whether in configuration mode. Returns a boolean."""
    +    return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def commit(self, delay_factor=1) +
    +
    +

    Commit the candidate configuration. +Commit the entered configuration. +Raise an error and return the failure +if the commit fails. +default: +command_string = commit

    +
    +Source code +
    def commit(self, delay_factor=1):
    +    """
    +    Commit the candidate configuration.
    +    Commit the entered configuration.
    +    Raise an error and return the failure
    +    if the commit fails.
    +    default:
    +       command_string = commit
    +    """
    +
    +    delay_factor = self.select_delay_factor(delay_factor)
    +    error_marker = "Can't commit configuration"
    +    command_string = "commit"
    +
    +    if self.check_config_mode():
    +        self.exit_config_mode()
    +
    +    output = self.send_command(
    +        command_string=command_string, delay_factor=delay_factor
    +    )
    +
    +    if error_marker in output:
    +        raise ValueError(
    +            "Commit failed with following errors:\n\n{}".format(output)
    +        )
    +    return output
    +
    +
    +
    +def config_mode(self, config_command='configure', pattern=')#') +
    +
    +

    Enter configuration mode.

    +
    +Source code +
    def config_mode(self, config_command="configure", pattern=r")#"):
    +    """Enter configuration mode."""
    +    return super().config_mode(config_command=config_command, pattern=pattern)
    +
    +
    +
    +def save_config(self, *args, **kwargs) +
    +
    +

    Not Implemented (use commit() method)

    +
    +Source code +
    def save_config(self, *args, **kwargs):
    +    """Not Implemented (use commit() method)"""
    +    raise NotImplementedError
    +
    +
    +
    +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.disable_paging(command="terminal datadump")
    +
    +    # Clear the read buffer
    +    time.sleep(0.3 * self.global_delay_factor)
    +    self.clear_buffer()
    +
    +
    +
    +

    Inherited members

    + +
    class EltexSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -166,6 +546,10 @@

    Classes

    :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
    Source code @@ -287,12 +671,23 @@

    Index

  • Sub-modules

  • Classes

    • +

      EltexEsrSSH

      + +
    • +
    • EltexSSH

      • save_config
      • @@ -305,7 +700,7 @@

        Eltex diff --git a/docs/netmiko/endace/endace_ssh.html b/docs/netmiko/endace/endace_ssh.html index 9df350e55..4cec95ca1 100644 --- a/docs/netmiko/endace/endace_ssh.html +++ b/docs/netmiko/endace/endace_ssh.html @@ -3,13 +3,13 @@ - + netmiko.endace.endace_ssh API documentation - + @@ -22,26 +22,19 @@

        Module netmiko.endace.endace_ssh

        Source code -
        from __future__ import unicode_literals
        -
        -
        -from netmiko.cisco_base_connection import CiscoSSHConnection
        +
        from netmiko.cisco_base_connection import CiscoSSHConnection
         import re
         
         
         class EndaceSSH(CiscoSSHConnection):
             def disable_paging(self, command="no cli session paging enable", delay_factor=1):
        -        return super(EndaceSSH, self).disable_paging(
        -            command=command, delay_factor=delay_factor
        -        )
        +        return super().disable_paging(command=command, delay_factor=delay_factor)
         
             def enable(self, cmd="enable", pattern="", re_flags=re.IGNORECASE):
        -        return super(EndaceSSH, self).enable(
        -            cmd=cmd, pattern=pattern, re_flags=re_flags
        -        )
        +        return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
         
             def check_config_mode(self, check_string="(config) #"):
        -        return super(EndaceSSH, self).check_config_mode(check_string=check_string)
        +        return super().check_config_mode(check_string=check_string)
         
             def config_mode(self, config_command="conf t", pattern=""):
                 output = ""
        @@ -58,16 +51,14 @@ 

        Module netmiko.endace.endace_ssh

        return output def exit_config_mode(self, exit_config="exit", pattern="#"): - return super(EndaceSSH, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( self, cmd="configuration write", confirm=False, confirm_response="" ): self.enable() self.config_mode() - return super(EndaceSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -83,7 +74,7 @@

        Classes

        class EndaceSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Base Class for cisco-like behavior.

        @@ -203,22 +194,22 @@

        Classes

        :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
        Source code
        class EndaceSSH(CiscoSSHConnection):
             def disable_paging(self, command="no cli session paging enable", delay_factor=1):
        -        return super(EndaceSSH, self).disable_paging(
        -            command=command, delay_factor=delay_factor
        -        )
        +        return super().disable_paging(command=command, delay_factor=delay_factor)
         
             def enable(self, cmd="enable", pattern="", re_flags=re.IGNORECASE):
        -        return super(EndaceSSH, self).enable(
        -            cmd=cmd, pattern=pattern, re_flags=re_flags
        -        )
        +        return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
         
             def check_config_mode(self, check_string="(config) #"):
        -        return super(EndaceSSH, self).check_config_mode(check_string=check_string)
        +        return super().check_config_mode(check_string=check_string)
         
             def config_mode(self, config_command="conf t", pattern=""):
                 output = ""
        @@ -235,16 +226,14 @@ 

        Classes

        return output def exit_config_mode(self, exit_config="exit", pattern="#"): - return super(EndaceSSH, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( self, cmd="configuration write", confirm=False, confirm_response="" ): self.enable() self.config_mode() - return super(EndaceSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -327,7 +316,7 @@

        -

        Generated by pdoc 0.6.2.

        +

        Generated by pdoc 0.6.3.

        diff --git a/docs/netmiko/endace/index.html b/docs/netmiko/endace/index.html index 735fb9ccd..f97bcacd6 100644 --- a/docs/netmiko/endace/index.html +++ b/docs/netmiko/endace/index.html @@ -3,13 +3,13 @@ - + netmiko.endace API documentation - + @@ -22,8 +22,7 @@

        Module netmiko.endace

        Source code -
        from __future__ import unicode_literals
        -from netmiko.endace.endace_ssh import EndaceSSH
        +
        from netmiko.endace.endace_ssh import EndaceSSH
         
         __all__ = ["EndaceSSH"]
        @@ -46,7 +45,7 @@

        Classes

        class EndaceSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Base Class for cisco-like behavior.

        @@ -166,22 +165,22 @@

        Classes

        :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
        Source code
        class EndaceSSH(CiscoSSHConnection):
             def disable_paging(self, command="no cli session paging enable", delay_factor=1):
        -        return super(EndaceSSH, self).disable_paging(
        -            command=command, delay_factor=delay_factor
        -        )
        +        return super().disable_paging(command=command, delay_factor=delay_factor)
         
             def enable(self, cmd="enable", pattern="", re_flags=re.IGNORECASE):
        -        return super(EndaceSSH, self).enable(
        -            cmd=cmd, pattern=pattern, re_flags=re_flags
        -        )
        +        return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags)
         
             def check_config_mode(self, check_string="(config) #"):
        -        return super(EndaceSSH, self).check_config_mode(check_string=check_string)
        +        return super().check_config_mode(check_string=check_string)
         
             def config_mode(self, config_command="conf t", pattern=""):
                 output = ""
        @@ -198,16 +197,14 @@ 

        Classes

        return output def exit_config_mode(self, exit_config="exit", pattern="#"): - return super(EndaceSSH, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( self, cmd="configuration write", confirm=False, confirm_response="" ): self.enable() self.config_mode() - return super(EndaceSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -295,7 +292,7 @@

        E diff --git a/docs/netmiko/enterasys/enterasys_ssh.html b/docs/netmiko/enterasys/enterasys_ssh.html index 8746d5077..5a9ba7bfe 100644 --- a/docs/netmiko/enterasys/enterasys_ssh.html +++ b/docs/netmiko/enterasys/enterasys_ssh.html @@ -3,13 +3,13 @@ - + netmiko.enterasys.enterasys_ssh API documentation - + @@ -24,7 +24,6 @@

        Module netmiko.enterasys.enterasys_ssh

        Source code
        """Enterasys support."""
        -from __future__ import unicode_literals
         import time
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
        @@ -57,7 +56,7 @@ 

        Classes

        class EnterasysSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Enterasys support.

        @@ -177,6 +176,10 @@

        Classes

        :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

        Source code @@ -309,7 +312,7 @@

        -

        Generated by pdoc 0.6.2.

        +

        Generated by pdoc 0.6.3.

        diff --git a/docs/netmiko/enterasys/index.html b/docs/netmiko/enterasys/index.html index 9cc07f3a4..1ce0ef9ff 100644 --- a/docs/netmiko/enterasys/index.html +++ b/docs/netmiko/enterasys/index.html @@ -3,13 +3,13 @@ - + netmiko.enterasys API documentation - + @@ -22,8 +22,7 @@

        Module netmiko.enterasys

        Source code -
        from __future__ import unicode_literals
        -from netmiko.enterasys.enterasys_ssh import EnterasysSSH
        +
        from netmiko.enterasys.enterasys_ssh import EnterasysSSH
         
         __all__ = ["EnterasysSSH"]
        @@ -46,7 +45,7 @@

        Classes

        class EnterasysSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Enterasys support.

        @@ -166,6 +165,10 @@

        Classes

        :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
        Source code @@ -303,7 +306,7 @@

        -

        Generated by pdoc 0.6.2.

        +

        Generated by pdoc 0.6.3.

        diff --git a/docs/netmiko/extreme/extreme_ers_ssh.html b/docs/netmiko/extreme/extreme_ers_ssh.html index f42154339..b7fac7009 100644 --- a/docs/netmiko/extreme/extreme_ers_ssh.html +++ b/docs/netmiko/extreme/extreme_ers_ssh.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_ers_ssh API documentation - + @@ -24,8 +24,6 @@

        Module netmiko.extreme.extreme_ers_ssh

        Source code
        """Netmiko support for Extreme Ethernet Routing Switch."""
        -from __future__ import print_function
        -from __future__ import unicode_literals
         import time
         from netmiko.cisco_base_connection import CiscoSSHConnection
         
        @@ -65,7 +63,7 @@ 

        Module netmiko.extreme.extreme_ers_ssh

        def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeErsSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -81,7 +79,7 @@

        Classes

        class ExtremeErsSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Netmiko support for Extreme Ethernet Routing Switch.

        @@ -201,6 +199,10 @@

        Classes

        :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
        Source code @@ -236,7 +238,7 @@

        Classes

        def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeErsSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -257,7 +259,7 @@

        Methods

        Source code
        def save_config(self, cmd="save config", confirm=False, confirm_response=""):
             """Save Config"""
        -    return super(ExtremeErsSSH, self).save_config(
        +    return super().save_config(
                 cmd=cmd, confirm=confirm, confirm_response=confirm_response
             )

        @@ -374,7 +376,7 @@

        -

        Generated by pdoc 0.6.2.

        +

        Generated by pdoc 0.6.3.

        diff --git a/docs/netmiko/extreme/extreme_exos.html b/docs/netmiko/extreme/extreme_exos.html index f52920fc9..0c7576eec 100644 --- a/docs/netmiko/extreme/extreme_exos.html +++ b/docs/netmiko/extreme/extreme_exos.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_exos API documentation - + @@ -24,7 +24,6 @@

        Module netmiko.extreme.extreme_exos

        Source code
        """Extreme support."""
        -from __future__ import unicode_literals
         import time
         import re
         from netmiko.cisco_base_connection import CiscoSSHConnection
        @@ -60,7 +59,7 @@ 

        Module netmiko.extreme.extreme_exos

        * testhost.4 # * testhost.5 # """ - cur_base_prompt = super(ExtremeExosBase, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) # Strip off any leading * or whitespace chars; strip off trailing period and digits match = re.search(r"[\*\s]*(.*)\.\d+", cur_base_prompt) if match: @@ -77,7 +76,7 @@

        Module netmiko.extreme.extreme_exos

        # refresh self.base_prompt self.set_base_prompt() - return super(ExtremeExosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def config_mode(self, config_command=""): """No configuration mode on Extreme Exos.""" @@ -85,7 +84,7 @@

        Module netmiko.extreme.extreme_exos

        def check_config_mode(self, check_string="#"): """Checks whether in configuration mode. Returns a boolean.""" - return super(ExtremeExosBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def exit_config_mode(self, exit_config=""): """No configuration mode on Extreme Exos.""" @@ -95,7 +94,7 @@

        Module netmiko.extreme.extreme_exos

        self, cmd="save configuration primary", confirm=False, confirm_response="" ): """Saves configuration.""" - return super(ExtremeExosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -108,7 +107,7 @@

        Module netmiko.extreme.extreme_exos

        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(ExtremeExosTelnet, self).__init__(*args, **kwargs)
        + super().__init__(*args, **kwargs)

        @@ -122,7 +121,7 @@

        Classes

        class ExtremeExosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

        Extreme Exos support.

        @@ -243,6 +242,10 @@

        Classes

        :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
        Source code @@ -276,7 +279,7 @@

        Classes

        * testhost.4 # * testhost.5 # """ - cur_base_prompt = super(ExtremeExosBase, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) # Strip off any leading * or whitespace chars; strip off trailing period and digits match = re.search(r"[\*\s]*(.*)\.\d+", cur_base_prompt) if match: @@ -293,7 +296,7 @@

        Classes

        # refresh self.base_prompt self.set_base_prompt() - return super(ExtremeExosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def config_mode(self, config_command=""): """No configuration mode on Extreme Exos.""" @@ -301,7 +304,7 @@

        Classes

        def check_config_mode(self, check_string="#"): """Checks whether in configuration mode. Returns a boolean.""" - return super(ExtremeExosBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def exit_config_mode(self, exit_config=""): """No configuration mode on Extreme Exos.""" @@ -311,7 +314,7 @@

        Classes

        self, cmd="save configuration primary", confirm=False, confirm_response="" ): """Saves configuration.""" - return super(ExtremeExosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
        @@ -337,7 +340,7 @@

        Methods

        Source code
        def check_config_mode(self, check_string="#"):
             """Checks whether in configuration mode. Returns a boolean."""
        -    return super(ExtremeExosBase, self).check_config_mode(check_string=check_string)
        + return super().check_config_mode(check_string=check_string)

        @@ -375,7 +378,7 @@

        Methods

        self, cmd="save configuration primary", confirm=False, confirm_response="" ): """Saves configuration.""" - return super(ExtremeExosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )

  • @@ -395,7 +398,7 @@

    Methods

    # refresh self.base_prompt self.set_base_prompt() - return super(ExtremeExosBase, self).send_command(*args, **kwargs)
    + return super().send_command(*args, **kwargs)

    @@ -430,7 +433,7 @@

    Methods

    * testhost.4 # * testhost.5 # """ - cur_base_prompt = super(ExtremeExosBase, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) # Strip off any leading * or whitespace chars; strip off trailing period and digits match = re.search(r"[\*\s]*(.*)\.\d+", cur_base_prompt) if match: @@ -485,7 +488,7 @@

    Inherited members

    class ExtremeExosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme Exos support.

    @@ -606,6 +609,10 @@

    Inherited members

    :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
    Source code @@ -790,6 +797,10 @@

    Inherited members

    :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
    Source code @@ -797,7 +808,7 @@

    Inherited members

    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(ExtremeExosTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -893,7 +904,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/extreme/extreme_netiron.html b/docs/netmiko/extreme/extreme_netiron.html index e45384b8c..2a473d155 100644 --- a/docs/netmiko/extreme/extreme_netiron.html +++ b/docs/netmiko/extreme/extreme_netiron.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_netiron API documentation - + @@ -22,14 +22,13 @@

      Module netmiko.extreme.extreme_netiron

      Source code -
      from __future__ import unicode_literals
      -from netmiko.cisco_base_connection import CiscoSSHConnection
      +
      from netmiko.cisco_base_connection import CiscoSSHConnection
       
       
       class ExtremeNetironBase(CiscoSSHConnection):
           def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
               """Save Config"""
      -        return super(ExtremeNetironBase, self).save_config(
      +        return super().save_config(
                   cmd=cmd, confirm=confirm, confirm_response=confirm_response
               )
       
      @@ -42,7 +41,7 @@ 

      Module netmiko.extreme.extreme_netiron

      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(ExtremeNetironTelnet, self).__init__(*args, **kwargs)
      + super().__init__(*args, **kwargs)
      @@ -56,7 +55,7 @@

      Classes

      class ExtremeNetironBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Base Class for cisco-like behavior.

      @@ -176,13 +175,17 @@

      Classes

      :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
      Source code
      class ExtremeNetironBase(CiscoSSHConnection):
           def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
               """Save Config"""
      -        return super(ExtremeNetironBase, self).save_config(
      +        return super().save_config(
                   cmd=cmd, confirm=confirm, confirm_response=confirm_response
               )
      @@ -208,7 +211,7 @@

      Methods

      Source code
      def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
           """Save Config"""
      -    return super(ExtremeNetironBase, self).save_config(
      +    return super().save_config(
               cmd=cmd, confirm=confirm, confirm_response=confirm_response
           )

    @@ -263,7 +266,7 @@

    Inherited members

    class ExtremeNetironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -383,6 +386,10 @@

    Inherited members

    :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
    Source code @@ -566,6 +573,10 @@

    Inherited members

    :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
    Source code @@ -573,7 +584,7 @@

    Inherited members

    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(ExtremeNetironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -664,7 +675,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/extreme/extreme_nos_ssh.html b/docs/netmiko/extreme/extreme_nos_ssh.html index 16829e766..ea7129162 100644 --- a/docs/netmiko/extreme/extreme_nos_ssh.html +++ b/docs/netmiko/extreme/extreme_nos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_nos_ssh API documentation - + @@ -24,7 +24,6 @@

      Module netmiko.extreme.extreme_nos_ssh

      Source code
      """Support for Extreme NOS/VDX."""
      -from __future__ import unicode_literals
       import time
       from netmiko.cisco_base_connection import CiscoSSHConnection
       
      @@ -53,7 +52,7 @@ 

      Module netmiko.extreme.extreme_nos_ssh

      confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
      @@ -69,7 +68,7 @@

      Classes

      class ExtremeNosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Support for Extreme NOS/VDX.

      @@ -189,6 +188,10 @@

      Classes

      :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
      Source code @@ -216,7 +219,7 @@

      Classes

      confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
      @@ -266,7 +269,7 @@

      Methods

      confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )

    @@ -361,7 +364,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/extreme/extreme_slx_ssh.html b/docs/netmiko/extreme/extreme_slx_ssh.html index 536399fa7..dfa4d39bb 100644 --- a/docs/netmiko/extreme/extreme_slx_ssh.html +++ b/docs/netmiko/extreme/extreme_slx_ssh.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_slx_ssh API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.extreme.extreme_slx_ssh

    Source code
    """Support for Extreme SLX."""
    -from __future__ import unicode_literals
     import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
    @@ -53,7 +52,7 @@ 

    Module netmiko.extreme.extreme_slx_ssh

    confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -69,7 +68,7 @@

    Classes

    class ExtremeSlxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Support for Extreme SLX.

    @@ -189,6 +188,10 @@

    Classes

    :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
    Source code @@ -216,7 +219,7 @@

    Classes

    confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -266,7 +269,7 @@

    Methods

    confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -361,7 +364,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/extreme/extreme_vsp_ssh.html b/docs/netmiko/extreme/extreme_vsp_ssh.html index 9bd0fa2de..e3d909b9c 100644 --- a/docs/netmiko/extreme/extreme_vsp_ssh.html +++ b/docs/netmiko/extreme/extreme_vsp_ssh.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_vsp_ssh API documentation - + @@ -24,8 +24,6 @@

    Module netmiko.extreme.extreme_vsp_ssh

    Source code
    """Extreme Virtual Services Platform Support."""
    -from __future__ import print_function
    -from __future__ import unicode_literals
     import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
    @@ -44,7 +42,7 @@ 

    Module netmiko.extreme.extreme_vsp_ssh

    def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeVspSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -60,7 +58,7 @@

    Classes

    class ExtremeVspSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme Virtual Services Platform Support.

    @@ -180,6 +178,10 @@

    Classes

    :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
    Source code @@ -197,7 +199,7 @@

    Classes

    def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeVspSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -218,7 +220,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
         """Save Config"""
    -    return super(ExtremeVspSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -316,7 +318,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/extreme/extreme_wing_ssh.html b/docs/netmiko/extreme/extreme_wing_ssh.html index 8eb83fe86..9e1a36aad 100644 --- a/docs/netmiko/extreme/extreme_wing_ssh.html +++ b/docs/netmiko/extreme/extreme_wing_ssh.html @@ -3,13 +3,13 @@ - + netmiko.extreme.extreme_wing_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.extreme.extreme_wing_ssh

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -51,7 +50,7 @@ 

    Classes

    class ExtremeWingSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme WiNG support.

    @@ -171,6 +170,10 @@

    Classes

    :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
    Source code @@ -287,7 +290,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/extreme/index.html b/docs/netmiko/extreme/index.html index 9a56cc881..c2eeeab47 100644 --- a/docs/netmiko/extreme/index.html +++ b/docs/netmiko/extreme/index.html @@ -3,13 +3,13 @@ - + netmiko.extreme API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.extreme

    Source code -
    from __future__ import unicode_literals
    -from netmiko.extreme.extreme_ers_ssh import ExtremeErsSSH
    +
    from netmiko.extreme.extreme_ers_ssh import ExtremeErsSSH
     from netmiko.extreme.extreme_exos import ExtremeExosSSH
     from netmiko.extreme.extreme_exos import ExtremeExosTelnet
     from netmiko.extreme.extreme_netiron import ExtremeNetironSSH
    @@ -88,7 +87,7 @@ 

    Classes

    class ExtremeErsSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Netmiko support for Extreme Ethernet Routing Switch.

    @@ -208,6 +207,10 @@

    Classes

    :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
    Source code @@ -243,7 +246,7 @@

    Classes

    def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeErsSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -264,7 +267,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
         """Save Config"""
    -    return super(ExtremeErsSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )

    @@ -354,7 +357,7 @@

    Inherited members

    class ExtremeExosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme Exos support.

    @@ -475,6 +478,10 @@

    Inherited members

    :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
    Source code @@ -659,6 +666,10 @@

    Inherited members

    :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
    Source code @@ -666,7 +677,7 @@

    Inherited members

    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(ExtremeExosTelnet, self).__init__(*args, **kwargs)
    + super().__init__(*args, **kwargs)

    Ancestors

      @@ -725,7 +736,7 @@

      Inherited members

    class ExtremeNetironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -845,6 +856,10 @@

    Inherited members

    :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
    Source code @@ -1028,6 +1043,10 @@

    Inherited members

    :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
    Source code @@ -1035,7 +1054,7 @@

    Inherited members

    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(ExtremeNetironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -1094,7 +1113,7 @@

      Inherited members

    class ExtremeNosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Support for Extreme NOS/VDX.

    @@ -1214,6 +1233,10 @@

    Inherited members

    :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
    Source code @@ -1241,7 +1264,7 @@

    Inherited members

    confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -1291,7 +1314,7 @@

    Methods

    confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -1357,7 +1380,7 @@

    Inherited members

    class ExtremeSlxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Support for Extreme SLX.

    @@ -1477,6 +1500,10 @@

    Inherited members

    :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
    Source code @@ -1504,7 +1531,7 @@

    Inherited members

    confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -1554,7 +1581,7 @@

    Methods

    confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -1620,7 +1647,7 @@

    Inherited members

    class ExtremeVspSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme Virtual Services Platform Support.

    @@ -1740,6 +1767,10 @@

    Inherited members

    :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
    Source code @@ -1757,7 +1788,7 @@

    Inherited members

    def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeVspSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -1778,7 +1809,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
         """Save Config"""
    -    return super(ExtremeVspSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -1849,7 +1880,7 @@

    Inherited members

    class ExtremeWingSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Extreme WiNG support.

    @@ -1969,6 +2000,10 @@

    Inherited members

    :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
    Source code @@ -2140,7 +2175,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/f5/f5_linux_ssh.html b/docs/netmiko/f5/f5_linux_ssh.html index 422c5bfa1..b477ccb4a 100644 --- a/docs/netmiko/f5/f5_linux_ssh.html +++ b/docs/netmiko/f5/f5_linux_ssh.html @@ -3,13 +3,13 @@ - + netmiko.f5.f5_linux_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.f5.f5_linux_ssh

    Source code -
    from __future__ import unicode_literals
    -from netmiko.linux.linux_ssh import LinuxSSH
    +
    from netmiko.linux.linux_ssh import LinuxSSH
     
     
     class F5LinuxSSH(LinuxSSH):
    @@ -41,7 +40,7 @@ 

    Classes

    class F5LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -161,6 +160,10 @@

    Classes

    :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
    Source code @@ -247,7 +250,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/f5/f5_tmsh_ssh.html b/docs/netmiko/f5/f5_tmsh_ssh.html index d747fe4c2..f97e793c1 100644 --- a/docs/netmiko/f5/f5_tmsh_ssh.html +++ b/docs/netmiko/f5/f5_tmsh_ssh.html @@ -3,13 +3,13 @@ - + netmiko.f5.f5_tmsh_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.f5.f5_tmsh_ssh

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.base_connection import BaseConnection
     
     
    @@ -45,7 +44,7 @@ 

    Module netmiko.f5.f5_tmsh_ssh

    """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() @@ -63,7 +62,7 @@

    Classes

    class F5TmshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -184,6 +183,10 @@

    Classes

    :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
    Source code @@ -205,7 +208,7 @@

    Classes

    """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() @@ -249,7 +252,7 @@

    Methods

    """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() @@ -333,7 +336,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/f5/index.html b/docs/netmiko/f5/index.html index 5dcebd4dc..7189f067f 100644 --- a/docs/netmiko/f5/index.html +++ b/docs/netmiko/f5/index.html @@ -3,13 +3,13 @@ - + netmiko.f5 API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.f5

    Source code -
    from __future__ import unicode_literals
    -from netmiko.f5.f5_tmsh_ssh import F5TmshSSH
    +
    from netmiko.f5.f5_tmsh_ssh import F5TmshSSH
     from netmiko.f5.f5_linux_ssh import F5LinuxSSH
     
     __all__ = ["F5TmshSSH", "F5LinuxSSH"]
    @@ -51,7 +50,7 @@

    Classes

    class F5LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -171,6 +170,10 @@

    Classes

    :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
    Source code @@ -234,7 +237,7 @@

    Inherited members

    class F5TmshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -355,6 +358,10 @@

    Inherited members

    :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
    Source code @@ -376,7 +383,7 @@

    Inherited members

    """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() @@ -420,7 +427,7 @@

    Methods

    """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() @@ -513,7 +520,7 @@

    F5TmshSSH diff --git a/docs/netmiko/flexvnf/flexvnf_ssh.html b/docs/netmiko/flexvnf/flexvnf_ssh.html index 3ad80511c..3d98954c7 100644 --- a/docs/netmiko/flexvnf/flexvnf_ssh.html +++ b/docs/netmiko/flexvnf/flexvnf_ssh.html @@ -3,13 +3,13 @@ - + netmiko.flexvnf.flexvnf_ssh API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.flexvnf.flexvnf_ssh

    Source code -
    from __future__ import unicode_literals
    -
    -import re
    +
    import re
     import time
     
     from netmiko.base_connection import BaseConnection
    @@ -81,11 +79,11 @@ 

    Module netmiko.flexvnf.flexvnf_ssh

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(FlexvnfSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(FlexvnfSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -161,7 +159,7 @@

    Module netmiko.flexvnf.flexvnf_ssh

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -188,15 +186,13 @@

    Module netmiko.flexvnf.flexvnf_ssh

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -243,7 +239,7 @@

    Classes

    class FlexvnfSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -364,6 +360,10 @@

    Classes

    :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
    Source code @@ -418,11 +418,11 @@

    Classes

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(FlexvnfSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(FlexvnfSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -498,7 +498,7 @@

    Classes

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -525,15 +525,13 @@

    Classes

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -583,7 +581,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Checks if the device is in configuration mode or not."""
    -    return super(FlexvnfSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)

    @@ -678,7 +676,7 @@

    Methods

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -705,9 +703,7 @@

    Methods

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output
    @@ -721,7 +717,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(FlexvnfSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)

    @@ -880,7 +876,7 @@

    Methods

    Source code
    def strip_prompt(self, *args, **kwargs):
         """Strip the trailing router prompt from the output."""
    -    a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs)
    +    a_string = super().strip_prompt(*args, **kwargs)
         return self.strip_context_items(a_string)

    @@ -962,7 +958,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/flexvnf/index.html b/docs/netmiko/flexvnf/index.html index 885f07325..b204a09b9 100644 --- a/docs/netmiko/flexvnf/index.html +++ b/docs/netmiko/flexvnf/index.html @@ -3,13 +3,13 @@ - + netmiko.flexvnf API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.flexvnf

    Source code -
    from __future__ import unicode_literals
    -from netmiko.flexvnf.flexvnf_ssh import FlexvnfSSH
    +
    from netmiko.flexvnf.flexvnf_ssh import FlexvnfSSH
     
     __all__ = ["FlexvnfSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class FlexvnfSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -167,6 +166,10 @@

    Classes

    :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
    Source code @@ -221,11 +224,11 @@

    Classes

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(FlexvnfSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(FlexvnfSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -301,7 +304,7 @@

    Classes

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -328,15 +331,13 @@

    Classes

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -386,7 +387,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Checks if the device is in configuration mode or not."""
    -    return super(FlexvnfSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -481,7 +482,7 @@

    Methods

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -508,9 +509,7 @@

    Methods

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output
    @@ -524,7 +523,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(FlexvnfSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -683,7 +682,7 @@

    Methods

    Source code
    def strip_prompt(self, *args, **kwargs):
         """Strip the trailing router prompt from the output."""
    -    a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs)
    +    a_string = super().strip_prompt(*args, **kwargs)
         return self.strip_context_items(a_string)
    @@ -770,7 +769,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/fortinet/fortinet_ssh.html b/docs/netmiko/fortinet/fortinet_ssh.html index 090ecaf7f..d88c73f26 100644 --- a/docs/netmiko/fortinet/fortinet_ssh.html +++ b/docs/netmiko/fortinet/fortinet_ssh.html @@ -3,13 +3,13 @@ - + netmiko.fortinet.fortinet_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.fortinet.fortinet_ssh

    Source code -
    from __future__ import unicode_literals
    -import paramiko
    +
    import paramiko
     import time
     import re
     from netmiko.cisco_base_connection import CiscoSSHConnection
    @@ -41,6 +40,21 @@ 

    Module netmiko.fortinet.fortinet_ssh

    def session_preparation(self): """Prepare the session after the connection has been established.""" + delay_factor = self.select_delay_factor(delay_factor=0) + output = "" + + # If "set post-login-banner enable" is set it will require you to press 'a' + # to accept the banner before you login. This will accept if it occurs + count = 1 + while count <= 30: + output += self.read_channel() + if "to accept" in output: + self.write_channel("a\r") + break + else: + time.sleep(0.33 * delay_factor) + count += 1 + self._test_channel_read() self.set_base_prompt(alt_prompt_terminator="$") self.disable_paging() @@ -99,7 +113,7 @@

    Module netmiko.fortinet.fortinet_ssh

    """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") @@ -131,7 +145,7 @@

    Classes

    class FortinetSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -251,6 +265,10 @@

    Classes

    :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
    Source code @@ -266,6 +284,21 @@

    Classes

    def session_preparation(self): """Prepare the session after the connection has been established.""" + delay_factor = self.select_delay_factor(delay_factor=0) + output = "" + + # If "set post-login-banner enable" is set it will require you to press 'a' + # to accept the banner before you login. This will accept if it occurs + count = 1 + while count <= 30: + output += self.read_channel() + if "to accept" in output: + self.write_channel("a\r") + break + else: + time.sleep(0.33 * delay_factor) + count += 1 + self._test_channel_read() self.set_base_prompt(alt_prompt_terminator="$") self.disable_paging() @@ -324,7 +357,7 @@

    Classes

    """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") @@ -363,7 +396,7 @@

    Methods

    """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") @@ -462,6 +495,21 @@

    Methods

    Source code
    def session_preparation(self):
         """Prepare the session after the connection has been established."""
    +    delay_factor = self.select_delay_factor(delay_factor=0)
    +    output = ""
    +
    +    # If "set post-login-banner enable" is set it will require you to press 'a'
    +    # to accept the banner before you login. This will accept if it occurs
    +    count = 1
    +    while count <= 30:
    +        output += self.read_channel()
    +        if "to accept" in output:
    +            self.write_channel("a\r")
    +            break
    +        else:
    +            time.sleep(0.33 * delay_factor)
    +        count += 1
    +
         self._test_channel_read()
         self.set_base_prompt(alt_prompt_terminator="$")
         self.disable_paging()
    @@ -546,7 +594,7 @@ 

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/fortinet/index.html b/docs/netmiko/fortinet/index.html index fc79cabe0..e6b006546 100644 --- a/docs/netmiko/fortinet/index.html +++ b/docs/netmiko/fortinet/index.html @@ -3,13 +3,13 @@ - + netmiko.fortinet API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.fortinet

    Source code -
    from __future__ import unicode_literals
    -from netmiko.fortinet.fortinet_ssh import FortinetSSH
    +
    from netmiko.fortinet.fortinet_ssh import FortinetSSH
     
     __all__ = ["FortinetSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class FortinetSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -166,6 +165,10 @@

    Classes

    :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

    Source code @@ -181,6 +184,21 @@

    Classes

    def session_preparation(self): """Prepare the session after the connection has been established.""" + delay_factor = self.select_delay_factor(delay_factor=0) + output = "" + + # If "set post-login-banner enable" is set it will require you to press 'a' + # to accept the banner before you login. This will accept if it occurs + count = 1 + while count <= 30: + output += self.read_channel() + if "to accept" in output: + self.write_channel("a\r") + break + else: + time.sleep(0.33 * delay_factor) + count += 1 + self._test_channel_read() self.set_base_prompt(alt_prompt_terminator="$") self.disable_paging() @@ -239,7 +257,7 @@

    Classes

    """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") @@ -278,7 +296,7 @@

    Methods

    """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") @@ -377,6 +395,21 @@

    Methods

    Source code
    def session_preparation(self):
         """Prepare the session after the connection has been established."""
    +    delay_factor = self.select_delay_factor(delay_factor=0)
    +    output = ""
    +
    +    # If "set post-login-banner enable" is set it will require you to press 'a'
    +    # to accept the banner before you login. This will accept if it occurs
    +    count = 1
    +    while count <= 30:
    +        output += self.read_channel()
    +        if "to accept" in output:
    +            self.write_channel("a\r")
    +            break
    +        else:
    +            time.sleep(0.33 * delay_factor)
    +        count += 1
    +
         self._test_channel_read()
         self.set_base_prompt(alt_prompt_terminator="$")
         self.disable_paging()
    @@ -466,7 +499,7 @@ 

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/hp/hp_comware.html b/docs/netmiko/hp/hp_comware.html index 39acd068d..87f290af3 100644 --- a/docs/netmiko/hp/hp_comware.html +++ b/docs/netmiko/hp/hp_comware.html @@ -3,13 +3,13 @@ - + netmiko.hp.hp_comware API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.hp.hp_comware

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -55,17 +53,15 @@ 

    Module netmiko.hp.hp_comware

    def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HPComwareBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit config mode.""" - return super(HPComwareBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Check whether device is in configuration mode. Return a boolean.""" - return super(HPComwareBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def set_base_prompt( self, pri_prompt_terminator=">", alt_prompt_terminator="]", delay_factor=1 @@ -80,7 +76,7 @@

    Module netmiko.hp.hp_comware

    This will be set on logging in, but not when entering system-view """ - prompt = super(HPComwareBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -106,7 +102,7 @@

    Module netmiko.hp.hp_comware

    def save_config(self, cmd="save force", confirm=False, confirm_response=""): """Save Config.""" - return super(HPComwareBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -119,7 +115,7 @@

    Module netmiko.hp.hp_comware

    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(HPComwareTelnet, self).__init__(*args, **kwargs)
    + super().__init__(*args, **kwargs)
    @@ -133,7 +129,7 @@

    Classes

    class HPComwareBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -253,6 +249,10 @@

    Classes

    :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

    Source code @@ -283,17 +283,15 @@

    Classes

    def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HPComwareBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit config mode.""" - return super(HPComwareBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Check whether device is in configuration mode. Return a boolean.""" - return super(HPComwareBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def set_base_prompt( self, pri_prompt_terminator=">", alt_prompt_terminator="]", delay_factor=1 @@ -308,7 +306,7 @@

    Classes

    This will be set on logging in, but not when entering system-view """ - prompt = super(HPComwareBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -334,7 +332,7 @@

    Classes

    def save_config(self, cmd="save force", confirm=False, confirm_response=""): """Save Config.""" - return super(HPComwareBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -360,7 +358,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Check whether device is in configuration mode. Return a boolean."""
    -    return super(HPComwareBase, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -384,7 +382,7 @@

    Methods

    Source code
    def config_mode(self, config_command="system-view"):
         """Enter configuration mode."""
    -    return super(HPComwareBase, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -408,9 +406,7 @@

    Methods

    Source code
    def exit_config_mode(self, exit_config="return", pattern=r">"):
         """Exit config mode."""
    -    return super(HPComwareBase, self).exit_config_mode(
    -        exit_config=exit_config, pattern=pattern
    -    )
    + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
    @@ -434,7 +430,7 @@

    Methods

    Source code
    def save_config(self, cmd="save force", confirm=False, confirm_response=""):
         """Save Config."""
    -    return super(HPComwareBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -496,7 +492,7 @@

    Methods

    This will be set on logging in, but not when entering system-view """ - prompt = super(HPComwareBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -551,7 +547,7 @@

    Inherited members

    class HPComwareSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -671,6 +667,10 @@

    Inherited members

    :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
    Source code @@ -854,6 +854,10 @@

    Inherited members

    :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
    Source code @@ -861,7 +865,7 @@

    Inherited members

    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(HPComwareTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -960,7 +964,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/hp/hp_procurve.html b/docs/netmiko/hp/hp_procurve.html index 946af9f91..6b0714e50 100644 --- a/docs/netmiko/hp/hp_procurve.html +++ b/docs/netmiko/hp/hp_procurve.html @@ -3,13 +3,13 @@ - + netmiko.hp.hp_procurve API documentation - + @@ -22,9 +22,7 @@

      Module netmiko.hp.hp_procurve

      Source code -
      from __future__ import print_function
      -from __future__ import unicode_literals
      -import re
      +
      import re
       import time
       import socket
       from os import path
      @@ -66,19 +64,39 @@ 

      Module netmiko.hp.hp_procurve

      default_username="manager", ): """Enter enable mode""" + delay_factor = self.select_delay_factor(delay_factor=0) if self.check_enable_mode(): return "" - output = self.send_command_timing(cmd) - if ( - "username" in output.lower() - or "login name" in output.lower() - or "user name" in output.lower() - ): - output += self.send_command_timing(default_username) - if "password" in output.lower(): - output += self.send_command_timing(self.secret) - log.debug("{}".format(output)) + + output = "" + i = 1 + max_attempts = 5 + while i <= max_attempts: + self.write_channel(cmd + self.RETURN) + time.sleep(0.3 * delay_factor) + new_output = self.read_channel() + username_pattern = r"(username|login|user name)" + if re.search(username_pattern, new_output, flags=re_flags): + output += new_output + new_output = self.send_command_timing(default_username) + if re.search(pattern, new_output, flags=re_flags): + output += new_output + self.write_channel(self.normalize_cmd(self.secret)) + new_output = self._read_channel_timing() + if self.check_enable_mode(): + output += new_output + return output + output += new_output + i += 1 + + log.debug(f"{output}") self.clear_buffer() + msg = ( + "Failed to enter enable mode. Please ensure you pass " + "the 'secret' argument to ConnectHandler." + ) + if not self.check_enable_mode(): + raise ValueError(msg) return output def cleanup(self): @@ -105,7 +123,7 @@

      Module netmiko.hp.hp_procurve

      def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Save Config.""" - return super(HPProcurveBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -131,7 +149,7 @@

      Module netmiko.hp.hp_procurve

      # Try one last time to past "Press any key to continue self.write_channel(self.RETURN) - super(HPProcurveSSH, self).session_preparation() + super().session_preparation() def _build_ssh_client(self): """Allow passwordless authentication for HP devices being provisioned.""" @@ -164,7 +182,7 @@

      Module netmiko.hp.hp_procurve

      max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -185,7 +203,7 @@

      Classes

      class HPProcurveBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Base Class for cisco-like behavior.

      @@ -305,6 +323,10 @@

      Classes

      :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
      Source code @@ -333,19 +355,39 @@

      Classes

      default_username="manager", ): """Enter enable mode""" + delay_factor = self.select_delay_factor(delay_factor=0) if self.check_enable_mode(): return "" - output = self.send_command_timing(cmd) - if ( - "username" in output.lower() - or "login name" in output.lower() - or "user name" in output.lower() - ): - output += self.send_command_timing(default_username) - if "password" in output.lower(): - output += self.send_command_timing(self.secret) - log.debug("{}".format(output)) + + output = "" + i = 1 + max_attempts = 5 + while i <= max_attempts: + self.write_channel(cmd + self.RETURN) + time.sleep(0.3 * delay_factor) + new_output = self.read_channel() + username_pattern = r"(username|login|user name)" + if re.search(username_pattern, new_output, flags=re_flags): + output += new_output + new_output = self.send_command_timing(default_username) + if re.search(pattern, new_output, flags=re_flags): + output += new_output + self.write_channel(self.normalize_cmd(self.secret)) + new_output = self._read_channel_timing() + if self.check_enable_mode(): + output += new_output + return output + output += new_output + i += 1 + + log.debug(f"{output}") self.clear_buffer() + msg = ( + "Failed to enter enable mode. Please ensure you pass " + "the 'secret' argument to ConnectHandler." + ) + if not self.check_enable_mode(): + raise ValueError(msg) return output def cleanup(self): @@ -372,7 +414,7 @@

      Classes

      def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Save Config.""" - return super(HPProcurveBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
      @@ -404,19 +446,39 @@

      Methods

      default_username="manager", ): """Enter enable mode""" + delay_factor = self.select_delay_factor(delay_factor=0) if self.check_enable_mode(): return "" - output = self.send_command_timing(cmd) - if ( - "username" in output.lower() - or "login name" in output.lower() - or "user name" in output.lower() - ): - output += self.send_command_timing(default_username) - if "password" in output.lower(): - output += self.send_command_timing(self.secret) - log.debug("{}".format(output)) + + output = "" + i = 1 + max_attempts = 5 + while i <= max_attempts: + self.write_channel(cmd + self.RETURN) + time.sleep(0.3 * delay_factor) + new_output = self.read_channel() + username_pattern = r"(username|login|user name)" + if re.search(username_pattern, new_output, flags=re_flags): + output += new_output + new_output = self.send_command_timing(default_username) + if re.search(pattern, new_output, flags=re_flags): + output += new_output + self.write_channel(self.normalize_cmd(self.secret)) + new_output = self._read_channel_timing() + if self.check_enable_mode(): + output += new_output + return output + output += new_output + i += 1 + + log.debug(f"{output}") self.clear_buffer() + msg = ( + "Failed to enter enable mode. Please ensure you pass " + "the 'secret' argument to ConnectHandler." + ) + if not self.check_enable_mode(): + raise ValueError(msg) return output

    @@ -429,7 +491,7 @@

    Methods

    Source code
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
         """Save Config."""
    -    return super(HPProcurveBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -506,7 +568,7 @@

    Inherited members

    class HPProcurveSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -626,6 +688,10 @@

    Inherited members

    :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
    Source code @@ -650,7 +716,7 @@

    Inherited members

    # Try one last time to past "Press any key to continue self.write_channel(self.RETURN) - super(HPProcurveSSH, self).session_preparation() + super().session_preparation() def _build_ssh_client(self): """Allow passwordless authentication for HP devices being provisioned.""" @@ -728,7 +794,7 @@

    Inherited members

    class HPProcurveTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -848,6 +914,10 @@

    Inherited members

    :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
    Source code @@ -862,7 +932,7 @@

    Inherited members

    max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -897,7 +967,7 @@

    Methods

    max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -1018,7 +1088,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/hp/index.html b/docs/netmiko/hp/index.html index d0f2c385a..dce1f864a 100644 --- a/docs/netmiko/hp/index.html +++ b/docs/netmiko/hp/index.html @@ -3,13 +3,13 @@ - + netmiko.hp API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.hp

    Source code -
    from __future__ import unicode_literals
    -from netmiko.hp.hp_procurve import HPProcurveSSH, HPProcurveTelnet
    +
    from netmiko.hp.hp_procurve import HPProcurveSSH, HPProcurveTelnet
     from netmiko.hp.hp_comware import HPComwareSSH, HPComwareTelnet
     
     __all__ = ["HPProcurveSSH", "HPProcurveTelnet", "HPComwareSSH", "HPComwareTelnet"]
    @@ -51,7 +50,7 @@

    Classes

    class HPComwareSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -171,6 +170,10 @@

    Classes

    :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
    Source code @@ -354,6 +357,10 @@

    Inherited members

    :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
    Source code @@ -361,7 +368,7 @@

    Inherited members

    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(HPComwareTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -420,7 +427,7 @@

      Inherited members

    class HPProcurveSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -540,6 +547,10 @@

    Inherited members

    :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
    Source code @@ -564,7 +575,7 @@

    Inherited members

    # Try one last time to past "Press any key to continue self.write_channel(self.RETURN) - super(HPProcurveSSH, self).session_preparation() + super().session_preparation() def _build_ssh_client(self): """Allow passwordless authentication for HP devices being provisioned.""" @@ -642,7 +653,7 @@

    Inherited members

    class HPProcurveTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -762,6 +773,10 @@

    Inherited members

    :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
    Source code @@ -776,7 +791,7 @@

    Inherited members

    max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -811,7 +826,7 @@

    Methods

    max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -912,7 +927,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/huawei/huawei.html b/docs/netmiko/huawei/huawei.html index 60ee74db9..76b701803 100644 --- a/docs/netmiko/huawei/huawei.html +++ b/docs/netmiko/huawei/huawei.html @@ -3,13 +3,13 @@ - + netmiko.huawei.huawei API documentation - + @@ -22,12 +22,10 @@

    Module netmiko.huawei.huawei

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import time
    +
    import time
     import re
     from netmiko.cisco_base_connection import CiscoBaseConnection
    -from netmiko.ssh_exception import NetMikoAuthenticationException
    +from netmiko.ssh_exception import NetmikoAuthenticationException
     from netmiko import log
     
     
    @@ -43,17 +41,15 @@ 

    Module netmiko.huawei.huawei

    def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HuaweiBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit configuration mode.""" - return super(HuaweiBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Checks whether in configuration mode. Returns a boolean.""" - return super(HuaweiBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def check_enable_mode(self, *args, **kwargs): """Huawei has no enable mode.""" @@ -95,7 +91,7 @@

    Module netmiko.huawei.huawei

    # Check that ends with a valid terminator character if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {0}".format(prompt)) + raise ValueError(f"Router prompt not found: {prompt}") # Strip off any leading HRP_. characters for USGv5 HA prompt = re.sub(r"^HRP_.", "", prompt, flags=re.M) @@ -104,13 +100,13 @@

    Module netmiko.huawei.huawei

    prompt = prompt[1:-1] prompt = prompt.strip() self.base_prompt = prompt - log.debug("prompt: {0}".format(self.base_prompt)) + log.debug(f"prompt: {self.base_prompt}") return self.base_prompt - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config(self, cmd="save", confirm=True, confirm_response="y"): """ Save Config for HuaweiSSH""" - return super(HuaweiBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -118,7 +114,15 @@

    Module netmiko.huawei.huawei

    class HuaweiSSH(HuaweiBase): """Huawei SSH driver.""" - pass + def special_login_handler(self): + """Handle password change request by ignoring it""" + + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" + output = self.read_until_prompt_or_pattern(password_change_prompt) + if re.search(password_change_prompt, output): + self.write_channel("N\n") + self.clear_buffer() + return output class HuaweiTelnet(HuaweiBase): @@ -136,7 +140,7 @@

    Module netmiko.huawei.huawei

    """Telnet login for Huawei Devices""" delay_factor = self.select_delay_factor(delay_factor) - password_change_prompt = re.escape("Change now? [Y/N]") + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" combined_pattern = r"({}|{}|{})".format( pri_prompt_terminator, alt_prompt_terminator, password_change_prompt ) @@ -185,8 +189,8 @@

    Module netmiko.huawei.huawei

    except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -199,8 +203,8 @@

    Module netmiko.huawei.huawei

    return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) class HuaweiVrpv8SSH(HuaweiSSH): @@ -222,7 +226,7 @@

    Module netmiko.huawei.huawei

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -235,9 +239,7 @@

    Module netmiko.huawei.huawei

    output += self.exit_config_mode() if error_marker in output: - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def save_config(self, *args, **kwargs): @@ -256,7 +258,7 @@

    Classes

    class HuaweiBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -376,6 +378,10 @@

    Classes

    :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
    Source code @@ -391,17 +397,15 @@

    Classes

    def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HuaweiBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit configuration mode.""" - return super(HuaweiBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Checks whether in configuration mode. Returns a boolean.""" - return super(HuaweiBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def check_enable_mode(self, *args, **kwargs): """Huawei has no enable mode.""" @@ -443,7 +447,7 @@

    Classes

    # Check that ends with a valid terminator character if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {0}".format(prompt)) + raise ValueError(f"Router prompt not found: {prompt}") # Strip off any leading HRP_. characters for USGv5 HA prompt = re.sub(r"^HRP_.", "", prompt, flags=re.M) @@ -452,13 +456,13 @@

    Classes

    prompt = prompt[1:-1] prompt = prompt.strip() self.base_prompt = prompt - log.debug("prompt: {0}".format(self.base_prompt)) + log.debug(f"prompt: {self.base_prompt}") return self.base_prompt - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config(self, cmd="save", confirm=True, confirm_response="y"): """ Save Config for HuaweiSSH""" - return super(HuaweiBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -483,7 +487,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Checks whether in configuration mode. Returns a boolean."""
    -    return super(HuaweiBase, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)

    @@ -507,7 +511,7 @@

    Methods

    Source code
    def config_mode(self, config_command="system-view"):
         """Enter configuration mode."""
    -    return super(HuaweiBase, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -531,9 +535,7 @@

    Methods

    Source code
    def exit_config_mode(self, exit_config="return", pattern=r">"):
         """Exit configuration mode."""
    -    return super(HuaweiBase, self).exit_config_mode(
    -        exit_config=exit_config, pattern=pattern
    -    )
    + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
    @@ -549,15 +551,15 @@

    Methods

    -def save_config(self, cmd='save', confirm=False, confirm_response='') +def save_config(self, cmd='save', confirm=True, confirm_response='y')

    Save Config for HuaweiSSH

    Source code -
    def save_config(self, cmd="save", confirm=False, confirm_response=""):
    +
    def save_config(self, cmd="save", confirm=True, confirm_response="y"):
         """ Save Config for HuaweiSSH"""
    -    return super(HuaweiBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -618,7 +620,7 @@

    Methods

    # Check that ends with a valid terminator character if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {0}".format(prompt)) + raise ValueError(f"Router prompt not found: {prompt}") # Strip off any leading HRP_. characters for USGv5 HA prompt = re.sub(r"^HRP_.", "", prompt, flags=re.M) @@ -627,7 +629,7 @@

    Methods

    prompt = prompt[1:-1] prompt = prompt.strip() self.base_prompt = prompt - log.debug("prompt: {0}".format(self.base_prompt)) + log.debug(f"prompt: {self.base_prompt}") return self.base_prompt
    @@ -674,7 +676,7 @@

    Inherited members

    class HuaweiSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Huawei SSH driver.

    @@ -794,13 +796,25 @@

    Inherited members

    :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
    Source code
    class HuaweiSSH(HuaweiBase):
         """Huawei SSH driver."""
     
    -    pass
    + def special_login_handler(self): + """Handle password change request by ignoring it""" + + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" + output = self.read_until_prompt_or_pattern(password_change_prompt) + if re.search(password_change_prompt, output): + self.write_channel("N\n") + self.clear_buffer() + return output

    Ancestors

      @@ -812,6 +826,27 @@

      Subclasses

      +

      Methods

      +
      +
      +def special_login_handler(self) +
      +
      +

      Handle password change request by ignoring it

      +
      +Source code +
      def special_login_handler(self):
      +    """Handle password change request by ignoring it"""
      +
      +    password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+"
      +    output = self.read_until_prompt_or_pattern(password_change_prompt)
      +    if re.search(password_change_prompt, output):
      +        self.write_channel("N\n")
      +        self.clear_buffer()
      +    return output
      +
      +
      +

      Inherited members

    class HuaweiTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Huawei Telnet driver.

    @@ -982,6 +1016,10 @@

    Inherited members

    :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
    Source code @@ -1000,7 +1038,7 @@

    Inherited members

    """Telnet login for Huawei Devices""" delay_factor = self.select_delay_factor(delay_factor) - password_change_prompt = re.escape("Change now? [Y/N]") + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" combined_pattern = r"({}|{}|{})".format( pri_prompt_terminator, alt_prompt_terminator, password_change_prompt ) @@ -1049,8 +1087,8 @@

    Inherited members

    except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -1063,8 +1101,8 @@

    Inherited members

    return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg)

    Ancestors

      @@ -1093,7 +1131,7 @@

      Methods

      """Telnet login for Huawei Devices""" delay_factor = self.select_delay_factor(delay_factor) - password_change_prompt = re.escape("Change now? [Y/N]") + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" combined_pattern = r"({}|{}|{})".format( pri_prompt_terminator, alt_prompt_terminator, password_change_prompt ) @@ -1142,8 +1180,8 @@

      Methods

      except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -1156,8 +1194,8 @@

      Methods

      return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg)
    @@ -1210,7 +1248,7 @@

    Inherited members

    class HuaweiVrpv8SSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Huawei SSH driver.

    @@ -1330,6 +1368,10 @@

    Inherited members

    :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
    Source code @@ -1352,7 +1394,7 @@

    Inherited members

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -1365,9 +1407,7 @@

    Inherited members

    output += self.exit_config_mode() if error_marker in output: - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def save_config(self, *args, **kwargs): @@ -1414,7 +1454,7 @@

    Methods

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -1427,9 +1467,7 @@

    Methods

    output += self.exit_config_mode() if error_marker in output: - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output
    @@ -1481,7 +1519,7 @@

    Inherited members

  • session_preparation
  • set_base_prompt
  • set_terminal_width
  • -
  • special_login_handler
  • +
  • special_login_handler
  • strip_ansi_escape_codes
  • strip_backspaces
  • strip_command
  • @@ -1524,6 +1562,9 @@

    HuaweiSSH

    +
  • HuaweiTelnet

    @@ -1544,7 +1585,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/huawei/index.html b/docs/netmiko/huawei/index.html index a48a3916b..0a8a20df9 100644 --- a/docs/netmiko/huawei/index.html +++ b/docs/netmiko/huawei/index.html @@ -3,13 +3,13 @@ - + netmiko.huawei API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.huawei

    Source code -
    from __future__ import unicode_literals
    -from netmiko.huawei.huawei import HuaweiSSH, HuaweiVrpv8SSH
    +
    from netmiko.huawei.huawei import HuaweiSSH, HuaweiVrpv8SSH
     from netmiko.huawei.huawei import HuaweiTelnet
     
     __all__ = ["HuaweiSSH", "HuaweiVrpv8SSH", "HuaweiTelnet"]
    @@ -47,7 +46,7 @@

    Classes

    class HuaweiSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Huawei SSH driver.

    @@ -167,13 +166,25 @@

    Classes

    :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
    Source code
    class HuaweiSSH(HuaweiBase):
         """Huawei SSH driver."""
     
    -    pass
    + def special_login_handler(self): + """Handle password change request by ignoring it""" + + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" + output = self.read_until_prompt_or_pattern(password_change_prompt) + if re.search(password_change_prompt, output): + self.write_channel("N\n") + self.clear_buffer() + return output

    Ancestors

    -
    -class NetmikoAuthError +
    +class NetmikoAuthenticationException (*args, **kwargs)

    SSH authentication exception based on Paramiko AuthenticationException.

    Source code -
    class NetMikoAuthenticationException(AuthenticationException):
    +
    class NetmikoAuthenticationException(AuthenticationException):
         """SSH authentication exception based on Paramiko AuthenticationException."""
     
         pass
    @@ -4214,15 +4484,15 @@

    Ancestors

  • builtins.BaseException
  • -
    -class NetmikoTimeoutError +
    +class NetmikoTimeoutException (*args, **kwargs)

    SSH session timed trying to connect to the device.

    Source code -
    class NetMikoTimeoutException(SSHException):
    +
    class NetmikoTimeoutException(SSHException):
         """SSH session timed trying to connect to the device."""
     
         pass
    @@ -4236,7 +4506,7 @@

    Ancestors

    class SCPConn -(ssh_conn) +(ssh_conn, socket_timeout=10.0)

    Establish a secure copy channel to the remote network device.

    @@ -4250,8 +4520,9 @@

    Ancestors

    Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn): + def __init__(self, ssh_conn, socket_timeout=10.0): self.ssh_ctl_chan = ssh_conn + self.socket_timeout = socket_timeout self.establish_scp_conn() def establish_scp_conn(self): @@ -4259,7 +4530,9 @@

    Ancestors

    ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport()) + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + ) def scp_transfer_file(self, source_file, dest_file): """Put file using SCP (for backwards compatibility).""" @@ -4303,7 +4576,9 @@

    Methods

    ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport())
    + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + )
    @@ -4463,7 +4738,6 @@

    Methods

    self.connection.write_channel(cmd + "\n") time.sleep(1) output = self.connection._read_channel_timing() - output = self.connection.strip_ansi_escape_codes(output) output = self.connection.strip_backspaces(output) return output @@ -4629,14 +4903,15 @@

    Index

  • netmiko.mrv
  • netmiko.netapp
  • netmiko.netmiko_globals
  • +
  • netmiko.nokia
  • netmiko.oneaccess
  • netmiko.ovs
  • netmiko.paloalto
  • netmiko.pluribus
  • -
  • netmiko.py23_compat
  • netmiko.quanta
  • netmiko.rad
  • netmiko.ruckus
  • +
  • netmiko.ruijie
  • netmiko.scp_functions
  • netmiko.scp_handler
  • netmiko.snmp_autodetect
  • @@ -4710,19 +4985,20 @@

    BaseC

    InLineTransfer

  • -

    NetMikoAuthenticationException

    +

    NetmikoAuthenticationException

  • -

    NetMikoTimeoutException

    +

    NetmikoTimeoutException

  • -

    NetMikoAuthenticationException

    +

    NetmikoAuthenticationException

  • -

    NetMikoTimeoutException

    +

    NetmikoTimeoutException

  • SCPConn

    @@ -4746,7 +5022,7 @@

    SSHDetect diff --git a/docs/netmiko/ipinfusion/index.html b/docs/netmiko/ipinfusion/index.html index 0adb12bf5..801a7e4ca 100644 --- a/docs/netmiko/ipinfusion/index.html +++ b/docs/netmiko/ipinfusion/index.html @@ -3,13 +3,13 @@ - + netmiko.ipinfusion API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ipinfusion

    Source code -
    from __future__ import unicode_literals
    -from netmiko.ipinfusion.ipinfusion_ocnos import (
    +
    from netmiko.ipinfusion.ipinfusion_ocnos import (
         IpInfusionOcNOSSSH,
         IpInfusionOcNOSTelnet,
     )
    @@ -169,6 +168,10 @@ 

    Classes

    :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
    Source code @@ -354,6 +357,10 @@

    Inherited members

    :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
    Source code @@ -385,7 +392,7 @@

    Inherited members

    ): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(IpInfusionOcNOSTelnet, self).telnet_login( + return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -481,7 +488,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/ipinfusion/ipinfusion_ocnos.html b/docs/netmiko/ipinfusion/ipinfusion_ocnos.html index e23c2b417..8598350fc 100644 --- a/docs/netmiko/ipinfusion/ipinfusion_ocnos.html +++ b/docs/netmiko/ipinfusion/ipinfusion_ocnos.html @@ -3,13 +3,13 @@ - + netmiko.ipinfusion.ipinfusion_ocnos API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, TTYPE
     from netmiko.cisco_base_connection import CiscoBaseConnection
     
    @@ -34,7 +33,7 @@ 

    Module netmiko.ipinfusion.ipinfusion_ocnos

    def __init__(self, *args, **kwargs): if kwargs.get("default_enter") is None: kwargs["default_enter"] = "\r" - return super(IpInfusionOcNOSBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): self._test_channel_read() @@ -47,7 +46,7 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    def save_config(self, cmd="write", confirm=False, confirm_response=""): """Saves Config Using write command""" - return super(IpInfusionOcNOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -86,7 +85,7 @@

    Module netmiko.ipinfusion.ipinfusion_ocnos

    ): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(IpInfusionOcNOSTelnet, self).telnet_login( + return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -227,6 +226,10 @@

    Classes

    :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
    Source code @@ -236,7 +239,7 @@

    Classes

    def __init__(self, *args, **kwargs): if kwargs.get("default_enter") is None: kwargs["default_enter"] = "\r" - return super(IpInfusionOcNOSBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): self._test_channel_read() @@ -249,7 +252,7 @@

    Classes

    def save_config(self, cmd="write", confirm=False, confirm_response=""): """Saves Config Using write command""" - return super(IpInfusionOcNOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -274,7 +277,7 @@

    Methods

    Source code
    def save_config(self, cmd="write", confirm=False, confirm_response=""):
         """Saves Config Using write command"""
    -    return super(IpInfusionOcNOSBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )

    @@ -449,6 +452,10 @@

    Inherited members

    :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
    Source code @@ -634,6 +641,10 @@

    Inherited members

    :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
    Source code @@ -665,7 +676,7 @@

    Inherited members

    ): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(IpInfusionOcNOSTelnet, self).telnet_login( + return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, @@ -762,7 +773,7 @@

    diff --git a/docs/netmiko/juniper/index.html b/docs/netmiko/juniper/index.html index 80a9e9f92..76e7e2bd1 100644 --- a/docs/netmiko/juniper/index.html +++ b/docs/netmiko/juniper/index.html @@ -3,13 +3,13 @@ - + netmiko.juniper API documentation - + @@ -22,10 +22,10 @@

    Module netmiko.juniper

    Source code -
    from __future__ import unicode_literals
    -from netmiko.juniper.juniper import JuniperSSH, JuniperTelnet, JuniperFileTransfer
    +
    from netmiko.juniper.juniper import JuniperSSH, JuniperTelnet, JuniperFileTransfer
    +from netmiko.juniper.juniper_screenos import JuniperScreenOsSSH
     
    -__all__ = ["JuniperSSH", "JuniperTelnet", "JuniperFileTransfer"]
    +__all__ = ["JuniperSSH", "JuniperTelnet", "JuniperFileTransfer", "JuniperScreenOsSSH"]
    @@ -35,6 +35,10 @@

    Sub-modules

    +
    netmiko.juniper.juniper_screenos
    +
    +
    +
    @@ -46,7 +50,7 @@

    Classes

    class JuniperFileTransfer -(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put') +(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put', **kwargs)

    Juniper SCP File Transfer driver.

    @@ -56,14 +60,21 @@

    Classes

    """Juniper SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(JuniperFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -81,9 +92,7 @@

    Classes

    ) def remote_md5(self, base_cmd="file checksum md5", remote_file=None): - return super(JuniperFileTransfer, self).remote_md5( - base_cmd=base_cmd, remote_file=remote_file - ) + return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) def enable_scp(self, cmd=None): raise NotImplementedError @@ -122,7 +131,7 @@

    Inherited members

    class JuniperSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with Juniper Networks devices.

    @@ -245,6 +254,10 @@

    Inherited members

    :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
    Source code @@ -306,6 +319,337 @@

    Inherited members

  • +
    +class JuniperScreenOsSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
    +
    +

    Implement methods for interacting with Juniper ScreenOS devices.

    +
        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
    +
    +
    +Source code +
    class JuniperScreenOsSSH(BaseConnection):
    +    """
    +    Implement methods for interacting with Juniper ScreenOS devices.
    +    """
    +
    +    def session_preparation(self):
    +        """
    +        Prepare the session after the connection has been established.
    +
    +        Disable paging (the '--more--' prompts).
    +        Set the base prompt for interaction ('>').
    +        """
    +        self._test_channel_read()
    +        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=""):
    +        """Save Config."""
    +        return self.send_command(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='') +
    +
    +

    Save Config.

    +
    +Source code +
    def save_config(self, cmd="save config", confirm=False, confirm_response=""):
    +    """Save Config."""
    +    return self.send_command(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 ('>').

    +
    +Source code +
    def session_preparation(self):
    +    """
    +    Prepare the session after the connection has been established.
    +
    +    Disable paging (the '--more--' prompts).
    +    Set the base prompt for interaction ('>').
    +    """
    +    self._test_channel_read()
    +    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()
    +
    +
    +
    +

    Inherited members

    + +
    class JuniperTelnet (*args, **kwargs) @@ -431,6 +775,10 @@

    Inherited members

    :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
    Source code @@ -438,7 +786,7 @@

    Inherited members

    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(JuniperTelnet, self).__init__(*args, **kwargs)
    + super().__init__(*args, **kwargs)

    Ancestors

    @@ -531,7 +893,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/juniper/juniper.html b/docs/netmiko/juniper/juniper.html index 70c683552..05876cf77 100644 --- a/docs/netmiko/juniper/juniper.html +++ b/docs/netmiko/juniper/juniper.html @@ -3,13 +3,13 @@ - + netmiko.juniper.juniper API documentation - + @@ -22,14 +22,11 @@

    Module netmiko.juniper.juniper

    Source code -
    from __future__ import unicode_literals
    -
    -import re
    +
    import re
     import time
     
     from netmiko.base_connection import BaseConnection
     from netmiko.scp_handler import BaseFileTransfer
    -from netmiko.py23_compat import text_type
     
     
     class JuniperBase(BaseConnection):
    @@ -50,6 +47,7 @@ 

    Module netmiko.juniper.juniper

    self._test_channel_read() self.enter_cli_mode() self.set_base_prompt() + self._disable_complete_on_space() self.disable_paging(command="set cli screen-length 0") self.set_terminal_width(command="set cli screen-width 511") # Clear the read buffer @@ -64,6 +62,21 @@

    Module netmiko.juniper.juniper

    """Return to the Juniper CLI.""" return self.send_command("exit", expect_string=r"[#>]") + def _disable_complete_on_space(self): + """ + Juniper tries to auto complete commands when you type a "space" character. + + This is a bad idea for automation as what your program is sending no longer matches + the command echo from the device. So we disable this behavior. + """ + delay_factor = self.select_delay_factor(delay_factor=0) + time.sleep(delay_factor * 0.1) + command = "set cli complete-on-space off" + self.write_channel(self.normalize_cmd(command)) + time.sleep(delay_factor * 0.1) + output = self.read_channel() + return output + def enter_cli_mode(self): """Check if at shell prompt root@ and go into CLI.""" delay_factor = self.select_delay_factor(delay_factor=0) @@ -96,11 +109,11 @@

    Module netmiko.juniper.juniper

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(JuniperBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(JuniperBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -166,7 +179,7 @@

    Module netmiko.juniper.juniper

    commit_marker = "configuration check succeeds" elif confirm: if confirm_delay: - command_string = "commit confirmed " + text_type(confirm_delay) + command_string = "commit confirmed " + str(confirm_delay) else: command_string = "commit confirmed" commit_marker = "commit confirmed will be automatically rolled back in" @@ -175,7 +188,7 @@

    Module netmiko.juniper.juniper

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -202,15 +215,13 @@

    Module netmiko.juniper.juniper

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(JuniperBase, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -250,21 +261,28 @@

    Module netmiko.juniper.juniper

    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(JuniperTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class JuniperFileTransfer(BaseFileTransfer): """Juniper SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(JuniperFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -282,9 +300,7 @@

    Module netmiko.juniper.juniper

    ) def remote_md5(self, base_cmd="file checksum md5", remote_file=None): - return super(JuniperFileTransfer, self).remote_md5( - base_cmd=base_cmd, remote_file=remote_file - ) + return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) def enable_scp(self, cmd=None): raise NotImplementedError @@ -304,7 +320,7 @@

    Classes

    class JuniperBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with Juniper Networks devices.

    @@ -427,6 +443,10 @@

    Classes

    :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
    Source code @@ -448,6 +468,7 @@

    Classes

    self._test_channel_read() self.enter_cli_mode() self.set_base_prompt() + self._disable_complete_on_space() self.disable_paging(command="set cli screen-length 0") self.set_terminal_width(command="set cli screen-width 511") # Clear the read buffer @@ -462,6 +483,21 @@

    Classes

    """Return to the Juniper CLI.""" return self.send_command("exit", expect_string=r"[#>]") + def _disable_complete_on_space(self): + """ + Juniper tries to auto complete commands when you type a "space" character. + + This is a bad idea for automation as what your program is sending no longer matches + the command echo from the device. So we disable this behavior. + """ + delay_factor = self.select_delay_factor(delay_factor=0) + time.sleep(delay_factor * 0.1) + command = "set cli complete-on-space off" + self.write_channel(self.normalize_cmd(command)) + time.sleep(delay_factor * 0.1) + output = self.read_channel() + return output + def enter_cli_mode(self): """Check if at shell prompt root@ and go into CLI.""" delay_factor = self.select_delay_factor(delay_factor=0) @@ -494,11 +530,11 @@

    Classes

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(JuniperBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(JuniperBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -564,7 +600,7 @@

    Classes

    commit_marker = "configuration check succeeds" elif confirm: if confirm_delay: - command_string = "commit confirmed " + text_type(confirm_delay) + command_string = "commit confirmed " + str(confirm_delay) else: command_string = "commit confirmed" commit_marker = "commit confirmed will be automatically rolled back in" @@ -573,7 +609,7 @@

    Classes

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -600,15 +636,13 @@

    Classes

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(JuniperBase, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -659,7 +693,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Checks if the device is in configuration mode or not."""
    -    return super(JuniperBase, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -745,7 +779,7 @@

    Methods

    commit_marker = "configuration check succeeds" elif confirm: if confirm_delay: - command_string = "commit confirmed " + text_type(confirm_delay) + command_string = "commit confirmed " + str(confirm_delay) else: command_string = "commit confirmed" commit_marker = "commit confirmed will be automatically rolled back in" @@ -754,7 +788,7 @@

    Methods

    if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -781,9 +815,7 @@

    Methods

    ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output
    @@ -797,7 +829,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(JuniperBase, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -892,6 +924,7 @@

    Methods

    self._test_channel_read() self.enter_cli_mode() self.set_base_prompt() + self._disable_complete_on_space() self.disable_paging(command="set cli screen-length 0") self.set_terminal_width(command="set cli screen-width 511") # Clear the read buffer @@ -949,7 +982,7 @@

    Methods

    Source code
    def strip_prompt(self, *args, **kwargs):
         """Strip the trailing router prompt from the output."""
    -    a_string = super(JuniperBase, self).strip_prompt(*args, **kwargs)
    +    a_string = super().strip_prompt(*args, **kwargs)
         return self.strip_context_items(a_string)
    @@ -995,7 +1028,7 @@

    Inherited members

    class JuniperFileTransfer -(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put') +(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put', **kwargs)

    Juniper SCP File Transfer driver.

    @@ -1005,14 +1038,21 @@

    Inherited members

    """Juniper SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(JuniperFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -1030,9 +1070,7 @@

    Inherited members

    ) def remote_md5(self, base_cmd="file checksum md5", remote_file=None): - return super(JuniperFileTransfer, self).remote_md5( - base_cmd=base_cmd, remote_file=remote_file - ) + return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) def enable_scp(self, cmd=None): raise NotImplementedError @@ -1071,7 +1109,7 @@

    Inherited members

    class JuniperSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with Juniper Networks devices.

    @@ -1194,6 +1232,10 @@

    Inherited members

    :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
    Source code @@ -1380,6 +1422,10 @@

    Inherited members

    :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
    Source code @@ -1387,7 +1433,7 @@

    Inherited members

    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(JuniperTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs)

    Ancestors

      @@ -1491,7 +1537,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/juniper/juniper_screenos.html b/docs/netmiko/juniper/juniper_screenos.html new file mode 100644 index 000000000..193a9fb44 --- /dev/null +++ b/docs/netmiko/juniper/juniper_screenos.html @@ -0,0 +1,457 @@ + + + + + + +netmiko.juniper.juniper_screenos API documentation + + + + + + + + + +
      +
      +
      +

      Module netmiko.juniper.juniper_screenos

      +
      +
      +
      +Source code +
      import time
      +from netmiko.base_connection import BaseConnection
      +
      +
      +class JuniperScreenOsSSH(BaseConnection):
      +    """
      +    Implement methods for interacting with Juniper ScreenOS devices.
      +    """
      +
      +    def session_preparation(self):
      +        """
      +        Prepare the session after the connection has been established.
      +
      +        Disable paging (the '--more--' prompts).
      +        Set the base prompt for interaction ('>').
      +        """
      +        self._test_channel_read()
      +        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=""):
      +        """Save Config."""
      +        return self.send_command(command_string=cmd)
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class JuniperScreenOsSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
      +
      +

      Implement methods for interacting with Juniper ScreenOS devices.

      +
          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
      +
      +
      +Source code +
      class JuniperScreenOsSSH(BaseConnection):
      +    """
      +    Implement methods for interacting with Juniper ScreenOS devices.
      +    """
      +
      +    def session_preparation(self):
      +        """
      +        Prepare the session after the connection has been established.
      +
      +        Disable paging (the '--more--' prompts).
      +        Set the base prompt for interaction ('>').
      +        """
      +        self._test_channel_read()
      +        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=""):
      +        """Save Config."""
      +        return self.send_command(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='') +
      +
      +

      Save Config.

      +
      +Source code +
      def save_config(self, cmd="save config", confirm=False, confirm_response=""):
      +    """Save Config."""
      +    return self.send_command(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 ('>').

      +
      +Source code +
      def session_preparation(self):
      +    """
      +    Prepare the session after the connection has been established.
      +
      +    Disable paging (the '--more--' prompts).
      +    Set the base prompt for interaction ('>').
      +    """
      +    self._test_channel_read()
      +    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()
      +
      +
      +
      +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + + + \ No newline at end of file diff --git a/docs/netmiko/keymile/index.html b/docs/netmiko/keymile/index.html index 85b3233c9..50645e78b 100644 --- a/docs/netmiko/keymile/index.html +++ b/docs/netmiko/keymile/index.html @@ -3,13 +3,13 @@ - + netmiko.keymile API documentation - + @@ -22,8 +22,7 @@

      Module netmiko.keymile

      Source code -
      from __future__ import unicode_literals
      -from netmiko.keymile.keymile_ssh import KeymileSSH
      +
      from netmiko.keymile.keymile_ssh import KeymileSSH
       from netmiko.keymile.keymile_nos_ssh import KeymileNOSSSH
       
       __all__ = ["KeymileSSH", "KeymileNOSSSH"]
      @@ -51,7 +50,7 @@

      Classes

      class KeymileNOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Common Methods for IOS (both SSH and telnet).

      @@ -171,6 +170,10 @@

      Classes

      :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
      Source code @@ -185,18 +188,14 @@

      Classes

      def _test_channel_read(self, count=40, pattern=""): """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" - output = super(KeymileNOSSSH, self)._test_channel_read( - count=count, pattern=pattern - ) + output = super()._test_channel_read(count=count, pattern=pattern) pattern = r"Login incorrect" if re.search(pattern, output): self.paramiko_cleanup() msg = "Authentication failure: unable to connect" - msg += "{device_type} {host}:{port}".format( - device_type=self.device_type, host=self.host, port=self.port - ) + msg += f"{self.device_type} {self.host}:{self.port}" msg += self.RESPONSE_RETURN + "Login incorrect" - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) else: return output @@ -397,13 +396,17 @@

      Inherited members

      :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
      Source code
      class KeymileSSH(CiscoIosBase):
           def __init__(self, **kwargs):
               kwargs.setdefault("default_enter", "\r\n")
      -        return super(KeymileSSH, self).__init__(**kwargs)
      +        return super().__init__(**kwargs)
       
           def session_preparation(self):
               """Prepare the session after the connection has been established."""
      @@ -444,13 +447,11 @@ 

      Inherited members

      """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string) + return super().strip_prompt(a_string=a_string) def set_base_prompt(self, pri_prompt_terminator=">", **kwargs): """ set prompt termination to >""" - return super(KeymileSSH, self).set_base_prompt( - pri_prompt_terminator=pri_prompt_terminator - )
      + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)

      Ancestors

        @@ -554,9 +555,7 @@

        Methods

        Source code
        def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
             """ set prompt termination  to >"""
        -    return super(KeymileSSH, self).set_base_prompt(
        -        pri_prompt_terminator=pri_prompt_terminator
        -    )
        + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)

    @@ -570,7 +569,7 @@

    Methods

    """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string)
    + return super().strip_prompt(a_string=a_string) @@ -661,7 +660,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/keymile/keymile_nos_ssh.html b/docs/netmiko/keymile/keymile_nos_ssh.html index ff5ab3a83..28abd11ee 100644 --- a/docs/netmiko/keymile/keymile_nos_ssh.html +++ b/docs/netmiko/keymile/keymile_nos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.keymile.keymile_nos_ssh API documentation - + @@ -27,7 +27,7 @@

    Module netmiko.keymile.keymile_nos_ssh

    from netmiko.cisco.cisco_ios import CiscoIosBase -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoAuthenticationException class KeymileNOSSSH(CiscoIosBase): @@ -41,18 +41,14 @@

    Module netmiko.keymile.keymile_nos_ssh

    def _test_channel_read(self, count=40, pattern=""): """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" - output = super(KeymileNOSSSH, self)._test_channel_read( - count=count, pattern=pattern - ) + output = super()._test_channel_read(count=count, pattern=pattern) pattern = r"Login incorrect" if re.search(pattern, output): self.paramiko_cleanup() msg = "Authentication failure: unable to connect" - msg += "{device_type} {host}:{port}".format( - device_type=self.device_type, host=self.host, port=self.port - ) + msg += f"{self.device_type} {self.host}:{self.port}" msg += self.RESPONSE_RETURN + "Login incorrect" - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) else: return output @@ -73,7 +69,7 @@

    Classes

    class KeymileNOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Common Methods for IOS (both SSH and telnet).

    @@ -193,6 +189,10 @@

    Classes

    :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
    Source code @@ -207,18 +207,14 @@

    Classes

    def _test_channel_read(self, count=40, pattern=""): """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" - output = super(KeymileNOSSSH, self)._test_channel_read( - count=count, pattern=pattern - ) + output = super()._test_channel_read(count=count, pattern=pattern) pattern = r"Login incorrect" if re.search(pattern, output): self.paramiko_cleanup() msg = "Authentication failure: unable to connect" - msg += "{device_type} {host}:{port}".format( - device_type=self.device_type, host=self.host, port=self.port - ) + msg += f"{self.device_type} {self.host}:{self.port}" msg += self.RESPONSE_RETURN + "Login incorrect" - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) else: return output @@ -325,7 +321,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/keymile/keymile_ssh.html b/docs/netmiko/keymile/keymile_ssh.html index b663494b4..9aae4c72c 100644 --- a/docs/netmiko/keymile/keymile_ssh.html +++ b/docs/netmiko/keymile/keymile_ssh.html @@ -3,13 +3,13 @@ - + netmiko.keymile.keymile_ssh API documentation - + @@ -30,7 +30,7 @@

    Module netmiko.keymile.keymile_ssh

    class KeymileSSH(CiscoIosBase): def __init__(self, **kwargs): kwargs.setdefault("default_enter", "\r\n") - return super(KeymileSSH, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): """Prepare the session after the connection has been established.""" @@ -71,13 +71,11 @@

    Module netmiko.keymile.keymile_ssh

    """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string) + return super().strip_prompt(a_string=a_string) def set_base_prompt(self, pri_prompt_terminator=">", **kwargs): """ set prompt termination to >""" - return super(KeymileSSH, self).set_base_prompt( - pri_prompt_terminator=pri_prompt_terminator - )
    + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)

    @@ -211,13 +209,17 @@

    Classes

    :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
    Source code
    class KeymileSSH(CiscoIosBase):
         def __init__(self, **kwargs):
             kwargs.setdefault("default_enter", "\r\n")
    -        return super(KeymileSSH, self).__init__(**kwargs)
    +        return super().__init__(**kwargs)
     
         def session_preparation(self):
             """Prepare the session after the connection has been established."""
    @@ -258,13 +260,11 @@ 

    Classes

    """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string) + return super().strip_prompt(a_string=a_string) def set_base_prompt(self, pri_prompt_terminator=">", **kwargs): """ set prompt termination to >""" - return super(KeymileSSH, self).set_base_prompt( - pri_prompt_terminator=pri_prompt_terminator - )
    + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)

    Ancestors

      @@ -368,9 +368,7 @@

      Methods

      Source code
      def set_base_prompt(self, pri_prompt_terminator=">", **kwargs):
           """ set prompt termination  to >"""
      -    return super(KeymileSSH, self).set_base_prompt(
      -        pri_prompt_terminator=pri_prompt_terminator
      -    )
      + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator)
    @@ -384,7 +382,7 @@

    Methods

    """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string)
    + return super().strip_prompt(a_string=a_string)
    @@ -463,7 +461,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/linux/index.html b/docs/netmiko/linux/index.html index 517b4fc48..86cefba27 100644 --- a/docs/netmiko/linux/index.html +++ b/docs/netmiko/linux/index.html @@ -3,13 +3,13 @@ - + netmiko.linux API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.linux

    Source code -
    from __future__ import unicode_literals
    -from netmiko.linux.linux_ssh import LinuxSSH, LinuxFileTransfer
    +
    from netmiko.linux.linux_ssh import LinuxSSH, LinuxFileTransfer
     
     __all__ = ["LinuxSSH", "LinuxFileTransfer"]
    @@ -46,7 +45,7 @@

    Classes

    class LinuxFileTransfer -(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put') +(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put', **kwargs)

    Linux SCP File Transfer driver.

    @@ -61,14 +60,21 @@

    Classes

    """ def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(LinuxFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -91,7 +97,7 @@

    Classes

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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 ) @@ -142,7 +148,7 @@

    Inherited members

    class LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -262,6 +268,10 @@

    Inherited members

    :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
    Source code @@ -269,7 +279,7 @@

    Inherited members

    def session_preparation(self): """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - return super(LinuxSSH, self).session_preparation() + return super().session_preparation() def _enter_shell(self): """Already in shell.""" @@ -290,7 +300,7 @@

    Inherited members

    delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -300,7 +310,7 @@

    Inherited members

    """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) @@ -308,7 +318,7 @@

    Inherited members

    """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo su"): + def config_mode(self, config_command="sudo -s"): """Attempt to become root.""" return self.enable(cmd=config_command) @@ -317,7 +327,7 @@

    Inherited members

    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): """Verify root""" - return super(LinuxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" @@ -331,7 +341,7 @@

    Inherited members

    raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE): + def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -344,7 +354,7 @@

    Inherited members

    self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -398,7 +408,7 @@

    Methods

    Source code
    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT):
         """Verify root"""
    -    return super(LinuxSSH, self).check_enable_mode(check_string=check_string)
    + return super().check_enable_mode(check_string=check_string)
    @@ -415,13 +425,13 @@

    Methods

    -def config_mode(self, config_command='sudo su') +def config_mode(self, config_command='sudo -s')

    Attempt to become root.

    Source code -
    def config_mode(self, config_command="sudo su"):
    +
    def config_mode(self, config_command="sudo -s"):
         """Attempt to become root."""
         return self.enable(cmd=config_command)
    @@ -439,13 +449,13 @@

    Methods

    -def enable(self, cmd='sudo su', pattern='ssword', re_flags=) +def enable(self, cmd='sudo -s', pattern='ssword', re_flags=)

    Attempt to become root.

    Source code -
    def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE):
    +
    def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE):
         """Attempt to become root."""
         delay_factor = self.select_delay_factor(delay_factor=0)
         output = ""
    @@ -458,7 +468,7 @@ 

    Methods

    self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -513,7 +523,7 @@

    Methods

    """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs )
    @@ -528,7 +538,7 @@

    Methods

    def session_preparation(self):
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    return super(LinuxSSH, self).session_preparation()
    + return super().session_preparation()
    @@ -545,7 +555,7 @@

    Methods

    delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -636,7 +646,7 @@

    Linux diff --git a/docs/netmiko/linux/linux_ssh.html b/docs/netmiko/linux/linux_ssh.html index 76411e2ed..e10fc0e93 100644 --- a/docs/netmiko/linux/linux_ssh.html +++ b/docs/netmiko/linux/linux_ssh.html @@ -3,13 +3,13 @@ - + netmiko.linux.linux_ssh API documentation - + @@ -22,16 +22,14 @@

    Module netmiko.linux.linux_ssh

    Source code -
    from __future__ import unicode_literals
    -
    -import os
    +
    import os
     import re
     import socket
     import time
     
     from netmiko.cisco_base_connection import CiscoSSHConnection
     from netmiko.cisco_base_connection import CiscoFileTransfer
    -from netmiko.ssh_exception import NetMikoTimeoutException
    +from netmiko.ssh_exception import NetmikoTimeoutException
     
     LINUX_PROMPT_PRI = os.getenv("NETMIKO_LINUX_PROMPT_PRI", "$")
     LINUX_PROMPT_ALT = os.getenv("NETMIKO_LINUX_PROMPT_ALT", "#")
    @@ -42,7 +40,7 @@ 

    Module netmiko.linux.linux_ssh

    def session_preparation(self): """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - return super(LinuxSSH, self).session_preparation() + return super().session_preparation() def _enter_shell(self): """Already in shell.""" @@ -63,7 +61,7 @@

    Module netmiko.linux.linux_ssh

    delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -73,7 +71,7 @@

    Module netmiko.linux.linux_ssh

    """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) @@ -81,7 +79,7 @@

    Module netmiko.linux.linux_ssh

    """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo su"): + def config_mode(self, config_command="sudo -s"): """Attempt to become root.""" return self.enable(cmd=config_command) @@ -90,7 +88,7 @@

    Module netmiko.linux.linux_ssh

    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): """Verify root""" - return super(LinuxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" @@ -104,7 +102,7 @@

    Module netmiko.linux.linux_ssh

    raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE): + def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -117,7 +115,7 @@

    Module netmiko.linux.linux_ssh

    self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -146,14 +144,21 @@

    Module netmiko.linux.linux_ssh

    """ def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(LinuxFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -176,7 +181,7 @@

    Module netmiko.linux.linux_ssh

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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 ) @@ -207,7 +212,7 @@

    Classes

    class LinuxFileTransfer -(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put') +(ssh_conn, source_file, dest_file, file_system='/var/tmp', direction='put', **kwargs)

    Linux SCP File Transfer driver.

    @@ -222,14 +227,21 @@

    Classes

    """ def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(LinuxFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -252,7 +264,7 @@

    Classes

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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 ) @@ -303,7 +315,7 @@

    Inherited members

    class LinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -423,6 +435,10 @@

    Inherited members

    :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
    Source code @@ -430,7 +446,7 @@

    Inherited members

    def session_preparation(self): """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - return super(LinuxSSH, self).session_preparation() + return super().session_preparation() def _enter_shell(self): """Already in shell.""" @@ -451,7 +467,7 @@

    Inherited members

    delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -461,7 +477,7 @@

    Inherited members

    """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) @@ -469,7 +485,7 @@

    Inherited members

    """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo su"): + def config_mode(self, config_command="sudo -s"): """Attempt to become root.""" return self.enable(cmd=config_command) @@ -478,7 +494,7 @@

    Inherited members

    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): """Verify root""" - return super(LinuxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" @@ -492,7 +508,7 @@

    Inherited members

    raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE): + def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -505,7 +521,7 @@

    Inherited members

    self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -559,7 +575,7 @@

    Methods

    Source code
    def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT):
         """Verify root"""
    -    return super(LinuxSSH, self).check_enable_mode(check_string=check_string)
    + return super().check_enable_mode(check_string=check_string)
    @@ -576,13 +592,13 @@

    Methods

    -def config_mode(self, config_command='sudo su') +def config_mode(self, config_command='sudo -s')

    Attempt to become root.

    Source code -
    def config_mode(self, config_command="sudo su"):
    +
    def config_mode(self, config_command="sudo -s"):
         """Attempt to become root."""
         return self.enable(cmd=config_command)
    @@ -600,13 +616,13 @@

    Methods

    -def enable(self, cmd='sudo su', pattern='ssword', re_flags=) +def enable(self, cmd='sudo -s', pattern='ssword', re_flags=)

    Attempt to become root.

    Source code -
    def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE):
    +
    def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE):
         """Attempt to become root."""
         delay_factor = self.select_delay_factor(delay_factor=0)
         output = ""
    @@ -619,7 +635,7 @@ 

    Methods

    self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -674,7 +690,7 @@

    Methods

    """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs )
    @@ -689,7 +705,7 @@

    Methods

    def session_preparation(self):
         """Prepare the session after the connection has been established."""
         self.ansi_escape_codes = True
    -    return super(LinuxSSH, self).session_preparation()
    + return super().session_preparation()
    @@ -706,7 +722,7 @@

    Methods

    delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -792,7 +808,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mellanox/index.html b/docs/netmiko/mellanox/index.html index ef4b3a2c0..76af52860 100644 --- a/docs/netmiko/mellanox/index.html +++ b/docs/netmiko/mellanox/index.html @@ -3,13 +3,13 @@ - + netmiko.mellanox API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.mellanox

    Source code -
    from __future__ import unicode_literals
    -from netmiko.mellanox.mellanox_mlnxos_ssh import MellanoxMlnxosSSH
    +
    from netmiko.mellanox.mellanox_mlnxos_ssh import MellanoxMlnxosSSH
     
     __all__ = ["MellanoxMlnxosSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class MellanoxMlnxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Mellanox MLNX-OS Switch support.

    @@ -166,6 +165,10 @@

    Classes

    :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
    Source code @@ -185,19 +188,13 @@

    Classes

    return output def config_mode(self, config_command="config term", pattern="#"): - return super(MellanoxMlnxosSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string="(config", pattern=r"#"): - return super(MellanoxMlnxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + 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(MellanoxMlnxosSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def exit_config_mode(self, exit_config="exit", pattern="#"): """Mellanox does not support a single command to completely exit configuration mode. @@ -218,7 +215,7 @@

    Classes

    if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output def save_config( @@ -286,7 +283,7 @@

    Methods

    if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output
    @@ -389,7 +386,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html b/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html index 38eee1379..be8a2533e 100644 --- a/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html +++ b/docs/netmiko/mellanox/mellanox_mlnxos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.mellanox.mellanox_mlnxos_ssh API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.mellanox.mellanox_mlnxos_ssh

    Source code
    """Mellanox MLNX-OS Switch support."""
    -from __future__ import unicode_literals
     import re
     from netmiko.cisco_base_connection import CiscoSSHConnection
     from netmiko import log
    @@ -46,19 +45,13 @@ 

    Module netmiko.mellanox.mellanox_mlnxos_ssh

    return output def config_mode(self, config_command="config term", pattern="#"): - return super(MellanoxMlnxosSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string="(config", pattern=r"#"): - return super(MellanoxMlnxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + 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(MellanoxMlnxosSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def exit_config_mode(self, exit_config="exit", pattern="#"): """Mellanox does not support a single command to completely exit configuration mode. @@ -79,7 +72,7 @@

    Module netmiko.mellanox.mellanox_mlnxos_ssh

    if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output def save_config( @@ -104,7 +97,7 @@

    Classes

    class MellanoxMlnxosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Mellanox MLNX-OS Switch support.

    @@ -224,6 +217,10 @@

    Classes

    :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

    Source code @@ -243,19 +240,13 @@

    Classes

    return output def config_mode(self, config_command="config term", pattern="#"): - return super(MellanoxMlnxosSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string="(config", pattern=r"#"): - return super(MellanoxMlnxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + 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(MellanoxMlnxosSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def exit_config_mode(self, exit_config="exit", pattern="#"): """Mellanox does not support a single command to completely exit configuration mode. @@ -276,7 +267,7 @@

    Classes

    if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output def save_config( @@ -344,7 +335,7 @@

    Methods

    if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output
    @@ -442,7 +433,7 @@

    diff --git a/docs/netmiko/mikrotik/index.html b/docs/netmiko/mikrotik/index.html index 29874c5b7..c291343af 100644 --- a/docs/netmiko/mikrotik/index.html +++ b/docs/netmiko/mikrotik/index.html @@ -3,13 +3,13 @@ - + netmiko.mikrotik API documentation - + @@ -166,6 +166,10 @@

    Classes

    :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

    Source code @@ -351,6 +355,10 @@

    Inherited members

    :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
    Source code @@ -447,7 +455,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mikrotik/mikrotik_ssh.html b/docs/netmiko/mikrotik/mikrotik_ssh.html index 041fead1a..e998f7e7e 100644 --- a/docs/netmiko/mikrotik/mikrotik_ssh.html +++ b/docs/netmiko/mikrotik/mikrotik_ssh.html @@ -3,13 +3,13 @@ - + netmiko.mikrotik.mikrotik_ssh API documentation - + @@ -34,7 +34,7 @@

    Module netmiko.mikrotik.mikrotik_ssh

    self._in_config_mode = False - return super(MikrotikBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self, *args, **kwargs): """Prepare the session after the connection has been established.""" @@ -54,7 +54,7 @@

    Module netmiko.mikrotik.mikrotik_ssh

    """ self.username += "+cetw511h4098" - def disable_paging(self): + def disable_paging(self, *args, **kwargs): """Microtik does not have paging by default.""" return "" @@ -263,6 +263,10 @@

    Classes

    :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
    Source code @@ -275,7 +279,7 @@

    Classes

    self._in_config_mode = False - return super(MikrotikBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self, *args, **kwargs): """Prepare the session after the connection has been established.""" @@ -295,7 +299,7 @@

    Classes

    """ self.username += "+cetw511h4098" - def disable_paging(self): + def disable_paging(self, *args, **kwargs): """Microtik does not have paging by default.""" return "" @@ -411,13 +415,13 @@

    Methods

    -def disable_paging(self) +def disable_paging(self, *args, **kwargs)

    Microtik does not have paging by default.

    Source code -
    def disable_paging(self):
    +
    def disable_paging(self, *args, **kwargs):
         """Microtik does not have paging by default."""
         return ""
    @@ -709,6 +713,10 @@

    Inherited members

    :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
    Source code @@ -894,6 +902,10 @@

    Inherited members

    :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
    Source code @@ -1001,7 +1013,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mrv/index.html b/docs/netmiko/mrv/index.html index 1bee9fcb7..75f88d986 100644 --- a/docs/netmiko/mrv/index.html +++ b/docs/netmiko/mrv/index.html @@ -3,13 +3,13 @@ - + netmiko.mrv API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.mrv

    Source code -
    from __future__ import unicode_literals
    -from netmiko.mrv.mrv_lx import MrvLxSSH
    +
    from netmiko.mrv.mrv_lx import MrvLxSSH
     from netmiko.mrv.mrv_ssh import MrvOptiswitchSSH
     
     __all__ = ["MrvOptiswitchSSH", "MrvLxSSH"]
    @@ -51,7 +50,7 @@

    Classes

    class MrvLxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    MRV Communications Driver (LX).

    @@ -171,6 +170,10 @@

    Classes

    :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
    Source code @@ -189,15 +192,15 @@

    Classes

    def check_enable_mode(self, check_string=">>"): """MRV has a >> for enable mode instead of # like Cisco""" - return super(MrvLxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(MrvLxSSH, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvLxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -218,7 +221,7 @@

    Methods

    Source code
    def check_enable_mode(self, check_string=">>"):
         """MRV has a >> for enable mode instead of # like Cisco"""
    -    return super(MrvLxSSH, self).check_enable_mode(check_string=check_string)
    + return super().check_enable_mode(check_string=check_string)
    @@ -230,7 +233,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(MrvLxSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )

    @@ -301,7 +304,7 @@

    Inherited members

    class MrvOptiswitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    MRV Communications Driver (OptiSwitch).

    @@ -421,6 +424,10 @@

    Inherited members

    :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
    Source code @@ -456,7 +463,7 @@

    Inherited members

    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvOptiswitchSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -501,7 +508,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(MrvOptiswitchSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -615,7 +622,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mrv/mrv_lx.html b/docs/netmiko/mrv/mrv_lx.html index ccf3a6f44..f85b3ded8 100644 --- a/docs/netmiko/mrv/mrv_lx.html +++ b/docs/netmiko/mrv/mrv_lx.html @@ -3,13 +3,13 @@ - + netmiko.mrv.mrv_lx API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.mrv.mrv_lx

    Source code
    """MRV Communications Driver (LX)."""
    -from __future__ import unicode_literals
     import time
     import re
     
    @@ -46,15 +45,15 @@ 

    Module netmiko.mrv.mrv_lx

    def check_enable_mode(self, check_string=">>"): """MRV has a >> for enable mode instead of # like Cisco""" - return super(MrvLxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(MrvLxSSH, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvLxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -70,7 +69,7 @@

    Classes

    class MrvLxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    MRV Communications Driver (LX).

    @@ -190,6 +189,10 @@

    Classes

    :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
    Source code @@ -208,15 +211,15 @@

    Classes

    def check_enable_mode(self, check_string=">>"): """MRV has a >> for enable mode instead of # like Cisco""" - return super(MrvLxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(MrvLxSSH, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvLxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -237,7 +240,7 @@

    Methods

    Source code
    def check_enable_mode(self, check_string=">>"):
         """MRV has a >> for enable mode instead of # like Cisco"""
    -    return super(MrvLxSSH, self).check_enable_mode(check_string=check_string)
    + return super().check_enable_mode(check_string=check_string)
    @@ -249,7 +252,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(MrvLxSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -348,7 +351,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/mrv/mrv_ssh.html b/docs/netmiko/mrv/mrv_ssh.html index d6833cce1..af5bea68a 100644 --- a/docs/netmiko/mrv/mrv_ssh.html +++ b/docs/netmiko/mrv/mrv_ssh.html @@ -3,13 +3,13 @@ - + netmiko.mrv.mrv_ssh API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.mrv.mrv_ssh

    Source code
    """MRV Communications Driver (OptiSwitch)."""
    -from __future__ import unicode_literals
     import time
     import re
     
    @@ -63,7 +62,7 @@ 

    Module netmiko.mrv.mrv_ssh

    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvOptiswitchSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -79,7 +78,7 @@

    Classes

    class MrvOptiswitchSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    MRV Communications Driver (OptiSwitch).

    @@ -199,6 +198,10 @@

    Classes

    :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
    Source code @@ -234,7 +237,7 @@

    Classes

    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvOptiswitchSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -279,7 +282,7 @@

    Methods

    Source code
    def save_config(self, cmd="save config flash", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(MrvOptiswitchSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -379,7 +382,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/netapp/index.html b/docs/netmiko/netapp/index.html index c131b7539..df81a163e 100644 --- a/docs/netmiko/netapp/index.html +++ b/docs/netmiko/netapp/index.html @@ -3,13 +3,13 @@ - + netmiko.netapp API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.netapp

    Source code -
    from __future__ import unicode_literals
    -from netmiko.netapp.netapp_cdot_ssh import NetAppcDotSSH
    +
    from netmiko.netapp.netapp_cdot_ssh import NetAppcDotSSH
     
     __all__ = ["NetAppcDotSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class NetAppcDotSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -167,6 +166,10 @@

    Classes

    :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
    Source code @@ -186,15 +189,15 @@

    Classes

    return output def check_config_mode(self, check_string="*>"): - return super(NetAppcDotSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode( self, config_command="set -privilege diagnostic -confirmations off" ): - return super(NetAppcDotSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"): - return super(NetAppcDotSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def enable(self, *args, **kwargs): """No enable mode on NetApp.""" @@ -336,7 +339,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/netapp/netapp_cdot_ssh.html b/docs/netmiko/netapp/netapp_cdot_ssh.html index 06e1de1d0..bced1ac06 100644 --- a/docs/netmiko/netapp/netapp_cdot_ssh.html +++ b/docs/netmiko/netapp/netapp_cdot_ssh.html @@ -3,13 +3,13 @@ - + netmiko.netapp.netapp_cdot_ssh API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.netapp.netapp_cdot_ssh

    Source code -
    from __future__ import unicode_literals
    -
    -from netmiko.base_connection import BaseConnection
    +
    from netmiko.base_connection import BaseConnection
     
     
     class NetAppcDotSSH(BaseConnection):
    @@ -43,15 +41,15 @@ 

    Module netmiko.netapp.netapp_cdot_ssh

    return output def check_config_mode(self, check_string="*>"): - return super(NetAppcDotSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode( self, config_command="set -privilege diagnostic -confirmations off" ): - return super(NetAppcDotSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"): - return super(NetAppcDotSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def enable(self, *args, **kwargs): """No enable mode on NetApp.""" @@ -75,7 +73,7 @@

    Classes

    class NetAppcDotSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Defines vendor independent methods.

    @@ -196,6 +194,10 @@

    Classes

    :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
    Source code @@ -215,15 +217,15 @@

    Classes

    return output def check_config_mode(self, check_string="*>"): - return super(NetAppcDotSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode( self, config_command="set -privilege diagnostic -confirmations off" ): - return super(NetAppcDotSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"): - return super(NetAppcDotSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def enable(self, *args, **kwargs): """No enable mode on NetApp.""" @@ -360,7 +362,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/netmiko_globals.html b/docs/netmiko/netmiko_globals.html index 4d9a2782e..ed9d9d903 100644 --- a/docs/netmiko/netmiko_globals.html +++ b/docs/netmiko/netmiko_globals.html @@ -3,13 +3,13 @@ - + netmiko.netmiko_globals API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.netmiko_globals

    Source code -
    from __future__ import unicode_literals
    -
    -MAX_BUFFER = 65535
    +
    MAX_BUFFER = 65535
     BACKSPACE_CHAR = "\x08"
    @@ -52,7 +50,7 @@

    Index

    diff --git a/docs/netmiko/nokia/index.html b/docs/netmiko/nokia/index.html new file mode 100644 index 000000000..6a317fc1b --- /dev/null +++ b/docs/netmiko/nokia/index.html @@ -0,0 +1,603 @@ + + + + + + +netmiko.nokia API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.nokia

    +
    +
    +
    +Source code +
    from netmiko.nokia.nokia_sros_ssh import NokiaSrosSSH
    +
    +__all__ = ["NokiaSrosSSH"]
    +
    +
    +
    +

    Sub-modules

    +
    +
    netmiko.nokia.nokia_sros_ssh
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class NokiaSrosSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
    +
    +

    Implement methods for interacting with Nokia SR OS devices.

    +

    Not applicable in Nokia SR OS (disabled): +- enable() +- exit_enable_mode() +- check_enable_mode()

    +

    Overriden methods to adapt Nokia SR OS behavior (changed): +- session_preparation() +- set_base_prompt() +- config_mode() +- exit_config_mode() +- check_config_mode() +- save_config() +- commit() +- strip_prompt()

    +
        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
    +
    +
    +Source code +
    class NokiaSrosSSH(BaseConnection):
    +    """
    +    Implement methods for interacting with Nokia SR OS devices.
    +
    +    Not applicable in Nokia SR OS (disabled):
    +        - enable()
    +        - exit_enable_mode()
    +        - check_enable_mode()
    +
    +    Overriden methods to adapt Nokia SR OS behavior (changed):
    +        - session_preparation()
    +        - set_base_prompt()
    +        - config_mode()
    +        - exit_config_mode()
    +        - check_config_mode()
    +        - save_config()
    +        - commit()
    +        - strip_prompt()
    +    """
    +
    +    def session_preparation(self):
    +        self._test_channel_read()
    +        self.set_base_prompt()
    +        # "@" indicates model-driven CLI (vs Classical CLI)
    +        if "@" in self.base_prompt:
    +            self.disable_paging(command="environment more false")
    +            self.set_terminal_width(command="environment console width 512")
    +        else:
    +            self.disable_paging(command="environment no more")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def set_base_prompt(self, *args, **kwargs):
    +        """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
    +
    +    def enable(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def check_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return True
    +
    +    def exit_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
    +        """Enable config edit-mode for Nokia SR OS"""
    +        output = ""
    +        # Only model-driven CLI supports config-mode
    +        if "@" in self.base_prompt:
    +            output += super().config_mode(
    +                config_command=config_command, pattern=pattern
    +            )
    +        return output
    +
    +    def exit_config_mode(self, *args, **kwargs):
    +        """Disable config edit-mode for Nokia SR OS"""
    +        output = self._exit_all()
    +        # Model-driven CLI
    +        if "@" in self.base_prompt and "(ex)[" in output:
    +            # Asterisk indicates changes were made.
    +            if "*(ex)[" in output:
    +                log.warning("Uncommitted changes! Discarding changes!")
    +                output += self._discard()
    +            cmd = "quit-config"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +        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"@"):
    +        """Check config mode for Nokia SR OS"""
    +        if "@" not in self.base_prompt:
    +            # Classical CLI
    +            return False
    +        else:
    +            # Model-driven CLI look for "exclusive"
    +            return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Persist configuration to cflash for Nokia SR OS"""
    +        output = self.send_command(command_string="/admin save")
    +        return output
    +
    +    def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs):
    +        """Model driven CLI requires you not exit from configuration mode."""
    +        if exit_config_mode is None:
    +            # Set to False if model-driven CLI
    +            exit_config_mode = False if "@" in self.base_prompt else True
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def commit(self, *args, **kwargs):
    +        """Activate changes from private candidate for Nokia SR OS"""
    +        output = self._exit_all()
    +        if "@" in self.base_prompt and "*(ex)[" in output:
    +            log.info("Apply uncommitted changes!")
    +            cmd = "commit"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +            output += self.read_until_pattern(r"@")
    +        return output
    +
    +    def _exit_all(self):
    +        """Return to the 'root' context."""
    +        exit_cmd = "exit all"
    +        self.write_channel(self.normalize_cmd(exit_cmd))
    +        # Make sure you read until you detect the command echo (avoid getting out of sync)
    +        return self.read_until_pattern(pattern=re.escape(exit_cmd))
    +
    +    def _discard(self):
    +        """Discard changes from private candidate for Nokia SR OS"""
    +        output = ""
    +        if "@" in self.base_prompt:
    +            cmd = "discard"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            new_output = self.read_until_pattern(pattern=re.escape(cmd))
    +            if "@" not in new_output:
    +                new_output += self.read_until_prompt()
    +            output += new_output
    +        return output
    +
    +    def strip_prompt(self, *args, **kwargs):
    +        """Strip prompt from the output."""
    +        output = super().strip_prompt(*args, **kwargs)
    +        if "@" in self.base_prompt:
    +            # Remove context prompt too
    +            strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*"
    +            return re.sub(strips, "", output)
    +        else:
    +            return output
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string='(ex)[', pattern='@') +
    +
    +

    Check config mode for Nokia SR OS

    +
    +Source code +
    def check_config_mode(self, check_string=r"(ex)[", pattern=r"@"):
    +    """Check config mode for Nokia SR OS"""
    +    if "@" not in self.base_prompt:
    +        # Classical CLI
    +        return False
    +    else:
    +        # Model-driven CLI look for "exclusive"
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def check_enable_mode(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def check_enable_mode(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return True
    +
    +
    +
    +def commit(self, *args, **kwargs) +
    +
    +

    Activate changes from private candidate for Nokia SR OS

    +
    +Source code +
    def commit(self, *args, **kwargs):
    +    """Activate changes from private candidate for Nokia SR OS"""
    +    output = self._exit_all()
    +    if "@" in self.base_prompt and "*(ex)[" in output:
    +        log.info("Apply uncommitted changes!")
    +        cmd = "commit"
    +        self.write_channel(self.normalize_cmd(cmd))
    +        output += self.read_until_pattern(pattern=re.escape(cmd))
    +        output += self.read_until_pattern(r"@")
    +    return output
    +
    +
    +
    +def config_mode(self, config_command='edit-config exclusive', pattern='\\(ex\\)\\[') +
    +
    +

    Enable config edit-mode for Nokia SR OS

    +
    +Source code +
    def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
    +    """Enable config edit-mode for Nokia SR OS"""
    +    output = ""
    +    # Only model-driven CLI supports config-mode
    +    if "@" in self.base_prompt:
    +        output += super().config_mode(
    +            config_command=config_command, pattern=pattern
    +        )
    +    return output
    +
    +
    +
    +def enable(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def enable(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return ""
    +
    +
    +
    +def exit_config_mode(self, *args, **kwargs) +
    +
    +

    Disable config edit-mode for Nokia SR OS

    +
    +Source code +
    def exit_config_mode(self, *args, **kwargs):
    +    """Disable config edit-mode for Nokia SR OS"""
    +    output = self._exit_all()
    +    # Model-driven CLI
    +    if "@" in self.base_prompt and "(ex)[" in output:
    +        # Asterisk indicates changes were made.
    +        if "*(ex)[" in output:
    +            log.warning("Uncommitted changes! Discarding changes!")
    +            output += self._discard()
    +        cmd = "quit-config"
    +        self.write_channel(self.normalize_cmd(cmd))
    +        output += self.read_until_pattern(pattern=re.escape(cmd))
    +    if self.check_config_mode():
    +        raise ValueError("Failed to exit configuration mode")
    +    return output
    +
    +
    +
    +def exit_enable_mode(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def exit_enable_mode(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return ""
    +
    +
    +
    +def save_config(self, *args, **kwargs) +
    +
    +

    Persist configuration to cflash for Nokia SR OS

    +
    +Source code +
    def save_config(self, *args, **kwargs):
    +    """Persist configuration to cflash for Nokia SR OS"""
    +    output = self.send_command(command_string="/admin save")
    +    return output
    +
    +
    +
    +def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs) +
    +
    +

    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):
    +    """Model driven CLI requires you not exit from configuration mode."""
    +    if exit_config_mode is None:
    +        # Set to False if model-driven CLI
    +        exit_config_mode = False if "@" in self.base_prompt else True
    +    return super().send_config_set(
    +        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +    )
    +
    +
    +
    +def set_base_prompt(self, *args, **kwargs) +
    +
    +

    Remove the > when navigating into the different config level.

    +
    +Source code +
    def set_base_prompt(self, *args, **kwargs):
    +    """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
    +
    +
    +
    +def strip_prompt(self, *args, **kwargs) +
    +
    +

    Strip prompt from the output.

    +
    +Source code +
    def strip_prompt(self, *args, **kwargs):
    +    """Strip prompt from the output."""
    +    output = super().strip_prompt(*args, **kwargs)
    +    if "@" in self.base_prompt:
    +        # Remove context prompt too
    +        strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*"
    +        return re.sub(strips, "", output)
    +    else:
    +        return output
    +
    +
    +
    +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/nokia/nokia_sros_ssh.html b/docs/netmiko/nokia/nokia_sros_ssh.html new file mode 100644 index 000000000..b843a0c35 --- /dev/null +++ b/docs/netmiko/nokia/nokia_sros_ssh.html @@ -0,0 +1,746 @@ + + + + + + +netmiko.nokia.nokia_sros_ssh API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.nokia.nokia_sros_ssh

    +
    +
    +
    +Source code +
    #!/usr/bin/python
    +# -*- coding: utf-8 -*-
    +# Copyright (c) 2014 - 2019 Kirk Byers
    +# Copyright (c) 2014 - 2019 Twin Bridges Technology
    +# Copyright (c) 2019 NOKIA Inc.
    +# MIT License - See License file at:
    +#   https://github.com/ktbyers/netmiko/blob/develop/LICENSE
    +
    +import re
    +import time
    +
    +from netmiko import log
    +from netmiko.base_connection import BaseConnection
    +
    +
    +class NokiaSrosSSH(BaseConnection):
    +    """
    +    Implement methods for interacting with Nokia SR OS devices.
    +
    +    Not applicable in Nokia SR OS (disabled):
    +        - enable()
    +        - exit_enable_mode()
    +        - check_enable_mode()
    +
    +    Overriden methods to adapt Nokia SR OS behavior (changed):
    +        - session_preparation()
    +        - set_base_prompt()
    +        - config_mode()
    +        - exit_config_mode()
    +        - check_config_mode()
    +        - save_config()
    +        - commit()
    +        - strip_prompt()
    +    """
    +
    +    def session_preparation(self):
    +        self._test_channel_read()
    +        self.set_base_prompt()
    +        # "@" indicates model-driven CLI (vs Classical CLI)
    +        if "@" in self.base_prompt:
    +            self.disable_paging(command="environment more false")
    +            self.set_terminal_width(command="environment console width 512")
    +        else:
    +            self.disable_paging(command="environment no more")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def set_base_prompt(self, *args, **kwargs):
    +        """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
    +
    +    def enable(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def check_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return True
    +
    +    def exit_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
    +        """Enable config edit-mode for Nokia SR OS"""
    +        output = ""
    +        # Only model-driven CLI supports config-mode
    +        if "@" in self.base_prompt:
    +            output += super().config_mode(
    +                config_command=config_command, pattern=pattern
    +            )
    +        return output
    +
    +    def exit_config_mode(self, *args, **kwargs):
    +        """Disable config edit-mode for Nokia SR OS"""
    +        output = self._exit_all()
    +        # Model-driven CLI
    +        if "@" in self.base_prompt and "(ex)[" in output:
    +            # Asterisk indicates changes were made.
    +            if "*(ex)[" in output:
    +                log.warning("Uncommitted changes! Discarding changes!")
    +                output += self._discard()
    +            cmd = "quit-config"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +        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"@"):
    +        """Check config mode for Nokia SR OS"""
    +        if "@" not in self.base_prompt:
    +            # Classical CLI
    +            return False
    +        else:
    +            # Model-driven CLI look for "exclusive"
    +            return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Persist configuration to cflash for Nokia SR OS"""
    +        output = self.send_command(command_string="/admin save")
    +        return output
    +
    +    def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs):
    +        """Model driven CLI requires you not exit from configuration mode."""
    +        if exit_config_mode is None:
    +            # Set to False if model-driven CLI
    +            exit_config_mode = False if "@" in self.base_prompt else True
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def commit(self, *args, **kwargs):
    +        """Activate changes from private candidate for Nokia SR OS"""
    +        output = self._exit_all()
    +        if "@" in self.base_prompt and "*(ex)[" in output:
    +            log.info("Apply uncommitted changes!")
    +            cmd = "commit"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +            output += self.read_until_pattern(r"@")
    +        return output
    +
    +    def _exit_all(self):
    +        """Return to the 'root' context."""
    +        exit_cmd = "exit all"
    +        self.write_channel(self.normalize_cmd(exit_cmd))
    +        # Make sure you read until you detect the command echo (avoid getting out of sync)
    +        return self.read_until_pattern(pattern=re.escape(exit_cmd))
    +
    +    def _discard(self):
    +        """Discard changes from private candidate for Nokia SR OS"""
    +        output = ""
    +        if "@" in self.base_prompt:
    +            cmd = "discard"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            new_output = self.read_until_pattern(pattern=re.escape(cmd))
    +            if "@" not in new_output:
    +                new_output += self.read_until_prompt()
    +            output += new_output
    +        return output
    +
    +    def strip_prompt(self, *args, **kwargs):
    +        """Strip prompt from the output."""
    +        output = super().strip_prompt(*args, **kwargs)
    +        if "@" in self.base_prompt:
    +            # Remove context prompt too
    +            strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*"
    +            return re.sub(strips, "", output)
    +        else:
    +            return output
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class NokiaSrosSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
    +
    +

    Implement methods for interacting with Nokia SR OS devices.

    +

    Not applicable in Nokia SR OS (disabled): +- enable() +- exit_enable_mode() +- check_enable_mode()

    +

    Overriden methods to adapt Nokia SR OS behavior (changed): +- session_preparation() +- set_base_prompt() +- config_mode() +- exit_config_mode() +- check_config_mode() +- save_config() +- commit() +- strip_prompt()

    +
        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
    +
    +
    +Source code +
    class NokiaSrosSSH(BaseConnection):
    +    """
    +    Implement methods for interacting with Nokia SR OS devices.
    +
    +    Not applicable in Nokia SR OS (disabled):
    +        - enable()
    +        - exit_enable_mode()
    +        - check_enable_mode()
    +
    +    Overriden methods to adapt Nokia SR OS behavior (changed):
    +        - session_preparation()
    +        - set_base_prompt()
    +        - config_mode()
    +        - exit_config_mode()
    +        - check_config_mode()
    +        - save_config()
    +        - commit()
    +        - strip_prompt()
    +    """
    +
    +    def session_preparation(self):
    +        self._test_channel_read()
    +        self.set_base_prompt()
    +        # "@" indicates model-driven CLI (vs Classical CLI)
    +        if "@" in self.base_prompt:
    +            self.disable_paging(command="environment more false")
    +            self.set_terminal_width(command="environment console width 512")
    +        else:
    +            self.disable_paging(command="environment no more")
    +
    +        # Clear the read buffer
    +        time.sleep(0.3 * self.global_delay_factor)
    +        self.clear_buffer()
    +
    +    def set_base_prompt(self, *args, **kwargs):
    +        """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
    +
    +    def enable(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def check_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return True
    +
    +    def exit_enable_mode(self, *args, **kwargs):
    +        """Nokia SR OS does not support enable-mode"""
    +        return ""
    +
    +    def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
    +        """Enable config edit-mode for Nokia SR OS"""
    +        output = ""
    +        # Only model-driven CLI supports config-mode
    +        if "@" in self.base_prompt:
    +            output += super().config_mode(
    +                config_command=config_command, pattern=pattern
    +            )
    +        return output
    +
    +    def exit_config_mode(self, *args, **kwargs):
    +        """Disable config edit-mode for Nokia SR OS"""
    +        output = self._exit_all()
    +        # Model-driven CLI
    +        if "@" in self.base_prompt and "(ex)[" in output:
    +            # Asterisk indicates changes were made.
    +            if "*(ex)[" in output:
    +                log.warning("Uncommitted changes! Discarding changes!")
    +                output += self._discard()
    +            cmd = "quit-config"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +        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"@"):
    +        """Check config mode for Nokia SR OS"""
    +        if "@" not in self.base_prompt:
    +            # Classical CLI
    +            return False
    +        else:
    +            # Model-driven CLI look for "exclusive"
    +            return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +    def save_config(self, *args, **kwargs):
    +        """Persist configuration to cflash for Nokia SR OS"""
    +        output = self.send_command(command_string="/admin save")
    +        return output
    +
    +    def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs):
    +        """Model driven CLI requires you not exit from configuration mode."""
    +        if exit_config_mode is None:
    +            # Set to False if model-driven CLI
    +            exit_config_mode = False if "@" in self.base_prompt else True
    +        return super().send_config_set(
    +            config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +        )
    +
    +    def commit(self, *args, **kwargs):
    +        """Activate changes from private candidate for Nokia SR OS"""
    +        output = self._exit_all()
    +        if "@" in self.base_prompt and "*(ex)[" in output:
    +            log.info("Apply uncommitted changes!")
    +            cmd = "commit"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            output += self.read_until_pattern(pattern=re.escape(cmd))
    +            output += self.read_until_pattern(r"@")
    +        return output
    +
    +    def _exit_all(self):
    +        """Return to the 'root' context."""
    +        exit_cmd = "exit all"
    +        self.write_channel(self.normalize_cmd(exit_cmd))
    +        # Make sure you read until you detect the command echo (avoid getting out of sync)
    +        return self.read_until_pattern(pattern=re.escape(exit_cmd))
    +
    +    def _discard(self):
    +        """Discard changes from private candidate for Nokia SR OS"""
    +        output = ""
    +        if "@" in self.base_prompt:
    +            cmd = "discard"
    +            self.write_channel(self.normalize_cmd(cmd))
    +            new_output = self.read_until_pattern(pattern=re.escape(cmd))
    +            if "@" not in new_output:
    +                new_output += self.read_until_prompt()
    +            output += new_output
    +        return output
    +
    +    def strip_prompt(self, *args, **kwargs):
    +        """Strip prompt from the output."""
    +        output = super().strip_prompt(*args, **kwargs)
    +        if "@" in self.base_prompt:
    +            # Remove context prompt too
    +            strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*"
    +            return re.sub(strips, "", output)
    +        else:
    +            return output
    +
    +

    Ancestors

    + +

    Methods

    +
    +
    +def check_config_mode(self, check_string='(ex)[', pattern='@') +
    +
    +

    Check config mode for Nokia SR OS

    +
    +Source code +
    def check_config_mode(self, check_string=r"(ex)[", pattern=r"@"):
    +    """Check config mode for Nokia SR OS"""
    +    if "@" not in self.base_prompt:
    +        # Classical CLI
    +        return False
    +    else:
    +        # Model-driven CLI look for "exclusive"
    +        return super().check_config_mode(check_string=check_string, pattern=pattern)
    +
    +
    +
    +def check_enable_mode(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def check_enable_mode(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return True
    +
    +
    +
    +def commit(self, *args, **kwargs) +
    +
    +

    Activate changes from private candidate for Nokia SR OS

    +
    +Source code +
    def commit(self, *args, **kwargs):
    +    """Activate changes from private candidate for Nokia SR OS"""
    +    output = self._exit_all()
    +    if "@" in self.base_prompt and "*(ex)[" in output:
    +        log.info("Apply uncommitted changes!")
    +        cmd = "commit"
    +        self.write_channel(self.normalize_cmd(cmd))
    +        output += self.read_until_pattern(pattern=re.escape(cmd))
    +        output += self.read_until_pattern(r"@")
    +    return output
    +
    +
    +
    +def config_mode(self, config_command='edit-config exclusive', pattern='\\(ex\\)\\[') +
    +
    +

    Enable config edit-mode for Nokia SR OS

    +
    +Source code +
    def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["):
    +    """Enable config edit-mode for Nokia SR OS"""
    +    output = ""
    +    # Only model-driven CLI supports config-mode
    +    if "@" in self.base_prompt:
    +        output += super().config_mode(
    +            config_command=config_command, pattern=pattern
    +        )
    +    return output
    +
    +
    +
    +def enable(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def enable(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return ""
    +
    +
    +
    +def exit_config_mode(self, *args, **kwargs) +
    +
    +

    Disable config edit-mode for Nokia SR OS

    +
    +Source code +
    def exit_config_mode(self, *args, **kwargs):
    +    """Disable config edit-mode for Nokia SR OS"""
    +    output = self._exit_all()
    +    # Model-driven CLI
    +    if "@" in self.base_prompt and "(ex)[" in output:
    +        # Asterisk indicates changes were made.
    +        if "*(ex)[" in output:
    +            log.warning("Uncommitted changes! Discarding changes!")
    +            output += self._discard()
    +        cmd = "quit-config"
    +        self.write_channel(self.normalize_cmd(cmd))
    +        output += self.read_until_pattern(pattern=re.escape(cmd))
    +    if self.check_config_mode():
    +        raise ValueError("Failed to exit configuration mode")
    +    return output
    +
    +
    +
    +def exit_enable_mode(self, *args, **kwargs) +
    +
    +

    Nokia SR OS does not support enable-mode

    +
    +Source code +
    def exit_enable_mode(self, *args, **kwargs):
    +    """Nokia SR OS does not support enable-mode"""
    +    return ""
    +
    +
    +
    +def save_config(self, *args, **kwargs) +
    +
    +

    Persist configuration to cflash for Nokia SR OS

    +
    +Source code +
    def save_config(self, *args, **kwargs):
    +    """Persist configuration to cflash for Nokia SR OS"""
    +    output = self.send_command(command_string="/admin save")
    +    return output
    +
    +
    +
    +def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs) +
    +
    +

    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):
    +    """Model driven CLI requires you not exit from configuration mode."""
    +    if exit_config_mode is None:
    +        # Set to False if model-driven CLI
    +        exit_config_mode = False if "@" in self.base_prompt else True
    +    return super().send_config_set(
    +        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
    +    )
    +
    +
    +
    +def set_base_prompt(self, *args, **kwargs) +
    +
    +

    Remove the > when navigating into the different config level.

    +
    +Source code +
    def set_base_prompt(self, *args, **kwargs):
    +    """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
    +
    +
    +
    +def strip_prompt(self, *args, **kwargs) +
    +
    +

    Strip prompt from the output.

    +
    +Source code +
    def strip_prompt(self, *args, **kwargs):
    +    """Strip prompt from the output."""
    +    output = super().strip_prompt(*args, **kwargs)
    +    if "@" in self.base_prompt:
    +        # Remove context prompt too
    +        strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*"
    +        return re.sub(strips, "", output)
    +    else:
    +        return output
    +
    +
    +
    +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/oneaccess/index.html b/docs/netmiko/oneaccess/index.html index 56b9a22b6..025a3c4b4 100644 --- a/docs/netmiko/oneaccess/index.html +++ b/docs/netmiko/oneaccess/index.html @@ -3,13 +3,13 @@ - + netmiko.oneaccess API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.oneaccess

    Source code -
    from __future__ import unicode_literals
    -from netmiko.oneaccess.oneaccess_oneos import OneaccessOneOSSSH, OneaccessOneOSTelnet
    +
    from netmiko.oneaccess.oneaccess_oneos import OneaccessOneOSSSH, OneaccessOneOSTelnet
     
     __all__ = ["OneaccessOneOSSSH", "OneaccessOneOSTelnet"]
    @@ -209,7 +208,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/oneaccess/oneaccess_oneos.html b/docs/netmiko/oneaccess/oneaccess_oneos.html index dce693829..966e530ea 100644 --- a/docs/netmiko/oneaccess/oneaccess_oneos.html +++ b/docs/netmiko/oneaccess/oneaccess_oneos.html @@ -3,13 +3,13 @@ - + netmiko.oneaccess.oneaccess_oneos API documentation - + @@ -24,10 +24,6 @@

    Module netmiko.oneaccess.oneaccess_oneos

    Source code
    """Netmiko driver for OneAccess ONEOS"""
    -
    -from __future__ import print_function
    -from __future__ import unicode_literals
    -
     from netmiko.cisco_base_connection import CiscoBaseConnection
     import time
     
    @@ -37,7 +33,7 @@ 

    Module netmiko.oneaccess.oneaccess_oneos

    """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(OneaccessOneOSBase, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def session_preparation(self): """Prepare connection - disable paging""" @@ -51,7 +47,7 @@

    Module netmiko.oneaccess.oneaccess_oneos

    def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Save config: write mem""" - return super(OneaccessOneOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -87,7 +83,7 @@

    Classes

    """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(OneaccessOneOSBase, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def session_preparation(self): """Prepare connection - disable paging""" @@ -101,7 +97,7 @@

    Classes

    def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Save config: write mem""" - return super(OneaccessOneOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -126,7 +122,7 @@

    Methods

    Source code
    def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
         """Save config: write mem"""
    -    return super(OneaccessOneOSBase, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )

    @@ -363,7 +359,7 @@

    diff --git a/docs/netmiko/ovs/index.html b/docs/netmiko/ovs/index.html index 32f6042a2..5010bbffd 100644 --- a/docs/netmiko/ovs/index.html +++ b/docs/netmiko/ovs/index.html @@ -3,13 +3,13 @@ - + netmiko.ovs API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ovs

    Source code -
    from __future__ import unicode_literals
    -from netmiko.ovs.ovs_linux_ssh import OvsLinuxSSH
    +
    from netmiko.ovs.ovs_linux_ssh import OvsLinuxSSH
     
     __all__ = ["OvsLinuxSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class OvsLinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -166,6 +165,10 @@

    Classes

    :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
    Source code @@ -257,7 +260,7 @@

    Ovs diff --git a/docs/netmiko/ovs/ovs_linux_ssh.html b/docs/netmiko/ovs/ovs_linux_ssh.html index 317f6fdfd..c9fc253b0 100644 --- a/docs/netmiko/ovs/ovs_linux_ssh.html +++ b/docs/netmiko/ovs/ovs_linux_ssh.html @@ -3,13 +3,13 @@ - + netmiko.ovs.ovs_linux_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ovs.ovs_linux_ssh

    Source code -
    from __future__ import unicode_literals
    -from netmiko.linux.linux_ssh import LinuxSSH
    +
    from netmiko.linux.linux_ssh import LinuxSSH
     
     
     class OvsLinuxSSH(LinuxSSH):
    @@ -41,7 +40,7 @@ 

    Classes

    class OvsLinuxSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -161,6 +160,10 @@

    Classes

    :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
    Source code @@ -247,7 +250,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/paloalto/index.html b/docs/netmiko/paloalto/index.html index a6996bc11..61dda196f 100644 --- a/docs/netmiko/paloalto/index.html +++ b/docs/netmiko/paloalto/index.html @@ -3,13 +3,13 @@ - + netmiko.paloalto API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.paloalto

    Source code -
    from __future__ import unicode_literals
    -from netmiko.paloalto.paloalto_panos import PaloAltoPanosSSH, PaloAltoPanosTelnet
    +
    from netmiko.paloalto.paloalto_panos import PaloAltoPanosSSH, PaloAltoPanosTelnet
     
     __all__ = ["PaloAltoPanosSSH", "PaloAltoPanosTelnet"]
    @@ -46,7 +45,7 @@

    Classes

    class PaloAltoPanosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with PaloAlto devices.

    @@ -169,6 +168,10 @@

    Classes

    :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
    Source code @@ -231,7 +234,7 @@

    Inherited members

    class PaloAltoPanosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with PaloAlto devices.

    @@ -354,6 +357,10 @@

    Inherited members

    :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
    Source code @@ -447,7 +454,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/paloalto/paloalto_panos.html b/docs/netmiko/paloalto/paloalto_panos.html index 52f96242a..eb91ca195 100644 --- a/docs/netmiko/paloalto/paloalto_panos.html +++ b/docs/netmiko/paloalto/paloalto_panos.html @@ -3,13 +3,13 @@ - + netmiko.paloalto.paloalto_panos API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.paloalto.paloalto_panos

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     import re
     from netmiko.base_connection import BaseConnection
     
    @@ -64,19 +63,15 @@ 

    Module netmiko.paloalto.paloalto_panos

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(PaloAltoPanosBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(PaloAltoPanosBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit", pattern=r">"): """Exit configuration mode.""" - return super(PaloAltoPanosBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def commit( self, @@ -121,7 +116,7 @@

    Module netmiko.paloalto.paloalto_panos

    if partial: command_string += " partial" if vsys: - command_string += " {0}".format(vsys) + command_string += f" {vsys}" if device_and_network: command_string += " device-and-network" if policy_and_objects: @@ -141,9 +136,7 @@

    Module netmiko.paloalto.paloalto_panos

    ) if commit_marker not in output.lower(): - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_command(self, command_string, output): @@ -188,7 +181,7 @@

    Module netmiko.paloalto.paloalto_panos

    def send_command(self, *args, **kwargs): """Palo Alto requires an extra delay""" kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5) - return super(PaloAltoPanosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def cleanup(self): """Gracefully exit the SSH session.""" @@ -220,7 +213,7 @@

    Classes

    class PaloAltoPanosBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with PaloAlto devices.

    @@ -343,6 +336,10 @@

    Classes

    :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
    Source code @@ -382,19 +379,15 @@

    Classes

    def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(PaloAltoPanosBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(PaloAltoPanosBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit", pattern=r">"): """Exit configuration mode.""" - return super(PaloAltoPanosBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def commit( self, @@ -439,7 +432,7 @@

    Classes

    if partial: command_string += " partial" if vsys: - command_string += " {0}".format(vsys) + command_string += f" {vsys}" if device_and_network: command_string += " device-and-network" if policy_and_objects: @@ -459,9 +452,7 @@

    Classes

    ) if commit_marker not in output.lower(): - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_command(self, command_string, output): @@ -506,7 +497,7 @@

    Classes

    def send_command(self, *args, **kwargs): """Palo Alto requires an extra delay""" kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5) - return super(PaloAltoPanosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def cleanup(self): """Gracefully exit the SSH session.""" @@ -538,9 +529,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="]"):
         """Checks if the device is in configuration mode or not."""
    -    return super(PaloAltoPanosBase, self).check_config_mode(
    -        check_string=check_string
    -    )
    + return super().check_config_mode(check_string=check_string)

    @@ -631,7 +620,7 @@

    Methods

    if partial: command_string += " partial" if vsys: - command_string += " {0}".format(vsys) + command_string += f" {vsys}" if device_and_network: command_string += " device-and-network" if policy_and_objects: @@ -651,9 +640,7 @@

    Methods

    ) if commit_marker not in output.lower(): - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output

    @@ -666,7 +653,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(PaloAltoPanosBase, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)

    @@ -690,9 +677,7 @@

    Methods

    Source code
    def exit_config_mode(self, exit_config="exit", pattern=r">"):
         """Exit configuration mode."""
    -    return super(PaloAltoPanosBase, self).exit_config_mode(
    -        exit_config=exit_config, pattern=pattern
    -    )
    + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)

    @@ -717,7 +702,7 @@

    Methods

    def send_command(self, *args, **kwargs):
         """Palo Alto requires an extra delay"""
         kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5)
    -    return super(PaloAltoPanosBase, self).send_command(*args, **kwargs)
    + return super().send_command(*args, **kwargs)
    @@ -856,7 +841,7 @@

    Inherited members

    class PaloAltoPanosSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with PaloAlto devices.

    @@ -979,6 +964,10 @@

    Inherited members

    :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
    Source code @@ -1041,7 +1030,7 @@

    Inherited members

    class PaloAltoPanosTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with PaloAlto devices.

    @@ -1164,6 +1153,10 @@

    Inherited members

    :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
    Source code @@ -1271,7 +1264,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/pluribus/index.html b/docs/netmiko/pluribus/index.html index 2f98596a5..dadb3c6e7 100644 --- a/docs/netmiko/pluribus/index.html +++ b/docs/netmiko/pluribus/index.html @@ -3,13 +3,13 @@ - + netmiko.pluribus API documentation - + @@ -166,6 +166,10 @@

    Classes

    :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
    Source code @@ -173,14 +177,12 @@

    Classes

    """Common methods for Pluribus.""" def __init__(self, *args, **kwargs): - super(PluribusSSH, self).__init__(*args, **kwargs) + 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(PluribusSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def session_preparation(self): """Prepare the netmiko session.""" @@ -252,9 +254,7 @@

    Methods

    Source code
    def disable_paging(self, command="pager off", delay_factor=1):
         """Make sure paging is disabled."""
    -    return super(PluribusSSH, self).disable_paging(
    -        command=command, delay_factor=delay_factor
    -    )
    + return super().disable_paging(command=command, delay_factor=delay_factor)

    @@ -368,7 +368,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/pluribus/pluribus_ssh.html b/docs/netmiko/pluribus/pluribus_ssh.html index 73175778e..e26673269 100644 --- a/docs/netmiko/pluribus/pluribus_ssh.html +++ b/docs/netmiko/pluribus/pluribus_ssh.html @@ -3,13 +3,13 @@ - + netmiko.pluribus.pluribus_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.pluribus.pluribus_ssh

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.base_connection import BaseConnection
     
     
    @@ -31,14 +30,12 @@ 

    Module netmiko.pluribus.pluribus_ssh

    """Common methods for Pluribus.""" def __init__(self, *args, **kwargs): - super(PluribusSSH, self).__init__(*args, **kwargs) + 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(PluribusSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def session_preparation(self): """Prepare the netmiko session.""" @@ -198,6 +195,10 @@

    Classes

    :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
    Source code @@ -205,14 +206,12 @@

    Classes

    """Common methods for Pluribus.""" def __init__(self, *args, **kwargs): - super(PluribusSSH, self).__init__(*args, **kwargs) + 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(PluribusSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def session_preparation(self): """Prepare the netmiko session.""" @@ -284,9 +283,7 @@

    Methods

    Source code
    def disable_paging(self, command="pager off", delay_factor=1):
         """Make sure paging is disabled."""
    -    return super(PluribusSSH, self).disable_paging(
    -        command=command, delay_factor=delay_factor
    -    )
    + return super().disable_paging(command=command, delay_factor=delay_factor)
    @@ -395,7 +392,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/quanta/index.html b/docs/netmiko/quanta/index.html index 6ad10e214..0af5c9dce 100644 --- a/docs/netmiko/quanta/index.html +++ b/docs/netmiko/quanta/index.html @@ -3,13 +3,13 @@ - + netmiko.quanta API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.quanta

    Source code -
    from __future__ import unicode_literals
    -from netmiko.quanta.quanta_mesh_ssh import QuantaMeshSSH
    +
    from netmiko.quanta.quanta_mesh_ssh import QuantaMeshSSH
     
     __all__ = ["QuantaMeshSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class QuantaMeshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -166,17 +165,21 @@

    Classes

    :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
    Source code
    class QuantaMeshSSH(CiscoSSHConnection):
         def disable_paging(self, command="no pager", delay_factor=1):
             """Disable paging"""
    -        return super(QuantaMeshSSH, self).disable_paging(command=command)
    +        return super().disable_paging(command=command)
     
         def config_mode(self, config_command="configure"):
             """Enter configuration mode."""
    -        return super(QuantaMeshSSH, self).config_mode(config_command=config_command)
    +        return super().config_mode(config_command=config_command)
     
         def save_config(
             self,
    @@ -185,7 +188,7 @@ 

    Classes

    confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -206,7 +209,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(QuantaMeshSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -218,7 +221,7 @@

    Methods

    Source code
    def disable_paging(self, command="no pager", delay_factor=1):
         """Disable paging"""
    -    return super(QuantaMeshSSH, self).disable_paging(command=command)
    + return super().disable_paging(command=command)
    @@ -235,7 +238,7 @@

    Methods

    confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -321,7 +324,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/quanta/quanta_mesh_ssh.html b/docs/netmiko/quanta/quanta_mesh_ssh.html index e9a7e9841..5e39381f0 100644 --- a/docs/netmiko/quanta/quanta_mesh_ssh.html +++ b/docs/netmiko/quanta/quanta_mesh_ssh.html @@ -3,13 +3,13 @@ - + netmiko.quanta.quanta_mesh_ssh API documentation - + @@ -22,18 +22,17 @@

    Module netmiko.quanta.quanta_mesh_ssh

    Source code -
    from __future__ import unicode_literals
    -from netmiko.cisco_base_connection import CiscoSSHConnection
    +
    from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
     class QuantaMeshSSH(CiscoSSHConnection):
         def disable_paging(self, command="no pager", delay_factor=1):
             """Disable paging"""
    -        return super(QuantaMeshSSH, self).disable_paging(command=command)
    +        return super().disable_paging(command=command)
     
         def config_mode(self, config_command="configure"):
             """Enter configuration mode."""
    -        return super(QuantaMeshSSH, self).config_mode(config_command=config_command)
    +        return super().config_mode(config_command=config_command)
     
         def save_config(
             self,
    @@ -42,7 +41,7 @@ 

    Module netmiko.quanta.quanta_mesh_ssh

    confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -58,7 +57,7 @@

    Classes

    class QuantaMeshSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Base Class for cisco-like behavior.

    @@ -178,17 +177,21 @@

    Classes

    :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
    Source code
    class QuantaMeshSSH(CiscoSSHConnection):
         def disable_paging(self, command="no pager", delay_factor=1):
             """Disable paging"""
    -        return super(QuantaMeshSSH, self).disable_paging(command=command)
    +        return super().disable_paging(command=command)
     
         def config_mode(self, config_command="configure"):
             """Enter configuration mode."""
    -        return super(QuantaMeshSSH, self).config_mode(config_command=config_command)
    +        return super().config_mode(config_command=config_command)
     
         def save_config(
             self,
    @@ -197,7 +200,7 @@ 

    Classes

    confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -218,7 +221,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(QuantaMeshSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -230,7 +233,7 @@

    Methods

    Source code
    def disable_paging(self, command="no pager", delay_factor=1):
         """Disable paging"""
    -    return super(QuantaMeshSSH, self).disable_paging(command=command)
    + return super().disable_paging(command=command)
    @@ -247,7 +250,7 @@

    Methods

    confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -328,7 +331,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/rad/index.html b/docs/netmiko/rad/index.html index ebc3c6661..127dfe892 100644 --- a/docs/netmiko/rad/index.html +++ b/docs/netmiko/rad/index.html @@ -3,13 +3,13 @@ - + netmiko.rad API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.rad

    Source code -
    from __future__ import unicode_literals
    -from netmiko.rad.rad_etx import RadETXSSH
    +
    from netmiko.rad.rad_etx import RadETXSSH
     from netmiko.rad.rad_etx import RadETXTelnet
     
     __all__ = ["RadETXSSH", "RadETXTelnet"]
    @@ -167,6 +166,10 @@

    Classes

    :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
    Source code @@ -176,7 +179,7 @@

    Classes

    def __init__(self, **kwargs): # 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(RadETXSSH, self).__init__(**kwargs)
    + return super().__init__(**kwargs)

    Ancestors

      @@ -233,7 +236,7 @@

      Inherited members

      class RadETXTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      RAD ETX Telnet Support.

      @@ -353,6 +356,10 @@

      Inherited members

      :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
      Source code @@ -370,7 +377,7 @@

      Inherited members

      password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs @@ -403,7 +410,7 @@

      Methods

      password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs @@ -494,7 +501,7 @@

      R diff --git a/docs/netmiko/rad/rad_etx.html b/docs/netmiko/rad/rad_etx.html index 0081dd7df..4c3eab1d7 100644 --- a/docs/netmiko/rad/rad_etx.html +++ b/docs/netmiko/rad/rad_etx.html @@ -3,13 +3,13 @@ - + netmiko.rad.rad_etx API documentation - + @@ -22,9 +22,7 @@

      Module netmiko.rad.rad_etx

      Source code -
      from __future__ import unicode_literals
      -from __future__ import print_function
      -import time
      +
      import time
       from netmiko.base_connection import BaseConnection
       
       
      @@ -67,9 +65,7 @@ 

      Module netmiko.rad.rad_etx

      def config_mode(self, config_command="config", pattern=">config"): """Enter into configuration mode on remote device.""" - return super(RadETXBase, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string=">config", pattern=""): """ @@ -77,15 +73,11 @@

      Module netmiko.rad.rad_etx

      Rad config starts with baseprompt>config. """ - return super(RadETXBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def exit_config_mode(self, exit_config="exit all", pattern="#"): """Exit from configuration mode.""" - return super(RadETXBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) class RadETXSSH(RadETXBase): @@ -94,7 +86,7 @@

      Module netmiko.rad.rad_etx

      def __init__(self, **kwargs): # 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(RadETXSSH, self).__init__(**kwargs) + return super().__init__(**kwargs) class RadETXTelnet(RadETXBase): @@ -111,7 +103,7 @@

      Module netmiko.rad.rad_etx

      password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs @@ -129,7 +121,7 @@

      Classes

      class RadETXBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      RAD ETX Support, Tested on RAD 203AX, 205A and 220A.

      @@ -249,6 +241,10 @@

      Classes

      :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
      Source code @@ -291,9 +287,7 @@

      Classes

      def config_mode(self, config_command="config", pattern=">config"): """Enter into configuration mode on remote device.""" - return super(RadETXBase, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string=">config", pattern=""): """ @@ -301,15 +295,11 @@

      Classes

      Rad config starts with baseprompt>config. """ - return super(RadETXBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def exit_config_mode(self, exit_config="exit all", pattern="#"): """Exit from configuration mode.""" - return super(RadETXBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - )
      + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)

      Ancestors

        @@ -336,9 +326,7 @@

        Methods

        Rad config starts with baseprompt>config. """ - return super(RadETXBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern)
      @@ -362,9 +350,7 @@

      Methods

      Source code
      def config_mode(self, config_command="config", pattern=">config"):
           """Enter into configuration mode on remote device."""
      -    return super(RadETXBase, self).config_mode(
      -        config_command=config_command, pattern=pattern
      -    )
      + return super().config_mode(config_command=config_command, pattern=pattern)
      @@ -388,9 +374,7 @@

      Methods

      Source code
      def exit_config_mode(self, exit_config="exit all", pattern="#"):
           """Exit from configuration mode."""
      -    return super(RadETXBase, self).exit_config_mode(
      -        exit_config=exit_config, pattern=pattern
      -    )
      + return super().exit_config_mode(exit_config=exit_config, pattern=pattern)
      @@ -591,6 +575,10 @@

      Inherited members

      :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
    Source code @@ -600,7 +588,7 @@

    Inherited members

    def __init__(self, **kwargs): # 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(RadETXSSH, self).__init__(**kwargs) + return super().__init__(**kwargs)

    Ancestors

      @@ -657,7 +645,7 @@

      Inherited members

      class RadETXTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      RAD ETX Telnet Support.

      @@ -777,6 +765,10 @@

      Inherited members

      :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
      Source code @@ -794,7 +786,7 @@

      Inherited members

      password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs @@ -827,7 +819,7 @@

      Methods

      password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs @@ -925,7 +917,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/ruckus/index.html b/docs/netmiko/ruckus/index.html index f5f2741eb..0acaca05d 100644 --- a/docs/netmiko/ruckus/index.html +++ b/docs/netmiko/ruckus/index.html @@ -3,13 +3,13 @@ - + netmiko.ruckus API documentation - + @@ -22,8 +22,7 @@

      Module netmiko.ruckus

      Source code -
      from __future__ import unicode_literals
      -from netmiko.ruckus.ruckus_fastiron import RuckusFastironSSH
      +
      from netmiko.ruckus.ruckus_fastiron import RuckusFastironSSH
       from netmiko.ruckus.ruckus_fastiron import RuckusFastironTelnet
       
       __all__ = ["RuckusFastironSSH", "RuckusFastironTelnet"]
      @@ -47,7 +46,7 @@

      Classes

      class RuckusFastironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Ruckus FastIron aka ICX support.

      @@ -167,6 +166,10 @@

      Classes

      :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
      Source code @@ -350,6 +353,10 @@

      Inherited members

      :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

    Source code @@ -357,7 +364,7 @@

    Inherited members

    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(RuckusFastironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def _process_option(self, tsocket, command, option): """ @@ -375,7 +382,7 @@

    Inherited members

    def telnet_login(self, *args, **kwargs): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(RuckusFastironTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs)

    Ancestors

      @@ -465,7 +472,7 @@

      -

      Generated by pdoc 0.6.2.

      +

      Generated by pdoc 0.6.3.

      diff --git a/docs/netmiko/ruckus/ruckus_fastiron.html b/docs/netmiko/ruckus/ruckus_fastiron.html index 8318adc37..2f7fbb269 100644 --- a/docs/netmiko/ruckus/ruckus_fastiron.html +++ b/docs/netmiko/ruckus/ruckus_fastiron.html @@ -3,13 +3,13 @@ - + netmiko.ruckus.ruckus_fastiron API documentation - + @@ -22,8 +22,7 @@

      Module netmiko.ruckus.ruckus_fastiron

      Source code -
      from __future__ import unicode_literals
      -import re
      +
      import re
       import time
       from telnetlib import DO, DONT, ECHO, IAC, WILL, WONT
       from netmiko.cisco_base_connection import CiscoSSHConnection
      @@ -70,8 +69,13 @@ 

      Module netmiko.ruckus.ruckus_fastiron

      output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() - return output + new_data = self.read_until_prompt() + output += new_data + if not re.search( + r"error.*incorrect.*password", new_data, flags=re.I + ): + return output + time.sleep(1) i += 1 @@ -84,7 +88,7 @@

      Module netmiko.ruckus.ruckus_fastiron

      def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves configuration.""" - return super(RuckusFastironBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -93,7 +97,7 @@

      Module netmiko.ruckus.ruckus_fastiron

      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(RuckusFastironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def _process_option(self, tsocket, command, option): """ @@ -111,7 +115,7 @@

      Module netmiko.ruckus.ruckus_fastiron

      def telnet_login(self, *args, **kwargs): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(RuckusFastironTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs) class RuckusFastironSSH(RuckusFastironBase): @@ -129,7 +133,7 @@

      Classes

      class RuckusFastironBase -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Ruckus FastIron aka ICX support.

      @@ -249,6 +253,10 @@

      Classes

      :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
      Source code @@ -293,8 +301,13 @@

      Classes

      output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() - return output + new_data = self.read_until_prompt() + output += new_data + if not re.search( + r"error.*incorrect.*password", new_data, flags=re.I + ): + return output + time.sleep(1) i += 1 @@ -307,7 +320,7 @@

      Classes

      def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves configuration.""" - return super(RuckusFastironBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
      @@ -364,8 +377,13 @@

      Methods

      output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() - return output + new_data = self.read_until_prompt() + output += new_data + if not re.search( + r"error.*incorrect.*password", new_data, flags=re.I + ): + return output + time.sleep(1) i += 1 @@ -386,7 +404,7 @@

      Methods

      Source code
      def save_config(self, cmd="write mem", confirm=False, confirm_response=""):
           """Saves configuration."""
      -    return super(RuckusFastironBase, self).save_config(
      +    return super().save_config(
               cmd=cmd, confirm=confirm, confirm_response=confirm_response
           )
      @@ -457,7 +475,7 @@

      Inherited members

      class RuckusFastironSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

      Ruckus FastIron aka ICX support.

      @@ -577,6 +595,10 @@

      Inherited members

      :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
      Source code @@ -760,6 +782,10 @@

      Inherited members

      :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
      Source code @@ -767,7 +793,7 @@

      Inherited members

      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(RuckusFastironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def _process_option(self, tsocket, command, option): """ @@ -785,7 +811,7 @@

      Inherited members

      def telnet_login(self, *args, **kwargs): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(RuckusFastironTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs)

      Ancestors

        @@ -878,7 +904,7 @@

        -

        Generated by pdoc 0.6.2.

        +

        Generated by pdoc 0.6.3.

        diff --git a/docs/netmiko/ruijie/index.html b/docs/netmiko/ruijie/index.html new file mode 100644 index 000000000..2a90a9a3e --- /dev/null +++ b/docs/netmiko/ruijie/index.html @@ -0,0 +1,460 @@ + + + + + + +netmiko.ruijie API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.ruijie

        +
        +
        +
        +Source code +
        from netmiko.ruijie.ruijie_os import RuijieOSSSH, RuijieOSTelnet
        +
        +__all__ = ["RuijieOSSSH", "RuijieOSTelnet"]
        +
        +
        +
        +

        Sub-modules

        +
        +
        netmiko.ruijie.ruijie_os
        +
        +

        Ruijie RGOS Support

        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class RuijieOSSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
        +
        +

        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.
        +    :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
        +
        +
        +Source code +
        class RuijieOSSSH(RuijieOSBase):
        +
        +    pass
        +
        +

        Ancestors

        + +

        Inherited members

        + +
        +
        +class RuijieOSTelnet +(*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.
        +    :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
        +
        +
        +Source code +
        class RuijieOSTelnet(RuijieOSBase):
        +    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)
        +
        +

        Ancestors

        + +

        Inherited members

        + +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file diff --git a/docs/netmiko/ruijie/ruijie_os.html b/docs/netmiko/ruijie/ruijie_os.html new file mode 100644 index 000000000..f8fa3bc53 --- /dev/null +++ b/docs/netmiko/ruijie/ruijie_os.html @@ -0,0 +1,729 @@ + + + + + + +netmiko.ruijie.ruijie_os API documentation + + + + + + + + + +
        +
        +
        +

        Module netmiko.ruijie.ruijie_os

        +
        +
        +

        Ruijie RGOS Support

        +
        +Source code +
        """Ruijie RGOS Support"""
        +from netmiko.cisco_base_connection import CiscoBaseConnection
        +import time
        +
        +
        +class RuijieOSBase(CiscoBaseConnection):
        +    def session_preparation(self):
        +        """Prepare the session after the connection has been established."""
        +        self._test_channel_read(pattern=r"[>#]")
        +        self.set_base_prompt()
        +        """Ruijie OS requires enable mode to set terminal width"""
        +        self.enable()
        +        self.disable_paging(command="terminal length 0")
        +        self.set_terminal_width(command="terminal width 256")
        +        # 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=""):
        +        """Save config: write"""
        +        return super().save_config(
        +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
        +        )
        +
        +
        +class RuijieOSSSH(RuijieOSBase):
        +
        +    pass
        +
        +
        +class RuijieOSTelnet(RuijieOSBase):
        +    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)
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        Classes

        +
        +
        +class RuijieOSBase +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
        +
        +

        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.
        +    :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
        +
        +
        +Source code +
        class RuijieOSBase(CiscoBaseConnection):
        +    def session_preparation(self):
        +        """Prepare the session after the connection has been established."""
        +        self._test_channel_read(pattern=r"[>#]")
        +        self.set_base_prompt()
        +        """Ruijie OS requires enable mode to set terminal width"""
        +        self.enable()
        +        self.disable_paging(command="terminal length 0")
        +        self.set_terminal_width(command="terminal width 256")
        +        # 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=""):
        +        """Save config: write"""
        +        return super().save_config(
        +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
        +        )
        +
        +

        Ancestors

        + +

        Subclasses

        + +

        Methods

        +
        +
        +def save_config(self, cmd='write', confirm=False, confirm_response='') +
        +
        +

        Save config: write

        +
        +Source code +
        def save_config(self, cmd="write", confirm=False, confirm_response=""):
        +    """Save config: write"""
        +    return super().save_config(
        +        cmd=cmd, confirm=confirm, confirm_response=confirm_response
        +    )
        +
        +
        +
        +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._test_channel_read(pattern=r"[>#]")
        +    self.set_base_prompt()
        +    """Ruijie OS requires enable mode to set terminal width"""
        +    self.enable()
        +    self.disable_paging(command="terminal length 0")
        +    self.set_terminal_width(command="terminal width 256")
        +    # Clear the read buffer
        +    time.sleep(0.3 * self.global_delay_factor)
        +    self.clear_buffer()
        +
        +
        +
        +

        Inherited members

        + +
        +
        +class RuijieOSSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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) +
        +
        +

        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.
        +    :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
        +
        +
        +Source code +
        class RuijieOSSSH(RuijieOSBase):
        +
        +    pass
        +
        +

        Ancestors

        + +

        Inherited members

        + +
        +
        +class RuijieOSTelnet +(*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.
        +    :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
        +
        +
        +Source code +
        class RuijieOSTelnet(RuijieOSBase):
        +    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)
        +
        +

        Ancestors

        + +

        Inherited members

        + +
        +
        +
        +
        + +
        + + + + + \ No newline at end of file diff --git a/docs/netmiko/scp_functions.html b/docs/netmiko/scp_functions.html index 01d0e6604..58f45a69f 100644 --- a/docs/netmiko/scp_functions.html +++ b/docs/netmiko/scp_functions.html @@ -3,13 +3,13 @@ - + netmiko.scp_functions API documentation - + @@ -35,9 +35,6 @@

        Module netmiko.scp_functions

        Currently only supports Cisco IOS and Cisco ASA. """ -from __future__ import print_function -from __future__ import unicode_literals - from netmiko import FileTransfer, InLineTransfer @@ -57,6 +54,7 @@

        Module netmiko.scp_functions

        disable_md5=False, inline_transfer=False, overwrite_file=False, + socket_timeout=10.0, ): """Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices. @@ -96,6 +94,7 @@

        Module netmiko.scp_functions

        "source_file": source_file, "dest_file": dest_file, "direction": direction, + "socket_timeout": socket_timeout, } if file_system is not None: scp_args["file_system"] = file_system @@ -148,7 +147,7 @@

        Module netmiko.scp_functions

        Functions

        -def file_transfer(ssh_conn, source_file, dest_file, file_system=None, direction='put', disable_md5=False, inline_transfer=False, overwrite_file=False) +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)

        Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices.

        @@ -169,6 +168,7 @@

        Functions

        disable_md5=False, inline_transfer=False, overwrite_file=False, + socket_timeout=10.0, ): """Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices. @@ -208,6 +208,7 @@

        Functions

        "source_file": source_file, "dest_file": dest_file, "direction": direction, + "socket_timeout": socket_timeout, } if file_system is not None: scp_args["file_system"] = file_system @@ -292,7 +293,7 @@

        Index

        diff --git a/docs/netmiko/scp_handler.html b/docs/netmiko/scp_handler.html index c94df15ba..20604c85b 100644 --- a/docs/netmiko/scp_handler.html +++ b/docs/netmiko/scp_handler.html @@ -3,13 +3,13 @@ - + netmiko.scp_handler API documentation - + @@ -35,14 +35,12 @@

        Module netmiko.scp_handler

        Currently only supports Cisco IOS and Cisco ASA. """ -from __future__ import print_function -from __future__ import unicode_literals - import re import os import hashlib import scp +import platform class SCPConn(object): @@ -52,8 +50,9 @@

        Module netmiko.scp_handler

        Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn): + def __init__(self, ssh_conn, socket_timeout=10.0): self.ssh_ctl_chan = ssh_conn + self.socket_timeout = socket_timeout self.establish_scp_conn() def establish_scp_conn(self): @@ -61,7 +60,9 @@

        Module netmiko.scp_handler

        ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport()) + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + ) def scp_transfer_file(self, source_file, dest_file): """Put file using SCP (for backwards compatibility).""" @@ -84,12 +85,19 @@

        Module netmiko.scp_handler

        """Class to manage SCP file transfer and associated SSH control channel.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system=None, + direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + self.socket_timeout = socket_timeout auto_flag = ( "cisco_ios" in ssh_conn.device_type @@ -124,7 +132,7 @@

        Module netmiko.scp_handler

        def establish_scp_conn(self): """Establish SCP connection.""" - self.scp_conn = SCPConn(self.ssh_ctl_chan) + self.scp_conn = SCPConn(self.ssh_ctl_chan, socket_timeout=self.socket_timeout) def close_scp_chan(self): """Close the SCP connection to the remote network device.""" @@ -133,7 +141,7 @@

        Module netmiko.scp_handler

        def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): """Return space available on remote device.""" - remote_cmd = "dir {}".format(self.file_system) + remote_cmd = f"dir {self.file_system}" remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) match = re.search(search_pattern, remote_output) if "kbytes" in match.group(0) or "Kbytes" in match.group(0): @@ -143,7 +151,7 @@

        Module netmiko.scp_handler

        def _remote_space_available_unix(self, search_pattern=""): """Return space available on *nix system (BSD/Linux).""" self.ssh_ctl_chan._enter_shell() - remote_cmd = "/bin/df -k {}".format(self.file_system) + remote_cmd = f"/bin/df -k {self.file_system}" remote_output = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -177,8 +185,17 @@

        Module netmiko.scp_handler

        def local_space_available(self): """Return space available on local filesystem.""" - destination_stats = os.statvfs(".") - return destination_stats.f_bsize * destination_stats.f_bavail + if platform.system() == "Windows": + import ctypes + + free_bytes = ctypes.c_ulonglong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceExW( + ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes) + ) + return free_bytes.value + else: + destination_stats = os.statvfs(".") + return destination_stats.f_bsize * destination_stats.f_bavail def verify_space_available(self, search_pattern=r"(\d+) \w+ free"): """Verify sufficient space is available on destination file system (return boolean).""" @@ -194,7 +211,7 @@

        Module netmiko.scp_handler

        """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}/{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( @@ -214,7 +231,7 @@

        Module netmiko.scp_handler

        """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 = "ls {}".format(self.file_system) + remote_cmd = f"ls {self.file_system}" remote_out = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -231,7 +248,7 @@

        Module netmiko.scp_handler

        elif self.direction == "get": remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Strip out "Directory of flash:/filename line remote_out = re.split(r"Directory of .*", remote_out) @@ -256,9 +273,9 @@

        Module netmiko.scp_handler

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_file = "{}/{}".format(self.file_system, remote_file) + remote_file = f"{self.file_system}/{remote_file}" if not remote_cmd: - remote_cmd = "ls -l {}".format(remote_file) + remote_cmd = f"ls -l {remote_file}" self.ssh_ctl_chan._enter_shell() remote_out = self.ssh_ctl_chan.send_command(remote_cmd, expect_string=r"[\$#]") @@ -280,12 +297,27 @@

        Module netmiko.scp_handler

        "Search pattern not found for remote file size during SCP transfer." ) - def file_md5(self, file_name): - """Compute MD5 hash of file.""" + def file_md5(self, file_name, add_newline=False): + """Compute MD5 hash of file. + + add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in + the string + + Args: + file_name: name of file to get md5 digest of + add_newline: add newline to end of file contents or not + + """ + file_hash = hashlib.md5() with open(file_name, "rb") as f: - file_contents = f.read() - file_hash = hashlib.md5(file_contents).hexdigest() - return file_hash + while True: + file_contents = f.read(512) + if not file_contents: + if add_newline: + file_contents + b"\n" + break + file_hash.update(file_contents) + return file_hash.hexdigest() @staticmethod def process_md5(md5_output, pattern=r"=\s+(\S+)"): @@ -300,7 +332,7 @@

        Module netmiko.scp_handler

        if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def compare_md5(self): """Compare md5 of file on network device to md5 of local file.""" @@ -321,7 +353,7 @@

        Module netmiko.scp_handler

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -335,13 +367,13 @@

        Module netmiko.scp_handler

        def get_file(self): """SCP copy the file from the remote device to local system.""" - source_file = "{}/{}".format(self.file_system, self.source_file) + 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): """SCP copy the file from the local system to the remote device.""" - destination = "{}/{}".format(self.file_system, self.dest_file) + 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() @@ -386,7 +418,7 @@

        Classes

        class BaseFileTransfer -(ssh_conn, source_file, dest_file, file_system=None, direction='put') +(ssh_conn, source_file, dest_file, file_system=None, direction='put', socket_timeout=10.0)

        Class to manage SCP file transfer and associated SSH control channel.

        @@ -396,12 +428,19 @@

        Classes

        """Class to manage SCP file transfer and associated SSH control channel.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system=None, + direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + self.socket_timeout = socket_timeout auto_flag = ( "cisco_ios" in ssh_conn.device_type @@ -436,7 +475,7 @@

        Classes

        def establish_scp_conn(self): """Establish SCP connection.""" - self.scp_conn = SCPConn(self.ssh_ctl_chan) + self.scp_conn = SCPConn(self.ssh_ctl_chan, socket_timeout=self.socket_timeout) def close_scp_chan(self): """Close the SCP connection to the remote network device.""" @@ -445,7 +484,7 @@

        Classes

        def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): """Return space available on remote device.""" - remote_cmd = "dir {}".format(self.file_system) + remote_cmd = f"dir {self.file_system}" remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) match = re.search(search_pattern, remote_output) if "kbytes" in match.group(0) or "Kbytes" in match.group(0): @@ -455,7 +494,7 @@

        Classes

        def _remote_space_available_unix(self, search_pattern=""): """Return space available on *nix system (BSD/Linux).""" self.ssh_ctl_chan._enter_shell() - remote_cmd = "/bin/df -k {}".format(self.file_system) + remote_cmd = f"/bin/df -k {self.file_system}" remote_output = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -489,8 +528,17 @@

        Classes

        def local_space_available(self): """Return space available on local filesystem.""" - destination_stats = os.statvfs(".") - return destination_stats.f_bsize * destination_stats.f_bavail + if platform.system() == "Windows": + import ctypes + + free_bytes = ctypes.c_ulonglong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceExW( + ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes) + ) + return free_bytes.value + else: + destination_stats = os.statvfs(".") + return destination_stats.f_bsize * destination_stats.f_bavail def verify_space_available(self, search_pattern=r"(\d+) \w+ free"): """Verify sufficient space is available on destination file system (return boolean).""" @@ -506,7 +554,7 @@

        Classes

        """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}/{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( @@ -526,7 +574,7 @@

        Classes

        """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 = "ls {}".format(self.file_system) + remote_cmd = f"ls {self.file_system}" remote_out = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -543,7 +591,7 @@

        Classes

        elif self.direction == "get": remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Strip out "Directory of flash:/filename line remote_out = re.split(r"Directory of .*", remote_out) @@ -568,9 +616,9 @@

        Classes

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_file = "{}/{}".format(self.file_system, remote_file) + remote_file = f"{self.file_system}/{remote_file}" if not remote_cmd: - remote_cmd = "ls -l {}".format(remote_file) + remote_cmd = f"ls -l {remote_file}" self.ssh_ctl_chan._enter_shell() remote_out = self.ssh_ctl_chan.send_command(remote_cmd, expect_string=r"[\$#]") @@ -592,12 +640,27 @@

        Classes

        "Search pattern not found for remote file size during SCP transfer." ) - def file_md5(self, file_name): - """Compute MD5 hash of file.""" + def file_md5(self, file_name, add_newline=False): + """Compute MD5 hash of file. + + add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in + the string + + Args: + file_name: name of file to get md5 digest of + add_newline: add newline to end of file contents or not + + """ + file_hash = hashlib.md5() with open(file_name, "rb") as f: - file_contents = f.read() - file_hash = hashlib.md5(file_contents).hexdigest() - return file_hash + while True: + file_contents = f.read(512) + if not file_contents: + if add_newline: + file_contents + b"\n" + break + file_hash.update(file_contents) + return file_hash.hexdigest() @staticmethod def process_md5(md5_output, pattern=r"=\s+(\S+)"): @@ -612,7 +675,7 @@

        Classes

        if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def compare_md5(self): """Compare md5 of file on network device to md5 of local file.""" @@ -633,7 +696,7 @@

        Classes

        remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -647,13 +710,13 @@

        Classes

        def get_file(self): """SCP copy the file from the remote device to local system.""" - source_file = "{}/{}".format(self.file_system, self.source_file) + 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): """SCP copy the file from the local system to the remote device.""" - destination = "{}/{}".format(self.file_system, self.dest_file) + 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() @@ -689,6 +752,7 @@

        Classes

        Subclasses

        @@ -717,7 +781,7 @@

        Static methods

        if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output))
        + raise ValueError(f"Invalid output from MD5 command: {md5_output}")

    @@ -734,7 +798,7 @@

    Methods

    """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}/{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( @@ -832,22 +896,46 @@

    Methods

    Source code
    def establish_scp_conn(self):
         """Establish SCP connection."""
    -    self.scp_conn = SCPConn(self.ssh_ctl_chan)
    + self.scp_conn = SCPConn(self.ssh_ctl_chan, socket_timeout=self.socket_timeout)
    -def file_md5(self, file_name) +def file_md5(self, file_name, add_newline=False)
    -

    Compute MD5 hash of file.

    +

    Compute MD5 hash of file.

    +

    add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in +the string

    +

    Args

    +
    +
    file_name
    +
    name of file to get md5 digest of
    +
    add_newline
    +
    add newline to end of file contents or not
    +
    Source code -
    def file_md5(self, file_name):
    -    """Compute MD5 hash of file."""
    +
    def file_md5(self, file_name, add_newline=False):
    +    """Compute MD5 hash of file.
    +
    +    add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in
    +    the string
    +
    +    Args:
    +      file_name: name of file to get md5 digest of
    +      add_newline: add newline to end of file contents or not
    +
    +    """
    +    file_hash = hashlib.md5()
         with open(file_name, "rb") as f:
    -        file_contents = f.read()
    -        file_hash = hashlib.md5(file_contents).hexdigest()
    -    return file_hash
    + while True: + file_contents = f.read(512) + if not file_contents: + if add_newline: + file_contents + b"\n" + break + file_hash.update(file_contents) + return file_hash.hexdigest()
    @@ -859,7 +947,7 @@

    Methods

    Source code
    def get_file(self):
         """SCP copy the file from the remote device to local system."""
    -    source_file = "{}/{}".format(self.file_system, self.source_file)
    +    source_file = f"{self.file_system}/{self.source_file}"
         self.scp_conn.scp_get_file(source_file, self.dest_file)
         self.scp_conn.close()
    @@ -873,8 +961,17 @@

    Methods

    Source code
    def local_space_available(self):
         """Return space available on local filesystem."""
    -    destination_stats = os.statvfs(".")
    -    return destination_stats.f_bsize * destination_stats.f_bavail
    + if platform.system() == "Windows": + import ctypes + + free_bytes = ctypes.c_ulonglong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceExW( + ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes) + ) + return free_bytes.value + else: + destination_stats = os.statvfs(".") + return destination_stats.f_bsize * destination_stats.f_bavail
    @@ -886,7 +983,7 @@

    Methods

    Source code
    def put_file(self):
         """SCP copy the file from the local system to the remote device."""
    -    destination = "{}/{}".format(self.file_system, self.dest_file)
    +    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()
    @@ -907,7 +1004,7 @@

    Methods

    elif self.direction == "get": remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Strip out "Directory of flash:/filename line remote_out = re.split(r"Directory of .*", remote_out) @@ -944,7 +1041,7 @@

    Methods

    remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5
    @@ -959,7 +1056,7 @@

    Methods

    Source code
    def remote_space_available(self, search_pattern=r"(\d+) \w+ free"):
         """Return space available on remote device."""
    -    remote_cmd = "dir {}".format(self.file_system)
    +    remote_cmd = f"dir {self.file_system}"
         remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd)
         match = re.search(search_pattern, remote_output)
         if "kbytes" in match.group(0) or "Kbytes" in match.group(0):
    @@ -1016,7 +1113,7 @@ 

    Methods

    class SCPConn -(ssh_conn) +(ssh_conn, socket_timeout=10.0)

    Establish a secure copy channel to the remote network device.

    @@ -1030,8 +1127,9 @@

    Methods

    Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn): + def __init__(self, ssh_conn, socket_timeout=10.0): self.ssh_ctl_chan = ssh_conn + self.socket_timeout = socket_timeout self.establish_scp_conn() def establish_scp_conn(self): @@ -1039,7 +1137,9 @@

    Methods

    ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport()) + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + ) def scp_transfer_file(self, source_file, dest_file): """Put file using SCP (for backwards compatibility).""" @@ -1083,7 +1183,9 @@

    Methods

    ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport())
    + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + )
    @@ -1178,7 +1280,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/snmp_autodetect.html b/docs/netmiko/snmp_autodetect.html index 4aace345b..a565b98a2 100644 --- a/docs/netmiko/snmp_autodetect.html +++ b/docs/netmiko/snmp_autodetect.html @@ -3,14 +3,14 @@ - + netmiko.snmp_autodetect API documentation - + @@ -58,8 +58,6 @@

    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 __future__ import unicode_literals - import re try: @@ -68,7 +66,6 @@

    Example:

    raise ImportError("pysnmp not installed; please install it: 'pip install pysnmp'") from netmiko.ssh_dispatcher import CLASS_MAPPER -from netmiko.py23_compat import text_type # Higher priority indicates a better match. @@ -85,7 +82,7 @@

    Example:

    }, "hp_comware": { "oid": ".1.3.6.1.2.1.1.1.0", - "expr": re.compile(r".*HP Comware.*", re.IGNORECASE), + "expr": re.compile(r".*HP(E)? Comware.*", re.IGNORECASE), "priority": 99, }, "hp_procurve": { @@ -143,6 +140,11 @@

    Example:

    "expr": re.compile(r".*Juniper.*"), "priority": 99, }, + "nokia_sros": { + "oid": ".1.3.6.1.2.1.1.1.0", + "expr": re.compile(r".*TiMOS.*"), + "priority": 99, + }, } # Ensure all SNMP device types are supported by Netmiko @@ -300,7 +302,7 @@

    Example:

    ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmpv2c(self, oid): @@ -329,7 +331,7 @@

    Example:

    ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmp(self, oid): @@ -366,16 +368,16 @@

    Example:

    oid = v["oid"] regex = v["expr"] - # Used cache data if we already queryied this OID - if self._response_cache.get(oid): - snmp_response = self._response_cache.get(oid) - else: - snmp_response = self._get_snmp(oid) - self._response_cache[oid] = snmp_response + # Used cache data if we already queryied this OID + if self._response_cache.get(oid): + snmp_response = self._response_cache.get(oid) + else: + snmp_response = self._get_snmp(oid) + self._response_cache[oid] = snmp_response - # See if we had a match - if re.search(regex, snmp_response): - return device_type + # See if we had a match + if re.search(regex, snmp_response): + return device_type return None
    @@ -590,7 +592,7 @@

    Methods

    ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmpv2c(self, oid): @@ -619,7 +621,7 @@

    Methods

    ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmp(self, oid): @@ -656,16 +658,16 @@

    Methods

    oid = v["oid"] regex = v["expr"] - # Used cache data if we already queryied this OID - if self._response_cache.get(oid): - snmp_response = self._response_cache.get(oid) - else: - snmp_response = self._get_snmp(oid) - self._response_cache[oid] = snmp_response + # Used cache data if we already queryied this OID + if self._response_cache.get(oid): + snmp_response = self._response_cache.get(oid) + else: + snmp_response = self._get_snmp(oid) + self._response_cache[oid] = snmp_response - # See if we had a match - if re.search(regex, snmp_response): - return device_type + # See if we had a match + if re.search(regex, snmp_response): + return device_type return None
    @@ -713,16 +715,16 @@

    Returns

    oid = v["oid"] regex = v["expr"] - # Used cache data if we already queryied this OID - if self._response_cache.get(oid): - snmp_response = self._response_cache.get(oid) - else: - snmp_response = self._get_snmp(oid) - self._response_cache[oid] = snmp_response + # Used cache data if we already queryied this OID + if self._response_cache.get(oid): + snmp_response = self._response_cache.get(oid) + else: + snmp_response = self._get_snmp(oid) + self._response_cache[oid] = snmp_response - # See if we had a match - if re.search(regex, snmp_response): - return device_type + # See if we had a match + if re.search(regex, snmp_response): + return device_type return None @@ -759,7 +761,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/ssh_autodetect.html b/docs/netmiko/ssh_autodetect.html index a5a690a87..2b33663df 100644 --- a/docs/netmiko/ssh_autodetect.html +++ b/docs/netmiko/ssh_autodetect.html @@ -3,14 +3,14 @@ - + netmiko.ssh_autodetect API documentation - + @@ -55,14 +55,8 @@

    Auto-detection section

    Netmiko connection creation section

    >>> remote_device['device_type'] = best_match
    +>>> connection = ConnectHandler(**remote_device)
     
    -
    -
    -
    -

    connection = ConnectHandler(**remote_device)

    -
    -
    -
    Source code
    """
    @@ -105,8 +99,6 @@ 

    Netmiko connection creation section >>> remote_device['device_type'] = best_match >>> connection = ConnectHandler(**remote_device) """ -from __future__ import unicode_literals - import re import time from netmiko.ssh_dispatcher import ConnectHandler @@ -329,7 +321,6 @@

    Netmiko connection creation section self.connection.write_channel(cmd + "\n") time.sleep(1) output = self.connection._read_channel_timing() - output = self.connection.strip_ansi_escape_codes(output) output = self.connection.strip_backspaces(output) return output @@ -529,7 +520,6 @@

    Methods

    self.connection.write_channel(cmd + "\n") time.sleep(1) output = self.connection._read_channel_timing() - output = self.connection.strip_ansi_escape_codes(output) output = self.connection.strip_backspaces(output) return output @@ -683,7 +673,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/ssh_exception.html b/docs/netmiko/ssh_exception.html index 9cc11dc00..41b78ca27 100644 --- a/docs/netmiko/ssh_exception.html +++ b/docs/netmiko/ssh_exception.html @@ -3,13 +3,13 @@ - + netmiko.ssh_exception API documentation - + @@ -22,21 +22,24 @@

    Module netmiko.ssh_exception

    Source code -
    from __future__ import unicode_literals
    -from paramiko.ssh_exception import SSHException
    +
    from paramiko.ssh_exception import SSHException
     from paramiko.ssh_exception import AuthenticationException
     
     
    -class NetMikoTimeoutException(SSHException):
    +class NetmikoTimeoutException(SSHException):
         """SSH session timed trying to connect to the device."""
     
         pass
     
     
    -class NetMikoAuthenticationException(AuthenticationException):
    +class NetmikoAuthenticationException(AuthenticationException):
         """SSH authentication exception based on Paramiko AuthenticationException."""
     
    -    pass
    + pass + + +NetMikoTimeoutException = NetmikoTimeoutException +NetMikoAuthenticationException = NetmikoAuthenticationException
    @@ -48,7 +51,7 @@

    Module netmiko.ssh_exception

    Classes

    -
    +
    class NetMikoAuthenticationException (*args, **kwargs)
    @@ -56,7 +59,7 @@

    Classes

    SSH authentication exception based on Paramiko AuthenticationException.

    Source code -
    class NetMikoAuthenticationException(AuthenticationException):
    +
    class NetmikoAuthenticationException(AuthenticationException):
         """SSH authentication exception based on Paramiko AuthenticationException."""
     
         pass
    @@ -69,7 +72,7 @@

    Ancestors

  • builtins.BaseException
  • -
    +
    class NetMikoTimeoutException (*args, **kwargs)
    @@ -77,7 +80,48 @@

    Ancestors

    SSH session timed trying to connect to the device.

    Source code -
    class NetMikoTimeoutException(SSHException):
    +
    class NetmikoTimeoutException(SSHException):
    +    """SSH session timed trying to connect to the device."""
    +
    +    pass
    +
    +

    Ancestors

    +
      +
    • paramiko.ssh_exception.SSHException
    • +
    • builtins.Exception
    • +
    • builtins.BaseException
    • +
    + +
    +class NetmikoAuthenticationException +(*args, **kwargs) +
    +
    +

    SSH authentication exception based on Paramiko AuthenticationException.

    +
    +Source code +
    class NetmikoAuthenticationException(AuthenticationException):
    +    """SSH authentication exception based on Paramiko AuthenticationException."""
    +
    +    pass
    +
    +

    Ancestors

    +
      +
    • paramiko.ssh_exception.AuthenticationException
    • +
    • paramiko.ssh_exception.SSHException
    • +
    • builtins.Exception
    • +
    • builtins.BaseException
    • +
    +
    +
    +class NetmikoTimeoutException +(*args, **kwargs) +
    +
    +

    SSH session timed trying to connect to the device.

    +
    +Source code +
    class NetmikoTimeoutException(SSHException):
         """SSH session timed trying to connect to the device."""
     
         pass
    @@ -106,10 +150,16 @@

    Index

  • Classes

  • @@ -117,7 +167,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/terminal_server/index.html b/docs/netmiko/terminal_server/index.html index a278e3ceb..58d96ee6f 100644 --- a/docs/netmiko/terminal_server/index.html +++ b/docs/netmiko/terminal_server/index.html @@ -3,13 +3,13 @@ - + netmiko.terminal_server API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.terminal_server

    Source code -
    from __future__ import unicode_literals
    -from netmiko.terminal_server.terminal_server import TerminalServerSSH
    +
    from netmiko.terminal_server.terminal_server import TerminalServerSSH
     from netmiko.terminal_server.terminal_server import TerminalServerTelnet
     
     __all__ = ["TerminalServerSSH", "TerminalServerTelnet"]
    @@ -47,7 +46,7 @@

    Classes

    class TerminalServerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Generic Terminal Server driver SSH.

    @@ -167,6 +166,10 @@

    Classes

    :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
    Source code @@ -230,7 +233,7 @@

    Inherited members

    class TerminalServerTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Generic Terminal Server driver telnet.

    @@ -350,6 +353,10 @@

    Inherited members

    :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
    Source code @@ -361,7 +368,7 @@

    Inherited members

    pass def std_login(self, *args, **kwargs): - return super(TerminalServerTelnet, self).telnet_login(*args, **kwargs)

    + return super().telnet_login(*args, **kwargs)

    Ancestors

      @@ -378,7 +385,7 @@

      Methods

      Source code
      def std_login(self, *args, **kwargs):
      -    return super(TerminalServerTelnet, self).telnet_login(*args, **kwargs)
      + return super().telnet_login(*args, **kwargs)
    @@ -466,7 +473,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/terminal_server/terminal_server.html b/docs/netmiko/terminal_server/terminal_server.html index bbbaaf50e..f443c1963 100644 --- a/docs/netmiko/terminal_server/terminal_server.html +++ b/docs/netmiko/terminal_server/terminal_server.html @@ -3,13 +3,13 @@ - + netmiko.terminal_server.terminal_server API documentation - + @@ -24,7 +24,6 @@

    Module netmiko.terminal_server.terminal_server Source code
    """Generic Terminal Server driver."""
    -from __future__ import unicode_literals
     from netmiko.base_connection import BaseConnection
     
     
    @@ -54,7 +53,7 @@ 

    Module netmiko.terminal_server.terminal_server

    + return super().telnet_login(*args, **kwargs)
    @@ -68,7 +67,7 @@

    Classes

    class TerminalServer -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Generic Terminal Server driver.

    @@ -190,6 +189,10 @@

    Classes

    :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
    Source code @@ -277,7 +280,7 @@

    Inherited members

    class TerminalServerSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Generic Terminal Server driver SSH.

    @@ -397,6 +400,10 @@

    Inherited members

    :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
    Source code @@ -460,7 +467,7 @@

    Inherited members

    class TerminalServerTelnet -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Generic Terminal Server driver telnet.

    @@ -580,6 +587,10 @@

    Inherited members

    :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
    Source code @@ -591,7 +602,7 @@

    Inherited members

    pass def std_login(self, *args, **kwargs): - return super(TerminalServerTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs)

    Ancestors

      @@ -608,7 +619,7 @@

      Methods

      Source code
      def std_login(self, *args, **kwargs):
      -    return super(TerminalServerTelnet, self).telnet_login(*args, **kwargs)
      + return super().telnet_login(*args, **kwargs)
    @@ -697,7 +708,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/ubiquiti/edge_ssh.html b/docs/netmiko/ubiquiti/edge_ssh.html index 30d91d73e..22d901ee0 100644 --- a/docs/netmiko/ubiquiti/edge_ssh.html +++ b/docs/netmiko/ubiquiti/edge_ssh.html @@ -3,13 +3,13 @@ - + netmiko.ubiquiti.edge_ssh API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ubiquiti.edge_ssh

    Source code -
    from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -50,23 +49,23 @@ 

    Module netmiko.ubiquiti.edge_ssh

    def check_config_mode(self, check_string=")#"): """Checks if the device is in configuration mode or not.""" - return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit"): """Exit configuration mode.""" - return super(UbiquitiEdgeSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" - return super(UbiquitiEdgeSSH, self).exit_enable_mode(exit_command=exit_command) + return super().exit_enable_mode(exit_command=exit_command) def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Saves configuration.""" - return super(UbiquitiEdgeSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -82,7 +81,7 @@

    Classes

    class UbiquitiEdgeSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implements support for Ubiquity EdgeSwitch devices.

    @@ -204,6 +203,10 @@

    Classes

    :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
    Source code @@ -230,23 +233,23 @@

    Classes

    def check_config_mode(self, check_string=")#"): """Checks if the device is in configuration mode or not.""" - return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit"): """Exit configuration mode.""" - return super(UbiquitiEdgeSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" - return super(UbiquitiEdgeSSH, self).exit_enable_mode(exit_command=exit_command) + return super().exit_enable_mode(exit_command=exit_command) def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Saves configuration.""" - return super(UbiquitiEdgeSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -267,7 +270,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string=")#"):
         """Checks if the device is in configuration mode or not."""
    -    return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -279,7 +282,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -291,7 +294,7 @@

    Methods

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

    Methods

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

    Methods

    Source code
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(UbiquitiEdgeSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -396,7 +399,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/ubiquiti/index.html b/docs/netmiko/ubiquiti/index.html index 7278abaa5..32e3e9964 100644 --- a/docs/netmiko/ubiquiti/index.html +++ b/docs/netmiko/ubiquiti/index.html @@ -3,13 +3,13 @@ - + netmiko.ubiquiti API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.ubiquiti

    Source code -
    from __future__ import unicode_literals
    -from netmiko.ubiquiti.edge_ssh import UbiquitiEdgeSSH
    +
    from netmiko.ubiquiti.edge_ssh import UbiquitiEdgeSSH
     
     __all__ = ["UbiquitiEdgeSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class UbiquitiEdgeSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implements support for Ubiquity EdgeSwitch devices.

    @@ -168,6 +167,10 @@

    Classes

    :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
    Source code @@ -194,23 +197,23 @@

    Classes

    def check_config_mode(self, check_string=")#"): """Checks if the device is in configuration mode or not.""" - return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit"): """Exit configuration mode.""" - return super(UbiquitiEdgeSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" - return super(UbiquitiEdgeSSH, self).exit_enable_mode(exit_command=exit_command) + return super().exit_enable_mode(exit_command=exit_command) def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Saves configuration.""" - return super(UbiquitiEdgeSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response )
    @@ -231,7 +234,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string=")#"):
         """Checks if the device is in configuration mode or not."""
    -    return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -243,7 +246,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure"):
         """Enter configuration mode."""
    -    return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command)
    + return super().config_mode(config_command=config_command)
    @@ -255,7 +258,7 @@

    Methods

    Source code
    def exit_config_mode(self, exit_config="exit"):
         """Exit configuration mode."""
    -    return super(UbiquitiEdgeSSH, self).exit_config_mode(exit_config=exit_config)
    + return super().exit_config_mode(exit_config=exit_config)
    @@ -267,7 +270,7 @@

    Methods

    Source code
    def exit_enable_mode(self, exit_command="exit"):
         """Exit enable mode."""
    -    return super(UbiquitiEdgeSSH, self).exit_enable_mode(exit_command=exit_command)
    + return super().exit_enable_mode(exit_command=exit_command)
    @@ -279,7 +282,7 @@

    Methods

    Source code
    def save_config(self, cmd="write memory", confirm=False, confirm_response=""):
         """Saves configuration."""
    -    return super(UbiquitiEdgeSSH, self).save_config(
    +    return super().save_config(
             cmd=cmd, confirm=confirm, confirm_response=confirm_response
         )
    @@ -365,7 +368,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/docs/netmiko/utilities.html b/docs/netmiko/utilities.html index 304f8d97f..7829c80fb 100644 --- a/docs/netmiko/utilities.html +++ b/docs/netmiko/utilities.html @@ -3,13 +3,13 @@ - + netmiko.utilities API documentation - + @@ -24,15 +24,12 @@

    Module netmiko.utilities

    Source code
    """Miscellaneous utility functions."""
    -from __future__ import print_function
    -from __future__ import unicode_literals
    -
     from glob import glob
     import sys
     import io
     import os
    +from pathlib import Path
     import serial.tools.list_ports
    -from netmiko.py23_compat import text_type
     from netmiko._textfsm import _clitable as clitable
     from netmiko._textfsm._clitable import CliTableError
     
    @@ -96,7 +93,7 @@ 

    Module netmiko.utilities

    with io.open(yaml_file, "rt", encoding="utf-8") as fname: return yaml.safe_load(fname) except IOError: - sys.exit("Unable to open YAML file: {0}".format(yaml_file)) + sys.exit(f"Unable to open YAML file: {yaml_file}") def load_devices(file_name=None): @@ -108,13 +105,10 @@

    Module netmiko.utilities

    def find_cfg_file(file_name=None): """ Search for netmiko_tools inventory file in the following order: - NETMIKO_TOOLS_CFG environment variable Current directory Home directory - Look for file named: .netmiko.yml or netmiko.yml - Also allow NETMIKO_TOOLS_CFG to point directly at a file """ if file_name: @@ -127,9 +121,7 @@

    Module netmiko.utilities

    # Filter optional_path if null search_paths = [path for path in search_paths if path] for path in search_paths: - files = glob("{}/.netmiko.yml".format(path)) + glob( - "{}/netmiko.yml".format(path) - ) + files = glob(f"{path}/.netmiko.yml") + glob(f"{path}/netmiko.yml") if files: return files[0] raise IOError( @@ -153,8 +145,8 @@

    Module netmiko.utilities

    print("\nDevices:") print("-" * 40) for a_device, device_type in inventory_devices: - device_type = " ({})".format(device_type) - print("{:<25}{:>15}".format(a_device, device_type)) + device_type = f" ({device_type})" + print(f"{a_device:<25}{device_type:>15}") print("\n\nGroups:") print("-" * 40) for a_group in inventory_groups: @@ -175,7 +167,7 @@

    Module netmiko.utilities

    def obtain_netmiko_filename(device_name): """Create file name based on device_name.""" _, netmiko_full_dir = find_netmiko_dir() - return "{}/{}.txt".format(netmiko_full_dir, device_name) + return f"{netmiko_full_dir}/{device_name}.txt" def write_tmp_file(device_name, output): @@ -194,7 +186,7 @@

    Module netmiko.utilities

    # Exists if not os.path.isdir(verify_dir): # Not a dir, raise an exception - raise ValueError("{} is not a directory".format(verify_dir)) + raise ValueError(f"{verify_dir} is not a directory") def find_netmiko_dir(): @@ -206,12 +198,12 @@

    Module netmiko.utilities

    netmiko_base_dir = os.path.expanduser(netmiko_base_dir) if netmiko_base_dir == "/": raise ValueError("/ cannot be netmiko_base_dir") - netmiko_full_dir = "{}/tmp".format(netmiko_base_dir) + netmiko_full_dir = f"{netmiko_base_dir}/tmp" return (netmiko_base_dir, netmiko_full_dir) def write_bytes(out_data, encoding="ascii"): - """Write Python2 and Python3 compatible byte stream.""" + """Legacy for Python2 and Python3 compatible byte stream.""" if sys.version_info[0] >= 3: if isinstance(out_data, type("")): if encoding == "utf-8": @@ -220,14 +212,6 @@

    Module netmiko.utilities

    return out_data.encode("ascii", "ignore") elif isinstance(out_data, type(b"")): return out_data - else: - if isinstance(out_data, type("")): - if encoding == "utf-8": - return out_data.encode("utf-8") - else: - return out_data.encode("ascii", "ignore") - elif isinstance(out_data, type(str(""))): - return out_data msg = "Invalid value for out_data neither unicode nor byte string: {}".format( out_data ) @@ -240,11 +224,11 @@

    Module netmiko.utilities

    cdc = next(serial.tools.list_ports.grep(name)) return cdc[0] except StopIteration: - msg = "device {} not found. ".format(name) + msg = f"device {name} not found. " msg += "available devices are: " ports = list(serial.tools.list_ports.comports()) for p in ports: - msg += "{},".format(text_type(p)) + msg += f"{str(p)}," raise ValueError(msg) @@ -282,22 +266,53 @@

    Module netmiko.utilities

    return objs -def get_structured_data(raw_output, platform, command): - """Convert raw CLI output to structured data using TextFSM template.""" - template_dir = get_template_dir() - index_file = os.path.join(template_dir, "index") - textfsm_obj = clitable.CliTable(index_file, template_dir) - attrs = {"Command": command, "Platform": platform} +def _textfsm_parse(textfsm_obj, raw_output, attrs, template_file=None): + """Perform the actual TextFSM parsing using the CliTable object.""" try: # Parse output through template - textfsm_obj.ParseCmd(raw_output, attrs) + if template_file is not None: + textfsm_obj.ParseCmd(raw_output, templates=template_file) + else: + textfsm_obj.ParseCmd(raw_output, attrs) structured_data = clitable_to_dict(textfsm_obj) output = raw_output if structured_data == [] else structured_data return output - except CliTableError: + except (FileNotFoundError, CliTableError): return raw_output +def get_structured_data(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. + """ + 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) + return _textfsm_parse(textfsm_obj, raw_output, attrs) + else: + template_path = Path(os.path.expanduser(template)) + template_file = template_path.name + template_dir = template_path.parents[0] + # CliTable with no index will fall-back to a TextFSM parsing behavior + textfsm_obj = clitable.CliTable(template_dir=template_dir) + return _textfsm_parse( + textfsm_obj, raw_output, attrs, template_file=template_file + ) + + def get_structured_data_genie(raw_output, platform, command): if not sys.version_info >= (3, 4): raise ValueError("Genie requires Python >= 3.4") @@ -366,11 +381,11 @@

    Functions

    cdc = next(serial.tools.list_ports.grep(name)) return cdc[0] except StopIteration: - msg = "device {} not found. ".format(name) + msg = f"device {name} not found. " msg += "available devices are: " ports = list(serial.tools.list_ports.comports()) for p in ports: - msg += "{},".format(text_type(p)) + msg += f"{str(p)}," raise ValueError(msg)
    @@ -414,8 +429,8 @@

    Functions

    print("\nDevices:") print("-" * 40) for a_device, device_type in inventory_devices: - device_type = " ({})".format(device_type) - print("{:<25}{:>15}".format(a_device, device_type)) + device_type = f" ({device_type})" + print(f"{a_device:<25}{device_type:>15}") print("\n\nGroups:") print("-" * 40) for a_group in inventory_groups: @@ -439,31 +454,28 @@

    Functions

    # Exists if not os.path.isdir(verify_dir): # Not a dir, raise an exception - raise ValueError("{} is not a directory".format(verify_dir))
    + raise ValueError(f"{verify_dir} is not a directory")
    def find_cfg_file(file_name=None)
    -

    Search for netmiko_tools inventory file in the following order:

    -

    NETMIKO_TOOLS_CFG environment variable +

    Search for netmiko_tools inventory file in the following order: +NETMIKO_TOOLS_CFG environment variable Current directory -Home directory

    -

    Look for file named: .netmiko.yml or netmiko.yml

    -

    Also allow NETMIKO_TOOLS_CFG to point directly at a file

    +Home directory +Look for file named: .netmiko.yml or netmiko.yml +Also allow NETMIKO_TOOLS_CFG to point directly at a file

    Source code
    def find_cfg_file(file_name=None):
         """
         Search for netmiko_tools inventory file in the following order:
    -
         NETMIKO_TOOLS_CFG environment variable
         Current directory
         Home directory
    -
         Look for file named: .netmiko.yml or netmiko.yml
    -
         Also allow NETMIKO_TOOLS_CFG to point directly at a file
         """
         if file_name:
    @@ -476,9 +488,7 @@ 

    Functions

    # Filter optional_path if null search_paths = [path for path in search_paths if path] for path in search_paths: - files = glob("{}/.netmiko.yml".format(path)) + glob( - "{}/netmiko.yml".format(path) - ) + files = glob(f"{path}/.netmiko.yml") + glob(f"{path}/netmiko.yml") if files: return files[0] raise IOError( @@ -503,31 +513,49 @@

    Functions

    netmiko_base_dir = os.path.expanduser(netmiko_base_dir) if netmiko_base_dir == "/": raise ValueError("/ cannot be netmiko_base_dir") - netmiko_full_dir = "{}/tmp".format(netmiko_base_dir) + netmiko_full_dir = f"{netmiko_base_dir}/tmp" return (netmiko_base_dir, netmiko_full_dir)
    -def get_structured_data(raw_output, platform, command) +def get_structured_data(raw_output, platform=None, command=None, template=None)
    -

    Convert raw CLI output to structured data using TextFSM template.

    +

    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(raw_output, platform, command):
    -    """Convert raw CLI output to structured data using TextFSM template."""
    -    template_dir = get_template_dir()
    -    index_file = os.path.join(template_dir, "index")
    -    textfsm_obj = clitable.CliTable(index_file, template_dir)
    -    attrs = {"Command": command, "Platform": platform}
    -    try:
    -        # Parse output through template
    -        textfsm_obj.ParseCmd(raw_output, attrs)
    -        structured_data = clitable_to_dict(textfsm_obj)
    -        output = raw_output if structured_data == [] else structured_data
    -        return output
    -    except CliTableError:
    -        return raw_output
    +
    def get_structured_data(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.
    +    """
    +    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)
    +        return _textfsm_parse(textfsm_obj, raw_output, attrs)
    +    else:
    +        template_path = Path(os.path.expanduser(template))
    +        template_file = template_path.name
    +        template_dir = template_path.parents[0]
    +        # CliTable with no index will fall-back to a TextFSM parsing behavior
    +        textfsm_obj = clitable.CliTable(template_dir=template_dir)
    +        return _textfsm_parse(
    +            textfsm_obj, raw_output, attrs, template_file=template_file
    +        )
    @@ -645,7 +673,7 @@

    Functions

    with io.open(yaml_file, "rt", encoding="utf-8") as fname: return yaml.safe_load(fname) except IOError: - sys.exit("Unable to open YAML file: {0}".format(yaml_file))
    + sys.exit(f"Unable to open YAML file: {yaml_file}")
    @@ -675,18 +703,18 @@

    Functions

    def obtain_netmiko_filename(device_name):
         """Create file name based on device_name."""
         _, netmiko_full_dir = find_netmiko_dir()
    -    return "{}/{}.txt".format(netmiko_full_dir, device_name)
    + return f"{netmiko_full_dir}/{device_name}.txt"
    def write_bytes(out_data, encoding='ascii')
    -

    Write Python2 and Python3 compatible byte stream.

    +

    Legacy for Python2 and Python3 compatible byte stream.

    Source code
    def write_bytes(out_data, encoding="ascii"):
    -    """Write Python2 and Python3 compatible byte stream."""
    +    """Legacy for Python2 and Python3 compatible byte stream."""
         if sys.version_info[0] >= 3:
             if isinstance(out_data, type("")):
                 if encoding == "utf-8":
    @@ -695,14 +723,6 @@ 

    Functions

    return out_data.encode("ascii", "ignore") elif isinstance(out_data, type(b"")): return out_data - else: - if isinstance(out_data, type("")): - if encoding == "utf-8": - return out_data.encode("utf-8") - else: - return out_data.encode("ascii", "ignore") - elif isinstance(out_data, type(str(""))): - return out_data msg = "Invalid value for out_data neither unicode nor byte string: {}".format( out_data ) @@ -762,7 +782,7 @@

    Index

    diff --git a/docs/netmiko/vyos/index.html b/docs/netmiko/vyos/index.html index 5afe84cdd..cb9ef9f81 100644 --- a/docs/netmiko/vyos/index.html +++ b/docs/netmiko/vyos/index.html @@ -3,13 +3,13 @@ - + netmiko.vyos API documentation - + @@ -22,8 +22,7 @@

    Module netmiko.vyos

    Source code -
    from __future__ import unicode_literals
    -from netmiko.vyos.vyos_ssh import VyOSSSH
    +
    from netmiko.vyos.vyos_ssh import VyOSSSH
     
     __all__ = ["VyOSSSH"]
    @@ -46,7 +45,7 @@

    Classes

    class VyOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with VyOS network devices.

    @@ -166,6 +165,10 @@

    Classes

    :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

    Source code @@ -195,13 +198,11 @@

    Classes

    def check_config_mode(self, check_string="#"): """Checks if the device is in configuration mode""" - return super(VyOSSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure", pattern=r"[edit]"): """Enter configuration mode.""" - return super(VyOSSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="exit", pattern=r"exit"): """Exit configuration mode""" @@ -236,7 +237,7 @@

    Classes

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -247,16 +248,14 @@

    Classes

    ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def set_base_prompt( self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -265,25 +264,10 @@

    Classes

    self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set( - self, - config_commands=None, - exit_config_mode=False, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - ): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """Remain in configuration mode.""" - return super(VyOSSSH, self).send_config_set( - config_commands=config_commands, - exit_config_mode=exit_config_mode, - delay_factor=delay_factor, - max_loops=max_loops, - strip_prompt=strip_prompt, - strip_command=strip_command, - config_mode_command=config_mode_command, + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def save_config(self, *args, **kwargs): @@ -307,7 +291,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="#"):
         """Checks if the device is in configuration mode"""
    -    return super(VyOSSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -353,7 +337,7 @@

    Methods

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -364,9 +348,7 @@

    Methods

    ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output
    @@ -379,9 +361,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure", pattern=r"[edit]"):
         """Enter configuration mode."""
    -    return super(VyOSSSH, self).config_mode(
    -        config_command=config_command, pattern=pattern
    -    )
    + return super().config_mode(config_command=config_command, pattern=pattern)
    @@ -444,31 +424,16 @@

    Methods

    -def send_config_set(self, config_commands=None, exit_config_mode=False, delay_factor=1, max_loops=150, strip_prompt=False, strip_command=False, config_mode_command=None) +def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs)

    Remain in configuration mode.

    Source code -
    def send_config_set(
    -    self,
    -    config_commands=None,
    -    exit_config_mode=False,
    -    delay_factor=1,
    -    max_loops=150,
    -    strip_prompt=False,
    -    strip_command=False,
    -    config_mode_command=None,
    -):
    +
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
         """Remain in configuration mode."""
    -    return super(VyOSSSH, self).send_config_set(
    -        config_commands=config_commands,
    -        exit_config_mode=exit_config_mode,
    -        delay_factor=delay_factor,
    -        max_loops=max_loops,
    -        strip_prompt=strip_prompt,
    -        strip_command=strip_command,
    -        config_mode_command=config_mode_command,
    +    return super().send_config_set(
    +        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
         )
    @@ -500,7 +465,7 @@

    Methods

    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -591,7 +556,7 @@

    VyOSSSH diff --git a/docs/netmiko/vyos/vyos_ssh.html b/docs/netmiko/vyos/vyos_ssh.html index 27c8c46ae..eaf08874d 100644 --- a/docs/netmiko/vyos/vyos_ssh.html +++ b/docs/netmiko/vyos/vyos_ssh.html @@ -3,13 +3,13 @@ - + netmiko.vyos.vyos_ssh API documentation - + @@ -22,9 +22,7 @@

    Module netmiko.vyos.vyos_ssh

    Source code -
    from __future__ import print_function
    -from __future__ import unicode_literals
    -import time
    +
    import time
     from netmiko.cisco_base_connection import CiscoSSHConnection
     
     
    @@ -54,13 +52,11 @@ 

    Module netmiko.vyos.vyos_ssh

    def check_config_mode(self, check_string="#"): """Checks if the device is in configuration mode""" - return super(VyOSSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure", pattern=r"[edit]"): """Enter configuration mode.""" - return super(VyOSSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="exit", pattern=r"exit"): """Exit configuration mode""" @@ -95,7 +91,7 @@

    Module netmiko.vyos.vyos_ssh

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -106,16 +102,14 @@

    Module netmiko.vyos.vyos_ssh

    ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def set_base_prompt( self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -124,25 +118,10 @@

    Module netmiko.vyos.vyos_ssh

    self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set( - self, - config_commands=None, - exit_config_mode=False, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - ): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """Remain in configuration mode.""" - return super(VyOSSSH, self).send_config_set( - config_commands=config_commands, - exit_config_mode=exit_config_mode, - delay_factor=delay_factor, - max_loops=max_loops, - strip_prompt=strip_prompt, - strip_command=strip_command, - config_mode_command=config_mode_command, + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def save_config(self, *args, **kwargs): @@ -161,7 +140,7 @@

    Classes

    class VyOSSSH -(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=8, banner_timeout=5, 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') +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, 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, timeout=100, session_timeout=60, auth_timeout=None, blocking_timeout=20, banner_timeout=15, 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)

    Implement methods for interacting with VyOS network devices.

    @@ -281,6 +260,10 @@

    Classes

    :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
    Source code @@ -310,13 +293,11 @@

    Classes

    def check_config_mode(self, check_string="#"): """Checks if the device is in configuration mode""" - return super(VyOSSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure", pattern=r"[edit]"): """Enter configuration mode.""" - return super(VyOSSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="exit", pattern=r"exit"): """Exit configuration mode""" @@ -351,7 +332,7 @@

    Classes

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -362,16 +343,14 @@

    Classes

    ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def set_base_prompt( self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -380,25 +359,10 @@

    Classes

    self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set( - self, - config_commands=None, - exit_config_mode=False, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - ): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """Remain in configuration mode.""" - return super(VyOSSSH, self).send_config_set( - config_commands=config_commands, - exit_config_mode=exit_config_mode, - delay_factor=delay_factor, - max_loops=max_loops, - strip_prompt=strip_prompt, - strip_command=strip_command, - config_mode_command=config_mode_command, + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def save_config(self, *args, **kwargs): @@ -422,7 +386,7 @@

    Methods

    Source code
    def check_config_mode(self, check_string="#"):
         """Checks if the device is in configuration mode"""
    -    return super(VyOSSSH, self).check_config_mode(check_string=check_string)
    + return super().check_config_mode(check_string=check_string)
    @@ -468,7 +432,7 @@

    Methods

    command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -479,9 +443,7 @@

    Methods

    ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output
    @@ -494,9 +456,7 @@

    Methods

    Source code
    def config_mode(self, config_command="configure", pattern=r"[edit]"):
         """Enter configuration mode."""
    -    return super(VyOSSSH, self).config_mode(
    -        config_command=config_command, pattern=pattern
    -    )
    + return super().config_mode(config_command=config_command, pattern=pattern)
    @@ -559,31 +519,16 @@

    Methods

    -def send_config_set(self, config_commands=None, exit_config_mode=False, delay_factor=1, max_loops=150, strip_prompt=False, strip_command=False, config_mode_command=None) +def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs)

    Remain in configuration mode.

    Source code -
    def send_config_set(
    -    self,
    -    config_commands=None,
    -    exit_config_mode=False,
    -    delay_factor=1,
    -    max_loops=150,
    -    strip_prompt=False,
    -    strip_command=False,
    -    config_mode_command=None,
    -):
    +
    def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs):
         """Remain in configuration mode."""
    -    return super(VyOSSSH, self).send_config_set(
    -        config_commands=config_commands,
    -        exit_config_mode=exit_config_mode,
    -        delay_factor=delay_factor,
    -        max_loops=max_loops,
    -        strip_prompt=strip_prompt,
    -        strip_command=strip_command,
    -        config_mode_command=config_mode_command,
    +    return super().send_config_set(
    +        config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs
         )
    @@ -615,7 +560,7 @@

    Methods

    self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -701,7 +646,7 @@

    -

    Generated by pdoc 0.6.2.

    +

    Generated by pdoc 0.6.3.

    diff --git a/netmiko/__init__.py b/netmiko/__init__.py index afeb27955..f7904436a 100644 --- a/netmiko/__init__.py +++ b/netmiko/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import logging # Logging configuration @@ -12,28 +11,29 @@ from netmiko.ssh_dispatcher import FileTransfer from netmiko.scp_handler import SCPConn from netmiko.cisco.cisco_ios import InLineTransfer -from netmiko.ssh_exception import NetMikoTimeoutException -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoTimeoutException, NetMikoTimeoutException +from netmiko.ssh_exception import ( + NetmikoAuthenticationException, + NetMikoAuthenticationException, +) from netmiko.ssh_autodetect import SSHDetect from netmiko.base_connection import BaseConnection from netmiko.scp_functions import file_transfer # Alternate naming -NetmikoTimeoutError = NetMikoTimeoutException -NetmikoAuthError = NetMikoAuthenticationException Netmiko = ConnectHandler -__version__ = "2.4.2" +__version__ = "3.0.0" __all__ = ( "ConnectHandler", "ssh_dispatcher", "platforms", "SCPConn", "FileTransfer", + "NetmikoTimeoutException", + "NetmikoAuthenticationException", "NetMikoTimeoutException", "NetMikoAuthenticationException", - "NetmikoTimeoutError", - "NetmikoAuthError", "InLineTransfer", "redispatch", "SSHDetect", diff --git a/netmiko/a10/__init__.py b/netmiko/a10/__init__.py index 4c343b4c2..6d812d3ca 100644 --- a/netmiko/a10/__init__.py +++ b/netmiko/a10/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.a10.a10_ssh import A10SSH __all__ = ["A10SSH"] diff --git a/netmiko/a10/a10_ssh.py b/netmiko/a10/a10_ssh.py index 64f150128..2588bfd7a 100644 --- a/netmiko/a10/a10_ssh.py +++ b/netmiko/a10/a10_ssh.py @@ -1,5 +1,4 @@ """A10 support.""" -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection diff --git a/netmiko/accedian/accedian_ssh.py b/netmiko/accedian/accedian_ssh.py index 93b2b14ce..91796e3e7 100644 --- a/netmiko/accedian/accedian_ssh.py +++ b/netmiko/accedian/accedian_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -36,7 +35,7 @@ def set_base_prompt( self, pri_prompt_terminator=":", alt_prompt_terminator="#", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(AccedianSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, diff --git a/netmiko/alcatel/__init__.py b/netmiko/alcatel/__init__.py index 8ab08646c..fe6f2d35d 100644 --- a/netmiko/alcatel/__init__.py +++ b/netmiko/alcatel/__init__.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals -from netmiko.alcatel.alcatel_sros_ssh import AlcatelSrosSSH from netmiko.alcatel.alcatel_aos_ssh import AlcatelAosSSH -__all__ = ["AlcatelSrosSSH", "AlcatelAosSSH"] +__all__ = ["AlcatelAosSSH"] diff --git a/netmiko/alcatel/alcatel_aos_ssh.py b/netmiko/alcatel/alcatel_aos_ssh.py index 117dc8f2b..6875ea319 100644 --- a/netmiko/alcatel/alcatel_aos_ssh.py +++ b/netmiko/alcatel/alcatel_aos_ssh.py @@ -1,6 +1,4 @@ """Alcatel-Lucent Enterprise AOS support (AOS6 and AOS8).""" -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -44,6 +42,6 @@ def save_config( self, cmd="write memory flash-synchro", confirm=False, confirm_response="" ): """Save Config""" - return super(AlcatelAosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/alcatel/alcatel_sros_ssh.py b/netmiko/alcatel/alcatel_sros_ssh.py deleted file mode 100644 index 3d136ea54..000000000 --- a/netmiko/alcatel/alcatel_sros_ssh.py +++ /dev/null @@ -1,80 +0,0 @@ -"""Alcatel-Lucent SROS support.""" -from __future__ import print_function -from __future__ import unicode_literals -import re -import time -from netmiko.cisco_base_connection import CiscoSSHConnection - - -class AlcatelSrosSSH(CiscoSSHConnection): - """Alcatel-Lucent SROS support.""" - - def session_preparation(self): - self._test_channel_read() - self.set_base_prompt() - self.disable_paging(command="environment no more") - # Clear the read buffer - time.sleep(0.3 * self.global_delay_factor) - self.clear_buffer() - - def set_base_prompt(self, *args, **kwargs): - """Remove the > when navigating into the different config level.""" - cur_base_prompt = super(AlcatelSrosSSH, self).set_base_prompt(*args, **kwargs) - match = re.search(r"(.*)(>.*)*#", cur_base_prompt) - if match: - # strip off >... from base_prompt - self.base_prompt = match.group(1) - return self.base_prompt - - def enable(self, cmd="enable-admin", pattern="ssword", re_flags=re.IGNORECASE): - """Enter enable mode.""" - return super(AlcatelSrosSSH, self).enable( - cmd=cmd, pattern=pattern, re_flags=re_flags - ) - - def check_enable_mode(self, check_string="CLI Already in admin mode"): - """Check whether we are in enable-admin mode. - SROS requires us to do this: - *A:HOSTNAME# enable-admin - MINOR: CLI Already in admin mode. - *A:HOSTNAME# - *A:HOSTNAME# enable-admin - Password: - MINOR: CLI Invalid password. - *A:HOSTNAME# - """ - output = self.send_command_timing("enable-admin") - if re.search(r"ssword", output): - # Just hit enter as we don't actually want to enter enable here - self.write_channel(self.normalize_cmd(self.RETURN)) - self.read_until_prompt() - return False - elif check_string in output: - return True - raise ValueError("Unexpected response in check_enable_mode() method") - - def exit_enable_mode(self, exit_command=""): - """No corresponding exit of enable mode on SROS.""" - pass - - def config_mode(self, config_command="configure", pattern="#"): - """ Enter into configuration mode on SROS device.""" - return super(AlcatelSrosSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) - - def exit_config_mode(self, exit_config="exit all", pattern="#"): - """ Exit from configuration mode.""" - return super(AlcatelSrosSSH, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) - - def check_config_mode(self, check_string="config", pattern="#"): - """ Checks if the device is in configuration mode or not. """ - return super(AlcatelSrosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) - - def save_config(self, *args, **kwargs): - """Not Implemented""" - raise NotImplementedError diff --git a/netmiko/apresia/__init__.py b/netmiko/apresia/__init__.py index bc0b61389..3992c66d1 100644 --- a/netmiko/apresia/__init__.py +++ b/netmiko/apresia/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.apresia.apresia_aeos import ApresiaAeosSSH, ApresiaAeosTelnet __all__ = ["ApresiaAeosSSH", "ApresiaAeosTelnet"] diff --git a/netmiko/apresia/apresia_aeos.py b/netmiko/apresia/apresia_aeos.py index e4073f219..bbab84582 100644 --- a/netmiko/apresia/apresia_aeos.py +++ b/netmiko/apresia/apresia_aeos.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -9,7 +8,6 @@ def session_preparation(self): self._test_channel_read(pattern=r"[>#]") self.set_base_prompt() self.disable_paging() - self.set_terminal_width(command="terminal width 511") # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() @@ -23,10 +21,6 @@ def disable_paging(self, command="", delay_factor=1): self.send_config_set("terminal length 0") self.exit_enable_mode() - def set_terminal_width(self, command="", delay_factor=1): - """No terminal width command mode on AEOS""" - pass - class ApresiaAeosSSH(ApresiaAeosBase): pass @@ -36,4 +30,4 @@ class ApresiaAeosTelnet(ApresiaAeosBase): 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(ApresiaAeosTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) diff --git a/netmiko/arista/__init__.py b/netmiko/arista/__init__.py index d42e1cf16..3b0def0ff 100644 --- a/netmiko/arista/__init__.py +++ b/netmiko/arista/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.arista.arista import AristaSSH, AristaTelnet, AristaFileTransfer __all__ = ["AristaSSH", "AristaTelnet", "AristaFileTransfer"] diff --git a/netmiko/arista/arista.py b/netmiko/arista/arista.py index 8dc760d91..a3c9c557a 100644 --- a/netmiko/arista/arista.py +++ b/netmiko/arista/arista.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection from netmiko.cisco_base_connection import CiscoFileTransfer @@ -25,13 +24,13 @@ def check_config_mode(self, check_string=")#", pattern=""): Can also be (s2) """ - log.debug("pattern: {0}".format(pattern)) + log.debug(f"pattern: {pattern}") self.write_channel(self.RETURN) output = self.read_until_pattern(pattern=pattern) - log.debug("check_config_mode: {0}".format(repr(output))) + log.debug(f"check_config_mode: {repr(output)}") output = output.replace("(s1)", "") output = output.replace("(s2)", "") - log.debug("check_config_mode: {0}".format(repr(output))) + log.debug(f"check_config_mode: {repr(output)}") return check_string in output def _enter_shell(self): @@ -51,7 +50,7 @@ class AristaTelnet(AristaBase): 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(AristaTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class AristaFileTransfer(CiscoFileTransfer): @@ -64,13 +63,15 @@ def __init__( dest_file, file_system="/mnt/flash", direction="put", + **kwargs, ): - return super(AristaFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -93,7 +94,7 @@ def remote_md5(self, base_cmd="verify /md5", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} file:{}/{}".format(base_cmd, self.file_system, remote_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 ) diff --git a/netmiko/aruba/__init__.py b/netmiko/aruba/__init__.py index 41083affe..e9350eacb 100644 --- a/netmiko/aruba/__init__.py +++ b/netmiko/aruba/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.aruba.aruba_ssh import ArubaSSH __all__ = ["ArubaSSH"] diff --git a/netmiko/aruba/aruba_ssh.py b/netmiko/aruba/aruba_ssh.py index c5910cc50..4cf9b3dcf 100644 --- a/netmiko/aruba/aruba_ssh.py +++ b/netmiko/aruba/aruba_ssh.py @@ -1,5 +1,4 @@ """Aruba OS support""" -from __future__ import unicode_literals import time import re from netmiko.cisco_base_connection import CiscoSSHConnection @@ -11,7 +10,7 @@ class ArubaSSH(CiscoSSHConnection): def __init__(self, **kwargs): if kwargs.get("default_enter") is None: kwargs["default_enter"] = "\r" - return super(ArubaSSH, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): """Aruba OS requires enable mode to disable paging.""" @@ -33,6 +32,4 @@ def check_config_mode(self, check_string="(config) #", pattern=""): """ if not pattern: pattern = re.escape(self.base_prompt[:16]) - return super(ArubaSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) diff --git a/netmiko/base_connection.py b/netmiko/base_connection.py index 55aa7492e..0784e4140 100644 --- a/netmiko/base_connection.py +++ b/netmiko/base_connection.py @@ -6,10 +6,6 @@ Also defines methods that should generally be supported by child classes """ - -from __future__ import print_function -from __future__ import unicode_literals - import io import re import socket @@ -24,10 +20,9 @@ from netmiko import log from netmiko.netmiko_globals import MAX_BUFFER, BACKSPACE_CHAR -from netmiko.py23_compat import string_types, bufferedio_types, text_type from netmiko.ssh_exception import ( - NetMikoTimeoutException, - NetMikoAuthenticationException, + NetmikoTimeoutException, + NetmikoAuthenticationException, ) from netmiko.utilities import ( write_bytes, @@ -68,8 +63,8 @@ def __init__( timeout=100, session_timeout=60, auth_timeout=None, - blocking_timeout=8, - banner_timeout=5, + blocking_timeout=20, + banner_timeout=15, keepalive=0, default_enter=None, response_return=None, @@ -80,6 +75,7 @@ def __init__( session_log_file_mode="write", allow_auto_change=False, encoding="ascii", + sock=None, ): """ Initialize attributes for establishing connection to target device. @@ -196,6 +192,10 @@ def __init__( :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 """ self.remote_conn = None @@ -237,6 +237,7 @@ def __init__( 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.session_log = None @@ -245,10 +246,10 @@ def __init__( # Ensures last write operations prior to disconnect are recorded. self._session_log_fin = False if session_log is not None: - if isinstance(session_log, string_types): + 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) - elif isinstance(session_log, bufferedio_types): + elif isinstance(session_log, io.BufferedIOBase): # In-memory buffer or an already open file handle self.session_log = session_log else: @@ -335,7 +336,7 @@ def _modify_connection_params(self): pass def _timeout_exceeded(self, start, msg="Timeout exceeded!"): - """Raise NetMikoTimeoutException if waiting too much in the serving queue. + """Raise NetmikoTimeoutException if waiting too much in the serving queue. :param start: Initial start time to see if session lock timeout has been exceeded :type start: float (from time.time() call i.e. epoch time) @@ -348,7 +349,7 @@ def _timeout_exceeded(self, start, msg="Timeout exceeded!"): return False if time.time() - start > self.session_timeout: # session_timeout exceeded - raise NetMikoTimeoutException(msg) + raise NetmikoTimeoutException(msg) return False def _lock_netmiko_session(self, start=None): @@ -408,7 +409,11 @@ def _write_session_log(self, data): data = data.replace(self.password, "********") if self.secret: data = data.replace(self.secret, "********") - self.session_log.write(write_bytes(data, encoding=self.encoding)) + 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 write_channel(self, out_data): @@ -475,7 +480,9 @@ def _read_channel(self): output += self.remote_conn.read(self.remote_conn.in_waiting).decode( "utf-8", "ignore" ) - log.debug("read_channel: {}".format(output)) + if self.ansi_escape_codes: + output = self.strip_ansi_escape_codes(output) + log.debug(f"read_channel: {output}") self._write_session_log(output) return output @@ -518,7 +525,7 @@ def _read_channel_expect(self, pattern="", re_flags=0, max_loops=150): output = "" if not pattern: pattern = re.escape(self.base_prompt) - log.debug("Pattern is: {}".format(pattern)) + log.debug(f"Pattern is: {pattern}") i = 1 loop_delay = 0.1 @@ -535,11 +542,13 @@ def _read_channel_expect(self, pattern="", re_flags=0, max_loops=150): if len(new_data) == 0: raise EOFError("Channel stream closed by remote device.") new_data = new_data.decode("utf-8", "ignore") - log.debug("_read_channel_expect read_data: {}".format(new_data)) + 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( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) finally: @@ -547,12 +556,12 @@ def _read_channel_expect(self, pattern="", re_flags=0, max_loops=150): elif self.protocol == "telnet" or "serial": output += self.read_channel() if re.search(pattern, output, flags=re_flags): - log.debug("Pattern found: {} {}".format(pattern, output)) + log.debug(f"Pattern found: {pattern} {output}") return output time.sleep(loop_delay * self.global_delay_factor) i += 1 - raise NetMikoTimeoutException( - "Timed-out reading channel, pattern not found in output: {}".format(pattern) + raise NetmikoTimeoutException( + f"Timed-out reading channel, pattern not found in output: {pattern}" ) def _read_channel_timing(self, delay_factor=1, max_loops=150): @@ -710,8 +719,8 @@ def telnet_login( i += 1 except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -723,9 +732,9 @@ def telnet_login( ): return return_msg - msg = "Login failed: {}".format(self.host) + msg = f"Login failed: {self.host}" self.remote_conn.close() - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) def _try_session_preparation(self): """ @@ -825,6 +834,7 @@ def _connect_params_dict(self): "timeout": self.timeout, "auth_timeout": self.auth_timeout, "banner_timeout": self.banner_timeout, + "sock": self.sock, } # Check if using SSH 'config' file mainly for SSH proxy support @@ -843,8 +853,6 @@ def _sanitize_output( :param strip_command: :type strip_command: """ - if self.ansi_escape_codes: - output = self.strip_ansi_escape_codes(output) output = self.normalize_linefeeds(output) if strip_command and command_string: command_string = self.normalize_linefeeds(command_string) @@ -856,8 +864,8 @@ def _sanitize_output( def establish_connection(self, width=None, height=None): """Establish SSH connection to the network device - Timeout will generate a NetMikoTimeoutException - Authentication failure will generate a NetMikoAuthenticationException + Timeout will generate a NetmikoTimeoutException + Authentication failure will generate a NetmikoAuthenticationException width and height are needed for Fortinet paging setting. @@ -887,19 +895,17 @@ def establish_connection(self, width=None, height=None): msg = "Connection to device timed-out: {device_type} {ip}:{port}".format( device_type=self.device_type, ip=self.host, port=self.port ) - raise NetMikoTimeoutException(msg) + raise NetmikoTimeoutException(msg) except paramiko.ssh_exception.AuthenticationException as auth_err: self.paramiko_cleanup() msg = "Authentication failure: unable to connect {device_type} {ip}:{port}".format( device_type=self.device_type, ip=self.host, port=self.port ) - msg += self.RETURN + text_type(auth_err) - raise NetMikoAuthenticationException(msg) + msg += self.RETURN + str(auth_err) + raise NetmikoAuthenticationException(msg) if self.verbose: - print( - "SSH connection established to {}:{}".format(self.host, self.port) - ) + print(f"SSH connection established to {self.host}:{self.port}") # Use invoke_shell to establish an 'interactive session' if width and height: @@ -956,7 +962,7 @@ def _increment_delay(main_delay, increment=1.1, maximum=8): 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): """Prepare for Paramiko SSH connection.""" @@ -1010,12 +1016,11 @@ def disable_paging(self, command="terminal length 0", delay_factor=1): self.clear_buffer() command = self.normalize_cmd(command) log.debug("In disable_paging") - log.debug("Command: {0}".format(command)) + log.debug(f"Command: {command}") self.write_channel(command) - output = self.read_until_prompt() - if self.ansi_escape_codes: - output = self.strip_ansi_escape_codes(output) - log.debug("{0}".format(output)) + # Make sure you read until you detect the command echo (avoid getting out of sync) + output = self.read_until_pattern(pattern=re.escape(command.strip())) + log.debug(f"{output}") log.debug("Exiting disable_paging") return output @@ -1036,9 +1041,8 @@ def set_terminal_width(self, command="", delay_factor=1): delay_factor = self.select_delay_factor(delay_factor) command = self.normalize_cmd(command) self.write_channel(command) - output = self.read_until_prompt() - if self.ansi_escape_codes: - output = self.strip_ansi_escape_codes(output) + # Make sure you read until you detect the command echo (avoid getting out of sync) + output = self.read_until_pattern(pattern=re.escape(command.strip())) return output def set_base_prompt( @@ -1065,7 +1069,7 @@ def set_base_prompt( """ prompt = self.find_prompt(delay_factor=delay_factor) if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {0}".format(repr(prompt))) + raise ValueError(f"Router prompt not found: {repr(prompt)}") # Strip off trailing terminator self.base_prompt = prompt[:-1] return self.base_prompt @@ -1079,24 +1083,26 @@ def find_prompt(self, delay_factor=1): delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() self.write_channel(self.RETURN) - time.sleep(delay_factor * 0.1) + sleep_time = delay_factor * 0.1 + time.sleep(sleep_time) # Initial attempt to get prompt prompt = self.read_channel() - if self.ansi_escape_codes: - prompt = self.strip_ansi_escape_codes(prompt) # Check if the only thing you received was a newline count = 0 prompt = prompt.strip() - while count <= 10 and not prompt: + while count <= 12 and not prompt: prompt = self.read_channel().strip() - if prompt: - if self.ansi_escape_codes: - prompt = self.strip_ansi_escape_codes(prompt).strip() - else: + if not prompt: self.write_channel(self.RETURN) - time.sleep(delay_factor * 0.1) + # log.debug(f"find_prompt sleep time: {sleep_time}") + 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 # If multiple lines in the output take the last line @@ -1104,14 +1110,25 @@ def find_prompt(self, delay_factor=1): prompt = prompt.split(self.RESPONSE_RETURN)[-1] prompt = prompt.strip() if not prompt: - raise ValueError("Unable to find prompt: {}".format(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): + def clear_buffer(self, backoff=True): """Read any data available in the channel.""" - self.read_channel() + sleep_time = 0.1 * self.global_delay_factor + for _ in range(10): + time.sleep(sleep_time) + data = self.read_channel() + 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 def send_command_timing( self, @@ -1122,7 +1139,9 @@ def send_command_timing( strip_command=True, normalize=True, use_textfsm=False, + textfsm_template=None, use_genie=False, + cmd_echo=False, ): """Execute command_string on the SSH channel using a delay-based mechanism. Generally used for show commands. @@ -1147,10 +1166,17 @@ def send_command_timing( :type normalize: bool :param use_textfsm: Process command output through TextFSM template (default: False). - :type normalize: bool + :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_genie: Process command output through PyATS/Genie parser (default: False). - :type normalize: bool + :type use_genie: bool + + :param cmd_echo: Verify command echo before proceeding (default: False). + :type cmd_echo: bool """ output = "" delay_factor = self.select_delay_factor(delay_factor) @@ -1159,7 +1185,27 @@ def send_command_timing( command_string = self.normalize_cmd(command_string) self.write_channel(command_string) - output = self._read_channel_timing( + + cmd = command_string.strip() + # if cmd is just an "enter" skip this section + if cmd and cmd_echo: + # 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 ) output = self._sanitize_output( @@ -1168,18 +1214,27 @@ def send_command_timing( command_string=command_string, strip_prompt=strip_prompt, ) + # If both TextFSM and Genie are set, try TextFSM then Genie - for parser_flag, parser_func in ( - (use_textfsm, get_structured_data), - (use_genie, get_structured_data_genie), - ): - if parser_flag: - structured_output = parser_func( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, string_types): - return structured_output + 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_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 def strip_prompt(self, a_string): @@ -1233,6 +1288,7 @@ def send_command( strip_command=True, normalize=True, use_textfsm=False, + textfsm_template=None, use_genie=False, ): """Execute command_string on the SSH channel using a pattern-based mechanism. Generally @@ -1266,6 +1322,9 @@ def send_command( :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_genie: Process command output through PyATS/Genie parser (default: False). :type normalize: bool """ @@ -1298,6 +1357,20 @@ def send_command( time.sleep(delay_factor * loop_delay) self.clear_buffer() self.write_channel(command_string) + new_data = "" + + cmd = command_string.strip() + # if cmd is just and "enter" skip this section + if cmd: + # 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}" i = 1 output = "" @@ -1306,11 +1379,7 @@ def send_command( # Keep reading data until search_pattern is found or until max_loops is reached. while i <= max_loops: - new_data = self.read_channel() if new_data: - if self.ansi_escape_codes: - new_data = self.strip_ansi_escape_codes(new_data) - output += new_data past_three_reads.append(new_data) @@ -1331,6 +1400,7 @@ def send_command( time.sleep(delay_factor * loop_delay) i += 1 + new_data = self.read_channel() else: # nobreak raise IOError( "Search pattern never detected in send_command_expect: {}".format( @@ -1346,17 +1416,23 @@ def send_command( ) # If both TextFSM and Genie are set, try TextFSM then Genie - for parser_flag, parser_func in ( - (use_textfsm, get_structured_data), - (use_genie, get_structured_data_genie), - ): - if parser_flag: - structured_output = parser_func( - output, platform=self.device_type, command=command_string.strip() - ) - # If we have structured data; return it. - if not isinstance(structured_output, string_types): - return structured_output + 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_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 return output def send_command_expect(self, *args, **kwargs): @@ -1397,12 +1473,17 @@ def strip_command(self, command_string, output): # Check for line wrap (remove backspaces) if backspace_char in output: output = output.replace(backspace_char, "") + + # Juniper has a weird case where the echoed command will be " \n" + # i.e. there is an extra space there. + cmd = command_string.strip() + if output.startswith(cmd): output_lines = output.split(self.RESPONSE_RETURN) new_output = output_lines[1:] return self.RESPONSE_RETURN.join(new_output) else: - command_length = len(command_string) - return output[command_length:] + # command_string isn't there; do nothing + return output def normalize_linefeeds(self, a_string): """Convert `\r\r\n`,`\r\n`, `\n\r` to `\n.` @@ -1464,7 +1545,7 @@ def enable(self, cmd="", pattern="ssword", re_flags=re.IGNORECASE): ) self.write_channel(self.normalize_cmd(self.secret)) output += self.read_until_prompt() - except NetMikoTimeoutException: + except NetmikoTimeoutException: raise ValueError(msg) if not self.check_enable_mode(): raise ValueError(msg) @@ -1513,7 +1594,10 @@ def config_mode(self, config_command="", pattern=""): output = "" if not self.check_config_mode(): self.write_channel(self.normalize_cmd(config_command)) - output = self.read_until_pattern(pattern=pattern) + # Make sure you read until you detect the command echo (avoid getting out of sync) + output += self.read_until_pattern(pattern=re.escape(config_command.strip())) + if not re.search(pattern, output, flags=re.M): + output += self.read_until_pattern(pattern=pattern) if not self.check_config_mode(): raise ValueError("Failed to enter configuration mode.") return output @@ -1530,10 +1614,13 @@ def exit_config_mode(self, exit_config="", pattern=""): output = "" if self.check_config_mode(): self.write_channel(self.normalize_cmd(exit_config)) - output = self.read_until_pattern(pattern=pattern) + # Make sure you read until you detect the command echo (avoid getting out of sync) + output += self.read_until_pattern(pattern=re.escape(exit_config.strip())) + if not re.search(pattern, output, flags=re.M): + output += self.read_until_pattern(pattern=pattern) if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output def send_config_from_file(self, config_file=None, **kwargs): @@ -1563,6 +1650,8 @@ def send_config_set( strip_prompt=False, strip_command=False, config_mode_command=None, + cmd_verify=True, + enter_config_mode=True, ): """ Send configuration commands down the SSH channel. @@ -1592,34 +1681,64 @@ def send_config_set( :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 + """ delay_factor = self.select_delay_factor(delay_factor) if config_commands is None: return "" - elif isinstance(config_commands, string_types): + elif isinstance(config_commands, str): config_commands = (config_commands,) if not hasattr(config_commands, "__iter__"): raise ValueError("Invalid argument passed into send_config_set") # Send config commands - cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() - output = self.config_mode(*cfg_mode_args) - for cmd in config_commands: - self.write_channel(self.normalize_cmd(cmd)) - if self.fast_cli: - pass - else: + if enter_config_mode: + cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() + output = self.config_mode(*cfg_mode_args) + + if self.fast_cli: + 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 + ) + elif not cmd_verify: + for cmd in config_commands: + self.write_channel(self.normalize_cmd(cmd)) time.sleep(delay_factor * 0.05) + # Gather output + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + 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 - # Gather output - output += self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops - ) if exit_config_mode: output += self.exit_config_mode() output = self._sanitize_output(output) - log.debug("{}".format(output)) + log.debug(f"{output}") return output def strip_ansi_escape_codes(self, string_buffer): @@ -1653,7 +1772,7 @@ def strip_ansi_escape_codes(self, string_buffer): :type string_buffer: str """ # noqa log.debug("In strip_ansi_escape_codes") - log.debug("repr = {}".format(repr(string_buffer))) + log.debug(f"repr = {repr(string_buffer)}") code_position_cursor = chr(27) + r"\[\d+;\d+H" code_show_cursor = chr(27) + r"\[\?25h" @@ -1709,8 +1828,9 @@ def strip_ansi_escape_codes(self, string_buffer): # CODE_NEXT_LINE must substitute with return output = re.sub(code_next_line, self.RETURN, output) - log.debug("new_output = {0}".format(output)) - log.debug("repr = {0}".format(repr(output))) + log.debug("Stripping ANSI escape codes") + log.debug(f"new_output = {output}") + log.debug(f"repr = {repr(output)}") return output @@ -1752,9 +1872,9 @@ def save_config(self, *args, **kwargs): def open_session_log(self, filename, mode="write"): """Open the session_log file.""" if mode == "append": - self.session_log = open(filename, mode="ab") + self.session_log = open(filename, mode="a") else: - self.session_log = open(filename, mode="wb") + self.session_log = open(filename, mode="w") self._session_log_close = True def close_session_log(self): diff --git a/netmiko/calix/__init__.py b/netmiko/calix/__init__.py index fbd608389..0cbf5f6d0 100644 --- a/netmiko/calix/__init__.py +++ b/netmiko/calix/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.calix.calix_b6 import CalixB6SSH, CalixB6Telnet __all__ = ["CalixB6SSH", "CalixB6Telnet"] diff --git a/netmiko/calix/calix_b6.py b/netmiko/calix/calix_b6.py index 992434e56..c49cde0c6 100644 --- a/netmiko/calix/calix_b6.py +++ b/netmiko/calix/calix_b6.py @@ -1,6 +1,4 @@ """Calix B6 SSH Driver for Netmiko""" -from __future__ import unicode_literals - import time from os import path @@ -23,7 +21,7 @@ class CalixB6Base(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(CalixB6Base, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def session_preparation(self): """Prepare the session after the connection has been established.""" @@ -63,10 +61,10 @@ def special_login_handler(self, delay_factor=1): def check_config_mode(self, check_string=")#", pattern=""): """Checks if the device is in configuration mode""" - return super(CalixB6Base, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def save_config(self, cmd="copy run start", confirm=False, confirm_response=""): - return super(CalixB6Base, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/checkpoint/__init__.py b/netmiko/checkpoint/__init__.py index debdcddc6..a3503a0a2 100644 --- a/netmiko/checkpoint/__init__.py +++ b/netmiko/checkpoint/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.checkpoint.checkpoint_gaia_ssh import CheckPointGaiaSSH __all__ = ["CheckPointGaiaSSH"] diff --git a/netmiko/checkpoint/checkpoint_gaia_ssh.py b/netmiko/checkpoint/checkpoint_gaia_ssh.py index 60fae47a1..8ec4019ba 100644 --- a/netmiko/checkpoint/checkpoint_gaia_ssh.py +++ b/netmiko/checkpoint/checkpoint_gaia_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.base_connection import BaseConnection diff --git a/netmiko/ciena/__init__.py b/netmiko/ciena/__init__.py index 1fd08a686..1cfee9397 100644 --- a/netmiko/ciena/__init__.py +++ b/netmiko/ciena/__init__.py @@ -1,4 +1,7 @@ -from __future__ import unicode_literals -from netmiko.ciena.ciena_saos_ssh import CienaSaosSSH +from netmiko.ciena.ciena_saos import ( + CienaSaosSSH, + CienaSaosTelnet, + CienaSaosFileTransfer, +) -__all__ = ["CienaSaosSSH"] +__all__ = ["CienaSaosSSH", "CienaSaosTelnet", "CienaSaosFileTransfer"] diff --git a/netmiko/ciena/ciena_saos.py b/netmiko/ciena/ciena_saos.py new file mode 100644 index 000000000..3067c5fc6 --- /dev/null +++ b/netmiko/ciena/ciena_saos.py @@ -0,0 +1,216 @@ +"""Ciena SAOS support.""" +import time +import re +import os +from netmiko.base_connection import BaseConnection +from netmiko.scp_handler import BaseFileTransfer + + +class CienaSaosBase(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() + 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): + """Enter the Bourne Shell.""" + output = self.send_command("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): + """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 + + 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=""): + """Saves Config.""" + return self.send_command(command_string=cmd) + + +class CienaSaosSSH(CienaSaosBase): + pass + + +class CienaSaosTelnet(CienaSaosBase): + 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) + + +class CienaSaosFileTransfer(BaseFileTransfer): + """Ciena SAOS SCP File Transfer driver.""" + + def __init__( + self, + ssh_conn, + source_file, + dest_file, + file_system="", + direction="put", + **kwargs, + ): + if file_system == "": + file_system = f"/tmp/users/{ssh_conn.username}" + return super().__init__( + ssh_conn=ssh_conn, + source_file=source_file, + dest_file=dest_file, + file_system=file_system, + direction=direction, + **kwargs, + ) + + def remote_space_available(self, search_pattern=""): + """ + Return space available on Ciena SAOS + + Output should only have the file-system that matches {self.file_system} + + Filesystem 1K-blocks Used Available Use% Mounted on + 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 = remote_output.strip() + err_msg = ( + f"Parsing error, unexpected output from {remote_cmd}:\n{remote_output}" + ) + + # First line is the header; file_system_line is the output we care about + header_line, filesystem_line = remote_output.splitlines() + + filesystem, _, _, space_avail, *_ = header_line.split() + if "Filesystem" != filesystem or "Avail" not in space_avail: + # Filesystem 1K-blocks Used Available Use% Mounted on + raise ValueError(err_msg) + + # Normalize output - in certain outputs ciena will line wrap (this fixes that) + # Strip the extra newline + # /dev/mapper/EN--VOL-config + # 4096 1476 2620 36% /etc/hosts + filesystem_line = re.sub(r"(^\S+$)\n", r"\1", filesystem_line, flags=re.M) + + # Checks to make sure what was returned is what we expect + _, k_blocks, used, space_avail, _, _ = filesystem_line.split() + for integer_check in (k_blocks, used, space_avail): + try: + int(integer_check) + except ValueError: + raise ValueError(err_msg) + + return int(space_avail) * 1024 + + def check_file_exists(self, remote_cmd=""): + """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) + search_string = re.escape(f"{self.file_system}/{self.dest_file}") + if "ERROR" in remote_out: + return False + elif re.search(search_string, remote_out): + return True + else: + raise ValueError("Unexpected output from check_file_exists") + elif self.direction == "get": + return os.path.exists(self.dest_file) + + def remote_file_size(self, remote_cmd="", remote_file=None): + """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 + + remote_file = f"{self.file_system}/{remote_file}" + + if not remote_cmd: + remote_cmd = f"file ls -l {remote_file}" + + remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) + + if "No such file or directory" in remote_out: + raise IOError("Unable to find file on remote system") + + escape_file_name = re.escape(remote_file) + pattern = r"^.* ({}).*$".format(escape_file_name) + match = re.search(pattern, remote_out, flags=re.M) + if match: + # Format: -rw-r--r-- 1 pyclass wheel 12 Nov 5 19:07 /var/tmp/test3.txt + line = match.group(0) + file_size = line.split()[4] + return int(file_size) + + raise ValueError( + "Search pattern not found for remote file size during SCP transfer." + ) + + def remote_md5(self, base_cmd="", remote_file=None): + """Calculate remote MD5 and returns the hash. + + This command can be CPU intensive on the remote device. + """ + if base_cmd == "": + base_cmd = "md5sum" + 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}" + + self.ssh_ctl_chan._enter_shell() + dest_md5 = self.ssh_ctl_chan.send_command( + 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"): + return super().enable_scp(cmd=cmd) + + def disable_scp(self, cmd="system server scp disable"): + return super().disable_scp(cmd=cmd) diff --git a/netmiko/ciena/ciena_saos_ssh.py b/netmiko/ciena/ciena_saos_ssh.py deleted file mode 100644 index d760a5b21..000000000 --- a/netmiko/ciena/ciena_saos_ssh.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Ciena SAOS support.""" -from __future__ import print_function -from __future__ import unicode_literals -import time -from netmiko.cisco_base_connection import CiscoSSHConnection - - -class CienaSaosSSH(CiscoSSHConnection): - """Ciena SAOS support.""" - - def session_preparation(self): - self._test_channel_read() - 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 enable(self, *args, **kwargs): - pass - - def save_config(self, *args, **kwargs): - """Not Implemented""" - raise NotImplementedError diff --git a/netmiko/cisco/__init__.py b/netmiko/cisco/__init__.py index a6fbcd734..ac3868e55 100644 --- a/netmiko/cisco/__init__.py +++ b/netmiko/cisco/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.cisco.cisco_ios import ( CiscoIosBase, CiscoIosSSH, diff --git a/netmiko/cisco/cisco_asa_ssh.py b/netmiko/cisco/cisco_asa_ssh.py index 833771e9f..ac9f92bd2 100644 --- a/netmiko/cisco/cisco_asa_ssh.py +++ b/netmiko/cisco/cisco_asa_ssh.py @@ -1,6 +1,4 @@ """Subclass specific to Cisco ASA.""" - -from __future__ import unicode_literals import re import time from netmiko.cisco_base_connection import CiscoSSHConnection, CiscoFileTransfer @@ -34,7 +32,7 @@ def send_command_timing(self, *args, **kwargs): If the ASA is in multi-context mode, then the base_prompt needs to be updated after each context change. """ - output = super(CiscoAsaSSH, self).send_command_timing(*args, **kwargs) + output = super().send_command_timing(*args, **kwargs) if len(args) >= 1: command_string = args[0] else: @@ -58,7 +56,7 @@ def send_command(self, *args, **kwargs): if len(args) <= 1: expect_string = kwargs.get("expect_string", "#") kwargs["expect_string"] = expect_string - output = super(CiscoAsaSSH, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) if "changeto" in command_string: self.set_base_prompt() @@ -77,7 +75,7 @@ def set_base_prompt(self, *args, **kwargs): This switch of ASA contexts can occur in configuration mode. If this happens the trailing '(config*' needs stripped off. """ - cur_base_prompt = super(CiscoAsaSSH, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) match = re.search(r"(.*)\(conf.*", cur_base_prompt) if match: # strip off (conf.* from base_prompt @@ -112,7 +110,7 @@ def asa_login(self): def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves Config""" - return super(CiscoAsaSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/cisco/cisco_ios.py b/netmiko/cisco/cisco_ios.py index e82a993ba..932f3c135 100644 --- a/netmiko/cisco/cisco_ios.py +++ b/netmiko/cisco/cisco_ios.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import time import re import os @@ -28,13 +26,11 @@ def check_config_mode(self, check_string=")#", pattern="#"): Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoIosBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves Config Using Copy Run Start""" - return super(CiscoIosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -74,6 +70,7 @@ def __init__( file_system=None, direction="put", source_config=None, + socket_timeout=10.0, ): if source_file and source_config: msg = "Invalid call to InLineTransfer both source_file and source_config specified." @@ -100,6 +97,8 @@ def __init__( else: self.file_system = file_system + self.socket_timeout = socket_timeout + @staticmethod def _read_file(file_name): with io.open(file_name, "rt", encoding="utf-8") as f: @@ -107,7 +106,7 @@ def _read_file(file_name): @staticmethod def _tcl_newline_rationalize(tcl_string): - """ + 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 will convert the "\r" to a "\n" i.e. you will see a "\n" inside the file on the @@ -139,9 +138,7 @@ def _enter_tcl_mode(self): ) for pattern in cmd_failed: if pattern in output: - raise ValueError( - "Failed to enter tclsh mode on router: {}".format(output) - ) + raise ValueError(f"Failed to enter tclsh mode on router: {output}") return output def _exit_tcl_mode(self): @@ -172,10 +169,7 @@ def file_md5(self, file_name): return hashlib.md5(file_contents).hexdigest() def config_md5(self, source_config): - """Compute MD5 hash of file.""" - file_contents = source_config + "\n" # Cisco IOS automatically adds this - file_contents = file_contents.encode("UTF-8") - return hashlib.md5(file_contents).hexdigest() + return super().file_md5(source_config, add_newline=True) def put_file(self): curlybrace = r"{" diff --git a/netmiko/cisco/cisco_nxos_ssh.py b/netmiko/cisco/cisco_nxos_ssh.py index 916a0fb7d..c45b92dbf 100644 --- a/netmiko/cisco/cisco_nxos_ssh.py +++ b/netmiko/cisco/cisco_nxos_ssh.py @@ -1,5 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals import re import time import os @@ -26,9 +24,7 @@ def normalize_linefeeds(self, a_string): def check_config_mode(self, check_string=")#", pattern="#"): """Checks if the device is in configuration mode or not.""" - return super(CiscoNxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) class CiscoNxosFileTransfer(CiscoFileTransfer): @@ -41,6 +37,7 @@ def __init__( dest_file, file_system="bootflash:", direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file @@ -61,11 +58,13 @@ def __init__( else: raise ValueError("Invalid direction specified") + self.socket_timeout = socket_timeout + def check_file_exists(self, remote_cmd=""): """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"{}.*Usage for".format(self.dest_file) if "No such file or directory" in remote_out: @@ -86,7 +85,7 @@ def remote_file_size(self, remote_cmd="", remote_file=None): remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Match line containing file name @@ -113,9 +112,7 @@ def remote_md5(self, base_cmd="show file", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}{} md5sum".format( - base_cmd, self.file_system, remote_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() def enable_scp(self, cmd=None): diff --git a/netmiko/cisco/cisco_s300.py b/netmiko/cisco/cisco_s300.py index 2630486e8..97599f8a7 100644 --- a/netmiko/cisco/cisco_s300.py +++ b/netmiko/cisco/cisco_s300.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -24,6 +23,6 @@ def session_preparation(self): time.sleep(0.3 * self.global_delay_factor) def save_config(self, cmd="write memory", confirm=True, confirm_response="Y"): - return super(CiscoS300SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/cisco/cisco_tp_tcce.py b/netmiko/cisco/cisco_tp_tcce.py index f0e30d0bf..1043deecb 100644 --- a/netmiko/cisco/cisco_tp_tcce.py +++ b/netmiko/cisco/cisco_tp_tcce.py @@ -5,7 +5,6 @@ Written by Ahmad Barrin """ -from __future__ import unicode_literals import time import re from netmiko.cisco_base_connection import CiscoSSHConnection @@ -15,7 +14,7 @@ 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(CiscoTpTcCeSSH, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def disable_paging(self, *args, **kwargs): """Paging is disabled by default.""" @@ -66,13 +65,6 @@ def send_command(self, *args, **kwargs): 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. - - command_string = command to execute - expect_string = pattern to search for uses re.search (use raw strings) - delay_factor = decrease the initial delay before we start looking for data - max_loops = number of iterations before we give up and raise an exception - strip_prompt = strip the trailing prompt from the output - strip_command = strip the leading command from the output """ if len(args) >= 2: expect_string = args[1] @@ -83,7 +75,7 @@ def send_command(self, *args, **kwargs): expect_string = self.RETURN + expect_string + self.RETURN kwargs.setdefault("expect_string", expect_string) - output = super(CiscoSSHConnection, self).send_command(*args, **kwargs) + output = super().send_command(*args, **kwargs) return output def save_config(self, *args, **kwargs): diff --git a/netmiko/cisco/cisco_wlc_ssh.py b/netmiko/cisco/cisco_wlc_ssh.py index 18c1f7854..21bf61c07 100644 --- a/netmiko/cisco/cisco_wlc_ssh.py +++ b/netmiko/cisco/cisco_wlc_ssh.py @@ -1,13 +1,9 @@ """Netmiko Cisco WLC support.""" -from __future__ import print_function -from __future__ import unicode_literals import time import re -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoAuthenticationException from netmiko.base_connection import BaseConnection -from netmiko.py23_compat import string_types -from netmiko import log class CiscoWlcSSH(BaseConnection): @@ -105,8 +101,8 @@ def session_preparation(self): try: self.set_base_prompt() except ValueError: - msg = "Authentication failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Authentication failed: {self.host}" + raise NetmikoAuthenticationException(msg) self.disable_paging(command="config paging disable") # Clear the read buffer @@ -121,59 +117,33 @@ def check_config_mode(self, check_string="config", pattern=""): """Checks if the device is in configuration mode or not.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).check_config_mode(check_string, pattern) + return super().check_config_mode(check_string, pattern) def config_mode(self, config_command="config", pattern=""): """Enter into config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).config_mode(config_command, pattern) + return super().config_mode(config_command, pattern) def exit_config_mode(self, exit_config="exit", pattern=""): """Exit config_mode.""" if not pattern: pattern = re.escape(self.base_prompt) - return super(CiscoWlcSSH, self).exit_config_mode(exit_config, pattern) + return super().exit_config_mode(exit_config, pattern) 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, + exit_config_mode=False, + enter_config_mode=False, + **kwargs, ): - """ - 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. - - Does not automatically exit/enter configuration mode. - """ - delay_factor = self.select_delay_factor(delay_factor) - if config_commands is None: - return "" - elif isinstance(config_commands, string_types): - config_commands = (config_commands,) - - if not hasattr(config_commands, "__iter__"): - raise ValueError("Invalid argument passed into send_config_set") - - # Send config commands - for cmd in config_commands: - self.write_channel(self.normalize_cmd(cmd)) - time.sleep(delay_factor * 0.5) - - # Gather output - output = self._read_channel_timing( - delay_factor=delay_factor, max_loops=max_loops + return super().send_config_set( + config_commands=config_commands, + exit_config_mode=exit_config_mode, + enter_config_mode=enter_config_mode, + **kwargs, ) - output = self._sanitize_output(output) - log.debug("{}".format(output)) - return output def save_config(self, cmd="save config", confirm=True, confirm_response="y"): """Saves Config.""" diff --git a/netmiko/cisco/cisco_xr.py b/netmiko/cisco/cisco_xr.py index a7e0f1683..e6986098c 100644 --- a/netmiko/cisco/cisco_xr.py +++ b/netmiko/cisco/cisco_xr.py @@ -1,9 +1,6 @@ -from __future__ import print_function -from __future__ import unicode_literals import time import re from netmiko.cisco_base_connection import CiscoBaseConnection, CiscoFileTransfer -from netmiko.py23_compat import text_type class CiscoXrBase(CiscoBaseConnection): @@ -17,10 +14,10 @@ def session_preparation(self): time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() - def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """IOS-XR requires you not exit from configuration mode.""" - return super(CiscoXrBase, self).send_config_set( - config_commands=config_commands, exit_config_mode=False, **kwargs + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def commit( @@ -71,26 +68,26 @@ def commit( if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' - label = text_type(label) + label = str(label) error_marker = "Failed to" alt_error_marker = "One or more commits have occurred from other" # Select proper command string based on arguments provided if label: if comment: - command_string = "commit label {} comment {}".format(label, comment) + command_string = f"commit label {label} comment {comment}" elif confirm: command_string = "commit label {} confirmed {}".format( - label, text_type(confirm_delay) + label, str(confirm_delay) ) else: - command_string = "commit label {}".format(label) + command_string = f"commit label {label}" elif confirm: - command_string = "commit confirmed {}".format(text_type(confirm_delay)) + command_string = f"commit confirmed {str(confirm_delay)}" elif comment: - command_string = "commit comment {}".format(comment) + command_string = f"commit comment {comment}" else: command_string = "commit" @@ -103,17 +100,13 @@ def commit( delay_factor=delay_factor, ) if error_marker in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(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 ) - raise ValueError( - "Commit failed with the following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output @@ -177,7 +170,7 @@ def process_md5(self, md5_output, pattern=r"^([a-fA-F0-9]+)$"): if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def remote_md5(self, base_cmd="show md5 file", remote_file=None): """ @@ -191,7 +184,7 @@ def remote_md5(self, base_cmd="show md5 file", remote_file=None): elif self.direction == "get": remote_file = self.source_file # IOS-XR requires both the leading slash and the slash between file-system and file here - remote_md5_cmd = "{} /{}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 diff --git a/netmiko/cisco_base_connection.py b/netmiko/cisco_base_connection.py index ed6e6ab7a..2ea7d86d3 100644 --- a/netmiko/cisco_base_connection.py +++ b/netmiko/cisco_base_connection.py @@ -1,8 +1,7 @@ """CiscoBaseConnection is netmiko SSH class for Cisco and Cisco-like platforms.""" -from __future__ import unicode_literals from netmiko.base_connection import BaseConnection from netmiko.scp_handler import BaseFileTransfer -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoAuthenticationException import re import time @@ -12,21 +11,15 @@ class CiscoBaseConnection(BaseConnection): def check_enable_mode(self, check_string="#"): """Check if in enable mode. Return boolean.""" - return super(CiscoBaseConnection, self).check_enable_mode( - check_string=check_string - ) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="ssword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(CiscoBaseConnection, self).enable( - cmd=cmd, pattern=pattern, re_flags=re_flags - ) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def exit_enable_mode(self, exit_command="disable"): """Exits enable (privileged exec) mode.""" - return super(CiscoBaseConnection, self).exit_enable_mode( - exit_command=exit_command - ) + return super().exit_enable_mode(exit_command=exit_command) def check_config_mode(self, check_string=")#", pattern=""): """ @@ -34,9 +27,7 @@ def check_config_mode(self, check_string=")#", pattern=""): Cisco IOS devices abbreviate the prompt at 20 chars in config mode """ - return super(CiscoBaseConnection, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def config_mode(self, config_command="config term", pattern=""): """ @@ -46,15 +37,11 @@ def config_mode(self, config_command="config term", pattern=""): """ if not pattern: pattern = re.escape(self.base_prompt[:16]) - return super(CiscoBaseConnection, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="end", pattern="#"): """Exit from configuration mode.""" - return super(CiscoBaseConnection, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, @@ -140,7 +127,7 @@ def telnet_login( msg = "Login failed - Password required, but none set: {}".format( self.host ) - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) # Check if proper data received if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( @@ -153,8 +140,8 @@ def telnet_login( i += 1 except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -167,8 +154,8 @@ def telnet_login( return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) def cleanup(self): """Gracefully exit the SSH session.""" @@ -189,7 +176,7 @@ def _autodetect_fs(self, cmd="dir", pattern=r"Directory of (.*)/"): if match: file_system = match.group(1) # Test file_system - cmd = "dir {}".format(file_system) + cmd = f"dir {file_system}" output = self.send_command_expect(cmd) if "% Invalid" in output or "%Error:" in output: raise ValueError( @@ -213,15 +200,23 @@ def save_config( """Saves Config.""" self.enable() if confirm: - output = self.send_command_timing(command_string=cmd) + output = self.send_command_timing( + command_string=cmd, strip_prompt=False, strip_command=False + ) if confirm_response: - output += self.send_command_timing(confirm_response) + output += self.send_command_timing( + confirm_response, strip_prompt=False, strip_command=False + ) else: # Send enter by default - output += self.send_command_timing(self.RETURN) + output += self.send_command_timing( + 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(command_string=cmd) + output = self.send_command( + command_string=cmd, strip_prompt=False, strip_command=False + ) return output diff --git a/netmiko/citrix/__init__.py b/netmiko/citrix/__init__.py index 53226e8d8..a9aa9a203 100644 --- a/netmiko/citrix/__init__.py +++ b/netmiko/citrix/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.citrix.netscaler_ssh import NetscalerSSH __all__ = ["NetscalerSSH"] diff --git a/netmiko/citrix/netscaler_ssh.py b/netmiko/citrix/netscaler_ssh.py index 985e24f08..1f16d5c64 100644 --- a/netmiko/citrix/netscaler_ssh.py +++ b/netmiko/citrix/netscaler_ssh.py @@ -12,7 +12,7 @@ def session_preparation(self): delay_factor = self.select_delay_factor(delay_factor=0) self._test_channel_read() self.set_base_prompt() - cmd = "{}set cli mode -page OFF{}".format(self.RETURN, self.RETURN) + 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() @@ -28,7 +28,7 @@ def set_base_prompt( """ prompt = self.find_prompt(delay_factor=delay_factor) if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {}".format(repr(prompt))) + raise ValueError(f"Router prompt not found: {repr(prompt)}") prompt = prompt.strip() if len(prompt) == 1: @@ -52,7 +52,7 @@ def exit_config_mode(self): def strip_prompt(self, a_string): """ Strip 'Done' from command output """ - output = super(NetscalerSSH, self).strip_prompt(a_string) + output = super().strip_prompt(a_string) lines = output.split(self.RESPONSE_RETURN) if "Done" in lines[-1]: return self.RESPONSE_RETURN.join(lines[:-1]) diff --git a/netmiko/cloudgenix/cloudgenix_ion.py b/netmiko/cloudgenix/cloudgenix_ion.py index c9a02306e..db0f7482b 100644 --- a/netmiko/cloudgenix/cloudgenix_ion.py +++ b/netmiko/cloudgenix/cloudgenix_ion.py @@ -1,13 +1,9 @@ -import time - -from netmiko import log from netmiko.cisco_base_connection import CiscoSSHConnection -from netmiko.py23_compat import string_types class CloudGenixIonSSH(CiscoSSHConnection): def establish_connection(self): - super(CloudGenixIonSSH, self).establish_connection(width=100, height=1000) + super().establish_connection(width=100, height=1000) def session_preparation(self, *args, **kwargs): """Prepare the session after the connection has been established.""" @@ -21,12 +17,12 @@ def disable_paging(self): return "" def find_prompt(self, delay_factor=1): - prompt = super(CloudGenixIonSSH, self).find_prompt() + prompt = super().find_prompt(delay_factor=delay_factor) prompt = self.strip_backspaces(prompt).strip() return prompt def strip_command(self, command_string, output): - output = super(CloudGenixIonSSH, self).strip_command(command_string, output) + 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 @@ -47,34 +43,7 @@ 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, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - ): - delay_factor = self.select_delay_factor(delay_factor) - if config_commands is None: - return "" - elif isinstance(config_commands, string_types): - config_commands = (config_commands,) - - if not hasattr(config_commands, "__iter__"): - raise ValueError("Invalid argument passed into send_config_set") - - # Send config commands - output = "" - for cmd in config_commands: - output += self.send_command(cmd) - if self.fast_cli: - pass - else: - time.sleep(delay_factor * 0.05) - - output = self._sanitize_output(output) - log.debug("{}".format(output)) - return output + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs + ) diff --git a/netmiko/coriant/coriant_ssh.py b/netmiko/coriant/coriant_ssh.py index cae0011fd..7df3ebf06 100644 --- a/netmiko/coriant/coriant_ssh.py +++ b/netmiko/coriant/coriant_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.cisco_base_connection import CiscoSSHConnection @@ -32,7 +31,7 @@ def set_base_prompt( self, pri_prompt_terminator=":", alt_prompt_terminator=">", delay_factor=2 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - super(CoriantSSH, self).set_base_prompt( + super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, diff --git a/netmiko/dell/__init__.py b/netmiko/dell/__init__.py index f0f42e0d0..238063516 100644 --- a/netmiko/dell/__init__.py +++ b/netmiko/dell/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.dell.dell_dnos6 import DellDNOS6SSH from netmiko.dell.dell_dnos6 import DellDNOS6Telnet from netmiko.dell.dell_force10_ssh import DellForce10SSH diff --git a/netmiko/dell/dell_dnos6.py b/netmiko/dell/dell_dnos6.py index 4f591e64b..ff341e2d1 100644 --- a/netmiko/dell/dell_dnos6.py +++ b/netmiko/dell/dell_dnos6.py @@ -1,5 +1,4 @@ """Dell N2/3/4000 base driver- supports DNOS6.""" -from __future__ import unicode_literals from netmiko.dell.dell_powerconnect import DellPowerConnectBase import time @@ -24,7 +23,7 @@ def save_config( confirm_response="", ): """Saves Config""" - return super(DellDNOS6Base, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/dell/dell_force10_ssh.py b/netmiko/dell/dell_force10_ssh.py index 52b5ad22e..0ab2f58d9 100644 --- a/netmiko/dell/dell_force10_ssh.py +++ b/netmiko/dell/dell_force10_ssh.py @@ -1,5 +1,4 @@ """Dell Force10 Driver - supports DNOS9.""" -from __future__ import unicode_literals from netmiko.cisco_base_connection import CiscoSSHConnection @@ -13,6 +12,6 @@ def save_config( confirm_response="", ): """Saves Config""" - return super(DellForce10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/dell/dell_isilon_ssh.py b/netmiko/dell/dell_isilon_ssh.py index 3a047ca65..860b82b8f 100644 --- a/netmiko/dell/dell_isilon_ssh.py +++ b/netmiko/dell/dell_isilon_ssh.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import time import re @@ -11,7 +9,7 @@ def set_base_prompt( self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Determine base prompt.""" - return super(DellIsilonSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -20,7 +18,7 @@ def set_base_prompt( def strip_ansi_escape_codes(self, string_buffer): """Remove Null code""" output = re.sub(r"\x00", "", string_buffer) - return super(DellIsilonSSH, self).strip_ansi_escape_codes(output) + return super().strip_ansi_escape_codes(output) def session_preparation(self): """Prepare the session after the connection has been established.""" @@ -43,7 +41,7 @@ def zsh_mode(self, delay_factor=1, prompt_terminator="$"): self.clear_buffer() def set_prompt(self, prompt_terminator="$"): - prompt = "PROMPT='%m{}'".format(prompt_terminator) + prompt = f"PROMPT='%m{prompt_terminator}'" command = self.RETURN + prompt + self.RETURN self.write_channel(command) @@ -64,7 +62,7 @@ def exit_enable_mode(self, *args, **kwargs): pass def check_config_mode(self, check_string="#"): - return super(DellIsilonSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="sudo su"): """Attempt to become root.""" @@ -85,4 +83,4 @@ def config_mode(self, config_command="sudo su"): def exit_config_mode(self, exit_config="exit"): """Exit enable mode.""" - return super(DellIsilonSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) diff --git a/netmiko/dell/dell_os10_ssh.py b/netmiko/dell/dell_os10_ssh.py index ba34434c3..a9a5581b9 100644 --- a/netmiko/dell/dell_os10_ssh.py +++ b/netmiko/dell/dell_os10_ssh.py @@ -16,7 +16,7 @@ def save_config( confirm_response="", ): """Saves Config""" - return super(DellOS10SSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -25,16 +25,21 @@ class DellOS10FileTransfer(BaseFileTransfer): """Dell EMC Networking OS10 SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/home/admin", + direction="put", + **kwargs, ): - if file_system is None: - file_system = "/home/admin" - super(DellOS10FileTransfer, self).__init__( + super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) self.folder_name = "/config" @@ -45,7 +50,7 @@ def remote_file_size(self, remote_cmd="", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_cmd = 'system "ls -l {}/{}"'.format(self.file_system, remote_file) + remote_cmd = f'system "ls -l {self.file_system}/{remote_file}"' remote_out = self.ssh_ctl_chan.send_command(remote_cmd) for line in remote_out.splitlines(): if remote_file in line: @@ -58,7 +63,7 @@ def remote_file_size(self, remote_cmd="", remote_file=None): def remote_space_available(self, search_pattern=r"(\d+) bytes free"): """Return space available on remote device.""" - remote_cmd = 'system "df {}"'.format(self.folder_name) + remote_cmd = f'system "df {self.folder_name}"' remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) for line in remote_output.splitlines(): if self.folder_name in line: @@ -79,7 +84,7 @@ def remote_md5(self, base_cmd="verify /md5", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = 'system "md5sum {}/{}"'.format(self.file_system, remote_file) + 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.process_md5(dest_md5) return dest_md5.strip() @@ -95,13 +100,13 @@ def check_file_exists(self, remote_cmd="dir home"): def put_file(self): """SCP copy the file from the local system to the remote device.""" - destination = "{}".format(self.dest_file) + 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): """SCP copy the file from the remote device to local system.""" - source_file = "{}".format(self.source_file) + source_file = f"{self.source_file}" self.scp_conn.scp_get_file(source_file, self.dest_file) self.scp_conn.close() diff --git a/netmiko/dell/dell_powerconnect.py b/netmiko/dell/dell_powerconnect.py index b38695f6f..4063495e8 100644 --- a/netmiko/dell/dell_powerconnect.py +++ b/netmiko/dell/dell_powerconnect.py @@ -1,5 +1,4 @@ """Dell PowerConnect Driver.""" -from __future__ import unicode_literals from paramiko import SSHClient import time from os import path @@ -30,7 +29,7 @@ def set_base_prompt( self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(DellPowerConnectBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -41,15 +40,11 @@ def set_base_prompt( def check_config_mode(self, check_string="(config)#"): """Checks if the device is in configuration mode""" - return super(DellPowerConnectBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="config"): """Enter configuration mode.""" - return super(DellPowerConnectBase, self).config_mode( - config_command=config_command - ) + return super().config_mode(config_command=config_command) class DellPowerConnectSSH(DellPowerConnectBase): diff --git a/netmiko/eltex/__init__.py b/netmiko/eltex/__init__.py index 6360b7f78..2e1fdedb3 100644 --- a/netmiko/eltex/__init__.py +++ b/netmiko/eltex/__init__.py @@ -1,4 +1,4 @@ -from __future__ import unicode_literals from netmiko.eltex.eltex_ssh import EltexSSH +from netmiko.eltex.eltex_esr_ssh import EltexEsrSSH -__all__ = ["EltexSSH"] +__all__ = ["EltexSSH", "EltexEsrSSH"] diff --git a/netmiko/eltex/eltex_esr_ssh.py b/netmiko/eltex/eltex_esr_ssh.py new file mode 100644 index 000000000..f3b4f4d2c --- /dev/null +++ b/netmiko/eltex/eltex_esr_ssh.py @@ -0,0 +1,103 @@ +import time +from netmiko.cisco_base_connection import CiscoSSHConnection + + +class EltexEsrSSH(CiscoSSHConnection): + """Netmiko support for routers Eltex ESR.""" + + 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.disable_paging(command="terminal datadump") + + # Clear the read buffer + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + + def config_mode(self, config_command="configure", pattern=r")#"): + """Enter configuration mode.""" + return super().config_mode(config_command=config_command, pattern=pattern) + + def check_config_mode(self, check_string="(config", pattern=""): + """Checks whether in configuration mode. Returns a boolean.""" + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def save_config(self, *args, **kwargs): + """Not Implemented (use commit() method)""" + raise NotImplementedError + + def commit(self, delay_factor=1): + """ + Commit the candidate configuration. + Commit the entered configuration. + Raise an error and return the failure + if the commit fails. + default: + command_string = commit + """ + + delay_factor = self.select_delay_factor(delay_factor) + error_marker = "Can't commit configuration" + command_string = "commit" + + if self.check_config_mode(): + self.exit_config_mode() + + output = self.send_command( + command_string=command_string, delay_factor=delay_factor + ) + + if error_marker in output: + raise ValueError( + "Commit failed with following errors:\n\n{}".format(output) + ) + return output + + def _confirm(self, delay_factor=1): + """ + Confirm the candidate configuration. + Raise an error and return the failure if the confirm fails. + """ + + delay_factor = self.select_delay_factor(delay_factor) + error_marker = "Nothing to confirm in configuration" + command_string = "confirm" + + if self.check_config_mode(): + self.exit_config_mode() + + output = self.send_command( + command_string=command_string, delay_factor=delay_factor + ) + + if error_marker in output: + raise ValueError( + "Confirm failed with following errors:\n\n{}".format(output) + ) + return output + + def _restore(self, delay_factor=1): + """ + Restore the candidate configuration. + + Raise an error and return the failure if the restore fails. + """ + + delay_factor = self.select_delay_factor(delay_factor) + error_marker = "Can't find backup of previous configuration!" + command_string = "restore" + + if self.check_config_mode(): + self.exit_config_mode() + + output = self.send_command( + command_string=command_string, delay_factor=delay_factor + ) + + if error_marker in output: + raise ValueError( + "Restore failed with following errors:\n\n{}".format(output) + ) + return output diff --git a/netmiko/eltex/eltex_ssh.py b/netmiko/eltex/eltex_ssh.py index 6c316ff27..4a62e5111 100644 --- a/netmiko/eltex/eltex_ssh.py +++ b/netmiko/eltex/eltex_ssh.py @@ -1,5 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection diff --git a/netmiko/endace/__init__.py b/netmiko/endace/__init__.py index 1f36a09a2..355e456af 100644 --- a/netmiko/endace/__init__.py +++ b/netmiko/endace/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.endace.endace_ssh import EndaceSSH __all__ = ["EndaceSSH"] diff --git a/netmiko/endace/endace_ssh.py b/netmiko/endace/endace_ssh.py index a1686db1a..e7d5bde26 100644 --- a/netmiko/endace/endace_ssh.py +++ b/netmiko/endace/endace_ssh.py @@ -1,23 +1,16 @@ -from __future__ import unicode_literals - - from netmiko.cisco_base_connection import CiscoSSHConnection import re class EndaceSSH(CiscoSSHConnection): def disable_paging(self, command="no cli session paging enable", delay_factor=1): - return super(EndaceSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def enable(self, cmd="enable", pattern="", re_flags=re.IGNORECASE): - return super(EndaceSSH, self).enable( - cmd=cmd, pattern=pattern, re_flags=re_flags - ) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def check_config_mode(self, check_string="(config) #"): - return super(EndaceSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="conf t", pattern=""): output = "" @@ -34,15 +27,13 @@ def config_mode(self, config_command="conf t", pattern=""): return output def exit_config_mode(self, exit_config="exit", pattern="#"): - return super(EndaceSSH, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def save_config( self, cmd="configuration write", confirm=False, confirm_response="" ): self.enable() self.config_mode() - return super(EndaceSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/enterasys/__init__.py b/netmiko/enterasys/__init__.py index 98d96007f..94f7e275d 100644 --- a/netmiko/enterasys/__init__.py +++ b/netmiko/enterasys/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.enterasys.enterasys_ssh import EnterasysSSH __all__ = ["EnterasysSSH"] diff --git a/netmiko/enterasys/enterasys_ssh.py b/netmiko/enterasys/enterasys_ssh.py index c1c701615..277bfd6d7 100644 --- a/netmiko/enterasys/enterasys_ssh.py +++ b/netmiko/enterasys/enterasys_ssh.py @@ -1,5 +1,4 @@ """Enterasys support.""" -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection diff --git a/netmiko/extreme/__init__.py b/netmiko/extreme/__init__.py index 8ce2b1740..ea335856c 100644 --- a/netmiko/extreme/__init__.py +++ b/netmiko/extreme/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.extreme.extreme_ers_ssh import ExtremeErsSSH from netmiko.extreme.extreme_exos import ExtremeExosSSH from netmiko.extreme.extreme_exos import ExtremeExosTelnet diff --git a/netmiko/extreme/extreme_ers_ssh.py b/netmiko/extreme/extreme_ers_ssh.py index c0619af18..9356c97c2 100644 --- a/netmiko/extreme/extreme_ers_ssh.py +++ b/netmiko/extreme/extreme_ers_ssh.py @@ -1,6 +1,4 @@ """Netmiko support for Extreme Ethernet Routing Switch.""" -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -40,6 +38,6 @@ def special_login_handler(self, delay_factor=1): def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeErsSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/extreme/extreme_exos.py b/netmiko/extreme/extreme_exos.py index 20ad9e9c9..e50fb51f5 100644 --- a/netmiko/extreme/extreme_exos.py +++ b/netmiko/extreme/extreme_exos.py @@ -1,5 +1,4 @@ """Extreme support.""" -from __future__ import unicode_literals import time import re from netmiko.cisco_base_connection import CiscoSSHConnection @@ -35,7 +34,7 @@ def set_base_prompt(self, *args, **kwargs): * testhost.4 # * testhost.5 # """ - cur_base_prompt = super(ExtremeExosBase, self).set_base_prompt(*args, **kwargs) + cur_base_prompt = super().set_base_prompt(*args, **kwargs) # Strip off any leading * or whitespace chars; strip off trailing period and digits match = re.search(r"[\*\s]*(.*)\.\d+", cur_base_prompt) if match: @@ -52,7 +51,7 @@ def send_command(self, *args, **kwargs): # refresh self.base_prompt self.set_base_prompt() - return super(ExtremeExosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def config_mode(self, config_command=""): """No configuration mode on Extreme Exos.""" @@ -60,7 +59,7 @@ def config_mode(self, config_command=""): def check_config_mode(self, check_string="#"): """Checks whether in configuration mode. Returns a boolean.""" - return super(ExtremeExosBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def exit_config_mode(self, exit_config=""): """No configuration mode on Extreme Exos.""" @@ -70,7 +69,7 @@ def save_config( self, cmd="save configuration primary", confirm=False, confirm_response="" ): """Saves configuration.""" - return super(ExtremeExosBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -83,4 +82,4 @@ class ExtremeExosTelnet(ExtremeExosBase): 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(ExtremeExosTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) diff --git a/netmiko/extreme/extreme_netiron.py b/netmiko/extreme/extreme_netiron.py index caff4b610..b12a5ac9b 100644 --- a/netmiko/extreme/extreme_netiron.py +++ b/netmiko/extreme/extreme_netiron.py @@ -1,11 +1,10 @@ -from __future__ import unicode_literals from netmiko.cisco_base_connection import CiscoSSHConnection class ExtremeNetironBase(CiscoSSHConnection): def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeNetironBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -18,4 +17,4 @@ class ExtremeNetironTelnet(ExtremeNetironBase): 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(ExtremeNetironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) diff --git a/netmiko/extreme/extreme_nos_ssh.py b/netmiko/extreme/extreme_nos_ssh.py index 04e9425ab..08bdb802e 100644 --- a/netmiko/extreme/extreme_nos_ssh.py +++ b/netmiko/extreme/extreme_nos_ssh.py @@ -1,5 +1,4 @@ """Support for Extreme NOS/VDX.""" -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -28,6 +27,6 @@ def save_config( confirm_response="y", ): """Save Config for Extreme VDX.""" - return super(ExtremeNosSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/extreme/extreme_slx_ssh.py b/netmiko/extreme/extreme_slx_ssh.py index 368ca50b6..e0e008c2e 100644 --- a/netmiko/extreme/extreme_slx_ssh.py +++ b/netmiko/extreme/extreme_slx_ssh.py @@ -1,5 +1,4 @@ """Support for Extreme SLX.""" -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -28,6 +27,6 @@ def save_config( confirm_response="y", ): """Save Config for Extreme SLX.""" - return super(ExtremeSlxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/extreme/extreme_vsp_ssh.py b/netmiko/extreme/extreme_vsp_ssh.py index 05f5f356f..77bf447b2 100644 --- a/netmiko/extreme/extreme_vsp_ssh.py +++ b/netmiko/extreme/extreme_vsp_ssh.py @@ -1,6 +1,4 @@ """Extreme Virtual Services Platform Support.""" -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -19,6 +17,6 @@ def session_preparation(self): def save_config(self, cmd="save config", confirm=False, confirm_response=""): """Save Config""" - return super(ExtremeVspSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/extreme/extreme_wing_ssh.py b/netmiko/extreme/extreme_wing_ssh.py index 7d737390c..e1c5b64a2 100644 --- a/netmiko/extreme/extreme_wing_ssh.py +++ b/netmiko/extreme/extreme_wing_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection diff --git a/netmiko/f5/__init__.py b/netmiko/f5/__init__.py index 79a0c9d17..93891c9e6 100644 --- a/netmiko/f5/__init__.py +++ b/netmiko/f5/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.f5.f5_tmsh_ssh import F5TmshSSH from netmiko.f5.f5_linux_ssh import F5LinuxSSH diff --git a/netmiko/f5/f5_linux_ssh.py b/netmiko/f5/f5_linux_ssh.py index 3f31c38a5..341b3fc56 100644 --- a/netmiko/f5/f5_linux_ssh.py +++ b/netmiko/f5/f5_linux_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.linux.linux_ssh import LinuxSSH diff --git a/netmiko/f5/f5_tmsh_ssh.py b/netmiko/f5/f5_tmsh_ssh.py index a66d00aa8..819bea891 100644 --- a/netmiko/f5/f5_tmsh_ssh.py +++ b/netmiko/f5/f5_tmsh_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.base_connection import BaseConnection @@ -21,7 +20,7 @@ def tmsh_mode(self, delay_factor=1): """tmsh command is equivalent to config command on F5.""" delay_factor = self.select_delay_factor(delay_factor) self.clear_buffer() - command = "{}tmsh{}".format(self.RETURN, self.RETURN) + command = f"{self.RETURN}tmsh{self.RETURN}" self.write_channel(command) time.sleep(1 * delay_factor) self.clear_buffer() diff --git a/netmiko/flexvnf/__init__.py b/netmiko/flexvnf/__init__.py index 427b8351b..77d0bc6d6 100644 --- a/netmiko/flexvnf/__init__.py +++ b/netmiko/flexvnf/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.flexvnf.flexvnf_ssh import FlexvnfSSH __all__ = ["FlexvnfSSH"] diff --git a/netmiko/flexvnf/flexvnf_ssh.py b/netmiko/flexvnf/flexvnf_ssh.py index 2933d86d0..a70e4ad7f 100644 --- a/netmiko/flexvnf/flexvnf_ssh.py +++ b/netmiko/flexvnf/flexvnf_ssh.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import re import time @@ -57,11 +55,11 @@ def exit_enable_mode(self, *args, **kwargs): def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(FlexvnfSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(FlexvnfSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -137,7 +135,7 @@ def commit( if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -164,15 +162,13 @@ def commit( ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(FlexvnfSSH, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): diff --git a/netmiko/fortinet/__init__.py b/netmiko/fortinet/__init__.py index 9dab0592a..35d7be570 100644 --- a/netmiko/fortinet/__init__.py +++ b/netmiko/fortinet/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.fortinet.fortinet_ssh import FortinetSSH __all__ = ["FortinetSSH"] diff --git a/netmiko/fortinet/fortinet_ssh.py b/netmiko/fortinet/fortinet_ssh.py index 79fc8274e..e617546e6 100644 --- a/netmiko/fortinet/fortinet_ssh.py +++ b/netmiko/fortinet/fortinet_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import paramiko import time import re @@ -17,6 +16,21 @@ def _modify_connection_params(self): def session_preparation(self): """Prepare the session after the connection has been established.""" + delay_factor = self.select_delay_factor(delay_factor=0) + output = "" + + # If "set post-login-banner enable" is set it will require you to press 'a' + # to accept the banner before you login. This will accept if it occurs + count = 1 + while count <= 30: + output += self.read_channel() + if "to accept" in output: + self.write_channel("a\r") + break + else: + time.sleep(0.33 * delay_factor) + count += 1 + self._test_channel_read() self.set_base_prompt(alt_prompt_terminator="$") self.disable_paging() @@ -75,7 +89,7 @@ def cleanup(self): """Re-enable paging globally.""" if self.allow_disable_global: # Return paging state - output_mode_cmd = "set output {}".format(self._output_mode) + output_mode_cmd = f"set output {self._output_mode}" enable_paging_commands = ["config system console", output_mode_cmd, "end"] if self.vdoms: enable_paging_commands.insert(0, "config global") diff --git a/netmiko/hp/__init__.py b/netmiko/hp/__init__.py index 5fb748db9..097cb7217 100644 --- a/netmiko/hp/__init__.py +++ b/netmiko/hp/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.hp.hp_procurve import HPProcurveSSH, HPProcurveTelnet from netmiko.hp.hp_comware import HPComwareSSH, HPComwareTelnet diff --git a/netmiko/hp/hp_comware.py b/netmiko/hp/hp_comware.py index 247783f37..6e3524762 100644 --- a/netmiko/hp/hp_comware.py +++ b/netmiko/hp/hp_comware.py @@ -1,5 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -31,17 +29,15 @@ def session_preparation(self): def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HPComwareBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit config mode.""" - return super(HPComwareBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Check whether device is in configuration mode. Return a boolean.""" - return super(HPComwareBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def set_base_prompt( self, pri_prompt_terminator=">", alt_prompt_terminator="]", delay_factor=1 @@ -56,7 +52,7 @@ def set_base_prompt( This will be set on logging in, but not when entering system-view """ - prompt = super(HPComwareBase, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -82,7 +78,7 @@ def check_enable_mode(self, check_string="]"): def save_config(self, cmd="save force", confirm=False, confirm_response=""): """Save Config.""" - return super(HPComwareBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -95,4 +91,4 @@ class HPComwareTelnet(HPComwareBase): 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(HPComwareTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) diff --git a/netmiko/hp/hp_procurve.py b/netmiko/hp/hp_procurve.py index e09e9f91c..745efb514 100644 --- a/netmiko/hp/hp_procurve.py +++ b/netmiko/hp/hp_procurve.py @@ -1,5 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals import re import time import socket @@ -42,19 +40,39 @@ def enable( default_username="manager", ): """Enter enable mode""" + delay_factor = self.select_delay_factor(delay_factor=0) if self.check_enable_mode(): return "" - output = self.send_command_timing(cmd) - if ( - "username" in output.lower() - or "login name" in output.lower() - or "user name" in output.lower() - ): - output += self.send_command_timing(default_username) - if "password" in output.lower(): - output += self.send_command_timing(self.secret) - log.debug("{}".format(output)) + + output = "" + i = 1 + max_attempts = 5 + while i <= max_attempts: + self.write_channel(cmd + self.RETURN) + time.sleep(0.3 * delay_factor) + new_output = self.read_channel() + username_pattern = r"(username|login|user name)" + if re.search(username_pattern, new_output, flags=re_flags): + output += new_output + new_output = self.send_command_timing(default_username) + if re.search(pattern, new_output, flags=re_flags): + output += new_output + self.write_channel(self.normalize_cmd(self.secret)) + new_output = self._read_channel_timing() + if self.check_enable_mode(): + output += new_output + return output + output += new_output + i += 1 + + log.debug(f"{output}") self.clear_buffer() + msg = ( + "Failed to enter enable mode. Please ensure you pass " + "the 'secret' argument to ConnectHandler." + ) + if not self.check_enable_mode(): + raise ValueError(msg) return output def cleanup(self): @@ -81,7 +99,7 @@ def cleanup(self): def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Save Config.""" - return super(HPProcurveBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -107,7 +125,7 @@ def session_preparation(self): # Try one last time to past "Press any key to continue self.write_channel(self.RETURN) - super(HPProcurveSSH, self).session_preparation() + super().session_preparation() def _build_ssh_client(self): """Allow passwordless authentication for HP devices being provisioned.""" @@ -140,7 +158,7 @@ def telnet_login( max_loops=60, ): """Telnet login: can be username/password or just password.""" - super(HPProcurveTelnet, self).telnet_login( + super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, diff --git a/netmiko/huawei/__init__.py b/netmiko/huawei/__init__.py index 3e7a956f1..6b7d814d1 100644 --- a/netmiko/huawei/__init__.py +++ b/netmiko/huawei/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.huawei.huawei import HuaweiSSH, HuaweiVrpv8SSH from netmiko.huawei.huawei import HuaweiTelnet diff --git a/netmiko/huawei/huawei.py b/netmiko/huawei/huawei.py index de05886cf..1d758b3c3 100644 --- a/netmiko/huawei/huawei.py +++ b/netmiko/huawei/huawei.py @@ -1,9 +1,7 @@ -from __future__ import print_function -from __future__ import unicode_literals import time import re from netmiko.cisco_base_connection import CiscoBaseConnection -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoAuthenticationException from netmiko import log @@ -19,17 +17,15 @@ def session_preparation(self): def config_mode(self, config_command="system-view"): """Enter configuration mode.""" - return super(HuaweiBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="return", pattern=r">"): """Exit configuration mode.""" - return super(HuaweiBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def check_config_mode(self, check_string="]"): """Checks whether in configuration mode. Returns a boolean.""" - return super(HuaweiBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def check_enable_mode(self, *args, **kwargs): """Huawei has no enable mode.""" @@ -71,7 +67,7 @@ def set_base_prompt( # Check that ends with a valid terminator character if not prompt[-1] in (pri_prompt_terminator, alt_prompt_terminator): - raise ValueError("Router prompt not found: {0}".format(prompt)) + raise ValueError(f"Router prompt not found: {prompt}") # Strip off any leading HRP_. characters for USGv5 HA prompt = re.sub(r"^HRP_.", "", prompt, flags=re.M) @@ -80,13 +76,13 @@ def set_base_prompt( prompt = prompt[1:-1] prompt = prompt.strip() self.base_prompt = prompt - log.debug("prompt: {0}".format(self.base_prompt)) + log.debug(f"prompt: {self.base_prompt}") return self.base_prompt - def save_config(self, cmd="save", confirm=False, confirm_response=""): + def save_config(self, cmd="save", confirm=True, confirm_response="y"): """ Save Config for HuaweiSSH""" - return super(HuaweiBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -94,7 +90,15 @@ def save_config(self, cmd="save", confirm=False, confirm_response=""): class HuaweiSSH(HuaweiBase): """Huawei SSH driver.""" - pass + def special_login_handler(self): + """Handle password change request by ignoring it""" + + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" + output = self.read_until_prompt_or_pattern(password_change_prompt) + if re.search(password_change_prompt, output): + self.write_channel("N\n") + self.clear_buffer() + return output class HuaweiTelnet(HuaweiBase): @@ -112,7 +116,7 @@ def telnet_login( """Telnet login for Huawei Devices""" delay_factor = self.select_delay_factor(delay_factor) - password_change_prompt = re.escape("Change now? [Y/N]") + password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+" combined_pattern = r"({}|{}|{})".format( pri_prompt_terminator, alt_prompt_terminator, password_change_prompt ) @@ -161,8 +165,8 @@ def telnet_login( except EOFError: self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) # Last try to see if we already logged in self.write_channel(self.TELNET_RETURN) @@ -175,8 +179,8 @@ def telnet_login( return return_msg self.remote_conn.close() - msg = "Login failed: {}".format(self.host) - raise NetMikoAuthenticationException(msg) + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) class HuaweiVrpv8SSH(HuaweiSSH): @@ -198,7 +202,7 @@ def commit(self, comment="", delay_factor=1): command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -211,9 +215,7 @@ def commit(self, comment="", delay_factor=1): output += self.exit_config_mode() if error_marker in output: - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def save_config(self, *args, **kwargs): diff --git a/netmiko/ipinfusion/__init__.py b/netmiko/ipinfusion/__init__.py index 974022d6d..a6781fe64 100644 --- a/netmiko/ipinfusion/__init__.py +++ b/netmiko/ipinfusion/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.ipinfusion.ipinfusion_ocnos import ( IpInfusionOcNOSSSH, IpInfusionOcNOSTelnet, diff --git a/netmiko/ipinfusion/ipinfusion_ocnos.py b/netmiko/ipinfusion/ipinfusion_ocnos.py index 2e634c482..ff71ee717 100644 --- a/netmiko/ipinfusion/ipinfusion_ocnos.py +++ b/netmiko/ipinfusion/ipinfusion_ocnos.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, TTYPE from netmiko.cisco_base_connection import CiscoBaseConnection @@ -10,7 +9,7 @@ class IpInfusionOcNOSBase(CiscoBaseConnection): def __init__(self, *args, **kwargs): if kwargs.get("default_enter") is None: kwargs["default_enter"] = "\r" - return super(IpInfusionOcNOSBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): self._test_channel_read() @@ -23,7 +22,7 @@ def session_preparation(self): def save_config(self, cmd="write", confirm=False, confirm_response=""): """Saves Config Using write command""" - return super(IpInfusionOcNOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -62,7 +61,7 @@ def telnet_login( ): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(IpInfusionOcNOSTelnet, self).telnet_login( + return super().telnet_login( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, username_pattern=username_pattern, diff --git a/netmiko/juniper/__init__.py b/netmiko/juniper/__init__.py index a57d37af6..fab726fe7 100644 --- a/netmiko/juniper/__init__.py +++ b/netmiko/juniper/__init__.py @@ -1,4 +1,4 @@ -from __future__ import unicode_literals from netmiko.juniper.juniper import JuniperSSH, JuniperTelnet, JuniperFileTransfer +from netmiko.juniper.juniper_screenos import JuniperScreenOsSSH -__all__ = ["JuniperSSH", "JuniperTelnet", "JuniperFileTransfer"] +__all__ = ["JuniperSSH", "JuniperTelnet", "JuniperFileTransfer", "JuniperScreenOsSSH"] diff --git a/netmiko/juniper/juniper.py b/netmiko/juniper/juniper.py index 962a5f33b..b7fa4a0c3 100644 --- a/netmiko/juniper/juniper.py +++ b/netmiko/juniper/juniper.py @@ -1,11 +1,8 @@ -from __future__ import unicode_literals - import re import time from netmiko.base_connection import BaseConnection from netmiko.scp_handler import BaseFileTransfer -from netmiko.py23_compat import text_type class JuniperBase(BaseConnection): @@ -26,6 +23,7 @@ def session_preparation(self): self._test_channel_read() self.enter_cli_mode() self.set_base_prompt() + self._disable_complete_on_space() self.disable_paging(command="set cli screen-length 0") self.set_terminal_width(command="set cli screen-width 511") # Clear the read buffer @@ -40,6 +38,21 @@ def _return_cli(self): """Return to the Juniper CLI.""" return self.send_command("exit", expect_string=r"[#>]") + def _disable_complete_on_space(self): + """ + Juniper tries to auto complete commands when you type a "space" character. + + This is a bad idea for automation as what your program is sending no longer matches + the command echo from the device. So we disable this behavior. + """ + delay_factor = self.select_delay_factor(delay_factor=0) + time.sleep(delay_factor * 0.1) + command = "set cli complete-on-space off" + self.write_channel(self.normalize_cmd(command)) + time.sleep(delay_factor * 0.1) + output = self.read_channel() + return output + def enter_cli_mode(self): """Check if at shell prompt root@ and go into CLI.""" delay_factor = self.select_delay_factor(delay_factor=0) @@ -72,11 +85,11 @@ def exit_enable_mode(self, *args, **kwargs): def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(JuniperBase, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(JuniperBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit configuration-mode"): """Exit configuration mode.""" @@ -142,7 +155,7 @@ def commit( commit_marker = "configuration check succeeds" elif confirm: if confirm_delay: - command_string = "commit confirmed " + text_type(confirm_delay) + command_string = "commit confirmed " + str(confirm_delay) else: command_string = "commit confirmed" commit_marker = "commit confirmed will be automatically rolled back in" @@ -151,7 +164,7 @@ def commit( if comment: if '"' in comment: raise ValueError("Invalid comment contains double quote") - comment = '"{0}"'.format(comment) + comment = f'"{comment}"' command_string += " comment " + comment if and_quit: @@ -178,15 +191,13 @@ def commit( ) if commit_marker not in output: - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_prompt(self, *args, **kwargs): """Strip the trailing router prompt from the output.""" - a_string = super(JuniperBase, self).strip_prompt(*args, **kwargs) + a_string = super().strip_prompt(*args, **kwargs) return self.strip_context_items(a_string) def strip_context_items(self, a_string): @@ -226,21 +237,28 @@ class JuniperTelnet(JuniperBase): 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(JuniperTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class JuniperFileTransfer(BaseFileTransfer): """Juniper SCP File Transfer driver.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(JuniperFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -258,9 +276,7 @@ def remote_file_size(self, remote_cmd="", remote_file=None): ) def remote_md5(self, base_cmd="file checksum md5", remote_file=None): - return super(JuniperFileTransfer, self).remote_md5( - base_cmd=base_cmd, remote_file=remote_file - ) + return super().remote_md5(base_cmd=base_cmd, remote_file=remote_file) def enable_scp(self, cmd=None): raise NotImplementedError diff --git a/netmiko/juniper/juniper_screenos.py b/netmiko/juniper/juniper_screenos.py new file mode 100644 index 000000000..0d826c8a2 --- /dev/null +++ b/netmiko/juniper/juniper_screenos.py @@ -0,0 +1,50 @@ +import time +from netmiko.base_connection import BaseConnection + + +class JuniperScreenOsSSH(BaseConnection): + """ + Implement methods for interacting with Juniper ScreenOS devices. + """ + + def session_preparation(self): + """ + Prepare the session after the connection has been established. + + Disable paging (the '--more--' prompts). + Set the base prompt for interaction ('>'). + """ + self._test_channel_read() + 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=""): + """Save Config.""" + return self.send_command(command_string=cmd) diff --git a/netmiko/keymile/__init__.py b/netmiko/keymile/__init__.py index af5611912..d96095cfb 100644 --- a/netmiko/keymile/__init__.py +++ b/netmiko/keymile/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.keymile.keymile_ssh import KeymileSSH from netmiko.keymile.keymile_nos_ssh import KeymileNOSSSH diff --git a/netmiko/keymile/keymile_nos_ssh.py b/netmiko/keymile/keymile_nos_ssh.py index 397bc710e..f9bb57d20 100644 --- a/netmiko/keymile/keymile_nos_ssh.py +++ b/netmiko/keymile/keymile_nos_ssh.py @@ -3,7 +3,7 @@ from netmiko.cisco.cisco_ios import CiscoIosBase -from netmiko.ssh_exception import NetMikoAuthenticationException +from netmiko.ssh_exception import NetmikoAuthenticationException class KeymileNOSSSH(CiscoIosBase): @@ -17,18 +17,14 @@ def session_preparation(self): def _test_channel_read(self, count=40, pattern=""): """Since Keymile NOS always returns True on paramiko.connect() we check the output for substring Login incorrect after connecting.""" - output = super(KeymileNOSSSH, self)._test_channel_read( - count=count, pattern=pattern - ) + output = super()._test_channel_read(count=count, pattern=pattern) pattern = r"Login incorrect" if re.search(pattern, output): self.paramiko_cleanup() msg = "Authentication failure: unable to connect" - msg += "{device_type} {host}:{port}".format( - device_type=self.device_type, host=self.host, port=self.port - ) + msg += f"{self.device_type} {self.host}:{self.port}" msg += self.RESPONSE_RETURN + "Login incorrect" - raise NetMikoAuthenticationException(msg) + raise NetmikoAuthenticationException(msg) else: return output diff --git a/netmiko/keymile/keymile_ssh.py b/netmiko/keymile/keymile_ssh.py index 89cf19015..c338b7686 100644 --- a/netmiko/keymile/keymile_ssh.py +++ b/netmiko/keymile/keymile_ssh.py @@ -6,7 +6,7 @@ class KeymileSSH(CiscoIosBase): def __init__(self, **kwargs): kwargs.setdefault("default_enter", "\r\n") - return super(KeymileSSH, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self): """Prepare the session after the connection has been established.""" @@ -47,10 +47,8 @@ def strip_prompt(self, a_string): """Remove appending empty line and prompt from output""" self._write_session_log(a_string) a_string = a_string[:-1] - return super(KeymileSSH, self).strip_prompt(a_string=a_string) + return super().strip_prompt(a_string=a_string) def set_base_prompt(self, pri_prompt_terminator=">", **kwargs): """ set prompt termination to >""" - return super(KeymileSSH, self).set_base_prompt( - pri_prompt_terminator=pri_prompt_terminator - ) + return super().set_base_prompt(pri_prompt_terminator=pri_prompt_terminator) diff --git a/netmiko/linux/__init__.py b/netmiko/linux/__init__.py index 0aa030d14..ccb938cf7 100644 --- a/netmiko/linux/__init__.py +++ b/netmiko/linux/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.linux.linux_ssh import LinuxSSH, LinuxFileTransfer __all__ = ["LinuxSSH", "LinuxFileTransfer"] diff --git a/netmiko/linux/linux_ssh.py b/netmiko/linux/linux_ssh.py index 41d30499e..441173feb 100644 --- a/netmiko/linux/linux_ssh.py +++ b/netmiko/linux/linux_ssh.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import os import re import socket @@ -7,7 +5,7 @@ from netmiko.cisco_base_connection import CiscoSSHConnection from netmiko.cisco_base_connection import CiscoFileTransfer -from netmiko.ssh_exception import NetMikoTimeoutException +from netmiko.ssh_exception import NetmikoTimeoutException LINUX_PROMPT_PRI = os.getenv("NETMIKO_LINUX_PROMPT_PRI", "$") LINUX_PROMPT_ALT = os.getenv("NETMIKO_LINUX_PROMPT_ALT", "#") @@ -18,7 +16,7 @@ class LinuxSSH(CiscoSSHConnection): def session_preparation(self): """Prepare the session after the connection has been established.""" self.ansi_escape_codes = True - return super(LinuxSSH, self).session_preparation() + return super().session_preparation() def _enter_shell(self): """Already in shell.""" @@ -39,7 +37,7 @@ def set_base_prompt( delay_factor=1, ): """Determine base prompt.""" - return super(LinuxSSH, self).set_base_prompt( + return super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -49,7 +47,7 @@ def send_config_set(self, config_commands=None, exit_config_mode=True, **kwargs) """Can't exit from root (if root)""" if self.username == "root": exit_config_mode = False - return super(LinuxSSH, self).send_config_set( + return super().send_config_set( config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) @@ -57,7 +55,7 @@ def check_config_mode(self, check_string=LINUX_PROMPT_ROOT): """Verify root""" return self.check_enable_mode(check_string=check_string) - def config_mode(self, config_command="sudo su"): + def config_mode(self, config_command="sudo -s"): """Attempt to become root.""" return self.enable(cmd=config_command) @@ -66,7 +64,7 @@ def exit_config_mode(self, exit_config="exit"): def check_enable_mode(self, check_string=LINUX_PROMPT_ROOT): """Verify root""" - return super(LinuxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" @@ -80,7 +78,7 @@ def exit_enable_mode(self, exit_command="exit"): raise ValueError("Failed to exit enable mode.") return output - def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE): + def enable(self, cmd="sudo -s", pattern="ssword", re_flags=re.IGNORECASE): """Attempt to become root.""" delay_factor = self.select_delay_factor(delay_factor=0) output = "" @@ -93,7 +91,7 @@ def enable(self, cmd="sudo su", pattern="ssword", re_flags=re.IGNORECASE): self.write_channel(self.normalize_cmd(self.secret)) self.set_base_prompt() except socket.timeout: - raise NetMikoTimeoutException( + raise NetmikoTimeoutException( "Timed-out reading channel, data not available." ) if not self.check_enable_mode(): @@ -122,14 +120,21 @@ class LinuxFileTransfer(CiscoFileTransfer): """ def __init__( - self, ssh_conn, source_file, dest_file, file_system="/var/tmp", direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system="/var/tmp", + direction="put", + **kwargs, ): - return super(LinuxFileTransfer, self).__init__( + return super().__init__( ssh_conn=ssh_conn, source_file=source_file, dest_file=dest_file, file_system=file_system, direction=direction, + **kwargs, ) def remote_space_available(self, search_pattern=""): @@ -152,7 +157,7 @@ def remote_md5(self, base_cmd="md5sum", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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 ) diff --git a/netmiko/mellanox/__init__.py b/netmiko/mellanox/__init__.py index 1061750b6..33c695273 100644 --- a/netmiko/mellanox/__init__.py +++ b/netmiko/mellanox/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.mellanox.mellanox_mlnxos_ssh import MellanoxMlnxosSSH __all__ = ["MellanoxMlnxosSSH"] diff --git a/netmiko/mellanox/mellanox_mlnxos_ssh.py b/netmiko/mellanox/mellanox_mlnxos_ssh.py index 2b7e9d918..bc0638f5c 100644 --- a/netmiko/mellanox/mellanox_mlnxos_ssh.py +++ b/netmiko/mellanox/mellanox_mlnxos_ssh.py @@ -1,5 +1,4 @@ """Mellanox MLNX-OS Switch support.""" -from __future__ import unicode_literals import re from netmiko.cisco_base_connection import CiscoSSHConnection from netmiko import log @@ -21,19 +20,13 @@ def enable(self, cmd="enable", pattern="#", re_flags=re.IGNORECASE): return output def config_mode(self, config_command="config term", pattern="#"): - return super(MellanoxMlnxosSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string="(config", pattern=r"#"): - return super(MellanoxMlnxosSSH, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + 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(MellanoxMlnxosSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def exit_config_mode(self, exit_config="exit", pattern="#"): """Mellanox does not support a single command to completely exit configuration mode. @@ -54,7 +47,7 @@ def exit_config_mode(self, exit_config="exit", pattern="#"): if self.check_config_mode(): raise ValueError("Failed to exit configuration mode") - log.debug("exit_config_mode: {}".format(output)) + log.debug(f"exit_config_mode: {output}") return output def save_config( diff --git a/netmiko/mikrotik/mikrotik_ssh.py b/netmiko/mikrotik/mikrotik_ssh.py index fd0987a78..68280517b 100644 --- a/netmiko/mikrotik/mikrotik_ssh.py +++ b/netmiko/mikrotik/mikrotik_ssh.py @@ -10,7 +10,7 @@ def __init__(self, **kwargs): self._in_config_mode = False - return super(MikrotikBase, self).__init__(**kwargs) + return super().__init__(**kwargs) def session_preparation(self, *args, **kwargs): """Prepare the session after the connection has been established.""" @@ -30,7 +30,7 @@ def _modify_connection_params(self): """ self.username += "+cetw511h4098" - def disable_paging(self): + def disable_paging(self, *args, **kwargs): """Microtik does not have paging by default.""" return "" diff --git a/netmiko/mrv/__init__.py b/netmiko/mrv/__init__.py index 19fdd9073..8bd3f2901 100644 --- a/netmiko/mrv/__init__.py +++ b/netmiko/mrv/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.mrv.mrv_lx import MrvLxSSH from netmiko.mrv.mrv_ssh import MrvOptiswitchSSH diff --git a/netmiko/mrv/mrv_lx.py b/netmiko/mrv/mrv_lx.py index ed660b3e0..6f3605dc0 100644 --- a/netmiko/mrv/mrv_lx.py +++ b/netmiko/mrv/mrv_lx.py @@ -1,5 +1,4 @@ """MRV Communications Driver (LX).""" -from __future__ import unicode_literals import time import re @@ -21,14 +20,14 @@ def session_preparation(self): def check_enable_mode(self, check_string=">>"): """MRV has a >> for enable mode instead of # like Cisco""" - return super(MrvLxSSH, self).check_enable_mode(check_string=check_string) + return super().check_enable_mode(check_string=check_string) def enable(self, cmd="enable", pattern="assword", re_flags=re.IGNORECASE): """Enter enable mode.""" - return super(MrvLxSSH, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) + return super().enable(cmd=cmd, pattern=pattern, re_flags=re_flags) def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvLxSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/mrv/mrv_ssh.py b/netmiko/mrv/mrv_ssh.py index 04fba130d..4529559ca 100644 --- a/netmiko/mrv/mrv_ssh.py +++ b/netmiko/mrv/mrv_ssh.py @@ -1,5 +1,4 @@ """MRV Communications Driver (OptiSwitch).""" -from __future__ import unicode_literals import time import re @@ -38,6 +37,6 @@ def enable(self, cmd="enable", pattern=r"#", re_flags=re.IGNORECASE): def save_config(self, cmd="save config flash", confirm=False, confirm_response=""): """Saves configuration.""" - return super(MrvOptiswitchSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/netapp/__init__.py b/netmiko/netapp/__init__.py index 050fb3ebf..23d5259fd 100644 --- a/netmiko/netapp/__init__.py +++ b/netmiko/netapp/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.netapp.netapp_cdot_ssh import NetAppcDotSSH __all__ = ["NetAppcDotSSH"] diff --git a/netmiko/netapp/netapp_cdot_ssh.py b/netmiko/netapp/netapp_cdot_ssh.py index aceb20b02..46dd41297 100644 --- a/netmiko/netapp/netapp_cdot_ssh.py +++ b/netmiko/netapp/netapp_cdot_ssh.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from netmiko.base_connection import BaseConnection @@ -19,15 +17,15 @@ def send_command_with_y(self, *args, **kwargs): return output def check_config_mode(self, check_string="*>"): - return super(NetAppcDotSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode( self, config_command="set -privilege diagnostic -confirmations off" ): - return super(NetAppcDotSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="set -privilege admin -confirmations off"): - return super(NetAppcDotSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def enable(self, *args, **kwargs): """No enable mode on NetApp.""" diff --git a/netmiko/netmiko_globals.py b/netmiko/netmiko_globals.py index 801b03c8a..bb021314f 100644 --- a/netmiko/netmiko_globals.py +++ b/netmiko/netmiko_globals.py @@ -1,4 +1,2 @@ -from __future__ import unicode_literals - MAX_BUFFER = 65535 BACKSPACE_CHAR = "\x08" diff --git a/netmiko/nokia/__init__.py b/netmiko/nokia/__init__.py new file mode 100644 index 000000000..87cabb5a3 --- /dev/null +++ b/netmiko/nokia/__init__.py @@ -0,0 +1,3 @@ +from netmiko.nokia.nokia_sros_ssh import NokiaSrosSSH + +__all__ = ["NokiaSrosSSH"] diff --git a/netmiko/nokia/nokia_sros_ssh.py b/netmiko/nokia/nokia_sros_ssh.py new file mode 100644 index 000000000..c5cb38e10 --- /dev/null +++ b/netmiko/nokia/nokia_sros_ssh.py @@ -0,0 +1,158 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright (c) 2014 - 2019 Kirk Byers +# Copyright (c) 2014 - 2019 Twin Bridges Technology +# Copyright (c) 2019 NOKIA Inc. +# MIT License - See License file at: +# https://github.com/ktbyers/netmiko/blob/develop/LICENSE + +import re +import time + +from netmiko import log +from netmiko.base_connection import BaseConnection + + +class NokiaSrosSSH(BaseConnection): + """ + Implement methods for interacting with Nokia SR OS devices. + + Not applicable in Nokia SR OS (disabled): + - enable() + - exit_enable_mode() + - check_enable_mode() + + Overriden methods to adapt Nokia SR OS behavior (changed): + - session_preparation() + - set_base_prompt() + - config_mode() + - exit_config_mode() + - check_config_mode() + - save_config() + - commit() + - strip_prompt() + """ + + def session_preparation(self): + self._test_channel_read() + self.set_base_prompt() + # "@" indicates model-driven CLI (vs Classical CLI) + if "@" in self.base_prompt: + self.disable_paging(command="environment more false") + self.set_terminal_width(command="environment console width 512") + else: + self.disable_paging(command="environment no more") + + # Clear the read buffer + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + + def set_base_prompt(self, *args, **kwargs): + """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 + + def enable(self, *args, **kwargs): + """Nokia SR OS does not support enable-mode""" + return "" + + def check_enable_mode(self, *args, **kwargs): + """Nokia SR OS does not support enable-mode""" + return True + + def exit_enable_mode(self, *args, **kwargs): + """Nokia SR OS does not support enable-mode""" + return "" + + def config_mode(self, config_command="edit-config exclusive", pattern=r"\(ex\)\["): + """Enable config edit-mode for Nokia SR OS""" + output = "" + # Only model-driven CLI supports config-mode + if "@" in self.base_prompt: + output += super().config_mode( + config_command=config_command, pattern=pattern + ) + return output + + def exit_config_mode(self, *args, **kwargs): + """Disable config edit-mode for Nokia SR OS""" + output = self._exit_all() + # Model-driven CLI + if "@" in self.base_prompt and "(ex)[" in output: + # Asterisk indicates changes were made. + if "*(ex)[" in output: + log.warning("Uncommitted changes! Discarding changes!") + output += self._discard() + cmd = "quit-config" + self.write_channel(self.normalize_cmd(cmd)) + output += self.read_until_pattern(pattern=re.escape(cmd)) + 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"@"): + """Check config mode for Nokia SR OS""" + if "@" not in self.base_prompt: + # Classical CLI + return False + else: + # Model-driven CLI look for "exclusive" + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def save_config(self, *args, **kwargs): + """Persist configuration to cflash for Nokia SR OS""" + output = self.send_command(command_string="/admin save") + return output + + def send_config_set(self, config_commands=None, exit_config_mode=None, **kwargs): + """Model driven CLI requires you not exit from configuration mode.""" + if exit_config_mode is None: + # Set to False if model-driven CLI + exit_config_mode = False if "@" in self.base_prompt else True + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs + ) + + def commit(self, *args, **kwargs): + """Activate changes from private candidate for Nokia SR OS""" + output = self._exit_all() + if "@" in self.base_prompt and "*(ex)[" in output: + log.info("Apply uncommitted changes!") + cmd = "commit" + self.write_channel(self.normalize_cmd(cmd)) + output += self.read_until_pattern(pattern=re.escape(cmd)) + output += self.read_until_pattern(r"@") + return output + + def _exit_all(self): + """Return to the 'root' context.""" + exit_cmd = "exit all" + self.write_channel(self.normalize_cmd(exit_cmd)) + # Make sure you read until you detect the command echo (avoid getting out of sync) + return self.read_until_pattern(pattern=re.escape(exit_cmd)) + + def _discard(self): + """Discard changes from private candidate for Nokia SR OS""" + output = "" + if "@" in self.base_prompt: + cmd = "discard" + self.write_channel(self.normalize_cmd(cmd)) + new_output = self.read_until_pattern(pattern=re.escape(cmd)) + if "@" not in new_output: + new_output += self.read_until_prompt() + output += new_output + return output + + def strip_prompt(self, *args, **kwargs): + """Strip prompt from the output.""" + output = super().strip_prompt(*args, **kwargs) + if "@" in self.base_prompt: + # Remove context prompt too + strips = r"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[\S*\][\r\n]*" + return re.sub(strips, "", output) + else: + return output diff --git a/netmiko/oneaccess/__init__.py b/netmiko/oneaccess/__init__.py index 7096c8e24..a3d597813 100644 --- a/netmiko/oneaccess/__init__.py +++ b/netmiko/oneaccess/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.oneaccess.oneaccess_oneos import OneaccessOneOSSSH, OneaccessOneOSTelnet __all__ = ["OneaccessOneOSSSH", "OneaccessOneOSTelnet"] diff --git a/netmiko/oneaccess/oneaccess_oneos.py b/netmiko/oneaccess/oneaccess_oneos.py index 192437b97..bb3acb438 100644 --- a/netmiko/oneaccess/oneaccess_oneos.py +++ b/netmiko/oneaccess/oneaccess_oneos.py @@ -1,8 +1,4 @@ """Netmiko driver for OneAccess ONEOS""" - -from __future__ import print_function -from __future__ import unicode_literals - from netmiko.cisco_base_connection import CiscoBaseConnection import time @@ -12,7 +8,7 @@ def __init__(self, *args, **kwargs): """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(OneaccessOneOSBase, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def session_preparation(self): """Prepare connection - disable paging""" @@ -26,7 +22,7 @@ def session_preparation(self): def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Save config: write mem""" - return super(OneaccessOneOSBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/ovs/__init__.py b/netmiko/ovs/__init__.py index 484cbf055..0177060af 100644 --- a/netmiko/ovs/__init__.py +++ b/netmiko/ovs/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.ovs.ovs_linux_ssh import OvsLinuxSSH __all__ = ["OvsLinuxSSH"] diff --git a/netmiko/ovs/ovs_linux_ssh.py b/netmiko/ovs/ovs_linux_ssh.py index efd76d20d..847f66ab9 100644 --- a/netmiko/ovs/ovs_linux_ssh.py +++ b/netmiko/ovs/ovs_linux_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.linux.linux_ssh import LinuxSSH diff --git a/netmiko/paloalto/__init__.py b/netmiko/paloalto/__init__.py index 1ec3f3299..50d005bf0 100644 --- a/netmiko/paloalto/__init__.py +++ b/netmiko/paloalto/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.paloalto.paloalto_panos import PaloAltoPanosSSH, PaloAltoPanosTelnet __all__ = ["PaloAltoPanosSSH", "PaloAltoPanosTelnet"] diff --git a/netmiko/paloalto/paloalto_panos.py b/netmiko/paloalto/paloalto_panos.py index 4a34aa0e9..ae3da0f72 100644 --- a/netmiko/paloalto/paloalto_panos.py +++ b/netmiko/paloalto/paloalto_panos.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time import re from netmiko.base_connection import BaseConnection @@ -40,19 +39,15 @@ def exit_enable_mode(self, *args, **kwargs): def check_config_mode(self, check_string="]"): """Checks if the device is in configuration mode or not.""" - return super(PaloAltoPanosBase, self).check_config_mode( - check_string=check_string - ) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(PaloAltoPanosBase, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit", pattern=r">"): """Exit configuration mode.""" - return super(PaloAltoPanosBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def commit( self, @@ -97,7 +92,7 @@ def commit( if partial: command_string += " partial" if vsys: - command_string += " {0}".format(vsys) + command_string += f" {vsys}" if device_and_network: command_string += " device-and-network" if policy_and_objects: @@ -117,9 +112,7 @@ def commit( ) if commit_marker not in output.lower(): - raise ValueError( - "Commit failed with the following errors:\n\n{0}".format(output) - ) + raise ValueError(f"Commit failed with the following errors:\n\n{output}") return output def strip_command(self, command_string, output): @@ -164,7 +157,7 @@ def send_command_expect(self, *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(PaloAltoPanosBase, self).send_command(*args, **kwargs) + return super().send_command(*args, **kwargs) def cleanup(self): """Gracefully exit the SSH session.""" diff --git a/netmiko/pluribus/pluribus_ssh.py b/netmiko/pluribus/pluribus_ssh.py index 2f5bdb5ce..dacab475f 100644 --- a/netmiko/pluribus/pluribus_ssh.py +++ b/netmiko/pluribus/pluribus_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.base_connection import BaseConnection @@ -7,14 +6,12 @@ class PluribusSSH(BaseConnection): """Common methods for Pluribus.""" def __init__(self, *args, **kwargs): - super(PluribusSSH, self).__init__(*args, **kwargs) + 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(PluribusSSH, self).disable_paging( - command=command, delay_factor=delay_factor - ) + return super().disable_paging(command=command, delay_factor=delay_factor) def session_preparation(self): """Prepare the netmiko session.""" diff --git a/netmiko/py23_compat.py b/netmiko/py23_compat.py deleted file mode 100644 index b3bba6ba7..000000000 --- a/netmiko/py23_compat.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Simplify Python3 compatibility. Modeled after six behavior for small set of things""" -from __future__ import print_function -from __future__ import unicode_literals - -import io -import sys - -PY2 = sys.version_info.major == 2 -PY3 = sys.version_info.major == 3 - -if PY3: - string_types = (str,) - text_type = str - bufferedio_types = io.BufferedIOBase -else: - string_types = (basestring,) # noqa - text_type = unicode # noqa - bufferedio_types = (io.BufferedIOBase, file) # noqa diff --git a/netmiko/quanta/__init__.py b/netmiko/quanta/__init__.py index fb8cf74c6..3e26d6f0b 100644 --- a/netmiko/quanta/__init__.py +++ b/netmiko/quanta/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.quanta.quanta_mesh_ssh import QuantaMeshSSH __all__ = ["QuantaMeshSSH"] diff --git a/netmiko/quanta/quanta_mesh_ssh.py b/netmiko/quanta/quanta_mesh_ssh.py index 0eb724295..0f4886062 100644 --- a/netmiko/quanta/quanta_mesh_ssh.py +++ b/netmiko/quanta/quanta_mesh_ssh.py @@ -1,15 +1,14 @@ -from __future__ import unicode_literals from netmiko.cisco_base_connection import CiscoSSHConnection class QuantaMeshSSH(CiscoSSHConnection): def disable_paging(self, command="no pager", delay_factor=1): """Disable paging""" - return super(QuantaMeshSSH, self).disable_paging(command=command) + return super().disable_paging(command=command) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(QuantaMeshSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def save_config( self, @@ -18,6 +17,6 @@ def save_config( confirm_response="", ): """Saves Config""" - return super(QuantaMeshSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/rad/__init__.py b/netmiko/rad/__init__.py index 120dd8f8d..f41afca6e 100644 --- a/netmiko/rad/__init__.py +++ b/netmiko/rad/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.rad.rad_etx import RadETXSSH from netmiko.rad.rad_etx import RadETXTelnet diff --git a/netmiko/rad/rad_etx.py b/netmiko/rad/rad_etx.py index 115982cac..16a523fbe 100644 --- a/netmiko/rad/rad_etx.py +++ b/netmiko/rad/rad_etx.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals -from __future__ import print_function import time from netmiko.base_connection import BaseConnection @@ -43,9 +41,7 @@ def exit_enable_mode(self, *args, **kwargs): def config_mode(self, config_command="config", pattern=">config"): """Enter into configuration mode on remote device.""" - return super(RadETXBase, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def check_config_mode(self, check_string=">config", pattern=""): """ @@ -53,15 +49,11 @@ def check_config_mode(self, check_string=">config", pattern=""): Rad config starts with baseprompt>config. """ - return super(RadETXBase, self).check_config_mode( - check_string=check_string, pattern=pattern - ) + return super().check_config_mode(check_string=check_string, pattern=pattern) def exit_config_mode(self, exit_config="exit all", pattern="#"): """Exit from configuration mode.""" - return super(RadETXBase, self).exit_config_mode( - exit_config=exit_config, pattern=pattern - ) + return super().exit_config_mode(exit_config=exit_config, pattern=pattern) class RadETXSSH(RadETXBase): @@ -70,7 +62,7 @@ class RadETXSSH(RadETXBase): def __init__(self, **kwargs): # 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(RadETXSSH, self).__init__(**kwargs) + return super().__init__(**kwargs) class RadETXTelnet(RadETXBase): @@ -87,7 +79,7 @@ def telnet_login( password> **** """ self.TELNET_RETURN = self.RETURN - return super(RadETXTelnet, self).telnet_login( + return super().telnet_login( username_pattern=username_pattern, alt_prompt_terminator=alt_prompt_term, **kwargs diff --git a/netmiko/ruckus/__init__.py b/netmiko/ruckus/__init__.py index bed3112cd..dfa47d854 100644 --- a/netmiko/ruckus/__init__.py +++ b/netmiko/ruckus/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.ruckus.ruckus_fastiron import RuckusFastironSSH from netmiko.ruckus.ruckus_fastiron import RuckusFastironTelnet diff --git a/netmiko/ruckus/ruckus_fastiron.py b/netmiko/ruckus/ruckus_fastiron.py index 56d8a0c79..d09ab5718 100644 --- a/netmiko/ruckus/ruckus_fastiron.py +++ b/netmiko/ruckus/ruckus_fastiron.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import re import time from telnetlib import DO, DONT, ECHO, IAC, WILL, WONT @@ -46,8 +45,13 @@ def enable( output += new_data if "ssword" in new_data: self.write_channel(self.normalize_cmd(self.secret)) - output += self.read_until_prompt() - return output + new_data = self.read_until_prompt() + output += new_data + if not re.search( + r"error.*incorrect.*password", new_data, flags=re.I + ): + return output + time.sleep(1) i += 1 @@ -60,7 +64,7 @@ def enable( def save_config(self, cmd="write mem", confirm=False, confirm_response=""): """Saves configuration.""" - return super(RuckusFastironBase, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) @@ -69,7 +73,7 @@ class RuckusFastironTelnet(RuckusFastironBase): 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(RuckusFastironTelnet, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def _process_option(self, tsocket, command, option): """ @@ -87,7 +91,7 @@ def _process_option(self, tsocket, command, option): def telnet_login(self, *args, **kwargs): # set callback function to handle telnet options. self.remote_conn.set_option_negotiation_callback(self._process_option) - return super(RuckusFastironTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs) class RuckusFastironSSH(RuckusFastironBase): diff --git a/netmiko/ruijie/__init__.py b/netmiko/ruijie/__init__.py new file mode 100644 index 000000000..f82157ae7 --- /dev/null +++ b/netmiko/ruijie/__init__.py @@ -0,0 +1,3 @@ +from netmiko.ruijie.ruijie_os import RuijieOSSSH, RuijieOSTelnet + +__all__ = ["RuijieOSSSH", "RuijieOSTelnet"] diff --git a/netmiko/ruijie/ruijie_os.py b/netmiko/ruijie/ruijie_os.py new file mode 100644 index 000000000..8d2b51ee0 --- /dev/null +++ b/netmiko/ruijie/ruijie_os.py @@ -0,0 +1,35 @@ +"""Ruijie RGOS Support""" +from netmiko.cisco_base_connection import CiscoBaseConnection +import time + + +class RuijieOSBase(CiscoBaseConnection): + def session_preparation(self): + """Prepare the session after the connection has been established.""" + self._test_channel_read(pattern=r"[>#]") + self.set_base_prompt() + """Ruijie OS requires enable mode to set terminal width""" + self.enable() + self.disable_paging(command="terminal length 0") + self.set_terminal_width(command="terminal width 256") + # 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=""): + """Save config: write""" + return super().save_config( + cmd=cmd, confirm=confirm, confirm_response=confirm_response + ) + + +class RuijieOSSSH(RuijieOSBase): + + pass + + +class RuijieOSTelnet(RuijieOSBase): + 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) diff --git a/netmiko/scp_functions.py b/netmiko/scp_functions.py index 91d5c8bca..452fcd781 100644 --- a/netmiko/scp_functions.py +++ b/netmiko/scp_functions.py @@ -7,9 +7,6 @@ Currently only supports Cisco IOS and Cisco ASA. """ -from __future__ import print_function -from __future__ import unicode_literals - from netmiko import FileTransfer, InLineTransfer @@ -29,6 +26,7 @@ def file_transfer( disable_md5=False, inline_transfer=False, overwrite_file=False, + socket_timeout=10.0, ): """Use Secure Copy or Inline (IOS-only) to transfer files to/from network devices. @@ -68,6 +66,7 @@ def file_transfer( "source_file": source_file, "dest_file": dest_file, "direction": direction, + "socket_timeout": socket_timeout, } if file_system is not None: scp_args["file_system"] = file_system diff --git a/netmiko/scp_handler.py b/netmiko/scp_handler.py index 452cd71d4..d4cebcd35 100644 --- a/netmiko/scp_handler.py +++ b/netmiko/scp_handler.py @@ -7,14 +7,12 @@ Currently only supports Cisco IOS and Cisco ASA. """ -from __future__ import print_function -from __future__ import unicode_literals - import re import os import hashlib import scp +import platform class SCPConn(object): @@ -24,8 +22,9 @@ class SCPConn(object): Must close the SCP connection to get the file to write to the remote filesystem """ - def __init__(self, ssh_conn): + def __init__(self, ssh_conn, socket_timeout=10.0): self.ssh_ctl_chan = ssh_conn + self.socket_timeout = socket_timeout self.establish_scp_conn() def establish_scp_conn(self): @@ -33,7 +32,9 @@ def establish_scp_conn(self): ssh_connect_params = self.ssh_ctl_chan._connect_params_dict() self.scp_conn = self.ssh_ctl_chan._build_ssh_client() self.scp_conn.connect(**ssh_connect_params) - self.scp_client = scp.SCPClient(self.scp_conn.get_transport()) + self.scp_client = scp.SCPClient( + self.scp_conn.get_transport(), socket_timeout=self.socket_timeout + ) def scp_transfer_file(self, source_file, dest_file): """Put file using SCP (for backwards compatibility).""" @@ -56,12 +57,19 @@ class BaseFileTransfer(object): """Class to manage SCP file transfer and associated SSH control channel.""" def __init__( - self, ssh_conn, source_file, dest_file, file_system=None, direction="put" + self, + ssh_conn, + source_file, + dest_file, + file_system=None, + direction="put", + socket_timeout=10.0, ): self.ssh_ctl_chan = ssh_conn self.source_file = source_file self.dest_file = dest_file self.direction = direction + self.socket_timeout = socket_timeout auto_flag = ( "cisco_ios" in ssh_conn.device_type @@ -96,7 +104,7 @@ def __exit__(self, exc_type, exc_value, traceback): def establish_scp_conn(self): """Establish SCP connection.""" - self.scp_conn = SCPConn(self.ssh_ctl_chan) + self.scp_conn = SCPConn(self.ssh_ctl_chan, socket_timeout=self.socket_timeout) def close_scp_chan(self): """Close the SCP connection to the remote network device.""" @@ -105,7 +113,7 @@ def close_scp_chan(self): def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): """Return space available on remote device.""" - remote_cmd = "dir {}".format(self.file_system) + remote_cmd = f"dir {self.file_system}" remote_output = self.ssh_ctl_chan.send_command_expect(remote_cmd) match = re.search(search_pattern, remote_output) if "kbytes" in match.group(0) or "Kbytes" in match.group(0): @@ -115,7 +123,7 @@ def remote_space_available(self, search_pattern=r"(\d+) \w+ free"): def _remote_space_available_unix(self, search_pattern=""): """Return space available on *nix system (BSD/Linux).""" self.ssh_ctl_chan._enter_shell() - remote_cmd = "/bin/df -k {}".format(self.file_system) + remote_cmd = f"/bin/df -k {self.file_system}" remote_output = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -149,8 +157,17 @@ def _remote_space_available_unix(self, search_pattern=""): def local_space_available(self): """Return space available on local filesystem.""" - destination_stats = os.statvfs(".") - return destination_stats.f_bsize * destination_stats.f_bavail + if platform.system() == "Windows": + import ctypes + + free_bytes = ctypes.c_ulonglong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceExW( + ctypes.c_wchar_p("."), None, None, ctypes.pointer(free_bytes) + ) + return free_bytes.value + else: + destination_stats = os.statvfs(".") + return destination_stats.f_bsize * destination_stats.f_bavail def verify_space_available(self, search_pattern=r"(\d+) \w+ free"): """Verify sufficient space is available on destination file system (return boolean).""" @@ -166,7 +183,7 @@ def check_file_exists(self, remote_cmd=""): """Check if the dest_file already exists on the file system (return boolean).""" if self.direction == "put": if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, self.dest_file) + remote_cmd = f"dir {self.file_system}/{self.dest_file}" remote_out = self.ssh_ctl_chan.send_command_expect(remote_cmd) search_string = r"Directory of .*{0}".format(self.dest_file) if ( @@ -186,7 +203,7 @@ def _check_file_exists_unix(self, remote_cmd=""): """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 = "ls {}".format(self.file_system) + remote_cmd = f"ls {self.file_system}" remote_out = self.ssh_ctl_chan.send_command( remote_cmd, expect_string=r"[\$#]" ) @@ -203,7 +220,7 @@ def remote_file_size(self, remote_cmd="", remote_file=None): elif self.direction == "get": remote_file = self.source_file if not remote_cmd: - remote_cmd = "dir {}/{}".format(self.file_system, remote_file) + remote_cmd = f"dir {self.file_system}/{remote_file}" remote_out = self.ssh_ctl_chan.send_command(remote_cmd) # Strip out "Directory of flash:/filename line remote_out = re.split(r"Directory of .*", remote_out) @@ -228,9 +245,9 @@ def _remote_file_size_unix(self, remote_cmd="", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_file = "{}/{}".format(self.file_system, remote_file) + remote_file = f"{self.file_system}/{remote_file}" if not remote_cmd: - remote_cmd = "ls -l {}".format(remote_file) + remote_cmd = f"ls -l {remote_file}" self.ssh_ctl_chan._enter_shell() remote_out = self.ssh_ctl_chan.send_command(remote_cmd, expect_string=r"[\$#]") @@ -252,12 +269,27 @@ def _remote_file_size_unix(self, remote_cmd="", remote_file=None): "Search pattern not found for remote file size during SCP transfer." ) - def file_md5(self, file_name): - """Compute MD5 hash of file.""" + def file_md5(self, file_name, add_newline=False): + """Compute MD5 hash of file. + + add_newline is needed to support Cisco IOS MD5 calculation which expects the newline in + the string + + Args: + file_name: name of file to get md5 digest of + add_newline: add newline to end of file contents or not + + """ + file_hash = hashlib.md5() with open(file_name, "rb") as f: - file_contents = f.read() - file_hash = hashlib.md5(file_contents).hexdigest() - return file_hash + while True: + file_contents = f.read(512) + if not file_contents: + if add_newline: + file_contents + b"\n" + break + file_hash.update(file_contents) + return file_hash.hexdigest() @staticmethod def process_md5(md5_output, pattern=r"=\s+(\S+)"): @@ -272,7 +304,7 @@ def process_md5(md5_output, pattern=r"=\s+(\S+)"): if match: return match.group(1) else: - raise ValueError("Invalid output from MD5 command: {}".format(md5_output)) + raise ValueError(f"Invalid output from MD5 command: {md5_output}") def compare_md5(self): """Compare md5 of file on network device to md5 of local file.""" @@ -293,7 +325,7 @@ def remote_md5(self, base_cmd="verify /md5", remote_file=None): remote_file = self.dest_file elif self.direction == "get": remote_file = self.source_file - remote_md5_cmd = "{} {}/{}".format(base_cmd, self.file_system, remote_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.process_md5(dest_md5) return dest_md5 @@ -307,13 +339,13 @@ def transfer_file(self): def get_file(self): """SCP copy the file from the remote device to local system.""" - source_file = "{}/{}".format(self.file_system, self.source_file) + 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): """SCP copy the file from the local system to the remote device.""" - destination = "{}/{}".format(self.file_system, self.dest_file) + 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() diff --git a/netmiko/snmp_autodetect.py b/netmiko/snmp_autodetect.py index 2928def6b..9da6d5269 100644 --- a/netmiko/snmp_autodetect.py +++ b/netmiko/snmp_autodetect.py @@ -20,8 +20,6 @@ Note, pysnmp is a required dependency for SNMPDetect and is intentionally not included in netmiko requirements. So installation of pysnmp might be required. """ -from __future__ import unicode_literals - import re try: @@ -30,7 +28,6 @@ raise ImportError("pysnmp not installed; please install it: 'pip install pysnmp'") from netmiko.ssh_dispatcher import CLASS_MAPPER -from netmiko.py23_compat import text_type # Higher priority indicates a better match. @@ -47,7 +44,7 @@ }, "hp_comware": { "oid": ".1.3.6.1.2.1.1.1.0", - "expr": re.compile(r".*HP Comware.*", re.IGNORECASE), + "expr": re.compile(r".*HP(E)? Comware.*", re.IGNORECASE), "priority": 99, }, "hp_procurve": { @@ -105,6 +102,11 @@ "expr": re.compile(r".*Juniper.*"), "priority": 99, }, + "nokia_sros": { + "oid": ".1.3.6.1.2.1.1.1.0", + "expr": re.compile(r".*TiMOS.*"), + "priority": 99, + }, } # Ensure all SNMP device types are supported by Netmiko @@ -262,7 +264,7 @@ def _get_snmpv3(self, oid): ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmpv2c(self, oid): @@ -291,7 +293,7 @@ def _get_snmpv2c(self, oid): ) if not error_detected and snmp_data[0][1]: - return text_type(snmp_data[0][1]) + return str(snmp_data[0][1]) return "" def _get_snmp(self, oid): @@ -328,15 +330,15 @@ def autodetect(self): oid = v["oid"] regex = v["expr"] - # Used cache data if we already queryied this OID - if self._response_cache.get(oid): - snmp_response = self._response_cache.get(oid) - else: - snmp_response = self._get_snmp(oid) - self._response_cache[oid] = snmp_response + # Used cache data if we already queryied this OID + if self._response_cache.get(oid): + snmp_response = self._response_cache.get(oid) + else: + snmp_response = self._get_snmp(oid) + self._response_cache[oid] = snmp_response - # See if we had a match - if re.search(regex, snmp_response): - return device_type + # See if we had a match + if re.search(regex, snmp_response): + return device_type return None diff --git a/netmiko/ssh_autodetect.py b/netmiko/ssh_autodetect.py index 5838cc43a..524a94195 100644 --- a/netmiko/ssh_autodetect.py +++ b/netmiko/ssh_autodetect.py @@ -38,8 +38,6 @@ >>> remote_device['device_type'] = best_match >>> connection = ConnectHandler(**remote_device) """ -from __future__ import unicode_literals - import re import time from netmiko.ssh_dispatcher import ConnectHandler @@ -262,7 +260,6 @@ def _send_command(self, cmd=""): self.connection.write_channel(cmd + "\n") time.sleep(1) output = self.connection._read_channel_timing() - output = self.connection.strip_ansi_escape_codes(output) output = self.connection.strip_backspaces(output) return output diff --git a/netmiko/ssh_dispatcher.py b/netmiko/ssh_dispatcher.py index 7e40c5b15..893b170f4 100644 --- a/netmiko/ssh_dispatcher.py +++ b/netmiko/ssh_dispatcher.py @@ -1,17 +1,14 @@ """Controls selection of proper class based on the device type.""" -from __future__ import unicode_literals - from netmiko.a10 import A10SSH from netmiko.accedian import AccedianSSH from netmiko.alcatel import AlcatelAosSSH -from netmiko.alcatel import AlcatelSrosSSH from netmiko.arista import AristaSSH, AristaTelnet from netmiko.arista import AristaFileTransfer from netmiko.apresia import ApresiaAeosSSH, ApresiaAeosTelnet from netmiko.aruba import ArubaSSH from netmiko.calix import CalixB6SSH, CalixB6Telnet from netmiko.checkpoint import CheckPointGaiaSSH -from netmiko.ciena import CienaSaosSSH +from netmiko.ciena import CienaSaosSSH, CienaSaosTelnet, CienaSaosFileTransfer from netmiko.cisco import CiscoAsaSSH, CiscoAsaFileTransfer from netmiko.cisco import ( CiscoIosSSH, @@ -34,7 +31,7 @@ from netmiko.dell import DellPowerConnectSSH from netmiko.dell import DellPowerConnectTelnet from netmiko.dell import DellIsilonSSH -from netmiko.eltex import EltexSSH +from netmiko.eltex import EltexSSH, EltexEsrSSH from netmiko.endace import EndaceSSH from netmiko.enterasys import EnterasysSSH from netmiko.extreme import ExtremeErsSSH @@ -53,7 +50,7 @@ from netmiko.hp import HPProcurveSSH, HPProcurveTelnet, HPComwareSSH, HPComwareTelnet from netmiko.huawei import HuaweiSSH, HuaweiVrpv8SSH, HuaweiTelnet from netmiko.ipinfusion import IpInfusionOcNOSSSH, IpInfusionOcNOSTelnet -from netmiko.juniper import JuniperSSH, JuniperTelnet +from netmiko.juniper import JuniperSSH, JuniperTelnet, JuniperScreenOsSSH from netmiko.juniper import JuniperFileTransfer from netmiko.keymile import KeymileSSH, KeymileNOSSSH from netmiko.linux import LinuxSSH, LinuxFileTransfer @@ -63,6 +60,7 @@ from netmiko.mrv import MrvLxSSH from netmiko.mrv import MrvOptiswitchSSH from netmiko.netapp import NetAppcDotSSH +from netmiko.nokia import NokiaSrosSSH from netmiko.oneaccess import OneaccessOneOSTelnet, OneaccessOneOSSSH from netmiko.ovs import OvsLinuxSSH from netmiko.paloalto import PaloAltoPanosSSH @@ -73,6 +71,7 @@ from netmiko.rad import RadETXTelnet from netmiko.ruckus import RuckusFastironSSH from netmiko.ruckus import RuckusFastironTelnet +from netmiko.ruijie import RuijieOSSSH, RuijieOSTelnet from netmiko.terminal_server import TerminalServerSSH from netmiko.terminal_server import TerminalServerTelnet from netmiko.ubiquiti import UbiquitiEdgeSSH @@ -84,7 +83,7 @@ "a10": A10SSH, "accedian": AccedianSSH, "alcatel_aos": AlcatelAosSSH, - "alcatel_sros": AlcatelSrosSSH, + "alcatel_sros": NokiaSrosSSH, "apresia_aeos": ApresiaAeosSSH, "arista_eos": AristaSSH, "aruba_os": ArubaSSH, @@ -117,6 +116,7 @@ "dell_isilon": DellIsilonSSH, "endace": EndaceSSH, "eltex": EltexSSH, + "eltex_esr": EltexEsrSSH, "enterasys": EnterasysSSH, "extreme": ExtremeExosSSH, "extreme_ers": ExtremeErsSSH, @@ -140,6 +140,7 @@ "ipinfusion_ocnos": IpInfusionOcNOSSSH, "juniper": JuniperSSH, "juniper_junos": JuniperSSH, + "juniper_screenos": JuniperScreenOsSSH, "keymile": KeymileSSH, "keymile_nos": KeymileNOSSSH, "linux": LinuxSSH, @@ -151,6 +152,7 @@ "mrv_optiswitch": MrvOptiswitchSSH, "netapp_cdot": NetAppcDotSSH, "netscaler": NetscalerSSH, + "nokia_sros": NokiaSrosSSH, "oneaccess_oneos": OneaccessOneOSSSH, "ovs_linux": OvsLinuxSSH, "paloalto_panos": PaloAltoPanosSSH, @@ -158,6 +160,7 @@ "quanta_mesh": QuantaMeshSSH, "rad_etx": RadETXSSH, "ruckus_fastiron": RuckusFastironSSH, + "ruijie_os": RuijieOSSSH, "ubiquiti_edge": UbiquitiEdgeSSH, "ubiquiti_edgeswitch": UbiquitiEdgeSSH, "vyatta_vyos": VyOSSSH, @@ -166,12 +169,13 @@ FILE_TRANSFER_MAP = { "arista_eos": AristaFileTransfer, + "ciena_saos": CienaSaosFileTransfer, "cisco_asa": CiscoAsaFileTransfer, "cisco_ios": CiscoIosFileTransfer, - "dell_os10": DellOS10FileTransfer, "cisco_nxos": CiscoNxosFileTransfer, "cisco_xe": CiscoIosFileTransfer, "cisco_xr": CiscoXrFileTransfer, + "dell_os10": DellOS10FileTransfer, "juniper_junos": JuniperFileTransfer, "linux": LinuxFileTransfer, } @@ -197,6 +201,7 @@ CLASS_MAPPER["brocade_fastiron_telnet"] = RuckusFastironTelnet CLASS_MAPPER["brocade_netiron_telnet"] = ExtremeNetironTelnet CLASS_MAPPER["calix_b6_telnet"] = CalixB6Telnet +CLASS_MAPPER["ciena_saos_telnet"] = CienaSaosTelnet CLASS_MAPPER["cisco_ios_telnet"] = CiscoIosTelnet CLASS_MAPPER["cisco_xr_telnet"] = CiscoXrTelnet CLASS_MAPPER["dell_dnos6_telnet"] = DellDNOS6Telnet @@ -214,6 +219,7 @@ CLASS_MAPPER["oneaccess_oneos_telnet"] = OneaccessOneOSTelnet CLASS_MAPPER["rad_etx_telnet"] = RadETXTelnet CLASS_MAPPER["ruckus_fastiron_telnet"] = RuckusFastironTelnet +CLASS_MAPPER["ruijie_os_telnet"] = RuijieOSTelnet # Add serial drivers CLASS_MAPPER["cisco_ios_serial"] = CiscoIosSerial diff --git a/netmiko/ssh_exception.py b/netmiko/ssh_exception.py index 92ec5653e..8e553e686 100644 --- a/netmiko/ssh_exception.py +++ b/netmiko/ssh_exception.py @@ -1,15 +1,18 @@ -from __future__ import unicode_literals from paramiko.ssh_exception import SSHException from paramiko.ssh_exception import AuthenticationException -class NetMikoTimeoutException(SSHException): +class NetmikoTimeoutException(SSHException): """SSH session timed trying to connect to the device.""" pass -class NetMikoAuthenticationException(AuthenticationException): +class NetmikoAuthenticationException(AuthenticationException): """SSH authentication exception based on Paramiko AuthenticationException.""" pass + + +NetMikoTimeoutException = NetmikoTimeoutException +NetMikoAuthenticationException = NetmikoAuthenticationException diff --git a/netmiko/terminal_server/__init__.py b/netmiko/terminal_server/__init__.py index 269ee8fce..d8025cef5 100644 --- a/netmiko/terminal_server/__init__.py +++ b/netmiko/terminal_server/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.terminal_server.terminal_server import TerminalServerSSH from netmiko.terminal_server.terminal_server import TerminalServerTelnet diff --git a/netmiko/terminal_server/terminal_server.py b/netmiko/terminal_server/terminal_server.py index 94c2626bc..670ac06e0 100644 --- a/netmiko/terminal_server/terminal_server.py +++ b/netmiko/terminal_server/terminal_server.py @@ -1,5 +1,4 @@ """Generic Terminal Server driver.""" -from __future__ import unicode_literals from netmiko.base_connection import BaseConnection @@ -29,4 +28,4 @@ def telnet_login(self, *args, **kwargs): pass def std_login(self, *args, **kwargs): - return super(TerminalServerTelnet, self).telnet_login(*args, **kwargs) + return super().telnet_login(*args, **kwargs) diff --git a/netmiko/ubiquiti/__init__.py b/netmiko/ubiquiti/__init__.py index 0f74d98f4..066697941 100644 --- a/netmiko/ubiquiti/__init__.py +++ b/netmiko/ubiquiti/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.ubiquiti.edge_ssh import UbiquitiEdgeSSH __all__ = ["UbiquitiEdgeSSH"] diff --git a/netmiko/ubiquiti/edge_ssh.py b/netmiko/ubiquiti/edge_ssh.py index aa5c5133d..9650e9e0b 100644 --- a/netmiko/ubiquiti/edge_ssh.py +++ b/netmiko/ubiquiti/edge_ssh.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -26,22 +25,22 @@ def session_preparation(self): def check_config_mode(self, check_string=")#"): """Checks if the device is in configuration mode or not.""" - return super(UbiquitiEdgeSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure"): """Enter configuration mode.""" - return super(UbiquitiEdgeSSH, self).config_mode(config_command=config_command) + return super().config_mode(config_command=config_command) def exit_config_mode(self, exit_config="exit"): """Exit configuration mode.""" - return super(UbiquitiEdgeSSH, self).exit_config_mode(exit_config=exit_config) + return super().exit_config_mode(exit_config=exit_config) def exit_enable_mode(self, exit_command="exit"): """Exit enable mode.""" - return super(UbiquitiEdgeSSH, self).exit_enable_mode(exit_command=exit_command) + return super().exit_enable_mode(exit_command=exit_command) def save_config(self, cmd="write memory", confirm=False, confirm_response=""): """Saves configuration.""" - return super(UbiquitiEdgeSSH, self).save_config( + return super().save_config( cmd=cmd, confirm=confirm, confirm_response=confirm_response ) diff --git a/netmiko/utilities.py b/netmiko/utilities.py index 1961c714f..c514b9e67 100644 --- a/netmiko/utilities.py +++ b/netmiko/utilities.py @@ -1,13 +1,10 @@ """Miscellaneous utility functions.""" -from __future__ import print_function -from __future__ import unicode_literals - from glob import glob import sys import io import os +from pathlib import Path import serial.tools.list_ports -from netmiko.py23_compat import text_type from netmiko._textfsm import _clitable as clitable from netmiko._textfsm._clitable import CliTableError @@ -71,7 +68,7 @@ def load_yaml_file(yaml_file): with io.open(yaml_file, "rt", encoding="utf-8") as fname: return yaml.safe_load(fname) except IOError: - sys.exit("Unable to open YAML file: {0}".format(yaml_file)) + sys.exit(f"Unable to open YAML file: {yaml_file}") def load_devices(file_name=None): @@ -83,13 +80,10 @@ def load_devices(file_name=None): def find_cfg_file(file_name=None): """ Search for netmiko_tools inventory file in the following order: - NETMIKO_TOOLS_CFG environment variable Current directory Home directory - Look for file named: .netmiko.yml or netmiko.yml - Also allow NETMIKO_TOOLS_CFG to point directly at a file """ if file_name: @@ -102,9 +96,7 @@ def find_cfg_file(file_name=None): # Filter optional_path if null search_paths = [path for path in search_paths if path] for path in search_paths: - files = glob("{}/.netmiko.yml".format(path)) + glob( - "{}/netmiko.yml".format(path) - ) + files = glob(f"{path}/.netmiko.yml") + glob(f"{path}/netmiko.yml") if files: return files[0] raise IOError( @@ -128,8 +120,8 @@ def display_inventory(my_devices): print("\nDevices:") print("-" * 40) for a_device, device_type in inventory_devices: - device_type = " ({})".format(device_type) - print("{:<25}{:>15}".format(a_device, device_type)) + device_type = f" ({device_type})" + print(f"{a_device:<25}{device_type:>15}") print("\n\nGroups:") print("-" * 40) for a_group in inventory_groups: @@ -150,7 +142,7 @@ def obtain_all_devices(my_devices): def obtain_netmiko_filename(device_name): """Create file name based on device_name.""" _, netmiko_full_dir = find_netmiko_dir() - return "{}/{}.txt".format(netmiko_full_dir, device_name) + return f"{netmiko_full_dir}/{device_name}.txt" def write_tmp_file(device_name, output): @@ -169,7 +161,7 @@ def ensure_dir_exists(verify_dir): # Exists if not os.path.isdir(verify_dir): # Not a dir, raise an exception - raise ValueError("{} is not a directory".format(verify_dir)) + raise ValueError(f"{verify_dir} is not a directory") def find_netmiko_dir(): @@ -181,12 +173,12 @@ def find_netmiko_dir(): netmiko_base_dir = os.path.expanduser(netmiko_base_dir) if netmiko_base_dir == "/": raise ValueError("/ cannot be netmiko_base_dir") - netmiko_full_dir = "{}/tmp".format(netmiko_base_dir) + netmiko_full_dir = f"{netmiko_base_dir}/tmp" return (netmiko_base_dir, netmiko_full_dir) def write_bytes(out_data, encoding="ascii"): - """Write Python2 and Python3 compatible byte stream.""" + """Legacy for Python2 and Python3 compatible byte stream.""" if sys.version_info[0] >= 3: if isinstance(out_data, type("")): if encoding == "utf-8": @@ -195,14 +187,6 @@ def write_bytes(out_data, encoding="ascii"): return out_data.encode("ascii", "ignore") elif isinstance(out_data, type(b"")): return out_data - else: - if isinstance(out_data, type("")): - if encoding == "utf-8": - return out_data.encode("utf-8") - else: - return out_data.encode("ascii", "ignore") - elif isinstance(out_data, type(str(""))): - return out_data msg = "Invalid value for out_data neither unicode nor byte string: {}".format( out_data ) @@ -215,11 +199,11 @@ def check_serial_port(name): cdc = next(serial.tools.list_ports.grep(name)) return cdc[0] except StopIteration: - msg = "device {} not found. ".format(name) + msg = f"device {name} not found. " msg += "available devices are: " ports = list(serial.tools.list_ports.comports()) for p in ports: - msg += "{},".format(text_type(p)) + msg += f"{str(p)}," raise ValueError(msg) @@ -257,22 +241,53 @@ def clitable_to_dict(cli_table): return objs -def get_structured_data(raw_output, platform, command): - """Convert raw CLI output to structured data using TextFSM template.""" - template_dir = get_template_dir() - index_file = os.path.join(template_dir, "index") - textfsm_obj = clitable.CliTable(index_file, template_dir) - attrs = {"Command": command, "Platform": platform} +def _textfsm_parse(textfsm_obj, raw_output, attrs, template_file=None): + """Perform the actual TextFSM parsing using the CliTable object.""" try: # Parse output through template - textfsm_obj.ParseCmd(raw_output, attrs) + if template_file is not None: + textfsm_obj.ParseCmd(raw_output, templates=template_file) + else: + textfsm_obj.ParseCmd(raw_output, attrs) structured_data = clitable_to_dict(textfsm_obj) output = raw_output if structured_data == [] else structured_data return output - except CliTableError: + except (FileNotFoundError, CliTableError): return raw_output +def get_structured_data(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. + """ + 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) + return _textfsm_parse(textfsm_obj, raw_output, attrs) + else: + template_path = Path(os.path.expanduser(template)) + template_file = template_path.name + template_dir = template_path.parents[0] + # CliTable with no index will fall-back to a TextFSM parsing behavior + textfsm_obj = clitable.CliTable(template_dir=template_dir) + return _textfsm_parse( + textfsm_obj, raw_output, attrs, template_file=template_file + ) + + def get_structured_data_genie(raw_output, platform, command): if not sys.version_info >= (3, 4): raise ValueError("Genie requires Python >= 3.4") diff --git a/netmiko/vyos/__init__.py b/netmiko/vyos/__init__.py index f169ebabb..b5c586e36 100644 --- a/netmiko/vyos/__init__.py +++ b/netmiko/vyos/__init__.py @@ -1,4 +1,3 @@ -from __future__ import unicode_literals from netmiko.vyos.vyos_ssh import VyOSSSH __all__ = ["VyOSSSH"] diff --git a/netmiko/vyos/vyos_ssh.py b/netmiko/vyos/vyos_ssh.py index e72745541..1efb031ea 100644 --- a/netmiko/vyos/vyos_ssh.py +++ b/netmiko/vyos/vyos_ssh.py @@ -1,5 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -30,13 +28,11 @@ def exit_enable_mode(self, *args, **kwargs): def check_config_mode(self, check_string="#"): """Checks if the device is in configuration mode""" - return super(VyOSSSH, self).check_config_mode(check_string=check_string) + return super().check_config_mode(check_string=check_string) def config_mode(self, config_command="configure", pattern=r"[edit]"): """Enter configuration mode.""" - return super(VyOSSSH, self).config_mode( - config_command=config_command, pattern=pattern - ) + return super().config_mode(config_command=config_command, pattern=pattern) def exit_config_mode(self, exit_config="exit", pattern=r"exit"): """Exit configuration mode""" @@ -71,7 +67,7 @@ def commit(self, comment="", delay_factor=0.1): command_string = "commit" if comment: - command_string += ' comment "{}"'.format(comment) + command_string += f' comment "{comment}"' output = self.config_mode() output += self.send_command_expect( @@ -82,16 +78,14 @@ def commit(self, comment="", delay_factor=0.1): ) if any(x in output for x in error_marker): - raise ValueError( - "Commit failed with following errors:\n\n{}".format(output) - ) + raise ValueError(f"Commit failed with following errors:\n\n{output}") return output def set_base_prompt( self, pri_prompt_terminator="$", alt_prompt_terminator="#", delay_factor=1 ): """Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output.""" - prompt = super(VyOSSSH, self).set_base_prompt( + prompt = super().set_base_prompt( pri_prompt_terminator=pri_prompt_terminator, alt_prompt_terminator=alt_prompt_terminator, delay_factor=delay_factor, @@ -100,25 +94,10 @@ def set_base_prompt( self.base_prompt = prompt[:-2].strip() return self.base_prompt - def send_config_set( - self, - config_commands=None, - exit_config_mode=False, - delay_factor=1, - max_loops=150, - strip_prompt=False, - strip_command=False, - config_mode_command=None, - ): + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): """Remain in configuration mode.""" - return super(VyOSSSH, self).send_config_set( - config_commands=config_commands, - exit_config_mode=exit_config_mode, - delay_factor=delay_factor, - max_loops=max_loops, - strip_prompt=strip_prompt, - strip_command=strip_command, - config_mode_command=config_mode_command, + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs ) def save_config(self, *args, **kwargs): diff --git a/release_process.txt b/release_process.txt index 18586bd44..c671ea0d5 100644 --- a/release_process.txt +++ b/release_process.txt @@ -1,6 +1,6 @@ -# Use pynetcio machine -# Use virtual environment = py36_netmiko +# Use pydev1 machine +# Use virtual environment = py3_netmiko # Run the following command to update docs: $ pdoc3 --html --output-dir docs netmiko --force diff --git a/requirements-dev.txt b/requirements-dev.txt index ac8f0e9e5..280e97067 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,8 +1,8 @@ -PyYAML==5.1 -pytest==4.6.3 +PyYAML==5.1.2 +pytest==5.1.2 pylama==7.7.1 -tox==3.13.1 +tox==3.13.2 twine==1.13.0 -pysnmp==4.4.9 -pdoc3==0.6.2; python_version >= '3.6' +pysnmp==4.4.11 +pdoc3==0.6.3 -r requirements.txt diff --git a/requirements-genie.txt b/requirements-genie.txt index 707710677..b26dbd6f6 100644 --- a/requirements-genie.txt +++ b/requirements-genie.txt @@ -1,2 +1,3 @@ -pyats>=19.7; python_version>="3.4" -genie>=19.7; python_version>="3.4" +# pyats and genie are not available for Python 3.8 yet +pyats>=19.7; python_version<"3.8" +genie>=19.7; python_version<"3.8" diff --git a/setup.cfg b/setup.cfg index d3d9701fc..db0a5cd89 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,10 @@ license_file = LICENSE [pylama] linters = mccabe,pep8,pyflakes ignore = D203,C901 -skip = tests/*,build/*,.tox/*,netmiko/_textfsm/*,examples/use_cases/* +skip = build/*,.tox/*,netmiko/_textfsm/*,examples/use_cases/* [pylama:pep8] max_line_length = 100 + +[tool:pytest] +addopts = -rs diff --git a/setup.py b/setup.py index 84588a942..59c9fb7ba 100644 --- a/setup.py +++ b/setup.py @@ -39,12 +39,10 @@ def find_version(*file_paths): license="MIT", classifiers=[ "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", ], packages=find_packages(exclude=("test*",)), install_requires=[ @@ -53,8 +51,6 @@ def find_version(*file_paths): "scp>=0.13.2", "pyserial", "textfsm", - 'enum34; python_version == "2.7"', - 'ipaddress; python_version == "2.7"', ], - extras_require={"test": ["pyyaml==5.1", "pytest>=4.6.3"]}, + extras_require={"test": ["pyyaml==5.1.2", "pytest>=5.1.2"]}, ) diff --git a/tests/SLOG/cisco881_slog.log b/tests/SLOG/cisco881_slog.log index 7b8e1e87c..d18bd25b0 100644 --- a/tests/SLOG/cisco881_slog.log +++ b/tests/SLOG/cisco881_slog.log @@ -1,21 +1,15 @@ - + cisco1# - cisco1#terminal length 0 -terminal length 0 cisco1#terminal width 511 -terminal width 511 cisco1# - cisco1#show ip interface brief -show ip interface brief -Interface IP-Address OK? Method Status Protocol -FastEthernet0 unassigned YES unset down down -FastEthernet1 unassigned YES unset down down -FastEthernet2 unassigned YES unset down down -FastEthernet3 unassigned YES unset down down -FastEthernet4 10.220.88.20 YES NVRAM up up -Vlan1 unassigned YES unset down down +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down cisco1# - cisco1#exit diff --git a/tests/SLOG/cisco881_slog_append.log b/tests/SLOG/cisco881_slog_append.log index 8ab89db3f..adda598b3 100644 --- a/tests/SLOG/cisco881_slog_append.log +++ b/tests/SLOG/cisco881_slog_append.log @@ -1,16 +1,16 @@ Initial file contents -cisco1# -cisco1#terminal length 0 -cisco1#terminal width 511 -cisco1# -cisco1#show ip interface brief -Interface IP-Address OK? Method Status Protocol -FastEthernet0 unassigned YES unset down down -FastEthernet1 unassigned YES unset down down -FastEthernet2 unassigned YES unset down down -FastEthernet3 unassigned YES unset down down -FastEthernet4 10.220.88.20 YES NVRAM up up -Vlan1 unassigned YES unset down down -cisco1# +cisco1# +cisco1#terminal length 0 +cisco1#terminal width 511 +cisco1# +cisco1#show ip interface brief +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down +cisco1# cisco1#exit diff --git a/tests/SLOG/cisco881_slog_append_compare.log b/tests/SLOG/cisco881_slog_append_compare.log index 24eff7b92..07f326255 100644 --- a/tests/SLOG/cisco881_slog_append_compare.log +++ b/tests/SLOG/cisco881_slog_append_compare.log @@ -1,14 +1,14 @@ -cisco1# -cisco1#terminal length 0 -cisco1#terminal width 511 -cisco1# -cisco1#show ip interface brief -Interface IP-Address OK? Method Status Protocol -FastEthernet0 unassigned YES unset down down -FastEthernet1 unassigned YES unset down down -FastEthernet2 unassigned YES unset down down -FastEthernet3 unassigned YES unset down down -FastEthernet4 10.220.88.20 YES NVRAM up up -Vlan1 unassigned YES unset down down -cisco1# +cisco1# +cisco1#terminal length 0 +cisco1#terminal width 511 +cisco1# +cisco1#show ip interface brief +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down +cisco1# cisco1#exit diff --git a/tests/SLOG/cisco881_slog_compare.log b/tests/SLOG/cisco881_slog_compare.log index 24eff7b92..07f326255 100644 --- a/tests/SLOG/cisco881_slog_compare.log +++ b/tests/SLOG/cisco881_slog_compare.log @@ -1,14 +1,14 @@ -cisco1# -cisco1#terminal length 0 -cisco1#terminal width 511 -cisco1# -cisco1#show ip interface brief -Interface IP-Address OK? Method Status Protocol -FastEthernet0 unassigned YES unset down down -FastEthernet1 unassigned YES unset down down -FastEthernet2 unassigned YES unset down down -FastEthernet3 unassigned YES unset down down -FastEthernet4 10.220.88.20 YES NVRAM up up -Vlan1 unassigned YES unset down down -cisco1# +cisco1# +cisco1#terminal length 0 +cisco1#terminal width 511 +cisco1# +cisco1#show ip interface brief +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down +cisco1# cisco1#exit diff --git a/tests/SLOG/cisco881_slog_wr.log b/tests/SLOG/cisco881_slog_wr.log new file mode 100644 index 000000000..56ea3931b --- /dev/null +++ b/tests/SLOG/cisco881_slog_wr.log @@ -0,0 +1,20 @@ +cisco1# + +cisco1#terminal length 0 +terminal length 0 +cisco1#terminal width 511 +terminal width 511 +cisco1# + +cisco1#show ip interface brief +show ip interface brief +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down +cisco1# + +cisco1#exit diff --git a/tests/SLOG/cisco881_slog_wr_compare.log b/tests/SLOG/cisco881_slog_wr_compare.log index b5d38c8f8..56ea3931b 100644 --- a/tests/SLOG/cisco881_slog_wr_compare.log +++ b/tests/SLOG/cisco881_slog_wr_compare.log @@ -1,20 +1,20 @@ cisco1# - + cisco1#terminal length 0 -terminal length 0 +terminal length 0 cisco1#terminal width 511 -terminal width 511 +terminal width 511 cisco1# - + cisco1#show ip interface brief -show ip interface brief -Interface IP-Address OK? Method Status Protocol -FastEthernet0 unassigned YES unset down down -FastEthernet1 unassigned YES unset down down -FastEthernet2 unassigned YES unset down down -FastEthernet3 unassigned YES unset down down -FastEthernet4 10.220.88.20 YES NVRAM up up -Vlan1 unassigned YES unset down down +show ip interface brief +Interface IP-Address OK? Method Status Protocol +FastEthernet0 unassigned YES unset down down +FastEthernet1 unassigned YES unset down down +FastEthernet2 unassigned YES unset down down +FastEthernet3 unassigned YES unset down down +FastEthernet4 10.220.88.20 YES NVRAM up up +Vlan1 unassigned YES unset down down cisco1# - + cisco1#exit diff --git a/tests/add_delay.sh b/tests/add_delay.sh new file mode 100755 index 000000000..5eef74d75 --- /dev/null +++ b/tests/add_delay.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Add delay for cisco3; must be root or sudo to execute +sudo -s /sbin/tc qdisc del dev eth0 root +sudo -s /sbin/tc qdisc add dev eth0 root handle 1: prio +sudo -s /sbin/tc qdisc add dev eth0 parent 1:3 handle 30: tbf rate 20kbit buffer 1600 limit 3000 +sudo -s /sbin/tc qdisc add dev eth0 parent 30:1 handle 31: netem delay 1000ms 10ms distribution normal loss 10% +sudo -s /sbin/tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 match ip dst 184.105.247.89/32 flowid 1:3 + diff --git a/tests/ciena_saos_commands.txt b/tests/ciena_saos_commands.txt new file mode 100644 index 000000000..f3601eb91 --- /dev/null +++ b/tests/ciena_saos_commands.txt @@ -0,0 +1,3 @@ +system set time-offset 7200 +system set timestamp local +system set time-offset 3600 diff --git a/tests/conftest.py b/tests/conftest.py index 7a07f61a7..4ae802cd0 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,7 +41,7 @@ def net_connect(request): @pytest.fixture() def net_connect_cm(request): """ - Create the SSH connection to the remote device using a context manager + Create the SSH connection to the remote device using a context manager retrieve the find_prompt() data and close the connection. """ device_under_test = request.config.getoption("test_device") @@ -65,6 +65,8 @@ def net_connect_slog_wr(request): test_devices = parse_yaml(PWD + "/etc/test_devices.yml") device = test_devices[device_under_test] device["verbose"] = False + # Overwrite default session_log location + device["session_log"] = "SLOG/cisco881_slog_wr.log" device["session_log_record_writes"] = True conn = ConnectHandler(**device) return conn @@ -140,17 +142,17 @@ def delete_file_ios(ssh_conn, dest_file_system, dest_file): if not dest_file: raise ValueError("Invalid dest file specified") - full_file_name = "{0}/{1}".format(dest_file_system, dest_file) + full_file_name = f"{dest_file_system}/{dest_file}" - cmd = "delete {0}".format(full_file_name) - output = ssh_conn.send_command_timing(cmd) + cmd = f"delete {full_file_name}" + output = ssh_conn.send_command_timing(cmd, delay_factor=2) if "Delete" in output and dest_file in output: - output += ssh_conn.send_command_timing("\n") + output += ssh_conn.send_command_timing("\n", delay_factor=2) if "Delete" in output and full_file_name in output and "confirm" in output: - output += ssh_conn.send_command_timing("y") + output += ssh_conn.send_command_timing("y", delay_factor=2) return output else: - output += ssh_conn.send_command_timing("n") + output += ssh_conn.send_command_timing("n", delay_factor=2) raise ValueError("An error happened deleting file on Cisco IOS") @@ -179,6 +181,14 @@ def delete_file_generic(ssh_conn, dest_file_system, dest_file): return output +def delete_file_ciena_saos(ssh_conn, dest_file_system, dest_file): + """Delete a remote file for a ciena device.""" + full_file_name = "{}/{}".format(dest_file_system, dest_file) + cmd = "file rm {}".format(full_file_name) + output = ssh_conn.send_command_timing(cmd, strip_command=False, strip_prompt=False) + return output + + @pytest.fixture(scope="module") def scp_fixture(request): """ @@ -206,6 +216,9 @@ def scp_fixture(request): platform = device["device_type"] dest_file_system = platform_args[platform]["file_system"] + if "ciena_saos" in platform and ssh_conn.username: + dest_file_system = f"/tmp/users/{ssh_conn.username}" + source_file = "test9.txt" dest_file = "test9.txt" local_file = "testx.txt" @@ -316,7 +329,7 @@ def tcl_fixture(request): @pytest.fixture(scope="module") def ssh_autodetect(request): - """Create an SSH autodetect object. + """Create an SSH autodetect object. return (ssh_conn, real_device_type) """ @@ -422,4 +435,9 @@ def get_platform_args(): "enable_scp": False, "delete_file": delete_file_dellos10, }, + "ciena_saos": { + "file_system": "/tmp/users/ciena", + "enable_scp": False, + "delete_file": delete_file_ciena_saos, + }, } diff --git a/tests/etc/commands.yml.example b/tests/etc/commands.yml.example index 7f06e5c35..d5ab89f59 100644 --- a/tests/etc/commands.yml.example +++ b/tests/etc/commands.yml.example @@ -58,6 +58,14 @@ juniper: rollback: 'rollback 0' commit_verification: "run show system commit" +juniper_screenos: + version: "get system version" + basic: "get route" + extended_output: "get config" # requires paging to be disabled + config: + - 'set alias test "test"' + config_verification: "get config | inc alias" + fortinet: version: "get system status" basic: "get system interface physical" @@ -274,3 +282,15 @@ keymile_nos: save_config_confirm: True save_config_response: '[OK]' +ruijie_os: + version: "show version" + basic: "show ip interface brief" + extended_output: "show version" + config: + - "logging buffered 20000" + - "no logging console" + - "logging buffered 20010" + config_verification: "show run | inc logging buffer" + save_config_cmd: 'write' + save_config_confirm: False + save_config_response: 'OK' diff --git a/tests/etc/responses.yml.example b/tests/etc/responses.yml.example index 1da7517e8..88132f0ff 100644 --- a/tests/etc/responses.yml.example +++ b/tests/etc/responses.yml.example @@ -21,6 +21,16 @@ juniper: cmd_response_final: 'archive size 120k files 3' commit_comment: 'Unit test on commit with comment' +juniper_screenos: + base_prompt: "ssg5-serial-" + router_prompt: "ssg5-serial->" + enable_prompt: "ssg5-serial->" + interface_ip: 100.65.1.1 + multiple_line_output: 'Total Config size' + version_banner: 'Version: 6.3.0.1.0.0.0.0' + cmd_response_init: "" + cmd_response_final: 'set alias test' + paloalto_panos: base_prompt: ntc@pa1 router_prompt: ntc@pa1> @@ -213,3 +223,13 @@ keymile_nos: interface_ip: 1.2.3.5 version_banner: "NOS version 2.09 #0001" multiple_line_output: "Interface br328" + +ruijie_os: + base_prompt: Ruijie + router_prompt : Ruijie> + enable_prompt: Ruijie# + interface_ip: 172.30.31.101 + version_banner: "Ruijie Networks" + multiple_line_output: "" + file_check_cmd: "logging buffered 8880" + save_config: 'OK' diff --git a/tests/etc/test_devices.yml.example b/tests/etc/test_devices.yml.example index 903c99dd4..8abb009c5 100644 --- a/tests/etc/test_devices.yml.example +++ b/tests/etc/test_devices.yml.example @@ -38,6 +38,12 @@ juniper: username: admin password: juniper123 +juniper_screenos: + device_type: juniper_screenos + ip: 100.65.1.1 + username: netscreen + password: netscreen + paloalto_panos: device_type: paloalto_panos ip: 10.10.10.15 @@ -171,3 +177,10 @@ keymile_nos: ip: 1.2.3.5 username: TEST password: TEST + +ruijie_os: + device_type: ruijie_os + ip: 1.1.1.1 + username: ruijie + password: ruijie + secret: ruijie diff --git a/tests/my_test.sh b/tests/my_test.sh new file mode 100755 index 000000000..e15414a67 --- /dev/null +++ b/tests/my_test.sh @@ -0,0 +1,12 @@ +#!/bin/sh +for i in `seq 5` ; do + py.test -s -v test_netmiko_scp.py --test_device cisco3 --pdb + py.test -s -v test_netmiko_show.py --test_device cisco3 --pdb + py.test -s -v test_netmiko_config.py --test_device cisco3 --pdb + py.test -s -v test_netmiko_config_acl.py --test_device cisco3 --pdb + if [ "$?" != "0" ]; then + break + fi +done +# py.test -s -v test_netmiko_show.py --test_device cisco3 +# py.test -s -v test_netmiko_show.py --test_device arista_sw diff --git a/tests/remove_delay.sh b/tests/remove_delay.sh new file mode 100755 index 000000000..4619b5d7f --- /dev/null +++ b/tests/remove_delay.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Remove delay for cisco3; must be root or sudo to execute +sudo -s /sbin/tc qdisc del dev eth0 root diff --git a/tests/test_cisco_ios_serial.py b/tests/test_cisco_ios_serial.py index bafafbf1f..f6c422dc8 100644 --- a/tests/test_cisco_ios_serial.py +++ b/tests/test_cisco_ios_serial.py @@ -3,8 +3,6 @@ This will run an command via serial on an cisco ios switch and so serial cable must be attached to the device """ - -from __future__ import print_function from netmiko import ConnectHandler import serial diff --git a/tests/test_cisco_w_key.py b/tests/test_cisco_w_key.py index c8034b010..be45bde23 100755 --- a/tests/test_cisco_w_key.py +++ b/tests/test_cisco_w_key.py @@ -1,6 +1,4 @@ #!/usr/bin/env python - -from __future__ import print_function from netmiko import ConnectHandler from os import path diff --git a/tests/test_enterasys_switch.py b/tests/test_enterasys_switch.py index c33dc3956..21cd55349 100755 --- a/tests/test_enterasys_switch.py +++ b/tests/test_enterasys_switch.py @@ -3,8 +3,6 @@ This will run an ssh command successfully on an enterasys SSA and so SSH must be enabled on the device """ - -from __future__ import print_function from netmiko import ConnectHandler diff --git a/tests/test_extreme_switch.py b/tests/test_extreme_switch.py index e00bcb07b..5d2089a96 100755 --- a/tests/test_extreme_switch.py +++ b/tests/test_extreme_switch.py @@ -3,8 +3,6 @@ This will run an ssh command successfully on an extreme switch and so SSH must be enabled on the device """ - -from __future__ import print_function from netmiko import ConnectHandler diff --git a/tests/test_import_netmiko.py b/tests/test_import_netmiko.py index 8a9807a10..bf71c9212 100644 --- a/tests/test_import_netmiko.py +++ b/tests/test_import_netmiko.py @@ -1,4 +1,4 @@ -from netmiko import ConnectHandler +from netmiko import ConnectHandler # noqa def test_placeholder(): diff --git a/tests/test_juniper_screenos.sh b/tests/test_juniper_screenos.sh new file mode 100755 index 000000000..0148c6c6f --- /dev/null +++ b/tests/test_juniper_screenos.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +RETURN_CODE=0 + +# Exit on the first test failure and set RETURN_CODE = 1 +echo "Starting tests...good luck:" \ +&& py.test -v test_netmiko_show.py --test_device juniper_screenos \ +&& py.test -v test_netmiko_config.py --test_device juniper_screenos \ +|| RETURN_CODE=1 + +exit $RETURN_CODE diff --git a/tests/test_linux.py b/tests/test_linux.py index f6a4a5032..4926fd96a 100755 --- a/tests/test_linux.py +++ b/tests/test_linux.py @@ -1,6 +1,4 @@ #!/usr/bin/env python - -from __future__ import print_function from netmiko import ConnectHandler diff --git a/tests/test_netmiko_autodetect.py b/tests/test_netmiko_autodetect.py index 72cfb2f7c..7051ee14a 100755 --- a/tests/test_netmiko_autodetect.py +++ b/tests/test_netmiko_autodetect.py @@ -1,9 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals -import time - - def test_ssh_connect(ssh_autodetect): """Verify the connection was established successfully.""" net_conn, real_device_type = ssh_autodetect diff --git a/tests/test_netmiko_commit.py b/tests/test_netmiko_commit.py index f748aa780..4442df9ab 100755 --- a/tests/test_netmiko_commit.py +++ b/tests/test_netmiko_commit.py @@ -90,7 +90,7 @@ def test_config_mode(net_connect, commands, expected_responses): Test enter config mode """ net_connect.config_mode() - assert net_connect.check_config_mode() == True + assert net_connect.check_config_mode() is True def test_commit_base(net_connect, commands, expected_responses): @@ -263,7 +263,7 @@ def test_commit_comment(net_connect, commands, expected_responses): if net_connect.device_type == "cisco_xr": commit_comment = tmp_output else: - commit_comment = tmp_output.split("\n")[2] + commit_comment = tmp_output.strip().split("\n")[1] assert expected_responses.get("commit_comment") in commit_comment.strip() @@ -390,7 +390,7 @@ def test_exit_config_mode(net_connect, commands, expected_responses): """ net_connect.exit_config_mode() time.sleep(1) - assert net_connect.check_config_mode() == False + assert net_connect.check_config_mode() is False def test_disconnect(net_connect, commands, expected_responses): diff --git a/tests/test_netmiko_config.py b/tests/test_netmiko_config.py index 1281a2744..da36d8e8a 100755 --- a/tests/test_netmiko_config.py +++ b/tests/test_netmiko_config.py @@ -1,8 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals - - def test_ssh_connect(net_connect, commands, expected_responses): """ Verify the connection was established successfully @@ -22,15 +18,18 @@ def test_enable_mode(net_connect, commands, expected_responses): enable_prompt = net_connect.find_prompt() assert enable_prompt == expected_responses["enable_prompt"] except AttributeError: - assert True == True + assert True def test_config_mode(net_connect, commands, expected_responses): """ Test enter config mode """ - net_connect.config_mode() - assert net_connect.check_config_mode() == True + # Behavior for devices with no config mode is to return null string + if net_connect.config_mode() != "": + assert net_connect.check_config_mode() is True + else: + assert True def test_exit_config_mode(net_connect, commands, expected_responses): @@ -38,7 +37,7 @@ def test_exit_config_mode(net_connect, commands, expected_responses): Test exit config mode """ net_connect.exit_config_mode() - assert net_connect.check_config_mode() == False + assert net_connect.check_config_mode() is False def test_command_set(net_connect, commands, expected_responses): diff --git a/tests/test_netmiko_config_acl.py b/tests/test_netmiko_config_acl.py new file mode 100755 index 000000000..82a3cd291 --- /dev/null +++ b/tests/test_netmiko_config_acl.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +import re +import pytest +from ipaddress import ip_address + + +def test_large_acl(net_connect, acl_entries=100): + """ + Test creating an ACL with tons of lines + """ + + platforms = { + "cisco_xe": { + "base_cmd": "ip access-list extended netmiko_test_large_acl", + "verify_cmd": "show ip access-lists netmiko_test_large_acl", + "offset": 4, + }, + "cisco_ios": { + "base_cmd": "ip access-list extended netmiko_test_large_acl", + "verify_cmd": "show ip access-lists netmiko_test_large_acl", + "offset": 4, + }, + "cisco_xr": { + "base_cmd": "ipv4 access-list netmiko_test_large_acl", + "verify_cmd": "show access-lists netmiko_test_large_acl", + "offset": 3, + }, + "cisco_nxos": { + "base_cmd": "ip access-list netmiko_test_large_acl", + "verify_cmd": "show ip access-lists netmiko_test_large_acl", + "offset": 4, + }, + } + + if net_connect.device_type not in platforms.keys(): + pytest.skip("Platform not supported for ACL test") + cmd = platforms[net_connect.device_type]["base_cmd"] + verify_cmd = platforms[net_connect.device_type]["verify_cmd"] + offset = platforms[net_connect.device_type]["offset"] + net_connect.send_config_set(f"no {cmd}") + if "cisco_xr" in net_connect.device_type: + net_connect.commit() + net_connect.exit_config_mode() + cfg_lines = [cmd] + + # Generate sequence of ACL entries + for i in range(1, acl_entries + 1): + if "cisco_xr" in net_connect.device_type: + cmd = f"permit ipv4 host {ip_address('192.168.0.0') + i} any" + else: + cmd = f"permit ip host {ip_address('192.168.0.0') + i} any" + cfg_lines.append(cmd) + + result = net_connect.send_config_set(cfg_lines) + if "cisco_xr" in net_connect.device_type: + net_connect.commit() + net_connect.exit_config_mode() + + # send_config_set should return same num lines + offset lines for entering/exiting cfg-mode + # NX-OS is will have more than one newline (per line) + result_list = re.split(r"\n+", result) + assert len(result_list) == len(cfg_lines) + offset + + # Check that length of lines in show of the acl matches lines configured + verify = net_connect.send_command(verify_cmd) + verify_list = re.split(r"\n+", verify.strip()) + # IOS-XR has a timestamp on the show command + if "UTC" in verify_list[0]: + verify_list.pop(0) + assert len(verify_list) == len(cfg_lines) + net_connect.send_config_set(f"no {cmd}") + if "cisco_xr" in net_connect.device_type: + net_connect.commit() + net_connect.exit_config_mode() + net_connect.disconnect() diff --git a/tests/test_netmiko_save.py b/tests/test_netmiko_save.py index 4fe25be11..1b89155c0 100755 --- a/tests/test_netmiko_save.py +++ b/tests/test_netmiko_save.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals def test_save_base(net_connect, commands, expected_responses): diff --git a/tests/test_netmiko_scp.py b/tests/test_netmiko_scp.py index 925e0c584..9852a1037 100755 --- a/tests/test_netmiko_scp.py +++ b/tests/test_netmiko_scp.py @@ -1,25 +1,17 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals -import time -import sys -import os import pytest -from datetime import datetime -from getpass import getpass -from netmiko import ConnectHandler, FileTransfer from netmiko import file_transfer -###def test_enable_scp(scp_fixture): -### ssh_conn, scp_transfer = scp_fixture -### -### scp_transfer.disable_scp() -### output = ssh_conn.send_command_expect("show run | inc scp") -### assert 'ip scp server enable' not in output -### -### scp_transfer.enable_scp() -### output = ssh_conn.send_command_expect("show run | inc scp") -### assert 'ip scp server enable' in output +# def test_enable_scp(scp_fixture): +# ssh_conn, scp_transfer = scp_fixture +# +# scp_transfer.disable_scp() +# output = ssh_conn.send_command_expect("show run | inc scp") +# assert 'ip scp server enable' not in output +# +# scp_transfer.enable_scp() +# output = ssh_conn.send_command_expect("show run | inc scp") +# assert 'ip scp server enable' in output def test_scp_put(scp_fixture): @@ -28,7 +20,7 @@ def test_scp_put(scp_fixture): assert False else: scp_transfer.put_file() - assert scp_transfer.check_file_exists() == True + assert scp_transfer.check_file_exists() is True def test_remote_space_available(scp_fixture, expected_responses): @@ -45,10 +37,10 @@ def test_local_space_available(scp_fixture): def test_verify_space_available_put(scp_fixture): ssh_conn, scp_transfer = scp_fixture - assert scp_transfer.verify_space_available() == True + assert scp_transfer.verify_space_available() is True # intentional make there not be enough space available scp_transfer.file_size = 100000000000 - assert scp_transfer.verify_space_available() == False + assert scp_transfer.verify_space_available() is False def test_remote_file_size(scp_fixture): @@ -65,7 +57,7 @@ def test_md5_methods(scp_fixture): remote_md5 = scp_transfer.remote_md5() assert remote_md5 == md5_value - assert scp_transfer.compare_md5() == True + assert scp_transfer.compare_md5() is True def test_disconnect(scp_fixture): @@ -76,10 +68,10 @@ def test_disconnect(scp_fixture): def test_verify_space_available_get(scp_fixture_get): ssh_conn, scp_transfer = scp_fixture_get - assert scp_transfer.verify_space_available() == True + assert scp_transfer.verify_space_available() is True # intentional make there not be enough space available - scp_transfer.file_size = 100000000000 - assert scp_transfer.verify_space_available() == False + scp_transfer.file_size = 100000000000000 + assert scp_transfer.verify_space_available() is False def test_scp_get(scp_fixture_get): @@ -101,7 +93,7 @@ def test_md5_methods_get(scp_fixture_get): md5_value = "d8df36973ff832b564ad84642d07a261" local_md5 = scp_transfer.file_md5("test9.txt") assert local_md5 == md5_value - assert scp_transfer.compare_md5() == True + assert scp_transfer.compare_md5() is True def test_disconnect_get(scp_fixture_get): diff --git a/tests/test_netmiko_session_log.py b/tests/test_netmiko_session_log.py index 381b9c806..7282bd2e1 100755 --- a/tests/test_netmiko_session_log.py +++ b/tests/test_netmiko_session_log.py @@ -1,11 +1,8 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals import time import hashlib import io from netmiko import ConnectHandler -from netmiko.py23_compat import bufferedio_types def calc_md5(file_name=None, contents=None): @@ -18,7 +15,7 @@ def calc_md5(file_name=None, contents=None): else: raise ValueError("Most specify either file_name or contents") - return hashlib.md5(contents).hexdigest() + return hashlib.md5(contents.strip()).hexdigest() def read_session_log(session_file, append=False): @@ -73,7 +70,7 @@ def test_session_log_write(net_connect_slog_wr, commands, expected_responses): session_action(net_connect_slog_wr, command) compare_file = expected_responses["compare_log_wr"] - session_file = expected_responses["session_log"] + session_file = expected_responses["session_log_wr"] session_log_md5(session_file, compare_file) @@ -122,7 +119,7 @@ def test_session_log_secrets(device_slog): conn._write_session_log("This is my password {}\n".format(conn.password)) conn._write_session_log("This is my secret {}\n".format(conn.secret)) - if not isinstance(conn.session_log, bufferedio_types): + if not isinstance(conn.session_log, io.BufferedIOBase): with open(conn.session_log.name, "r") as f: session_log = f.read() if conn.password: diff --git a/tests/test_netmiko_show.py b/tests/test_netmiko_show.py index 96e587e47..f8484aa58 100755 --- a/tests/test_netmiko_show.py +++ b/tests/test_netmiko_show.py @@ -14,12 +14,14 @@ test_enable_mode: verify enter enable mode test_disconnect: cleanly disconnect the SSH session """ - -from __future__ import print_function -from __future__ import unicode_literals import pytest import time +# import logging + +# logging.basicConfig(filename="test.log", level=logging.DEBUG) +# logger = logging.getLogger("netmiko") + def test_disable_paging(net_connect, commands, expected_responses): """Verify paging is disabled by looking for string after when paging would normally occur.""" @@ -28,11 +30,6 @@ def test_disable_paging(net_connect, commands, expected_responses): net_connect.send_command("clear logging") multiple_line_output = net_connect.send_command(commands["extended_output"]) assert expected_responses["multiple_line_output"] in multiple_line_output - if net_connect.device_type == "arista_eos": - # Arista output is slow and has router-name in output - time.sleep(5) - net_connect.clear_buffer() - net_connect.send_command("clear logging", expect_string="#") def test_ssh_connect(net_connect, commands, expected_responses): @@ -53,6 +50,9 @@ def test_send_command_timing(net_connect, commands, expected_responses): net_connect.clear_buffer() show_ip = net_connect.send_command_timing(commands["basic"]) assert expected_responses["interface_ip"] in show_ip + # Force verification of command echo + show_ip = net_connect.send_command_timing(commands["basic"], cmd_echo=True) + assert expected_responses["interface_ip"] in show_ip def test_send_command(net_connect, commands, expected_responses): @@ -63,6 +63,17 @@ def test_send_command(net_connect, commands, expected_responses): assert expected_responses["interface_ip"] in show_ip_alt +def test_send_command_juniper(net_connect, commands, expected_responses): + """Verify Juniper complete on space is disabled.""" + # If complete on space is enabled will get re-written to "show ipv6 neighbors" + if net_connect.device_type == "juniper_junos": + net_connect.write_channel("show ip neighbors\n") + output = net_connect.read_until_prompt() + assert "show ip neighbors" in output + else: + assert pytest.skip() + + def test_send_command_textfsm(net_connect, commands, expected_responses): """Verify a command can be sent down the channel successfully using send_command method.""" @@ -108,7 +119,7 @@ def test_send_command_genie(net_connect, commands, expected_responses): "cisco_nxos", "cisco_asa", ]: - assert pytest.skip("TextFSM/ntc-templates not supported on this platform") + assert pytest.skip("Genie not supported on this platform") else: time.sleep(1) net_connect.clear_buffer() @@ -146,8 +157,8 @@ def test_normalize_linefeeds(net_connect, commands, expected_responses): """Ensure no '\r\n' sequences.""" show_version = net_connect.send_command_timing(commands["version"]) show_version_alt = net_connect.send_command(commands["version"]) - assert not "\r\n" in show_version - assert not "\r\n" in show_version_alt + assert "\r\n" not in show_version + assert "\r\n" not in show_version_alt def test_clear_buffer(net_connect, commands, expected_responses): @@ -173,7 +184,7 @@ def test_enable_mode(net_connect, commands, expected_responses): enable_prompt = net_connect.find_prompt() assert enable_prompt == expected_responses["enable_prompt"] except AttributeError: - assert True == True + assert True is True def test_disconnect(net_connect, commands, expected_responses): diff --git a/tests/test_netmiko_tcl.py b/tests/test_netmiko_tcl.py index 387bedeae..ccb08e961 100755 --- a/tests/test_netmiko_tcl.py +++ b/tests/test_netmiko_tcl.py @@ -1,14 +1,4 @@ #!/usr/bin/env python -from __future__ import print_function -from __future__ import unicode_literals -import time -import sys -import os -from datetime import datetime -from getpass import getpass -from netmiko import ConnectHandler, InLineTransfer - - def test_tcl_put(tcl_fixture): ssh_conn, transfer = tcl_fixture if transfer.check_file_exists(): @@ -17,7 +7,7 @@ def test_tcl_put(tcl_fixture): transfer._enter_tcl_mode() transfer.put_file() transfer._exit_tcl_mode() - assert transfer.check_file_exists() == True + assert transfer.check_file_exists() is True def test_remote_space_available(tcl_fixture): @@ -28,10 +18,10 @@ def test_remote_space_available(tcl_fixture): def test_verify_space_available_put(tcl_fixture): ssh_conn, transfer = tcl_fixture - assert transfer.verify_space_available() == True + assert transfer.verify_space_available() is True # intentional make there not be enough space available transfer.file_size = 1000000000 - assert transfer.verify_space_available() == False + assert transfer.verify_space_available() is False def test_remote_file_size(tcl_fixture): @@ -46,7 +36,7 @@ def test_md5_methods(tcl_fixture): remote_md5 = transfer.remote_md5() assert remote_md5 == md5_value - assert transfer.compare_md5() == True + assert transfer.compare_md5() is True def test_disconnect(tcl_fixture): diff --git a/tests/test_suite_alt.sh b/tests/test_suite_alt.sh index 67e345fe9..ba7e03f82 100755 --- a/tests/test_suite_alt.sh +++ b/tests/test_suite_alt.sh @@ -8,16 +8,19 @@ echo "Starting tests...good luck:" \ && py.test -v test_netmiko_scp.py --test_device cisco3 \ && py.test -v test_netmiko_show.py --test_device cisco3 \ && py.test -v test_netmiko_config.py --test_device cisco3 \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco3 \ \ && echo "Cisco IOS SSH (including SCP) using key auth" \ && py.test -v test_netmiko_tcl.py --test_device cisco881_key \ && py.test -v test_netmiko_show.py --test_device cisco881_key \ && py.test -v test_netmiko_config.py --test_device cisco881_key \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco881_key \ \ && echo "Cisco IOS SSH (including SCP)" \ && py.test -v test_netmiko_tcl.py --test_device cisco881 \ && py.test -v test_netmiko_show.py --test_device cisco881 \ && py.test -v test_netmiko_config.py --test_device cisco881 \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco881 \ && py.test -v test_netmiko_session_log.py --test_device cisco881_slog \ \ && echo "Cisco IOS SSH fast_cli (including SCP)" \ @@ -28,14 +31,17 @@ echo "Starting tests...good luck:" \ && echo "Cisco IOS using SSH config with SSH Proxy" \ && py.test -v test_netmiko_show.py --test_device cisco881_ssh_config \ && py.test -v test_netmiko_config.py --test_device cisco881_ssh_config \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco881_ssh_config \ \ && echo "Cisco IOS using SSH config with SSH Proxy using ProxyJump" \ && py.test -v test_netmiko_show.py --test_device cisco881_ssh_proxyjump \ && py.test -v test_netmiko_config.py --test_device cisco881_ssh_proxyjump \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco881_ssh_proxyjump \ \ && echo "Cisco IOS telnet" \ && py.test -v test_netmiko_show.py --test_device cisco881_telnet \ && py.test -v test_netmiko_config.py --test_device cisco881_telnet \ +&& py.test -v test_netmiko_config_acl.py --test_device cisco881_telnet \ \ && echo "Cisco SG300" \ && py.test -v test_netmiko_show.py --test_device cisco_s300 \ @@ -45,6 +51,7 @@ echo "Starting tests...good luck:" \ && py.test -v test_netmiko_scp.py --test_device arista_sw \ && py.test -v test_netmiko_show.py --test_device arista_sw \ && py.test -v test_netmiko_config.py --test_device arista_sw \ +&& py.test -v test_netmiko_config_acl.py --test_device arista_sw \ \ && echo "Juniper" \ && py.test -v test_netmiko_scp.py --test_device juniper_srx \ diff --git a/tests/test_utils.py b/tests/test_utils.py index d4769831a..719a96cf2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,9 +2,6 @@ """ Implement common functions for tests """ -from __future__ import print_function -from __future__ import unicode_literals - import io import sys diff --git a/tests/unit/test_base_connection.py b/tests/unit/test_base_connection.py index daa9e7765..81d1af3cc 100755 --- a/tests/unit/test_base_connection.py +++ b/tests/unit/test_base_connection.py @@ -4,7 +4,7 @@ from os.path import dirname, join from threading import Lock -from netmiko import NetMikoTimeoutException +from netmiko import NetmikoTimeoutException from netmiko.base_connection import BaseConnection RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc") @@ -18,20 +18,20 @@ def __init__(self, **kwargs): def test_timeout_exceeded(): - """Raise NetMikoTimeoutException if waiting too much""" + """Raise NetmikoTimeoutException if waiting too much""" connection = FakeBaseConnection(session_timeout=10) start = time.time() - 11 try: connection._timeout_exceeded(start) - except NetMikoTimeoutException as exc: - assert isinstance(exc, NetMikoTimeoutException) + except NetmikoTimeoutException as exc: + assert isinstance(exc, NetmikoTimeoutException) return assert False def test_timeout_not_exceeded(): - """Do not raise NetMikoTimeoutException if not waiting too much""" + """Do not raise NetmikoTimeoutException if not waiting too much""" connection = FakeBaseConnection(session_timeout=10) start = time.time() assert not connection._timeout_exceeded(start) @@ -59,6 +59,7 @@ def test_use_ssh_file(): auth_timeout=None, banner_timeout=10, ssh_config_file=join(RESOURCE_FOLDER, "ssh_config"), + sock=None, ) connect_dict = connection._connect_params_dict() @@ -102,6 +103,7 @@ def test_use_ssh_file_proxyjump(): auth_timeout=None, banner_timeout=10, ssh_config_file=join(RESOURCE_FOLDER, "ssh_config_proxyjump"), + sock=None, ) connect_dict = connection._connect_params_dict() @@ -144,6 +146,7 @@ def test_connect_params_dict(): auth_timeout=None, banner_timeout=10, ssh_config_file=None, + sock=None, ) expected = { @@ -159,6 +162,7 @@ def test_connect_params_dict(): "passphrase": None, "auth_timeout": None, "banner_timeout": 10, + "sock": None, } result = connection._connect_params_dict() assert result == expected @@ -382,7 +386,7 @@ def lock_unlock_timeout(timeout=0): try: connection._lock_netmiko_session() - except NetMikoTimeoutException: + except NetmikoTimeoutException: return finally: assert connection._session_locker.locked() diff --git a/tests/unit/test_utilities.py b/tests/unit/test_utilities.py index 2f97b8c35..a6fbfc509 100755 --- a/tests/unit/test_utilities.py +++ b/tests/unit/test_utilities.py @@ -4,6 +4,8 @@ from os.path import dirname, join, relpath import sys +import pytest + from netmiko import utilities from netmiko._textfsm import _clitable as clitable @@ -37,7 +39,7 @@ def test_invalid_yaml_file(): def test_find_cfg_file(): """ Search for netmiko_tools config file in the following order: - + NETMIKO_TOOLS_CFG environment variable Current directory Home directory @@ -149,7 +151,7 @@ def test_bytes_to_bytes(): def test_invalid_data_to_bytes(): """Convert an invalid data type to bytes""" try: - utilities.write_bytes(456779) + utilities.write_bytes(456_779) except ValueError as exc: assert isinstance(exc, ValueError) return @@ -187,7 +189,7 @@ def test_clitable_to_dict(): assert result == [{"model": "4500"}] -def test_get_structured_data(): +def test_textfsm_w_index(): """Convert raw CLI output to structured data using TextFSM template""" os.environ["NET_TEXTFSM"] = RESOURCE_FOLDER raw_output = "Cisco IOS Software, Catalyst 4500 L3 Switch Software" @@ -197,7 +199,7 @@ def test_get_structured_data(): assert result == [{"model": "4500"}] -def test_get_structured_data_relative_path(): +def test_textfsm_index_relative_path(): """Test relative path for textfsm ntc directory""" os.environ["NET_TEXTFSM"] = RELATIVE_RESOURCE_FOLDER raw_output = "Cisco IOS Software, Catalyst 4500 L3 Switch Software" @@ -207,12 +209,60 @@ def test_get_structured_data_relative_path(): assert result == [{"model": "4500"}] +def test_textfsm_direct_template(): + """Convert raw CLI output to structured data using TextFSM template (no index).""" + raw_output = "Cisco IOS Software, Catalyst 4500 L3 Switch Software" + result = utilities.get_structured_data( + raw_output, + platform="cisco_ios", + command="show version", + template=f"{RESOURCE_FOLDER}/cisco_ios_show_version.template", + ) + assert result == [{"model": "4500"}] + + # Should also work with no-platform or command + result = utilities.get_structured_data( + raw_output, template=f"{RESOURCE_FOLDER}/cisco_ios_show_version.template" + ) + assert result == [{"model": "4500"}] + + +def test_textfsm_failed_parsing(): + """Verify raw_output is returned if TextFSM template parsing fails.""" + raw_output = "This is not 'show version' output" + result = utilities.get_structured_data( + raw_output, + platform="cisco_ios", + command="show version", + template=f"{RESOURCE_FOLDER}/nothinghere", + ) + assert result == raw_output + + +def test_textfsm_missing_template(): + """Verify raw_output is returned if TextFSM template is missing.""" + raw_output = "Cisco IOS Software, Catalyst 4500 L3 Switch Software" + result = utilities.get_structured_data( + raw_output, + platform="cisco_ios", + command="show version", + template=f"{RESOURCE_FOLDER}/nothinghere", + ) + assert result == raw_output + + +@pytest.mark.skipif( + sys.version_info >= (3, 8), + reason="The genie package is not available for Python 3.8 yet", +) def test_get_structured_data_genie(): """Convert raw CLI output to structured data using Genie""" - if not sys.version_info >= (3, 4): - assert True - return - raw_output = """Cisco IOS Software, C3560CX Software (C3560CX-UNIVERSALK9-M), Version 15.2(4)E7, RELEASE SOFTWARE (fc2) + + header_line = ( + "Cisco IOS Software, C3560CX Software (C3560CX-UNIVERSALK9-M), " + "Version 15.2(4)E7, RELEASE SOFTWARE (fc2)" + ) + raw_output = """ Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2018 by Cisco Systems, Inc. Compiled Tue 18-Sep-18 13:20 by prod_rel_team @@ -278,6 +328,7 @@ def test_get_structured_data_genie(): Configuration register is 0xF """ + raw_output = header_line + raw_output result = utilities.get_structured_data_genie( raw_output, platform="cisco_xe", command="show version" ) diff --git a/tox.ini b/tox.ini index 3a670c4e7..2b443c120 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,15 @@ [tox] -envlist = py27,py35,py36,py37 +envlist = py3{6,7,8},black,pylama +skip_missing_interpreters = true + +[travis] +python = + 3.6: py36,black,pylama + +[travis:env] +TRAVIS_BUILD_STAGE_NAME = + Lint: black,pylama + Test: py3{6,7,8} [testenv] deps =