diff --git a/PLATFORMS.md b/PLATFORMS.md index ff3790b70..66d3246ab 100644 --- a/PLATFORMS.md +++ b/PLATFORMS.md @@ -27,6 +27,7 @@ - Dell OS9 (Force10) - Dell OS10 - Dell PowerConnect +- Ericsson IPOS - Extreme ERS (Avaya) - Extreme VSP (Avaya) - Extreme VDX (Brocade) @@ -48,6 +49,7 @@ - Pluribus - Ruckus ICX/FastIron - Ruijie Networks +- Supermicro SMIS - TPLink JetStream - Ubiquiti EdgeSwitch - Vyatta VyOS @@ -58,7 +60,10 @@ - A10 - Accedian +- Allied Telesis AlliedWare Plus - Aruba +- Brocade Fabric OS +- C-DOT CROS - Ciena SAOS - Citrix Netscaler - Cisco Telepresence diff --git a/docs/netmiko/a10/a10_ssh.html b/docs/netmiko/a10/a10_ssh.html index 43cde3613..842617403 100644 --- a/docs/netmiko/a10/a10_ssh.html +++ b/docs/netmiko/a10/a10_ssh.html @@ -288,6 +288,7 @@

Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/a10/index.html b/docs/netmiko/a10/index.html index 7d22e4798..e9bc02dba 100644 --- a/docs/netmiko/a10/index.html +++ b/docs/netmiko/a10/index.html @@ -272,6 +272,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/accedian/accedian_ssh.html b/docs/netmiko/accedian/accedian_ssh.html index 2e180dd02..6eb8fafc4 100644 --- a/docs/netmiko/accedian/accedian_ssh.html +++ b/docs/netmiko/accedian/accedian_ssh.html @@ -362,6 +362,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/accedian/index.html b/docs/netmiko/accedian/index.html index bda9fb0bf..5129c6543 100644 --- a/docs/netmiko/accedian/index.html +++ b/docs/netmiko/accedian/index.html @@ -325,6 +325,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/adtran/adtran.html b/docs/netmiko/adtran/adtran.html index 2c19c553b..e3eda974c 100644 --- a/docs/netmiko/adtran/adtran.html +++ b/docs/netmiko/adtran/adtran.html @@ -330,6 +330,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -524,6 +525,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -722,6 +724,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/adtran/index.html b/docs/netmiko/adtran/index.html index 6b9386fb4..43bc6695f 100644 --- a/docs/netmiko/adtran/index.html +++ b/docs/netmiko/adtran/index.html @@ -217,6 +217,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -415,6 +416,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/alcatel/alcatel_aos_ssh.html b/docs/netmiko/alcatel/alcatel_aos_ssh.html index ca743956c..93c9c3d88 100644 --- a/docs/netmiko/alcatel/alcatel_aos_ssh.html +++ b/docs/netmiko/alcatel/alcatel_aos_ssh.html @@ -380,6 +380,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/alcatel/index.html b/docs/netmiko/alcatel/index.html index 078d561b8..2a79906db 100644 --- a/docs/netmiko/alcatel/index.html +++ b/docs/netmiko/alcatel/index.html @@ -342,6 +342,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/allied_telesis/allied_telesis_awplus.html b/docs/netmiko/allied_telesis/allied_telesis_awplus.html new file mode 100644 index 000000000..6f462da97 --- /dev/null +++ b/docs/netmiko/allied_telesis/allied_telesis_awplus.html @@ -0,0 +1,597 @@ + + + + + + +netmiko.allied_telesis.allied_telesis_awplus API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.allied_telesis.allied_telesis_awplus

    +
    +
    +
    +Source code +
    from netmiko.cisco_base_connection import CiscoBaseConnection
    +import time
    +
    +
    +class AlliedTelesisAwplusBase(CiscoBaseConnection):
    +    """Implement methods for interacting with Allied Telesis 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 ('>').
    +        """
    +        """ AWPlus Configuration """
    +
    +        self.disable_paging()
    +        self.set_base_prompt()
    +        time.sleep(0.3 * self.global_delay_factor)
    +
    +    def _enter_shell(self):
    +        """Enter the Bourne Shell."""
    +        return self.send_command("start shell sh", expect_string=r"[\$#]")
    +
    +    def _return_cli(self):
    +        """Return to the Awplus CLI."""
    +        return self.send_command("exit", expect_string=r"[#>]")
    +
    +    def exit_config_mode(self, exit_config="exit", pattern=""):
    +        """Exit configuration mode."""
    +        output = ""
    +        if self.check_config_mode():
    +            output = self.send_command_timing(
    +                exit_config, strip_prompt=False, strip_command=False
    +            )
    +            if "Exit with uncommitted changes?" in output:
    +                output += self.send_command_timing(
    +                    "yes", strip_prompt=False, strip_command=False
    +                )
    +            if self.check_config_mode():
    +                raise ValueError("Failed to exit configuration mode")
    +        return output
    +
    +
    +class AlliedTelesisAwplusSSH(AlliedTelesisAwplusBase):
    +    pass
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

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

    Implement methods for interacting with Allied Telesis 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
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +    :type global_cmd_verify: bool|None
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +    :type auto_connect: bool
    +
    +
    +Source code +
    class AlliedTelesisAwplusBase(CiscoBaseConnection):
    +    """Implement methods for interacting with Allied Telesis 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 ('>').
    +        """
    +        """ AWPlus Configuration """
    +
    +        self.disable_paging()
    +        self.set_base_prompt()
    +        time.sleep(0.3 * self.global_delay_factor)
    +
    +    def _enter_shell(self):
    +        """Enter the Bourne Shell."""
    +        return self.send_command("start shell sh", expect_string=r"[\$#]")
    +
    +    def _return_cli(self):
    +        """Return to the Awplus CLI."""
    +        return self.send_command("exit", expect_string=r"[#>]")
    +
    +    def exit_config_mode(self, exit_config="exit", pattern=""):
    +        """Exit configuration mode."""
    +        output = ""
    +        if self.check_config_mode():
    +            output = self.send_command_timing(
    +                exit_config, strip_prompt=False, strip_command=False
    +            )
    +            if "Exit with uncommitted changes?" in output:
    +                output += self.send_command_timing(
    +                    "yes", strip_prompt=False, strip_command=False
    +                )
    +            if self.check_config_mode():
    +                raise ValueError("Failed to exit configuration mode")
    +        return output
    +
    +

    Ancestors

    + +

    Subclasses

    + +

    Methods

    +
    +
    +def exit_config_mode(self, exit_config='exit', pattern='') +
    +
    +

    Exit configuration mode.

    +
    +Source code +
    def exit_config_mode(self, exit_config="exit", pattern=""):
    +    """Exit configuration mode."""
    +    output = ""
    +    if self.check_config_mode():
    +        output = self.send_command_timing(
    +            exit_config, strip_prompt=False, strip_command=False
    +        )
    +        if "Exit with uncommitted changes?" in output:
    +            output += self.send_command_timing(
    +                "yes", strip_prompt=False, strip_command=False
    +            )
    +        if self.check_config_mode():
    +            raise ValueError("Failed to exit configuration mode")
    +    return output
    +
    +
    +
    +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 ('>').
    +    """
    +    """ AWPlus Configuration """
    +
    +    self.disable_paging()
    +    self.set_base_prompt()
    +    time.sleep(0.3 * self.global_delay_factor)
    +
    +
    +
    +

    Inherited members

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

    Implement methods for interacting with Allied Telesis 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
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +    :type global_cmd_verify: bool|None
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +    :type auto_connect: bool
    +
    +
    +Source code +
    class AlliedTelesisAwplusSSH(AlliedTelesisAwplusBase):
    +    pass
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/allied_telesis/index.html b/docs/netmiko/allied_telesis/index.html new file mode 100644 index 000000000..accdd643b --- /dev/null +++ b/docs/netmiko/allied_telesis/index.html @@ -0,0 +1,277 @@ + + + + + + +netmiko.allied_telesis API documentation + + + + + + + + + +
    +
    +
    +

    Module netmiko.allied_telesis

    +
    +
    +
    +Source code +
    from netmiko.allied_telesis.allied_telesis_awplus import AlliedTelesisAwplusSSH
    +
    +__all__ = ["AlliedTelesisAwplusSSH"]
    +
    +
    +
    +

    Sub-modules

    +
    +
    netmiko.allied_telesis.allied_telesis_awplus
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

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

    Implement methods for interacting with Allied Telesis 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
    +
    +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
    +            (default: None). Global attribute takes precedence over function `cmd_verify`
    +            argument. Value of `None` indicates to use function `cmd_verify` argument.
    +    :type global_cmd_verify: bool|None
    +
    +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
    +            part of the object creation (default: True).
    +    :type auto_connect: bool
    +
    +
    +Source code +
    class AlliedTelesisAwplusSSH(AlliedTelesisAwplusBase):
    +    pass
    +
    +

    Ancestors

    + +

    Inherited members

    + +
    +
    +
    +
    + +
    + + + + + \ No newline at end of file diff --git a/docs/netmiko/apresia/apresia_aeos.html b/docs/netmiko/apresia/apresia_aeos.html index f1cbd8913..cd3dfd6fd 100644 --- a/docs/netmiko/apresia/apresia_aeos.html +++ b/docs/netmiko/apresia/apresia_aeos.html @@ -281,6 +281,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -476,6 +477,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -675,6 +677,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/apresia/index.html b/docs/netmiko/apresia/index.html index 22f48fea4..1c569d740 100644 --- a/docs/netmiko/apresia/index.html +++ b/docs/netmiko/apresia/index.html @@ -218,6 +218,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -417,6 +418,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/arista/arista.html b/docs/netmiko/arista/arista.html index c849f7302..59b03bb3e 100644 --- a/docs/netmiko/arista/arista.html +++ b/docs/netmiko/arista/arista.html @@ -468,6 +468,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -755,6 +756,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -954,6 +956,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/arista/index.html b/docs/netmiko/arista/index.html index f68d8cd46..a9a4e1087 100644 --- a/docs/netmiko/arista/index.html +++ b/docs/netmiko/arista/index.html @@ -310,6 +310,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • @@ -509,6 +510,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/aruba/aruba_ssh.html b/docs/netmiko/aruba/aruba_ssh.html index 4ff52af1d..e38861c6d 100644 --- a/docs/netmiko/aruba/aruba_ssh.html +++ b/docs/netmiko/aruba/aruba_ssh.html @@ -357,6 +357,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/aruba/index.html b/docs/netmiko/aruba/index.html index 7b5031e92..e071fc610 100644 --- a/docs/netmiko/aruba/index.html +++ b/docs/netmiko/aruba/index.html @@ -313,6 +313,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/base_connection.html b/docs/netmiko/base_connection.html index c86939989..1b793275c 100644 --- a/docs/netmiko/base_connection.html +++ b/docs/netmiko/base_connection.html @@ -52,6 +52,7 @@

    Module netmiko.base_connection

    from netmiko.ssh_exception import ( NetmikoTimeoutException, NetmikoAuthenticationException, + ConfigInvalidException, ) from netmiko.utilities import ( write_bytes, @@ -59,6 +60,7 @@

    Module netmiko.base_connection

    get_structured_data, get_structured_data_genie, get_structured_data_ttp, + run_ttp_template, select_cmd_verify, ) from netmiko.utilities import m_exec_time # noqa @@ -248,6 +250,8 @@

    Module netmiko.base_connection

    :type auto_connect: bool """ self.remote_conn = None + # Does the platform support a configuration mode + self._config_mode = True self.TELNET_RETURN = "\r\n" if default_enter is None: @@ -1159,7 +1163,9 @@

    Module netmiko.base_connection

    # Retry by sleeping .33 and then double sleep until 5 attempts (.33, .66, 1.32, etc) @retry( - wait=wait_exponential(multiplier=0.33, min=0, max=5), stop=stop_after_attempt(5) + wait=wait_exponential(multiplier=0.33, min=0, max=5), + stop=stop_after_attempt(5), + reraise=True, ) def set_base_prompt( self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 @@ -1699,19 +1705,32 @@

    Module netmiko.base_connection

    "Failed to enter enable mode. Please ensure you pass " "the 'secret' argument to ConnectHandler." ) + + # Check if in enable mode if not self.check_enable_mode(): + # Send "enable" mode command self.write_channel(self.normalize_cmd(cmd)) try: - output += self.read_until_pattern(pattern=re.escape(cmd.strip())) - if pattern not in output: + # Read the command echo + end_data = "" + if self.global_cmd_verify is not False: + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + end_data = output.split(cmd.strip())[-1] + + # Search for trailing prompt or password pattern + if pattern not in output and self.base_prompt not in end_data: output += self.read_until_prompt_or_pattern( pattern=pattern, re_flags=re_flags ) - self.write_channel(self.normalize_cmd(self.secret)) - if enable_pattern: + # Send the "secret" in response to password pattern + if re.search(pattern, output): + self.write_channel(self.normalize_cmd(self.secret)) + output += self.read_until_prompt() + + # Search for terminating pattern if defined + if enable_pattern and not re.search(enable_pattern, output): output += self.read_until_pattern(pattern=enable_pattern) else: - output += self.read_until_prompt() if not self.check_enable_mode(): raise ValueError(msg) except NetmikoTimeoutException: @@ -1828,6 +1847,7 @@

    Module netmiko.base_connection

    config_mode_command=None, cmd_verify=True, enter_config_mode=True, + error_pattern="", ): """ Send configuration commands down the SSH channel. @@ -1864,6 +1884,9 @@

    Module netmiko.base_connection

    :param enter_config_mode: Do you enter config mode before sending config commands :type exit_config_mode: bool + :param error_pattern: Regular expression pattern to detect config errors in the + output. + :type error_pattern: str """ delay_factor = self.select_delay_factor(delay_factor) if config_commands is None: @@ -1880,21 +1903,35 @@

    Module netmiko.base_connection

    cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() output += self.config_mode(*cfg_mode_args) - if self.fast_cli and self._legacy_mode: + # If error_pattern is perform output gathering line by line and not fast_cli mode. + if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output output += self._read_channel_timing( delay_factor=delay_factor, max_loops=max_loops ) + 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 - ) + + # Gather the output incrementally due to error_pattern requirements + if error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + + # Standard output gathering (no error_pattern) + if not error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) @@ -1912,6 +1949,11 @@

    Module netmiko.base_connection

    new_output = self.read_until_pattern(pattern=pattern) output += new_output + if error_pattern: + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + if exit_config_mode: output += self.exit_config_mode() output = self._sanitize_output(output) @@ -2064,6 +2106,41 @@

    Module netmiko.base_connection

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

    Classes

    :type auto_connect: bool """ self.remote_conn = None + # Does the platform support a configuration mode + self._config_mode = True self.TELNET_RETURN = "\r\n" if default_enter is None: @@ -3312,7 +3391,9 @@

    Classes

    # Retry by sleeping .33 and then double sleep until 5 attempts (.33, .66, 1.32, etc) @retry( - wait=wait_exponential(multiplier=0.33, min=0, max=5), stop=stop_after_attempt(5) + wait=wait_exponential(multiplier=0.33, min=0, max=5), + stop=stop_after_attempt(5), + reraise=True, ) def set_base_prompt( self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 @@ -3852,19 +3933,32 @@

    Classes

    "Failed to enter enable mode. Please ensure you pass " "the 'secret' argument to ConnectHandler." ) + + # Check if in enable mode if not self.check_enable_mode(): + # Send "enable" mode command self.write_channel(self.normalize_cmd(cmd)) try: - output += self.read_until_pattern(pattern=re.escape(cmd.strip())) - if pattern not in output: + # Read the command echo + end_data = "" + if self.global_cmd_verify is not False: + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + end_data = output.split(cmd.strip())[-1] + + # Search for trailing prompt or password pattern + if pattern not in output and self.base_prompt not in end_data: output += self.read_until_prompt_or_pattern( pattern=pattern, re_flags=re_flags ) - self.write_channel(self.normalize_cmd(self.secret)) - if enable_pattern: + # Send the "secret" in response to password pattern + if re.search(pattern, output): + self.write_channel(self.normalize_cmd(self.secret)) + output += self.read_until_prompt() + + # Search for terminating pattern if defined + if enable_pattern and not re.search(enable_pattern, output): output += self.read_until_pattern(pattern=enable_pattern) else: - output += self.read_until_prompt() if not self.check_enable_mode(): raise ValueError(msg) except NetmikoTimeoutException: @@ -3981,6 +4075,7 @@

    Classes

    config_mode_command=None, cmd_verify=True, enter_config_mode=True, + error_pattern="", ): """ Send configuration commands down the SSH channel. @@ -4017,6 +4112,9 @@

    Classes

    :param enter_config_mode: Do you enter config mode before sending config commands :type exit_config_mode: bool + :param error_pattern: Regular expression pattern to detect config errors in the + output. + :type error_pattern: str """ delay_factor = self.select_delay_factor(delay_factor) if config_commands is None: @@ -4033,21 +4131,35 @@

    Classes

    cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() output += self.config_mode(*cfg_mode_args) - if self.fast_cli and self._legacy_mode: + # If error_pattern is perform output gathering line by line and not fast_cli mode. + if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output output += self._read_channel_timing( delay_factor=delay_factor, max_loops=max_loops ) + 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 - ) + + # Gather the output incrementally due to error_pattern requirements + if error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + + # Standard output gathering (no error_pattern) + if not error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) @@ -4065,6 +4177,11 @@

    Classes

    new_output = self.read_until_pattern(pattern=pattern) output += new_output + if error_pattern: + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + if exit_config_mode: output += self.exit_config_mode() output = self._sanitize_output(output) @@ -4215,7 +4332,42 @@

    Classes

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

    Subclasses

    Static methods

    @@ -1059,6 +1065,9 @@

    Args

    line = match.group(0) # Format will be 26 -rw- 6738 Jul 30 2016 19:49:50 -07:00 filename file_size = line.split()[2] + else: + raise IOError("Unable to parse 'dir' output in remote_file_size method") + if "Error opening" in remote_out or "No such file or directory" in remote_out: raise IOError("Unable to find file on remote system") else: diff --git a/docs/netmiko/sixwind/index.html b/docs/netmiko/sixwind/index.html index 87a8b7363..e4fd355a5 100644 --- a/docs/netmiko/sixwind/index.html +++ b/docs/netmiko/sixwind/index.html @@ -218,6 +218,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/sixwind/sixwind_os.html b/docs/netmiko/sixwind/sixwind_os.html index 883da569d..082d12150 100644 --- a/docs/netmiko/sixwind/sixwind_os.html +++ b/docs/netmiko/sixwind/sixwind_os.html @@ -577,6 +577,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • @@ -770,6 +771,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • save_config
  • select_delay_factor
  • send_command
  • diff --git a/docs/netmiko/sophos/index.html b/docs/netmiko/sophos/index.html index 026d103f1..c1fdb11c3 100644 --- a/docs/netmiko/sophos/index.html +++ b/docs/netmiko/sophos/index.html @@ -384,6 +384,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/sophos/sophos_sfos_ssh.html b/docs/netmiko/sophos/sophos_sfos_ssh.html index 5ca165a62..bfb528c2b 100644 --- a/docs/netmiko/sophos/sophos_sfos_ssh.html +++ b/docs/netmiko/sophos/sophos_sfos_ssh.html @@ -434,6 +434,7 @@

    Inherited members

  • read_until_pattern
  • read_until_prompt
  • read_until_prompt_or_pattern
  • +
  • run_ttp
  • select_delay_factor
  • send_command
  • send_command_expect
  • diff --git a/docs/netmiko/ssh_autodetect.html b/docs/netmiko/ssh_autodetect.html index 666bfab41..b501cbe61 100644 --- a/docs/netmiko/ssh_autodetect.html +++ b/docs/netmiko/ssh_autodetect.html @@ -231,9 +231,9 @@

    Netmiko connection creation section "priority": 99, "dispatch": "_autodetect_std", }, - "brocade_netiron": { + "extreme_netiron": { "cmd": "show version", - "search_patterns": [r"NetIron"], + "search_patterns": [r"(NetIron|MLX)"], "priority": 99, "dispatch": "_autodetect_std", }, @@ -273,6 +273,18 @@

    Netmiko connection creation section "priority": 99, "dispatch": "_autodetect_std", }, + "paloalto_panos": { + "cmd": "show system info", + "search_patterns": [r"model:\s+PA"], + "priority": 99, + "dispatch": "_autodetect_std", + }, + "supermicro_smis": { + "cmd": "show system info", + "search_patterns": [r"Super Micro Computer"], + "priority": 99, + "dispatch": "_autodetect_std", + }, } # Sort SSH_MAPPER_BASE such that the most common commands are first diff --git a/docs/netmiko/ssh_exception.html b/docs/netmiko/ssh_exception.html index 41b78ca27..ebadb55ba 100644 --- a/docs/netmiko/ssh_exception.html +++ b/docs/netmiko/ssh_exception.html @@ -38,6 +38,12 @@

    Module netmiko.ssh_exception

    pass +class ConfigInvalidException(Exception): + """Exception raised for invalid configuration error.""" + + pass + + NetMikoTimeoutException = NetmikoTimeoutException NetMikoAuthenticationException = NetmikoAuthenticationException
    @@ -51,6 +57,25 @@

    Module netmiko.ssh_exception

    Classes

    +
    +class ConfigInvalidException +(*args, **kwargs) +
    +
    +

    Exception raised for invalid configuration error.

    +
    +Source code +
    class ConfigInvalidException(Exception):
    +    """Exception raised for invalid configuration error."""
    +
    +    pass
    +
    +

    Ancestors

    +
      +
    • builtins.Exception
    • +
    • builtins.BaseException
    • +
    +
    class NetMikoAuthenticationException (*args, **kwargs) @@ -150,6 +175,9 @@

    Index

  • Classes

    • +

      ConfigInvalidException

      +
    • +
    • NetmikoAuthenticationException

    • diff --git a/docs/netmiko/supermicro/index.html b/docs/netmiko/supermicro/index.html new file mode 100644 index 000000000..a95c7ef44 --- /dev/null +++ b/docs/netmiko/supermicro/index.html @@ -0,0 +1,476 @@ + + + + + + +netmiko.supermicro API documentation + + + + + + + + + +
      +
      +
      +

      Module netmiko.supermicro

      +
      +
      +
      +Source code +
      from netmiko.supermicro.smci_smis import SmciSwitchSmisTelnet, SmciSwitchSmisSSH
      +
      +__all__ = ["SmciSwitchSmisSSH", "SmciSwitchSmisTelnet"]
      +
      +
      +
      +

      Sub-modules

      +
      +
      netmiko.supermicro.smci_smis
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

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

      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
      +
      +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      +            (default: None). Global attribute takes precedence over function `cmd_verify`
      +            argument. Value of `None` indicates to use function `cmd_verify` argument.
      +    :type global_cmd_verify: bool|None
      +
      +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      +            part of the object creation (default: True).
      +    :type auto_connect: bool
      +
      +
      +Source code +
      class SmciSwitchSmisSSH(SmciSwitchSmisBase):
      +    pass
      +
      +

      Ancestors

      + +

      Inherited members

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

      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
      +
      +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      +            (default: None). Global attribute takes precedence over function `cmd_verify`
      +            argument. Value of `None` indicates to use function `cmd_verify` argument.
      +    :type global_cmd_verify: bool|None
      +
      +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      +            part of the object creation (default: True).
      +    :type auto_connect: bool
      +
      +
      +Source code +
      class SmciSwitchSmisTelnet(SmciSwitchSmisBase):
      +    pass
      +
      +

      Ancestors

      + +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + + + \ No newline at end of file diff --git a/docs/netmiko/supermicro/smci_smis.html b/docs/netmiko/supermicro/smci_smis.html new file mode 100644 index 000000000..55a55bcae --- /dev/null +++ b/docs/netmiko/supermicro/smci_smis.html @@ -0,0 +1,803 @@ + + + + + + +netmiko.supermicro.smci_smis API documentation + + + + + + + + + +
      +
      +
      +

      Module netmiko.supermicro.smci_smis

      +
      +
      +
      +Source code +
      from netmiko.cisco_base_connection import CiscoBaseConnection
      +import time
      +
      +
      +class SmciSwitchSmisBase(CiscoBaseConnection):
      +    def session_preparation(self):
      +        """Prepare the session after the connection has been established."""
      +        self._test_channel_read(pattern=r"[>#]")
      +        self.set_base_prompt()
      +        self.config_mode()
      +        self.disable_paging(command="set cli pagination off")
      +        self.set_terminal_width(command="terminal width 511")
      +        self.exit_config_mode()
      +        # Clear the read buffer
      +        time.sleep(0.3 * self.global_delay_factor)
      +        self.clear_buffer()
      +
      +    def check_enable_mode(self, check_string="#"):
      +        """Check if in enable mode. Return boolean."""
      +        return super().check_enable_mode(check_string=check_string)
      +
      +    def enable(self, *args, **kwargs):
      +        """Supermicro switch does not support enable-mode command"""
      +        return ""
      +
      +    def exit_enable_mode(self, *args, **kwargs):
      +        """Supermicro switch does not support enable-mode command"""
      +        return ""
      +
      +    def save_config(
      +        self, cmd="write startup-config", confirm=False, confirm_response=""
      +    ):
      +        """Save config"""
      +        return super().save_config(
      +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
      +        )
      +
      +
      +class SmciSwitchSmisSSH(SmciSwitchSmisBase):
      +    pass
      +
      +
      +class SmciSwitchSmisTelnet(SmciSwitchSmisBase):
      +    pass
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

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

      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
      +
      +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      +            (default: None). Global attribute takes precedence over function `cmd_verify`
      +            argument. Value of `None` indicates to use function `cmd_verify` argument.
      +    :type global_cmd_verify: bool|None
      +
      +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      +            part of the object creation (default: True).
      +    :type auto_connect: bool
      +
      +
      +Source code +
      class SmciSwitchSmisBase(CiscoBaseConnection):
      +    def session_preparation(self):
      +        """Prepare the session after the connection has been established."""
      +        self._test_channel_read(pattern=r"[>#]")
      +        self.set_base_prompt()
      +        self.config_mode()
      +        self.disable_paging(command="set cli pagination off")
      +        self.set_terminal_width(command="terminal width 511")
      +        self.exit_config_mode()
      +        # Clear the read buffer
      +        time.sleep(0.3 * self.global_delay_factor)
      +        self.clear_buffer()
      +
      +    def check_enable_mode(self, check_string="#"):
      +        """Check if in enable mode. Return boolean."""
      +        return super().check_enable_mode(check_string=check_string)
      +
      +    def enable(self, *args, **kwargs):
      +        """Supermicro switch does not support enable-mode command"""
      +        return ""
      +
      +    def exit_enable_mode(self, *args, **kwargs):
      +        """Supermicro switch does not support enable-mode command"""
      +        return ""
      +
      +    def save_config(
      +        self, cmd="write startup-config", confirm=False, confirm_response=""
      +    ):
      +        """Save config"""
      +        return super().save_config(
      +            cmd=cmd, confirm=confirm, confirm_response=confirm_response
      +        )
      +
      +

      Ancestors

      + +

      Subclasses

      + +

      Methods

      +
      +
      +def enable(self, *args, **kwargs) +
      +
      +

      Supermicro switch does not support enable-mode command

      +
      +Source code +
      def enable(self, *args, **kwargs):
      +    """Supermicro switch does not support enable-mode command"""
      +    return ""
      +
      +
      +
      +def exit_enable_mode(self, *args, **kwargs) +
      +
      +

      Supermicro switch does not support enable-mode command

      +
      +Source code +
      def exit_enable_mode(self, *args, **kwargs):
      +    """Supermicro switch does not support enable-mode command"""
      +    return ""
      +
      +
      +
      +def save_config(self, cmd='write startup-config', confirm=False, confirm_response='') +
      +
      +

      Save config

      +
      +Source code +
      def save_config(
      +    self, cmd="write startup-config", confirm=False, confirm_response=""
      +):
      +    """Save config"""
      +    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()
      +    self.config_mode()
      +    self.disable_paging(command="set cli pagination off")
      +    self.set_terminal_width(command="terminal width 511")
      +    self.exit_config_mode()
      +    # Clear the read buffer
      +    time.sleep(0.3 * self.global_delay_factor)
      +    self.clear_buffer()
      +
      +
      +
      +

      Inherited members

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

      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
      +
      +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      +            (default: None). Global attribute takes precedence over function `cmd_verify`
      +            argument. Value of `None` indicates to use function `cmd_verify` argument.
      +    :type global_cmd_verify: bool|None
      +
      +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      +            part of the object creation (default: True).
      +    :type auto_connect: bool
      +
      +
      +Source code +
      class SmciSwitchSmisSSH(SmciSwitchSmisBase):
      +    pass
      +
      +

      Ancestors

      + +

      Inherited members

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

      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
      +
      +    :param global_cmd_verify: Control whether command echo verification is enabled or disabled
      +            (default: None). Global attribute takes precedence over function `cmd_verify`
      +            argument. Value of `None` indicates to use function `cmd_verify` argument.
      +    :type global_cmd_verify: bool|None
      +
      +    :param auto_connect: Control whether Netmiko automatically establishes the connection as
      +            part of the object creation (default: True).
      +    :type auto_connect: bool
      +
      +
      +Source code +
      class SmciSwitchSmisTelnet(SmciSwitchSmisBase):
      +    pass
      +
      +

      Ancestors

      + +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + + + \ No newline at end of file diff --git a/docs/netmiko/terminal_server/index.html b/docs/netmiko/terminal_server/index.html index 26f873dd5..658cecf4d 100644 --- a/docs/netmiko/terminal_server/index.html +++ b/docs/netmiko/terminal_server/index.html @@ -219,6 +219,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -434,6 +435,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/terminal_server/terminal_server.html b/docs/netmiko/terminal_server/terminal_server.html index c3422ca2a..fa98044c0 100644 --- a/docs/netmiko/terminal_server/terminal_server.html +++ b/docs/netmiko/terminal_server/terminal_server.html @@ -267,6 +267,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -462,6 +463,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -677,6 +679,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/tplink/index.html b/docs/netmiko/tplink/index.html index 5eb7455e4..920c2f37a 100644 --- a/docs/netmiko/tplink/index.html +++ b/docs/netmiko/tplink/index.html @@ -245,6 +245,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -488,6 +489,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/tplink/tplink_jetstream.html b/docs/netmiko/tplink/tplink_jetstream.html index 298f8d098..36f53f13b 100644 --- a/docs/netmiko/tplink/tplink_jetstream.html +++ b/docs/netmiko/tplink/tplink_jetstream.html @@ -657,6 +657,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -878,6 +879,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -1121,6 +1123,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/ubiquiti/edge_ssh.html b/docs/netmiko/ubiquiti/edge_ssh.html index d42dbacd2..402cbea11 100644 --- a/docs/netmiko/ubiquiti/edge_ssh.html +++ b/docs/netmiko/ubiquiti/edge_ssh.html @@ -360,6 +360,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/ubiquiti/edgerouter_ssh.html b/docs/netmiko/ubiquiti/edgerouter_ssh.html index 6fb2f9cd2..b257382de 100644 --- a/docs/netmiko/ubiquiti/edgerouter_ssh.html +++ b/docs/netmiko/ubiquiti/edgerouter_ssh.html @@ -272,6 +272,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/ubiquiti/index.html b/docs/netmiko/ubiquiti/index.html index 9827fde53..e3197ce7f 100644 --- a/docs/netmiko/ubiquiti/index.html +++ b/docs/netmiko/ubiquiti/index.html @@ -272,6 +272,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • @@ -573,6 +574,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • @@ -841,6 +843,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/ubiquiti/unifiswitch_ssh.html b/docs/netmiko/ubiquiti/unifiswitch_ssh.html index b221741cd..b79ab6250 100644 --- a/docs/netmiko/ubiquiti/unifiswitch_ssh.html +++ b/docs/netmiko/ubiquiti/unifiswitch_ssh.html @@ -321,6 +321,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • diff --git a/docs/netmiko/utilities.html b/docs/netmiko/utilities.html index fd8e1bfbe..190c4020d 100644 --- a/docs/netmiko/utilities.html +++ b/docs/netmiko/utilities.html @@ -33,6 +33,7 @@

      Module netmiko.utilities

      from datetime import datetime from netmiko._textfsm import _clitable as clitable from netmiko._textfsm._clitable import CliTableError +from netmiko import log try: from ttp import ttp @@ -66,6 +67,7 @@

      Module netmiko.utilities

      # Dictionary mapping 'show run' for vendors with different command SHOW_RUN_MAPPER = { + "brocade_fos": "configShow", "juniper": "show configuration", "juniper_junos": "show configuration", "extreme": "show configuration", @@ -92,6 +94,7 @@

      Module netmiko.utilities

      "brocade_fastiron": "show running-config", "brocade_netiron": "show running-config", "alcatel_aos": "show configuration snapshot", + "cros_mtbr": "show running-config", } # Expand SHOW_RUN_MAPPER to include '_ssh' key @@ -397,6 +400,73 @@

      Module netmiko.utilities

      return raw_output +def run_ttp_template(connection, template, res_kwargs, **kwargs): + """ + Helper function to run TTP template parsing. + + :param connection: Netmiko connection object + :type connection: obj + + :param template: TTP template + :type template: str + + :param res_kwargs: ``**res_kwargs`` arguments for TTP result method + :type res_kwargs: dict + + :param kwargs: ``**kwargs`` for TTP object instantiation + :type kwargs: dict + """ + if not TTP_INSTALLED: + msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n" + raise ValueError(msg) + + parser = ttp(template=template, **kwargs) + + # get inputs load for TTP template + ttp_inputs_load = parser.get_input_load() + log.debug("run_ttp_template: inputs load - {}".format(ttp_inputs_load)) + + # go over template's inputs and collect output from devices + for template_name, inputs in ttp_inputs_load.items(): + for input_name, input_params in inputs.items(): + method = input_params.get("method", "send_command") + method_kwargs = input_params.get("kwargs", {}) + commands = input_params.get("commands", None) + + # run sanity checks + if method not in dir(connection): + log.warning( + "run_ttp_template: '{}' input, unsupported method '{}', skipping".format( + input_name, method + ) + ) + continue + elif not commands: + log.warning( + "run_ttp_template: '{}' input no commands to collect, skipping".format( + input_name + ) + ) + continue + + # collect commands output from device + output = [ + getattr(connection, method)(command_string=command, **method_kwargs) + for command in commands + ] + output = "\n".join(output) + + # add collected output to TTP parser object + parser.add_input( + data=output, input_name=input_name, template_name=template_name + ) + + # run parsing in single process + parser.parse(one=True) + + return parser.result(**res_kwargs) + + def get_structured_data_genie(raw_output, platform, command): if not sys.version_info >= (3, 4): raise ValueError("Genie requires Python >= 3.4") @@ -941,6 +1011,88 @@

      Functions

      return f"{netmiko_full_dir}/{device_name}.txt"
      +
      +def run_ttp_template(connection, template, res_kwargs, **kwargs) +
      +
      +

      Helper function to run TTP template parsing.

      +

      :param connection: Netmiko connection object +:type connection: obj

      +

      :param template: TTP template +:type template: str

      +

      :param res_kwargs: **res_kwargs arguments for TTP result method +:type res_kwargs: dict

      +

      :param kwargs: **kwargs for TTP object instantiation +:type kwargs: dict

      +
      +Source code +
      def run_ttp_template(connection, template, res_kwargs, **kwargs):
      +    """
      +    Helper function to run TTP template parsing.
      +
      +    :param connection: Netmiko connection object
      +    :type connection: obj
      +
      +    :param template: TTP template
      +    :type template: str
      +
      +    :param res_kwargs: ``**res_kwargs`` arguments for TTP result method
      +    :type res_kwargs: dict
      +
      +    :param kwargs: ``**kwargs`` for TTP object instantiation
      +    :type kwargs: dict
      +    """
      +    if not TTP_INSTALLED:
      +        msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n"
      +        raise ValueError(msg)
      +
      +    parser = ttp(template=template, **kwargs)
      +
      +    # get inputs load for TTP template
      +    ttp_inputs_load = parser.get_input_load()
      +    log.debug("run_ttp_template: inputs load - {}".format(ttp_inputs_load))
      +
      +    # go over template's inputs and collect output from devices
      +    for template_name, inputs in ttp_inputs_load.items():
      +        for input_name, input_params in inputs.items():
      +            method = input_params.get("method", "send_command")
      +            method_kwargs = input_params.get("kwargs", {})
      +            commands = input_params.get("commands", None)
      +
      +            # run sanity checks
      +            if method not in dir(connection):
      +                log.warning(
      +                    "run_ttp_template: '{}' input, unsupported method '{}', skipping".format(
      +                        input_name, method
      +                    )
      +                )
      +                continue
      +            elif not commands:
      +                log.warning(
      +                    "run_ttp_template: '{}' input no commands to collect, skipping".format(
      +                        input_name
      +                    )
      +                )
      +                continue
      +
      +            # collect commands output from device
      +            output = [
      +                getattr(connection, method)(command_string=command, **method_kwargs)
      +                for command in commands
      +            ]
      +            output = "\n".join(output)
      +
      +            # add collected output to TTP parser object
      +            parser.add_input(
      +                data=output, input_name=input_name, template_name=template_name
      +            )
      +
      +    # run parsing in single process
      +    parser.parse(one=True)
      +
      +    return parser.result(**res_kwargs)
      +
      +
      def select_cmd_verify(func)
      @@ -1031,6 +1183,7 @@

      Index

    • m_exec_time
    • obtain_all_devices
    • obtain_netmiko_filename
    • +
    • run_ttp_template
    • select_cmd_verify
    • write_bytes
    • write_tmp_file
    • diff --git a/docs/netmiko/vyos/index.html b/docs/netmiko/vyos/index.html index 815a0eb88..ef027acb5 100644 --- a/docs/netmiko/vyos/index.html +++ b/docs/netmiko/vyos/index.html @@ -511,6 +511,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/vyos/vyos_ssh.html b/docs/netmiko/vyos/vyos_ssh.html index 1e9f27cc2..b713d8eb0 100644 --- a/docs/netmiko/vyos/vyos_ssh.html +++ b/docs/netmiko/vyos/vyos_ssh.html @@ -607,6 +607,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/watchguard/fireware_ssh.html b/docs/netmiko/watchguard/fireware_ssh.html index 0258b3b1e..d47c6ab4f 100644 --- a/docs/netmiko/watchguard/fireware_ssh.html +++ b/docs/netmiko/watchguard/fireware_ssh.html @@ -320,6 +320,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/watchguard/index.html b/docs/netmiko/watchguard/index.html index 83594f1b2..e0e24b391 100644 --- a/docs/netmiko/watchguard/index.html +++ b/docs/netmiko/watchguard/index.html @@ -294,6 +294,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • diff --git a/docs/netmiko/yamaha/index.html b/docs/netmiko/yamaha/index.html index de5771555..91890b3dd 100644 --- a/docs/netmiko/yamaha/index.html +++ b/docs/netmiko/yamaha/index.html @@ -219,6 +219,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -242,7 +243,7 @@

      Inherited members

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

      Yamaha Telnet driver.

      @@ -381,7 +382,10 @@

      Inherited members

      class YamahaTelnet(YamahaBase):
           """Yamaha Telnet driver."""
       
      -    pass
      + def __init__(self, *args, **kwargs): + default_enter = kwargs.get("default_enter") + kwargs["default_enter"] = "\n" if default_enter is None else default_enter + super().__init__(*args, **kwargs)

      Ancestors

        @@ -415,6 +419,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • diff --git a/docs/netmiko/yamaha/yamaha.html b/docs/netmiko/yamaha/yamaha.html index df28b0930..5e8b974e5 100644 --- a/docs/netmiko/yamaha/yamaha.html +++ b/docs/netmiko/yamaha/yamaha.html @@ -53,7 +53,8 @@

        Module netmiko.yamaha.yamaha

        output = self.read_channel() if "(Y/N)" in output: self.write_channel("N") - output += self.read_until_prompt() + if self.base_prompt not in output: + output += self.read_until_prompt() if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output @@ -91,7 +92,10 @@

        Module netmiko.yamaha.yamaha

        class YamahaTelnet(YamahaBase): """Yamaha Telnet driver.""" - pass
        + def __init__(self, *args, **kwargs): + default_enter = kwargs.get("default_enter") + kwargs["default_enter"] = "\n" if default_enter is None else default_enter + super().__init__(*args, **kwargs)
      @@ -269,7 +273,8 @@

      Classes

      output = self.read_channel() if "(Y/N)" in output: self.write_channel("N") - output += self.read_until_prompt() + if self.base_prompt not in output: + output += self.read_until_prompt() if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output @@ -368,7 +373,8 @@

      Methods

      output = self.read_channel() if "(Y/N)" in output: self.write_channel("N") - output += self.read_until_prompt() + if self.base_prompt not in output: + output += self.read_until_prompt() if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output
      @@ -430,6 +436,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • select_delay_factor
    • send_command
    • send_command_expect
    • @@ -624,6 +631,7 @@

      Inherited members

    • read_until_pattern
    • read_until_prompt
    • read_until_prompt_or_pattern
    • +
    • run_ttp
    • save_config
    • select_delay_factor
    • send_command
    • @@ -647,7 +655,7 @@

      Inherited members

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

      Yamaha Telnet driver.

      @@ -786,7 +794,10 @@

      Inherited members

      class YamahaTelnet(YamahaBase):
           """Yamaha Telnet driver."""
       
      -    pass
      + def __init__(self, *args, **kwargs): + default_enter = kwargs.get("default_enter") + kwargs["default_enter"] = "\n" if default_enter is None else default_enter + super().__init__(*args, **kwargs)

      Ancestors

        @@ -820,6 +831,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • diff --git a/docs/netmiko/zte/index.html b/docs/netmiko/zte/index.html index ab7170fee..9bb3e5292 100644 --- a/docs/netmiko/zte/index.html +++ b/docs/netmiko/zte/index.html @@ -218,6 +218,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • @@ -437,6 +438,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • diff --git a/docs/netmiko/zte/zte_zxros.html b/docs/netmiko/zte/zte_zxros.html index 357ce04f9..504f96f93 100644 --- a/docs/netmiko/zte/zte_zxros.html +++ b/docs/netmiko/zte/zte_zxros.html @@ -335,6 +335,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • select_delay_factor
      • send_command
      • send_command_expect
      • @@ -528,6 +529,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • @@ -747,6 +749,7 @@

        Inherited members

      • read_until_pattern
      • read_until_prompt
      • read_until_prompt_or_pattern
      • +
      • run_ttp
      • save_config
      • select_delay_factor
      • send_command
      • diff --git a/netmiko/__init__.py b/netmiko/__init__.py index e6a0cb17a..e426b46bc 100644 --- a/netmiko/__init__.py +++ b/netmiko/__init__.py @@ -16,6 +16,7 @@ NetmikoAuthenticationException, NetMikoAuthenticationException, ) +from netmiko.ssh_exception import ConfigInvalidException from netmiko.ssh_autodetect import SSHDetect from netmiko.base_connection import BaseConnection from netmiko.scp_functions import file_transfer, progress_bar @@ -23,7 +24,7 @@ # Alternate naming Netmiko = ConnectHandler -__version__ = "3.3.3" +__version__ = "3.4.0" __all__ = ( "ConnectHandler", "ssh_dispatcher", @@ -32,6 +33,7 @@ "FileTransfer", "NetmikoTimeoutException", "NetmikoAuthenticationException", + "ConfigInvalidException", "NetMikoTimeoutException", "NetMikoAuthenticationException", "InLineTransfer", diff --git a/netmiko/allied_telesis/__init__.py b/netmiko/allied_telesis/__init__.py new file mode 100644 index 000000000..c1041b3b2 --- /dev/null +++ b/netmiko/allied_telesis/__init__.py @@ -0,0 +1,3 @@ +from netmiko.allied_telesis.allied_telesis_awplus import AlliedTelesisAwplusSSH + +__all__ = ["AlliedTelesisAwplusSSH"] diff --git a/netmiko/allied_telesis/allied_telesis_awplus.py b/netmiko/allied_telesis/allied_telesis_awplus.py new file mode 100644 index 000000000..fec35f12f --- /dev/null +++ b/netmiko/allied_telesis/allied_telesis_awplus.py @@ -0,0 +1,46 @@ +from netmiko.cisco_base_connection import CiscoBaseConnection +import time + + +class AlliedTelesisAwplusBase(CiscoBaseConnection): + """Implement methods for interacting with Allied Telesis 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 ('>'). + """ + """ AWPlus Configuration """ + + self.disable_paging() + self.set_base_prompt() + time.sleep(0.3 * self.global_delay_factor) + + def _enter_shell(self): + """Enter the Bourne Shell.""" + return self.send_command("start shell sh", expect_string=r"[\$#]") + + def _return_cli(self): + """Return to the Awplus CLI.""" + return self.send_command("exit", expect_string=r"[#>]") + + def exit_config_mode(self, exit_config="exit", pattern=""): + """Exit configuration mode.""" + output = "" + if self.check_config_mode(): + output = self.send_command_timing( + exit_config, strip_prompt=False, strip_command=False + ) + if "Exit with uncommitted changes?" in output: + output += self.send_command_timing( + "yes", strip_prompt=False, strip_command=False + ) + if self.check_config_mode(): + raise ValueError("Failed to exit configuration mode") + return output + + +class AlliedTelesisAwplusSSH(AlliedTelesisAwplusBase): + pass diff --git a/netmiko/base_connection.py b/netmiko/base_connection.py index 403ba3881..161bcd25c 100644 --- a/netmiko/base_connection.py +++ b/netmiko/base_connection.py @@ -24,6 +24,7 @@ from netmiko.ssh_exception import ( NetmikoTimeoutException, NetmikoAuthenticationException, + ConfigInvalidException, ) from netmiko.utilities import ( write_bytes, @@ -31,6 +32,7 @@ get_structured_data, get_structured_data_genie, get_structured_data_ttp, + run_ttp_template, select_cmd_verify, ) from netmiko.utilities import m_exec_time # noqa @@ -220,6 +222,8 @@ def __init__( :type auto_connect: bool """ self.remote_conn = None + # Does the platform support a configuration mode + self._config_mode = True self.TELNET_RETURN = "\r\n" if default_enter is None: @@ -1131,7 +1135,9 @@ def set_terminal_width( # Retry by sleeping .33 and then double sleep until 5 attempts (.33, .66, 1.32, etc) @retry( - wait=wait_exponential(multiplier=0.33, min=0, max=5), stop=stop_after_attempt(5) + wait=wait_exponential(multiplier=0.33, min=0, max=5), + stop=stop_after_attempt(5), + reraise=True, ) def set_base_prompt( self, pri_prompt_terminator="#", alt_prompt_terminator=">", delay_factor=1 @@ -1671,19 +1677,32 @@ def enable( "Failed to enter enable mode. Please ensure you pass " "the 'secret' argument to ConnectHandler." ) + + # Check if in enable mode if not self.check_enable_mode(): + # Send "enable" mode command self.write_channel(self.normalize_cmd(cmd)) try: - output += self.read_until_pattern(pattern=re.escape(cmd.strip())) - if pattern not in output: + # Read the command echo + end_data = "" + if self.global_cmd_verify is not False: + output += self.read_until_pattern(pattern=re.escape(cmd.strip())) + end_data = output.split(cmd.strip())[-1] + + # Search for trailing prompt or password pattern + if pattern not in output and self.base_prompt not in end_data: output += self.read_until_prompt_or_pattern( pattern=pattern, re_flags=re_flags ) - self.write_channel(self.normalize_cmd(self.secret)) - if enable_pattern: + # Send the "secret" in response to password pattern + if re.search(pattern, output): + self.write_channel(self.normalize_cmd(self.secret)) + output += self.read_until_prompt() + + # Search for terminating pattern if defined + if enable_pattern and not re.search(enable_pattern, output): output += self.read_until_pattern(pattern=enable_pattern) else: - output += self.read_until_prompt() if not self.check_enable_mode(): raise ValueError(msg) except NetmikoTimeoutException: @@ -1800,6 +1819,7 @@ def send_config_set( config_mode_command=None, cmd_verify=True, enter_config_mode=True, + error_pattern="", ): """ Send configuration commands down the SSH channel. @@ -1836,6 +1856,9 @@ def send_config_set( :param enter_config_mode: Do you enter config mode before sending config commands :type exit_config_mode: bool + :param error_pattern: Regular expression pattern to detect config errors in the + output. + :type error_pattern: str """ delay_factor = self.select_delay_factor(delay_factor) if config_commands is None: @@ -1852,21 +1875,35 @@ def send_config_set( cfg_mode_args = (config_mode_command,) if config_mode_command else tuple() output += self.config_mode(*cfg_mode_args) - if self.fast_cli and self._legacy_mode: + # If error_pattern is perform output gathering line by line and not fast_cli mode. + if self.fast_cli and self._legacy_mode and not error_pattern: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) # Gather output output += self._read_channel_timing( delay_factor=delay_factor, max_loops=max_loops ) + 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 - ) + + # Gather the output incrementally due to error_pattern requirements + if error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + + # Standard output gathering (no error_pattern) + if not error_pattern: + output += self._read_channel_timing( + delay_factor=delay_factor, max_loops=max_loops + ) + else: for cmd in config_commands: self.write_channel(self.normalize_cmd(cmd)) @@ -1884,6 +1921,11 @@ def send_config_set( new_output = self.read_until_pattern(pattern=pattern) output += new_output + if error_pattern: + if re.search(error_pattern, output, flags=re.M): + msg = f"Invalid input detected at command: {cmd}" + raise ConfigInvalidException(msg) + if exit_config_mode: output += self.exit_config_mode() output = self._sanitize_output(output) @@ -2036,6 +2078,41 @@ def close_session_log(self): self.session_log.close() self.session_log = None + def run_ttp(self, template, res_kwargs={}, **kwargs): + """ + Run TTP template parsing by using input parameters to collect + devices output. + + :param template: template content, OS path to template or reference + to template within TTP templates collection in + ttp://path/to/template.txt format + :type template: str + + :param res_kwargs: ``**res_kwargs`` arguments to pass to TTP result method + :type res_kwargs: dict + + :param kwargs: any other ``**kwargs`` to use for TTP object instantiation + :type kwargs: dict + + TTP template must have inputs defined together with below parameters. + + :param method: name of Netmiko connection object method to call, default ``send_command`` + :type method: str + + :param kwargs: Netmiko connection object method arguments + :type kwargs: dict + + :param commands: list of commands to collect + :type commands: list + + Inputs' load could be of one of the supported formats and controlled by input's ``load`` + attribute, supported values - python, yaml or json. For each input output collected + from device and parsed accordingly. + """ + return run_ttp_template( + connection=self, template=template, res_kwargs=res_kwargs, **kwargs + ) + class TelnetConnection(BaseConnection): pass diff --git a/netmiko/brocade/__init__.py b/netmiko/brocade/__init__.py new file mode 100644 index 000000000..a244ca541 --- /dev/null +++ b/netmiko/brocade/__init__.py @@ -0,0 +1,3 @@ +from netmiko.brocade.brocade_fos_ssh import BrocadeFOSSSH + +__all__ = ["BrocadeFOSSSH"] diff --git a/netmiko/brocade/brocade_fos_ssh.py b/netmiko/brocade/brocade_fos_ssh.py new file mode 100644 index 000000000..3953ef5e2 --- /dev/null +++ b/netmiko/brocade/brocade_fos_ssh.py @@ -0,0 +1,42 @@ +import time +import re +from netmiko.cisco_base_connection import CiscoSSHConnection + + +class BrocadeFOSSSH(CiscoSSHConnection): + """Brocade Fabric OS support""" + + def __init__(self, **kwargs): + if kwargs.get("default_enter") is None: + kwargs["default_enter"] = "\r" + return super().__init__(**kwargs) + + def session_preparation(self): + self._test_channel_read() + self.set_base_prompt() + + # Clear the read buffer + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + + def check_enable_mode(self, check_string=">"): + """No enable mode. Always return True.""" + return True + + def enable(self, cmd="", pattern="", enable_pattern=None, re_flags=re.IGNORECASE): + """No Enable Mode.""" + return "" + + def exit_enable_mode(self, exit_command=""): + """No Enable Mode.""" + return "" + + def check_config_mode(self, check_string="", pattern=""): + return True + + def config_mode(self, config_command="", pattern="", re_flags=0): + """No config mode.""" + return "" + + def exit_config_mode(self, exit_config="", pattern="#"): + return "" diff --git a/netmiko/cdot/__init__.py b/netmiko/cdot/__init__.py new file mode 100644 index 000000000..199ab7c9e --- /dev/null +++ b/netmiko/cdot/__init__.py @@ -0,0 +1,3 @@ +from netmiko.cdot.cdot_cros_ssh import CdotCrosSSH + +__all__ = ["CdotCrosSSH"] diff --git a/netmiko/cdot/cdot_cros_ssh.py b/netmiko/cdot/cdot_cros_ssh.py new file mode 100644 index 000000000..136be5ff7 --- /dev/null +++ b/netmiko/cdot/cdot_cros_ssh.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# CDOT = Centre for Development of Telematics, India +# CROS = CDOT Router OS +# Script: cros_ssh.py +# Author: Maloy Ghosh +# +# Purpose: Provide basic SSH connection to CROS based router products + +from netmiko.cisco_base_connection import CiscoBaseConnection +import time + + +class CdotCrosSSH(CiscoBaseConnection): + """Implement methods for interacting with CROS network devices.""" + + def session_preparation(self): + """Prepare the session after the connection has been established.""" + self._test_channel_read() + self.set_base_prompt() + self._disable_complete_on_space() + self.disable_paging(command="screen-length 0") + self.set_terminal_width(command="screen-width 511") + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + return + + def send_config_set(self, config_commands=None, exit_config_mode=False, **kwargs): + """CROS requires you not exit from configuration mode.""" + return super().send_config_set( + config_commands=config_commands, exit_config_mode=exit_config_mode, **kwargs + ) + + def check_config_mode(self, check_string=")#", pattern=r"[#\$]"): + """Checks if device is in configuration mode""" + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def config_mode(self, config_command="config", pattern=""): + """Enter configuration mode.""" + return super().config_mode(config_command=config_command, pattern=pattern) + + def commit(self, comment="", delay_factor=1, and_quit=True): + """ + Commit the candidate configuration. + + Commit the entered configuration. Raise an error and return the failure + if the commit fails. + + default: + command_string = commit + comment: + command_string = commit comment + + """ + + delay_factor = self.select_delay_factor(delay_factor) + + command_string = "commit" + commit_marker = ["Commit complete", "No modifications to commit"] + + if comment: + if '"' in comment: + raise ValueError("Invalid comment contains double quote") + command_string += f' comment "{comment}"' + + output = self.config_mode() + output += self.send_command( + command_string, + strip_prompt=False, + strip_command=True, + delay_factor=delay_factor, + ) + + if not (any(x in output for x in commit_marker)): + raise ValueError(f"Commit failed with the following errors:\n\n{output}") + if and_quit: + self.exit_config_mode() + return output + + def check_enable_mode(self, *args, **kwargs): + """No enable mode on CROS.""" + return True + + def enable(self, *args, **kwargs): + """No enable mode on CROS.""" + return "" + + def exit_enable_mode(self, *args, **kwargs): + """No enable mode on CROS.""" + return "" + + def _disable_complete_on_space(self): + """ + CROS 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 = "complete-on-space false" + self.write_channel(self.normalize_cmd(command)) + time.sleep(delay_factor * 0.1) + output = self.read_channel() + return output diff --git a/netmiko/cisco/cisco_asa_ssh.py b/netmiko/cisco/cisco_asa_ssh.py index 92dfc393e..544a79ed5 100644 --- a/netmiko/cisco/cisco_asa_ssh.py +++ b/netmiko/cisco/cisco_asa_ssh.py @@ -14,23 +14,16 @@ def __init__(self, *args, **kwargs): kwargs.setdefault("allow_auto_change", True) return super().__init__(*args, **kwargs) - def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): - return super().check_config_mode(check_string=check_string, pattern=pattern) - - def enable( - self, - cmd="enable", - pattern="ssword", - enable_pattern=r"\#", - re_flags=re.IGNORECASE, - ): - return super().enable( - cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags - ) - def session_preparation(self): """Prepare the session after the connection has been established.""" + # Make sure the ASA is ready + command = "show curpriv\n" + self.write_channel(command) + self.read_until_pattern(pattern=re.escape(command.strip())) + + # The 'enable' call requires the base_prompt to be set. + self.set_base_prompt() if self.secret: self.enable() else: @@ -49,6 +42,20 @@ def session_preparation(self): self.set_base_prompt() + def check_config_mode(self, check_string=")#", pattern=r"[>\#]"): + return super().check_config_mode(check_string=check_string, pattern=pattern) + + def enable( + self, + cmd="enable", + pattern="ssword", + enable_pattern=r"\#", + re_flags=re.IGNORECASE, + ): + return super().enable( + cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags + ) + def send_command_timing(self, *args, **kwargs): """ If the ASA is in multi-context mode, then the base_prompt needs to be diff --git a/netmiko/cisco/cisco_xr.py b/netmiko/cisco/cisco_xr.py index 8978aa842..636a92f6e 100644 --- a/netmiko/cisco/cisco_xr.py +++ b/netmiko/cisco/cisco_xr.py @@ -136,6 +136,9 @@ def exit_config_mode(self, exit_config="end", pattern=""): output += self.read_until_pattern( pattern=re.escape(exit_config.strip()) ) + # Read until we detect either an Uncommitted change or the end prompt + if not re.search(r"(Uncommitted|#$)", output): + output += self.read_until_pattern(pattern=r"(Uncommitted|#$)") if "Uncommitted changes found" in output: self.write_channel(self.normalize_cmd("no\n")) output += self.read_until_pattern(pattern=r"[>#]") diff --git a/netmiko/cisco_base_connection.py b/netmiko/cisco_base_connection.py index 61ec7e162..9f4cef77d 100644 --- a/netmiko/cisco_base_connection.py +++ b/netmiko/cisco_base_connection.py @@ -49,13 +49,13 @@ def config_mode(self, config_command="configure terminal", pattern="", re_flags= config_command=config_command, pattern=pattern, re_flags=re_flags ) - def exit_config_mode(self, exit_config="end", pattern="#"): + def exit_config_mode(self, exit_config="end", pattern=r"\#"): """Exit from configuration mode.""" return super().exit_config_mode(exit_config=exit_config, pattern=pattern) def serial_login( self, - pri_prompt_terminator=r"#\s*$", + pri_prompt_terminator=r"\#\s*$", alt_prompt_terminator=r">\s*$", username_pattern=r"(?:user:|username|login)", pwd_pattern=r"assword", @@ -80,7 +80,7 @@ def serial_login( def telnet_login( self, - pri_prompt_terminator=r"#\s*$", + pri_prompt_terminator=r"\#\s*$", alt_prompt_terminator=r">\s*$", username_pattern=r"(?:user:|username|login|user name)", pwd_pattern=r"assword", diff --git a/netmiko/extreme/extreme_netiron.py b/netmiko/extreme/extreme_netiron.py index b12a5ac9b..c075d228b 100644 --- a/netmiko/extreme/extreme_netiron.py +++ b/netmiko/extreme/extreme_netiron.py @@ -1,3 +1,4 @@ +import time from netmiko.cisco_base_connection import CiscoSSHConnection @@ -8,6 +9,17 @@ def save_config(self, cmd="write memory", confirm=False, confirm_response=""): cmd=cmd, confirm=confirm, confirm_response=confirm_response ) + def session_preparation(self): + """Prepare the session after the connection has been established.""" + self._test_channel_read() + self.set_base_prompt() + self.disable_paging(command="skip-page-display") + self.set_terminal_width() + + # Clear the read buffer + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + class ExtremeNetironSSH(ExtremeNetironBase): pass diff --git a/netmiko/f5/f5_tmsh_ssh.py b/netmiko/f5/f5_tmsh_ssh.py index 9885cbec9..ad6975ecb 100644 --- a/netmiko/f5/f5_tmsh_ssh.py +++ b/netmiko/f5/f5_tmsh_ssh.py @@ -9,6 +9,7 @@ def session_preparation(self): self.set_base_prompt() self.tmsh_mode() self.set_base_prompt() + self._config_mode = False cmd = 'run /util bash -c "stty cols 255"' self.set_terminal_width(command=cmd, pattern="run") self.disable_paging( @@ -25,3 +26,31 @@ def tmsh_mode(self, delay_factor=1): time.sleep(1 * delay_factor) self.clear_buffer() return None + + def exit_tmsh(self): + output = self.send_command("quit", expect_string=r"#") + self.set_base_prompt() + return output + + def cleanup(self, command="exit"): + """Gracefully exit the SSH session.""" + try: + self.exit_tmsh() + except Exception: + pass + + # Always try to send final 'exit' (command) + self._session_log_fin = True + self.write_channel(command + self.RETURN) + + def check_config_mode(self, check_string="", pattern=""): + """Checks if the device is in configuration mode or not.""" + return True + + def config_mode(self, config_command=""): + """No config mode for F5 devices.""" + return "" + + def exit_config_mode(self, exit_config=""): + """No config mode for F5 devices.""" + return "" diff --git a/netmiko/nokia/__init__.py b/netmiko/nokia/__init__.py index c921cc047..41f573d2d 100755 --- a/netmiko/nokia/__init__.py +++ b/netmiko/nokia/__init__.py @@ -1,3 +1,7 @@ -from netmiko.nokia.nokia_sros_ssh import NokiaSrosSSH, NokiaSrosFileTransfer +from netmiko.nokia.nokia_sros import ( + NokiaSrosSSH, + NokiaSrosTelnet, + NokiaSrosFileTransfer, +) -__all__ = ["NokiaSrosSSH", "NokiaSrosFileTransfer"] +__all__ = ["NokiaSrosSSH", "NokiaSrosFileTransfer", "NokiaSrosTelnet"] diff --git a/netmiko/nokia/nokia_sros_ssh.py b/netmiko/nokia/nokia_sros.py old mode 100755 new mode 100644 similarity index 96% rename from netmiko/nokia/nokia_sros_ssh.py rename to netmiko/nokia/nokia_sros.py index 3a9b59ca8..31d5149f9 --- a/netmiko/nokia/nokia_sros_ssh.py +++ b/netmiko/nokia/nokia_sros.py @@ -15,9 +15,10 @@ from netmiko.scp_handler import BaseFileTransfer -class NokiaSrosSSH(BaseConnection): +class NokiaSros(BaseConnection): """ - Implement methods for interacting with Nokia SR OS devices. + Implement methods for interacting with Nokia SR OS devices + for both SSH and telnet. Not applicable in Nokia SR OS (disabled): - exit_enable_mode() @@ -217,6 +218,18 @@ def cleanup(self, command="logout"): self.write_channel(command + self.RETURN) +class NokiaSrosSSH(NokiaSros): + """Nokia SR OS SSH driver.""" + + pass + + +class NokiaSrosTelnet(NokiaSros): + """Nokia SR OS Telnet driver.""" + + pass + + class NokiaSrosFileTransfer(BaseFileTransfer): def __init__( self, ssh_conn, source_file, dest_file, hash_supported=False, **kwargs @@ -279,10 +292,11 @@ def remote_file_size(self, remote_cmd=None, remote_file=None): if "File Not Found" in remote_out: raise IOError("Unable to find file on remote system") + dest_file_name = remote_file.replace("\\", "/").split("/")[-1] # Parse dir output for filename. Output format is: - # "10/16/2019 10:00p 6738 {filename}" + # "10/16/2019 10:00p 6738 {dest_file_name}" - pattern = r"\S+\s+\S+\s+(\d+)\s+{}".format(re.escape(remote_file)) + pattern = r"\S+\s+\S+\s+(\d+)\s+{}".format(re.escape(dest_file_name)) match = re.search(pattern, remote_out) if not match: diff --git a/netmiko/paloalto/paloalto_panos.py b/netmiko/paloalto/paloalto_panos.py index 4676b1b5b..3cb935c99 100644 --- a/netmiko/paloalto/paloalto_panos.py +++ b/netmiko/paloalto/paloalto_panos.py @@ -18,9 +18,11 @@ def session_preparation(self): Disable paging (the '--more--' prompts). Set the base prompt for interaction ('>'). """ + self.ansi_escape_codes = True self._test_channel_read() self.set_base_prompt(delay_factor=20) self.disable_paging(command="set cli pager off") + self.disable_paging(command="set cli scripting-mode on") # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) self.clear_buffer() diff --git a/netmiko/scp_handler.py b/netmiko/scp_handler.py index 70d387333..6b4939bed 100644 --- a/netmiko/scp_handler.py +++ b/netmiko/scp_handler.py @@ -257,6 +257,9 @@ def remote_file_size(self, remote_cmd="", remote_file=None): line = match.group(0) # Format will be 26 -rw- 6738 Jul 30 2016 19:49:50 -07:00 filename file_size = line.split()[2] + else: + raise IOError("Unable to parse 'dir' output in remote_file_size method") + if "Error opening" in remote_out or "No such file or directory" in remote_out: raise IOError("Unable to find file on remote system") else: diff --git a/netmiko/ssh_autodetect.py b/netmiko/ssh_autodetect.py index b343d5784..c610db7cc 100644 --- a/netmiko/ssh_autodetect.py +++ b/netmiko/ssh_autodetect.py @@ -170,9 +170,9 @@ "priority": 99, "dispatch": "_autodetect_std", }, - "brocade_netiron": { + "extreme_netiron": { "cmd": "show version", - "search_patterns": [r"NetIron"], + "search_patterns": [r"(NetIron|MLX)"], "priority": 99, "dispatch": "_autodetect_std", }, @@ -212,6 +212,18 @@ "priority": 99, "dispatch": "_autodetect_std", }, + "paloalto_panos": { + "cmd": "show system info", + "search_patterns": [r"model:\s+PA"], + "priority": 99, + "dispatch": "_autodetect_std", + }, + "supermicro_smis": { + "cmd": "show system info", + "search_patterns": [r"Super Micro Computer"], + "priority": 99, + "dispatch": "_autodetect_std", + }, } # Sort SSH_MAPPER_BASE such that the most common commands are first diff --git a/netmiko/ssh_dispatcher.py b/netmiko/ssh_dispatcher.py index 3188f9631..99cde1699 100755 --- a/netmiko/ssh_dispatcher.py +++ b/netmiko/ssh_dispatcher.py @@ -3,12 +3,15 @@ from netmiko.accedian import AccedianSSH from netmiko.adtran import AdtranOSSSH, AdtranOSTelnet from netmiko.alcatel import AlcatelAosSSH +from netmiko.allied_telesis import AlliedTelesisAwplusSSH from netmiko.arista import AristaSSH, AristaTelnet from netmiko.arista import AristaFileTransfer from netmiko.apresia import ApresiaAeosSSH, ApresiaAeosTelnet from netmiko.aruba import ArubaSSH +from netmiko.brocade import BrocadeFOSSSH from netmiko.broadcom import BroadcomIcosSSH from netmiko.calix import CalixB6SSH, CalixB6Telnet +from netmiko.cdot import CdotCrosSSH from netmiko.centec import CentecOSSSH, CentecOSTelnet from netmiko.checkpoint import CheckPointGaiaSSH from netmiko.ciena import CienaSaosSSH, CienaSaosTelnet, CienaSaosFileTransfer @@ -67,7 +70,7 @@ from netmiko.mrv import MrvLxSSH from netmiko.mrv import MrvOptiswitchSSH from netmiko.netapp import NetAppcDotSSH -from netmiko.nokia import NokiaSrosSSH, NokiaSrosFileTransfer +from netmiko.nokia import NokiaSrosSSH, NokiaSrosFileTransfer, NokiaSrosTelnet from netmiko.netgear import NetgearProSafeSSH from netmiko.oneaccess import OneaccessOneOSTelnet, OneaccessOneOSSSH from netmiko.ovs import OvsLinuxSSH @@ -96,6 +99,8 @@ from netmiko.yamaha import YamahaTelnet from netmiko.zte import ZteZxrosSSH from netmiko.zte import ZteZxrosTelnet +from netmiko.supermicro import SmciSwitchSmisSSH +from netmiko.supermicro import SmciSwitchSmisTelnet GenericSSH = TerminalServerSSH GenericTelnet = TerminalServerTelnet @@ -107,6 +112,7 @@ "adtran_os": AdtranOSSSH, "alcatel_aos": AlcatelAosSSH, "alcatel_sros": NokiaSrosSSH, + "allied_telesis_awplus": AlliedTelesisAwplusSSH, "apresia_aeos": ApresiaAeosSSH, "arista_eos": AristaSSH, "aruba_os": ArubaSSH, @@ -115,6 +121,7 @@ "avaya_ers": ExtremeErsSSH, "avaya_vsp": ExtremeVspSSH, "broadcom_icos": BroadcomIcosSSH, + "brocade_fos": BrocadeFOSSSH, "brocade_fastiron": RuckusFastironSSH, "brocade_netiron": ExtremeNetironSSH, "brocade_nos": ExtremeNosSSH, @@ -122,6 +129,7 @@ "brocade_vyos": VyOSSSH, "checkpoint_gaia": CheckPointGaiaSSH, "calix_b6": CalixB6SSH, + "cdot_cros": CdotCrosSSH, "centec_os": CentecOSSSH, "ciena_saos": CienaSaosSSH, "cisco_asa": CiscoAsaSSH, @@ -198,6 +206,7 @@ "ruijie_os": RuijieOSSSH, "sixwind_os": SixwindOSSSH, "sophos_sfos": SophosSfosSSH, + "supermicro_smis": SmciSwitchSmisSSH, "tplink_jetstream": TPLinkJetStreamSSH, "ubiquiti_edge": UbiquitiEdgeSSH, "ubiquiti_edgerouter": UbiquitiEdgeRouterSSH, @@ -265,12 +274,14 @@ CLASS_MAPPER["huawei_olt_telnet"] = HuaweiSmartAXSSH CLASS_MAPPER["ipinfusion_ocnos_telnet"] = IpInfusionOcNOSTelnet CLASS_MAPPER["juniper_junos_telnet"] = JuniperTelnet -CLASS_MAPPER["paloalto_panos_telnet"] = PaloAltoPanosTelnet +CLASS_MAPPER["nokia_sros_telnet"] = NokiaSrosTelnet CLASS_MAPPER["oneaccess_oneos_telnet"] = OneaccessOneOSTelnet +CLASS_MAPPER["paloalto_panos_telnet"] = PaloAltoPanosTelnet CLASS_MAPPER["rad_etx_telnet"] = RadETXTelnet CLASS_MAPPER["raisecom_telnet"] = RaisecomRoapTelnet CLASS_MAPPER["ruckus_fastiron_telnet"] = RuckusFastironTelnet CLASS_MAPPER["ruijie_os_telnet"] = RuijieOSTelnet +CLASS_MAPPER["supermicro_smis_telnet"] = SmciSwitchSmisTelnet CLASS_MAPPER["tplink_jetstream_telnet"] = TPLinkJetStreamTelnet CLASS_MAPPER["yamaha_telnet"] = YamahaTelnet CLASS_MAPPER["zte_zxros_telnet"] = ZteZxrosTelnet diff --git a/netmiko/ssh_exception.py b/netmiko/ssh_exception.py index 8e553e686..cb0468927 100644 --- a/netmiko/ssh_exception.py +++ b/netmiko/ssh_exception.py @@ -14,5 +14,11 @@ class NetmikoAuthenticationException(AuthenticationException): pass +class ConfigInvalidException(Exception): + """Exception raised for invalid configuration error.""" + + pass + + NetMikoTimeoutException = NetmikoTimeoutException NetMikoAuthenticationException = NetmikoAuthenticationException diff --git a/netmiko/supermicro/__init__.py b/netmiko/supermicro/__init__.py new file mode 100644 index 000000000..6a04c1613 --- /dev/null +++ b/netmiko/supermicro/__init__.py @@ -0,0 +1,3 @@ +from netmiko.supermicro.smci_smis import SmciSwitchSmisTelnet, SmciSwitchSmisSSH + +__all__ = ["SmciSwitchSmisSSH", "SmciSwitchSmisTelnet"] diff --git a/netmiko/supermicro/smci_smis.py b/netmiko/supermicro/smci_smis.py new file mode 100644 index 000000000..560c68a77 --- /dev/null +++ b/netmiko/supermicro/smci_smis.py @@ -0,0 +1,44 @@ +from netmiko.cisco_base_connection import CiscoBaseConnection +import time + + +class SmciSwitchSmisBase(CiscoBaseConnection): + def session_preparation(self): + """Prepare the session after the connection has been established.""" + self._test_channel_read(pattern=r"[>#]") + self.set_base_prompt() + self.config_mode() + self.disable_paging(command="set cli pagination off") + self.set_terminal_width(command="terminal width 511") + self.exit_config_mode() + # Clear the read buffer + time.sleep(0.3 * self.global_delay_factor) + self.clear_buffer() + + def check_enable_mode(self, check_string="#"): + """Check if in enable mode. Return boolean.""" + return super().check_enable_mode(check_string=check_string) + + def enable(self, *args, **kwargs): + """Supermicro switch does not support enable-mode command""" + return "" + + def exit_enable_mode(self, *args, **kwargs): + """Supermicro switch does not support enable-mode command""" + return "" + + def save_config( + self, cmd="write startup-config", confirm=False, confirm_response="" + ): + """Save config""" + return super().save_config( + cmd=cmd, confirm=confirm, confirm_response=confirm_response + ) + + +class SmciSwitchSmisSSH(SmciSwitchSmisBase): + pass + + +class SmciSwitchSmisTelnet(SmciSwitchSmisBase): + pass diff --git a/netmiko/utilities.py b/netmiko/utilities.py index c9da0f534..1d3b2acaa 100644 --- a/netmiko/utilities.py +++ b/netmiko/utilities.py @@ -8,6 +8,7 @@ from datetime import datetime from netmiko._textfsm import _clitable as clitable from netmiko._textfsm._clitable import CliTableError +from netmiko import log try: from ttp import ttp @@ -41,6 +42,7 @@ # Dictionary mapping 'show run' for vendors with different command SHOW_RUN_MAPPER = { + "brocade_fos": "configShow", "juniper": "show configuration", "juniper_junos": "show configuration", "extreme": "show configuration", @@ -67,6 +69,7 @@ "brocade_fastiron": "show running-config", "brocade_netiron": "show running-config", "alcatel_aos": "show configuration snapshot", + "cros_mtbr": "show running-config", } # Expand SHOW_RUN_MAPPER to include '_ssh' key @@ -372,6 +375,73 @@ def get_structured_data_ttp(raw_output, template=None): return raw_output +def run_ttp_template(connection, template, res_kwargs, **kwargs): + """ + Helper function to run TTP template parsing. + + :param connection: Netmiko connection object + :type connection: obj + + :param template: TTP template + :type template: str + + :param res_kwargs: ``**res_kwargs`` arguments for TTP result method + :type res_kwargs: dict + + :param kwargs: ``**kwargs`` for TTP object instantiation + :type kwargs: dict + """ + if not TTP_INSTALLED: + msg = "\nTTP is not installed. Please PIP install ttp:\n" "pip install ttp\n" + raise ValueError(msg) + + parser = ttp(template=template, **kwargs) + + # get inputs load for TTP template + ttp_inputs_load = parser.get_input_load() + log.debug("run_ttp_template: inputs load - {}".format(ttp_inputs_load)) + + # go over template's inputs and collect output from devices + for template_name, inputs in ttp_inputs_load.items(): + for input_name, input_params in inputs.items(): + method = input_params.get("method", "send_command") + method_kwargs = input_params.get("kwargs", {}) + commands = input_params.get("commands", None) + + # run sanity checks + if method not in dir(connection): + log.warning( + "run_ttp_template: '{}' input, unsupported method '{}', skipping".format( + input_name, method + ) + ) + continue + elif not commands: + log.warning( + "run_ttp_template: '{}' input no commands to collect, skipping".format( + input_name + ) + ) + continue + + # collect commands output from device + output = [ + getattr(connection, method)(command_string=command, **method_kwargs) + for command in commands + ] + output = "\n".join(output) + + # add collected output to TTP parser object + parser.add_input( + data=output, input_name=input_name, template_name=template_name + ) + + # run parsing in single process + parser.parse(one=True) + + return parser.result(**res_kwargs) + + 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/yamaha/yamaha.py b/netmiko/yamaha/yamaha.py index 650f2c7b8..484de7617 100644 --- a/netmiko/yamaha/yamaha.py +++ b/netmiko/yamaha/yamaha.py @@ -29,7 +29,8 @@ def exit_enable_mode(self, exit_command="exit"): output = self.read_channel() if "(Y/N)" in output: self.write_channel("N") - output += self.read_until_prompt() + if self.base_prompt not in output: + output += self.read_until_prompt() if self.check_enable_mode(): raise ValueError("Failed to exit enable mode.") return output @@ -67,4 +68,7 @@ class YamahaSSH(YamahaBase): class YamahaTelnet(YamahaBase): """Yamaha Telnet driver.""" - pass + def __init__(self, *args, **kwargs): + default_enter = kwargs.get("default_enter") + kwargs["default_enter"] = "\n" if default_enter is None else default_enter + super().__init__(*args, **kwargs) diff --git a/release_process.txt b/release_process.txt index 32598f0e7..c145cbb5a 100644 --- a/release_process.txt +++ b/release_process.txt @@ -9,17 +9,17 @@ $ pdoc3 --html --output-dir docs netmiko --force # README.md is entry point at https://ktbyers.github.io/netmiko/ which then links to... # https://ktbyers.github.io/netmiko/docs/netmiko/index.html for full docs -# python setup.py sdist bdist_wheel - # Make sure you have rolled the version in __init__.py # Merge into master / checkout master (use PR in GitHub for this) +# python setup.py sdist bdist_wheel + # Check FIX issues in _release.sh # Run ./_release.sh # Create a tag for the version git tag -a v3.3.3 -m "Version 3.3.3 Release" -git push origin v3.3.3 +git push origin_ssh v3.3.3 diff --git a/requirements-dev.txt b/requirements-dev.txt index 85ea63a32..ded8934e9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ black==18.9b0 -PyYAML==5.3.1 +PyYAML==5.4 pytest==5.1.2 pylama==7.7.1 twine==1.13.0 diff --git a/tests/brocade_fastiron_commands.txt b/tests/brocade_fastiron_commands.txt deleted file mode 100644 index d0f9bce11..000000000 --- a/tests/brocade_fastiron_commands.txt +++ /dev/null @@ -1,3 +0,0 @@ -logging buffered 4000 -logging buffered 3000 -no logging console diff --git a/tests/brocade_netiron_commands.txt b/tests/brocade_netiron_commands.txt deleted file mode 100644 index d0f9bce11..000000000 --- a/tests/brocade_netiron_commands.txt +++ /dev/null @@ -1,3 +0,0 @@ -logging buffered 4000 -logging buffered 3000 -no logging console diff --git a/tests/etc/commands.yml.example b/tests/etc/commands.yml.example index 0149b1042..d2a81aa70 100644 --- a/tests/etc/commands.yml.example +++ b/tests/etc/commands.yml.example @@ -52,6 +52,7 @@ cisco_s300: config_verification: "show run" config_file: "cisco_ios_commands.txt" save_config_confirm: True + save_config_response: '' cisco_asa: version: "show version" @@ -425,6 +426,19 @@ centec_os: save_config_cmd: 'write' save_config_response: 'OK' +supermicro_nos: + version: "show version" + basic: "show ip interface" + extended_output: "show version" + config: + - "logging buffered 110" + - "logging buffered 110" + config_verification: "show run" + save_config_cmd: "write startup-config" + save_config_confirm: False + save_config_response: '[OK]' + support_commit: False + sophos_sfos: version: "system diagnostics show version-info" basic: "system diagnostics utilities route lookup 172.16.16.16" diff --git a/tests/etc/responses.yml.example b/tests/etc/responses.yml.example index e001f330e..2fa4173d8 100644 --- a/tests/etc/responses.yml.example +++ b/tests/etc/responses.yml.example @@ -268,6 +268,17 @@ centec_os: version_banner: "Centec Networks" multiple_line_output: "" +supermicro_nos: + base_prompt: SMIS + router_prompt: SMIS> + enable_prompt: SMIS# + interface_ip: 192.168.10.15 + version_banner: "Firmware Version" + multiple_line_output: "" + save_config: '[OK]' + cmd_response_init: "logging buffered 110" + cmd_response_final: "logging buffered 110" + sophos_sfos: base_prompt: "console" router_prompt: "console>" diff --git a/tests/etc/test_devices.yml.example b/tests/etc/test_devices.yml.example index ab79e71e6..d3dc90338 100644 --- a/tests/etc/test_devices.yml.example +++ b/tests/etc/test_devices.yml.example @@ -204,6 +204,12 @@ centec_os: password: centec secret: centec +supermicro_nos: + device_type: supermicro_nos + ip: 192.168.10.15 + username: ADMIN + password: ADMIN + sophos_sfos: device_type: sophos_sfos ip: 172.16.16.16 diff --git a/tests/f5_commands.yml b/tests/f5_commands.yml new file mode 100644 index 000000000..6205599db --- /dev/null +++ b/tests/f5_commands.yml @@ -0,0 +1,9 @@ +f5_tmsh: + version: "show sys version" + basic: "show sys ip-address" + extended_output: "show sys version" + config: + - "modify cli preference history-size 400" # base command + - "modify cli preference history-size 500" # something you can verify has changed + config_verification: "show running-config all-properties | grep history-size" + support_commit: False diff --git a/tests/test_cros_mtbr.py b/tests/test_cros_mtbr.py new file mode 100755 index 000000000..e3f48b801 --- /dev/null +++ b/tests/test_cros_mtbr.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Script: test_cros_mtbr.py +# Author: Maloy Ghosh +# +# Purpose: + +from netmiko import ConnectHandler + + +cros = { + "device_type": "cros_mtbr", + "host": "10.0.3.3", + "username": "rootsystem", + "password": "Root@123", +} + + +def main(): + nc = ConnectHandler(**cros) + + output = nc.send_command("show interface configuration brief") + print(output) + + output = nc.send_config_set( + [ + "interface physical 7/1/3", + "admin-status up", + "ipv4 address 1.1.1.1 prefix 24", + ] + ) + print(output) + + output = nc.commit() + print(output) + + output = nc.send_command("show interface configuration brief") + print(output) + + +if __name__ == "__main__": + main() diff --git a/tests/test_f5.sh b/tests/test_f5.sh new file mode 100644 index 000000000..0acae4ed8 --- /dev/null +++ b/tests/test_f5.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 f5 \ +&& py.test -v test_netmiko_config.py --test_device f5 \ +|| RETURN_CODE=1 + +exit $RETURN_CODE diff --git a/tests/test_netmiko_config.py b/tests/test_netmiko_config.py index e8d11c6ca..51ff15c04 100755 --- a/tests/test_netmiko_config.py +++ b/tests/test_netmiko_config.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import pytest def test_ssh_connect(net_connect, commands, expected_responses): @@ -31,15 +32,16 @@ def test_config_mode(net_connect, commands, expected_responses): if net_connect.config_mode() != "": assert net_connect.check_config_mode() is True else: - assert True + pytest.skip("Platform doesn't support config mode.") 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() is False + """Test exit config mode.""" + if net_connect._config_mode: + net_connect.exit_config_mode() + assert net_connect.check_config_mode() is False + else: + pytest.skip("Platform doesn't support config mode.") def test_config_set(net_connect, commands, expected_responses): diff --git a/tests/test_supermicro.sh b/tests/test_supermicro.sh new file mode 100644 index 000000000..ef004d273 --- /dev/null +++ b/tests/test_supermicro.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 supermicro_nos \ +&& py.test -v test_netmiko_config.py --test_device supermicro_nos \ +|| RETURN_CODE=1 + +exit $RETURN_CODE diff --git a/tests/test_ttp_run_template.py b/tests/test_ttp_run_template.py new file mode 100644 index 000000000..a05da55e5 --- /dev/null +++ b/tests/test_ttp_run_template.py @@ -0,0 +1,560 @@ +import sys +import pytest + +sys.path.insert(0, "..") # need it to run "python test_ttp_run_template.py" + +from netmiko import ConnectHandler # noqa + +try: + from ttp import ttp # noqa + + TTP_INSTALLED = True + +except ImportError: + TTP_INSTALLED = False + +try: + from ttp_templates import get_template # noqa + + TTP_TEMPLATES_INSTALLED = True + +except ImportError: + TTP_TEMPLATES_INSTALLED = False + +skip_if_no_ttp = pytest.mark.skipif( + TTP_INSTALLED is False, reason="Failed to import TTP module" +) +skip_if_no_ttp_templates = pytest.mark.skipif( + TTP_TEMPLATES_INSTALLED is False, reason="Failed to import TTP templates module" +) + +lab = { + "device_type": "cisco_ios", + "host": "1.2.3.4", + "username": "cisco", + "password": "cisco", + "auto_connect": False, # stop Netmiko trying connect to device +} + + +@skip_if_no_ttp +def mock_output(command_string, *args, **kwargs): + outputs = { + "show run | inc ntp": """ +ntp server 8.8.8.8 +ntp server 7.7.7.8 +ntp server 1.1.1.2 +ntp server 3.3.3.3 +ntp server 7.7.7.7 + """, + "show run | inc aaa": """ +aaa new-model +aaa authentication login default local +aaa authorization exec default local +aaa session-id common + """, + "show run | sec interface": """ +interface Loopback0 + description Routing Loopback + ip address 10.0.0.10 255.255.255.255 + ip ospf 1 area 0 + ipv6 address 2001::10/128 +interface Loopback100 + ip address 1.1.1.100 255.255.255.255 +interface Ethernet0/0 + description Main Interface for L3 features testing + no ip address + duplex auto +interface Ethernet0/0.102 + description to_vIOS1_Gi0/0.102 + encapsulation dot1Q 102 + ip address 10.1.102.10 255.255.255.0 + ipv6 address 2001:102::10/64 +interface Ethernet0/0.107 + description to_IOL2_Eth0/0.107 + encapsulation dot1Q 107 + ip address 10.1.107.10 255.255.255.0 + ip ospf network point-to-point + ip ospf 1 area 0 + ipv6 address 2001:107::10/64 +interface Ethernet0/0.2000 + encapsulation dot1Q 2000 + vrf forwarding MGMT + ip address 192.168.217.10 255.255.255.0 +interface Ethernet0/1 + no ip address + duplex auto +interface Ethernet0/2 + no ip address + duplex auto +interface Ethernet0/3 + no ip address + shutdown + duplex auto + """, + } + return outputs[command_string] + + +connection = ConnectHandler(**lab) + +# override send command method to return mock data +setattr(connection, "send_command", mock_output) + + +@skip_if_no_ttp +def test_run_ttp_template_from_text(): + template = """ + +commands: + - show run | inc ntp + - show run | inc aaa + + + +commands = [ + "show run | sec interface" +] + + + +ntp server {{ ntp_servers | joinmatches(",") }} +aaa authentication login {{ authen | PHRASE }} +aaa authorization exec {{ author_exec | PHRASE }} + + + +interface {{ interface }} + description {{ description | re(".+") }} + encapsulation dot1Q {{ dot1q }} + ip address {{ ip }} {{ mask }} + + """ + res = connection.run_ttp(template) + assert res == [ + [ + { + "misc": [ + {"ntp_servers": "8.8.8.8"}, + {"ntp_servers": "7.7.7.8"}, + {"ntp_servers": "1.1.1.2"}, + {"ntp_servers": "3.3.3.3"}, + { + "authen": "default local", + "author_exec": "default local", + "ntp_servers": "7.7.7.7", + }, + ] + }, + { + "interfaces": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "dot1q": "102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "dot1q": "107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "dot1q": "2000", + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + }, + ] + ] + + +@skip_if_no_ttp +def test_run_ttp_template_from_text_with_res_kwargs(): + template = """ + +commands: + - show run | inc ntp + - show run | inc aaa + + + +commands = [ + "show run | sec interface" +] + + + +ntp server {{ ntp_servers | joinmatches(",") }} +aaa authentication login {{ authen | PHRASE }} +aaa authorization exec {{ author_exec | PHRASE }} + + + +interface {{ interface }} + description {{ description | re(".+") }} + encapsulation dot1Q {{ dot1q }} + ip address {{ ip }} {{ mask }} + + """ + res = connection.run_ttp(template, res_kwargs={"structure": "flat_list"}) + assert res == [ + { + "misc": [ + {"ntp_servers": "8.8.8.8"}, + {"ntp_servers": "7.7.7.8"}, + {"ntp_servers": "1.1.1.2"}, + {"ntp_servers": "3.3.3.3"}, + { + "authen": "default local", + "author_exec": "default local", + "ntp_servers": "7.7.7.7", + }, + ] + }, + { + "interfaces": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "dot1q": "102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "dot1q": "107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "dot1q": "2000", + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + }, + ] + + +@skip_if_no_ttp +def test_run_ttp_template_from_file(): + template = "./test_ttp_run_template_1.txt" + res = connection.run_ttp(template) + assert res == [ + [ + { + "misc": [ + {"ntp_servers": "8.8.8.8"}, + {"ntp_servers": "7.7.7.8"}, + {"ntp_servers": "1.1.1.2"}, + {"ntp_servers": "3.3.3.3"}, + { + "authen": "default local", + "author_exec": "default local", + "ntp_servers": "7.7.7.7", + }, + ] + }, + { + "interfaces": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "dot1q": "102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "dot1q": "107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "dot1q": "2000", + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + }, + ] + ] + + +@skip_if_no_ttp +@skip_if_no_ttp_templates +def test_run_ttp_template_from_ttp_templates(): + template = "ttp://misc/ttp_templates_tests/netmiko_cisco_ios_interfaces.txt" + res = connection.run_ttp(template) + assert res == [ + { + "intf_cfg": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + } + ] + + +@skip_if_no_ttp +def test_run_ttp_template_default_input(): + template = """ + +This template used in to test Netmiko run_ttp method + + + + """ + res = connection.run_ttp(template) + assert res == [ + { + "intf_cfg": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + } + ] + + +@skip_if_no_ttp +def test_run_ttp_template_dict_struct(): + template = """ + +This template used in to test Netmiko run_ttp method + + + + """ + res = connection.run_ttp(template, res_kwargs={"structure": "dictionary"}) + assert res == { + "interfaces": { + "intf_cfg": [ + { + "description": "Routing Loopback", + "interface": "Loopback0", + "ip": "10.0.0.10", + "mask": "255.255.255.255", + }, + { + "interface": "Loopback100", + "ip": "1.1.1.100", + "mask": "255.255.255.255", + }, + { + "description": "Main Interface for L3 features " "testing", + "interface": "Ethernet0/0", + }, + { + "description": "to_vIOS1_Gi0/0.102", + "interface": "Ethernet0/0.102", + "ip": "10.1.102.10", + "mask": "255.255.255.0", + }, + { + "description": "to_IOL2_Eth0/0.107", + "interface": "Ethernet0/0.107", + "ip": "10.1.107.10", + "mask": "255.255.255.0", + }, + { + "interface": "Ethernet0/0.2000", + "ip": "192.168.217.10", + "mask": "255.255.255.0", + }, + {"interface": "Ethernet0/1"}, + {"interface": "Ethernet0/2"}, + {"interface": "Ethernet0/3"}, + ] + } + } + + +@skip_if_no_ttp +def test_run_ttp_template_with_errors(): + """ + Input ntp_and_aaa does not have command parameter. + Input interfaces_cfg has wrong method. + """ + template = """ + +commmmmands: + - show run | inc ntp + - show run | inc aaa + + + +method = "does_not_exist" +commands = [ + "show run | sec interface" +] + + + +ntp server {{ ntp_servers | joinmatches(",") }} +aaa authentication login {{ authen | PHRASE }} +aaa authorization exec {{ author_exec | PHRASE }} + + + +interface {{ interface }} + description {{ description | re(".+") }} + encapsulation dot1Q {{ dot1q }} + ip address {{ ip }} {{ mask }} + + """ + res = connection.run_ttp(template) + assert res == [[]] diff --git a/tests/test_ttp_run_template_1.txt b/tests/test_ttp_run_template_1.txt new file mode 100644 index 000000000..2e9b799b2 --- /dev/null +++ b/tests/test_ttp_run_template_1.txt @@ -0,0 +1,24 @@ + +commands: + - show run | inc ntp + - show run | inc aaa + + + +commands = [ + "show run | sec interface" +] + + + +ntp server {{ ntp_servers | joinmatches(",") }} +aaa authentication login {{ authen | PHRASE }} +aaa authorization exec {{ author_exec | PHRASE }} + + + +interface {{ interface }} + description {{ description | re(".+") }} + encapsulation dot1Q {{ dot1q }} + ip address {{ ip }} {{ mask }} + \ No newline at end of file diff --git a/tests_new/test_netmiko_config.py b/tests_new/test_netmiko_config.py index 89eab7860..767dffba2 100755 --- a/tests_new/test_netmiko_config.py +++ b/tests_new/test_netmiko_config.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import pytest +from netmiko import ConfigInvalidException def test_ssh_connect(net_connect, commands, expected_responses): @@ -89,9 +90,11 @@ def test_config_hostname(net_connect, commands, expected_responses): net_connect.send_config_set(command) new_hostname = net_connect.find_prompt() assert hostname in new_hostname + # Reset prompt back to original value net_connect.set_base_prompt() net_connect.send_config_set(f"hostname {current_hostname}") + net_connect.set_base_prompt() def test_config_from_file(net_connect, commands, expected_responses): @@ -111,6 +114,36 @@ def test_config_from_file(net_connect, commands, expected_responses): net_connect.save_config() +def test_config_error_pattern(net_connect, commands, expected_responses): + """ + Raise exception when config_error_str is present in output + """ + config_base = commands.get("config") + config_err = commands.get("invalid_config") + config_list = config_base + [config_err] + error_pattern = commands.get("error_pattern") + + # Should not raise an exception since error_pattern not specified + net_connect.send_config_set(config_commands=config_list) + + if config_list and error_pattern: + with pytest.raises(ConfigInvalidException): + net_connect.send_config_set( + config_commands=config_list, error_pattern=error_pattern + ) + + # Try it with cmd_verify=True also + with pytest.raises(ConfigInvalidException): + net_connect.send_config_set( + config_commands=config_list, + error_pattern=error_pattern, + cmd_verify=True, + ) + + else: + print("Skipping test: no error_pattern supplied.") + + def test_disconnect(net_connect, commands, expected_responses): """ Terminate the SSH session